Search in sources :

Example 1 with DynamicMap

use of com.google.gerrit.extensions.registration.DynamicMap in project gerrit by GerritCodeReview.

the class GetServerInfo method getDownloadSchemeInfo.

private DownloadSchemeInfo getDownloadSchemeInfo(DownloadScheme scheme, DynamicMap<DownloadCommand> downloadCommands, DynamicMap<CloneCommand> cloneCommands) {
    DownloadSchemeInfo info = new DownloadSchemeInfo();
    info.url = scheme.getUrl("${project}");
    info.isAuthRequired = toBoolean(scheme.isAuthRequired());
    info.isAuthSupported = toBoolean(scheme.isAuthSupported());
    info.commands = new HashMap<>();
    for (DynamicMap.Entry<DownloadCommand> e : downloadCommands) {
        String commandName = e.getExportName();
        DownloadCommand command = e.getProvider().get();
        String c = command.getCommand(scheme, "${project}", "${ref}");
        if (c != null) {
            info.commands.put(commandName, c);
        }
    }
    info.cloneCommands = new HashMap<>();
    for (DynamicMap.Entry<CloneCommand> e : cloneCommands) {
        String commandName = e.getExportName();
        CloneCommand command = e.getProvider().get();
        String c = command.getCommand(scheme, "${project-path}/${project-base-name}");
        if (c != null) {
            c = c.replaceAll("\\$\\{project-path\\}/\\$\\{project-base-name\\}", "\\$\\{project\\}");
            info.cloneCommands.put(commandName, c);
        }
    }
    return info;
}
Also used : CloneCommand(com.google.gerrit.extensions.config.CloneCommand) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) DownloadCommand(com.google.gerrit.extensions.config.DownloadCommand) DownloadSchemeInfo(com.google.gerrit.extensions.common.DownloadSchemeInfo)

Example 2 with DynamicMap

use of com.google.gerrit.extensions.registration.DynamicMap in project gerrit by GerritCodeReview.

the class GetServerInfo method getDownloadInfo.

private DownloadInfo getDownloadInfo(DynamicMap<DownloadScheme> downloadSchemes, DynamicMap<DownloadCommand> downloadCommands, DynamicMap<CloneCommand> cloneCommands, AllowedFormats archiveFormats) {
    DownloadInfo info = new DownloadInfo();
    info.schemes = new HashMap<>();
    for (DynamicMap.Entry<DownloadScheme> e : downloadSchemes) {
        DownloadScheme scheme = e.getProvider().get();
        if (scheme.isEnabled() && scheme.getUrl("${project}") != null) {
            info.schemes.put(e.getExportName(), getDownloadSchemeInfo(scheme, downloadCommands, cloneCommands));
        }
    }
    info.archives = archiveFormats.getAllowed().stream().map(ArchiveFormat::getShortName).collect(toList());
    return info;
}
Also used : DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) ArchiveFormat(com.google.gerrit.server.change.ArchiveFormat) DownloadInfo(com.google.gerrit.extensions.common.DownloadInfo) DownloadScheme(com.google.gerrit.extensions.config.DownloadScheme)

Example 3 with DynamicMap

use of com.google.gerrit.extensions.registration.DynamicMap in project gerrit by GerritCodeReview.

the class ConfigInfoImpl method getPluginConfig.

private Map<String, Map<String, ConfigParameterInfo>> getPluginConfig(ProjectState project, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsName allProjects) {
    TreeMap<String, Map<String, ConfigParameterInfo>> pluginConfig = new TreeMap<>();
    for (Entry<ProjectConfigEntry> e : pluginConfigEntries) {
        ProjectConfigEntry configEntry = e.getProvider().get();
        PluginConfig cfg = cfgFactory.getFromProjectConfig(project, e.getPluginName());
        String configuredValue = cfg.getString(e.getExportName());
        ConfigParameterInfo p = new ConfigParameterInfo();
        p.displayName = configEntry.getDisplayName();
        p.description = configEntry.getDescription();
        p.warning = configEntry.getWarning(project);
        p.type = configEntry.getType();
        p.permittedValues = configEntry.getPermittedValues();
        p.editable = configEntry.isEditable(project) ? true : null;
        if (configEntry.isInheritable() && !allProjects.equals(project.getProject().getNameKey())) {
            PluginConfig cfgWithInheritance = cfgFactory.getFromProjectConfigWithInheritance(project, e.getPluginName());
            p.inheritable = true;
            p.value = configEntry.onRead(project, cfgWithInheritance.getString(e.getExportName(), configEntry.getDefaultValue()));
            p.configuredValue = configuredValue;
            p.inheritedValue = getInheritedValue(project, cfgFactory, e);
        } else {
            if (configEntry.getType() == ProjectConfigEntryType.ARRAY) {
                p.values = configEntry.onRead(project, Arrays.asList(cfg.getStringList(e.getExportName())));
            } else {
                p.value = configEntry.onRead(project, configuredValue != null ? configuredValue : configEntry.getDefaultValue());
            }
        }
        Map<String, ConfigParameterInfo> pc = pluginConfig.get(e.getPluginName());
        if (pc == null) {
            pc = new TreeMap<>();
            pluginConfig.put(e.getPluginName(), pc);
        }
        pc.put(e.getExportName(), p);
    }
    return !pluginConfig.isEmpty() ? pluginConfig : null;
}
Also used : PluginConfig(com.google.gerrit.server.config.PluginConfig) ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) TreeMap(java.util.TreeMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) Map(java.util.Map)

Example 4 with DynamicMap

use of com.google.gerrit.extensions.registration.DynamicMap in project gerrit by GerritCodeReview.

the class ChangeJson method populateFetchMap.

public static void populateFetchMap(DownloadScheme scheme, DynamicMap<DownloadCommand> commands, String projectName, String refName, FetchInfo fetchInfo) {
    for (DynamicMap.Entry<DownloadCommand> e2 : commands) {
        String commandName = e2.getExportName();
        DownloadCommand command = e2.getProvider().get();
        String c = command.getCommand(scheme, projectName, refName);
        if (c != null) {
            addCommand(fetchInfo, commandName, c);
        }
    }
}
Also used : DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) DownloadCommand(com.google.gerrit.extensions.config.DownloadCommand)

Example 5 with DynamicMap

use of com.google.gerrit.extensions.registration.DynamicMap in project gerrit by GerritCodeReview.

the class PluginGuiceEnvironment method reattachMap.

private void reattachMap(ListMultimap<TypeLiteral<?>, ReloadableRegistrationHandle<?>> oldHandles, Map<TypeLiteral<?>, DynamicMap<?>> maps, @Nullable Injector src, Plugin newPlugin) {
    if (src == null || maps == null || maps.isEmpty()) {
        return;
    }
    for (Map.Entry<TypeLiteral<?>, DynamicMap<?>> e : maps.entrySet()) {
        @SuppressWarnings("unchecked") TypeLiteral<Object> type = (TypeLiteral<Object>) e.getKey();
        @SuppressWarnings("unchecked") PrivateInternals_DynamicMapImpl<Object> map = (PrivateInternals_DynamicMapImpl<Object>) e.getValue();
        Map<Annotation, ReloadableRegistrationHandle<?>> am = new HashMap<>();
        for (ReloadableRegistrationHandle<?> h : oldHandles.get(type)) {
            Annotation a = h.getKey().getAnnotation();
            if (a != null && !UNIQUE_ANNOTATION.isInstance(a)) {
                am.put(a, h);
            }
        }
        for (Binding<?> binding : bindings(src, e.getKey())) {
            @SuppressWarnings("unchecked") Binding<Object> b = (Binding<Object>) binding;
            Key<Object> key = b.getKey();
            if (key.getAnnotation() == null) {
                continue;
            }
            @SuppressWarnings("unchecked") ReloadableRegistrationHandle<Object> h = (ReloadableRegistrationHandle<Object>) am.remove(key.getAnnotation());
            if (h != null) {
                replace(newPlugin, h, b);
                oldHandles.remove(type, h);
            } else {
                newPlugin.add(map.put(newPlugin.getName(), b.getKey(), b.getProvider()));
            }
        }
    }
}
Also used : Binding(com.google.inject.Binding) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Annotation(java.lang.annotation.Annotation) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap) TypeLiteral(com.google.inject.TypeLiteral) ReloadableRegistrationHandle(com.google.gerrit.extensions.registration.ReloadableRegistrationHandle) PrivateInternals_DynamicMapImpl(com.google.gerrit.extensions.registration.PrivateInternals_DynamicMapImpl) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Aggregations

DynamicMap (com.google.gerrit.extensions.registration.DynamicMap)8 Map (java.util.Map)5 TreeMap (java.util.TreeMap)4 HashMap (java.util.HashMap)3 DownloadCommand (com.google.gerrit.extensions.config.DownloadCommand)2 IdString (com.google.gerrit.extensions.restapi.IdString)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 RestResource (com.google.gerrit.extensions.restapi.RestResource)2 RestView (com.google.gerrit.extensions.restapi.RestView)2 LinkedHashMap (java.util.LinkedHashMap)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1 Throwables (com.google.common.base.Throwables)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1