Search in sources :

Example 1 with BooleanProjectConfig

use of com.google.gerrit.entities.BooleanProjectConfig in project gerrit by GerritCodeReview.

the class ProjectConfig method onLoad.

@Override
protected void onLoad() throws IOException, ConfigInvalidException {
    if (baseConfig.isPresent()) {
        baseConfig.get().load();
    }
    readGroupList();
    rulesId = getObjectId("rules.pl");
    Config rc = readConfig(PROJECT_CONFIG, baseConfig);
    Project.Builder p = Project.builder(projectName);
    p.setDescription(Strings.nullToEmpty(rc.getString(PROJECT, null, KEY_DESCRIPTION)));
    if (revision != null) {
        p.setConfigRefState(revision.toObjectId().name());
    }
    if (rc.getStringList(ACCESS, null, KEY_INHERIT_FROM).length > 1) {
        // The config must not contain more than one parent to inherit from
        // as there is no guarantee which of the parents would be used then.
        error("Cannot inherit from multiple projects");
    }
    p.setParent(rc.getString(ACCESS, null, KEY_INHERIT_FROM));
    for (BooleanProjectConfig config : BooleanProjectConfig.values()) {
        p.setBooleanConfig(config, getEnum(rc, config.getSection(), config.getSubSection(), config.getName(), InheritableBoolean.INHERIT));
    }
    p.setMaxObjectSizeLimit(rc.getString(RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT));
    p.setSubmitType(getEnum(rc, SUBMIT, null, KEY_ACTION, DEFAULT_SUBMIT_TYPE));
    p.setState(getEnum(rc, PROJECT, null, KEY_STATE, DEFAULT_STATE_VALUE));
    p.setDefaultDashboard(rc.getString(DASHBOARD, null, KEY_DEFAULT));
    p.setLocalDefaultDashboard(rc.getString(DASHBOARD, null, KEY_LOCAL_DEFAULT));
    this.project = p.build();
    loadAccountsSection(rc);
    loadContributorAgreements(rc);
    loadAccessSections(rc);
    loadBranchOrderSection(rc);
    loadNotifySections(rc);
    loadLabelSections(rc);
    loadSubmitRequirementSections(rc);
    loadCommentLinkSections(rc);
    loadSubscribeSections(rc);
    mimeTypes = ConfiguredMimeTypes.create(projectName.get(), rc);
    loadPluginSections(rc);
    loadProjectLevelConfigs();
    loadReceiveSection(rc);
    loadExtensionPanelSections(rc);
}
Also used : Project(com.google.gerrit.entities.Project) Config(org.eclipse.jgit.lib.Config) PluginConfig(com.google.gerrit.server.config.PluginConfig) NotifyConfig(com.google.gerrit.entities.NotifyConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) StoredConfig(org.eclipse.jgit.lib.StoredConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig)

Example 2 with BooleanProjectConfig

use of com.google.gerrit.entities.BooleanProjectConfig in project gerrit by GerritCodeReview.

the class ProjectConfig method onSave.

@Override
protected boolean onSave(CommitBuilder commit) throws IOException, ConfigInvalidException {
    if (commit.getMessage() == null || "".equals(commit.getMessage())) {
        commit.setMessage("Updated project configuration\n");
    }
    Config rc = readConfig(PROJECT_CONFIG);
    Project p = project;
    if (p.getDescription() != null && !p.getDescription().isEmpty()) {
        rc.setString(PROJECT, null, KEY_DESCRIPTION, p.getDescription());
    } else {
        rc.unset(PROJECT, null, KEY_DESCRIPTION);
    }
    set(rc, ACCESS, null, KEY_INHERIT_FROM, p.getParentName());
    for (BooleanProjectConfig config : BooleanProjectConfig.values()) {
        set(rc, config.getSection(), config.getSubSection(), config.getName(), p.getBooleanConfig(config), InheritableBoolean.INHERIT);
    }
    set(rc, RECEIVE, null, KEY_MAX_OBJECT_SIZE_LIMIT, validMaxObjectSizeLimit(p.getMaxObjectSizeLimit()));
    set(rc, SUBMIT, null, KEY_ACTION, p.getSubmitType(), DEFAULT_SUBMIT_TYPE);
    set(rc, PROJECT, null, KEY_STATE, p.getState(), DEFAULT_STATE_VALUE);
    set(rc, DASHBOARD, null, KEY_DEFAULT, p.getDefaultDashboard());
    set(rc, DASHBOARD, null, KEY_LOCAL_DEFAULT, p.getLocalDefaultDashboard());
    Set<AccountGroup.UUID> keepGroups = new HashSet<>();
    saveAccountsSection(rc, keepGroups);
    saveContributorAgreements(rc, keepGroups);
    saveAccessSections(rc, keepGroups);
    saveNotifySections(rc, keepGroups);
    savePluginSections(rc, keepGroups);
    groupList.retainUUIDs(keepGroups);
    saveLabelSections(rc);
    saveSubmitRequirementSections(rc);
    saveCommentLinkSections(rc);
    saveSubscribeSections(rc);
    saveBranchOrderSection(rc);
    saveConfig(PROJECT_CONFIG, rc);
    saveGroupList();
    return true;
}
Also used : Project(com.google.gerrit.entities.Project) Config(org.eclipse.jgit.lib.Config) PluginConfig(com.google.gerrit.server.config.PluginConfig) NotifyConfig(com.google.gerrit.entities.NotifyConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) StoredConfig(org.eclipse.jgit.lib.StoredConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) HashSet(java.util.HashSet)

Example 3 with BooleanProjectConfig

use of com.google.gerrit.entities.BooleanProjectConfig in project gerrit by GerritCodeReview.

the class PutConfig method apply.

public ConfigInfo apply(ProjectState projectState, ConfigInput input) throws ResourceNotFoundException, BadRequestException, ResourceConflictException {
    Project.NameKey projectName = projectState.getNameKey();
    if (input == null) {
        throw new BadRequestException("config is required");
    }
    try (MetaDataUpdate md = metaDataUpdateFactory.get().create(projectName)) {
        ProjectConfig projectConfig = projectConfigFactory.read(md);
        projectConfig.updateProject(p -> {
            p.setDescription(Strings.emptyToNull(input.description));
            for (BooleanProjectConfig cfg : BooleanProjectConfig.values()) {
                InheritableBoolean val = BooleanProjectConfigTransformations.get(cfg, input);
                if (val != null) {
                    p.setBooleanConfig(cfg, val);
                }
            }
            if (input.maxObjectSizeLimit != null) {
                p.setMaxObjectSizeLimit(input.maxObjectSizeLimit);
            }
            if (input.submitType != null) {
                p.setSubmitType(input.submitType);
            }
            if (input.state != null) {
                p.setState(input.state);
            }
        });
        if (input.pluginConfigValues != null) {
            setPluginConfigValues(projectState, projectConfig, input.pluginConfigValues);
        }
        if (input.commentLinks != null) {
            updateCommentLinks(projectConfig, input.commentLinks);
        }
        md.setMessage("Modified project settings\n");
        try {
            projectConfig.commit(md);
            projectCache.evictAndReindex(projectConfig.getProject());
            md.getRepository().setGitwebDescription(projectConfig.getProject().getDescription());
        } catch (IOException e) {
            if (e.getCause() instanceof ConfigInvalidException) {
                throw new ResourceConflictException("Cannot update " + projectName + ": " + e.getCause().getMessage());
            }
            logger.atWarning().withCause(e).log("Failed to update config of project %s.", projectName);
            throw new ResourceConflictException("Cannot update " + projectName);
        }
        ProjectState state = projectStateFactory.create(projectConfigFactory.read(md).getCacheable());
        return ConfigInfoCreator.constructInfo(serverEnableSignedPush, state, user.get(), pluginConfigEntries, cfgFactory, allProjects, uiActions, views);
    } catch (RepositoryNotFoundException notFound) {
        throw new ResourceNotFoundException(projectName.get(), notFound);
    } catch (ConfigInvalidException err) {
        throw new ResourceConflictException("Cannot read project " + projectName, err);
    } catch (IOException err) {
        throw new ResourceConflictException("Cannot update project " + projectName, err);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) Project(com.google.gerrit.entities.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ProjectState(com.google.gerrit.server.project.ProjectState) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig)

Example 4 with BooleanProjectConfig

use of com.google.gerrit.entities.BooleanProjectConfig in project gerrit by GerritCodeReview.

the class ConfigInfoCreator method constructInfo.

@SuppressWarnings("deprecation")
public static ConfigInfo constructInfo(boolean serverEnableSignedPush, ProjectState projectState, CurrentUser user, DynamicMap<ProjectConfigEntry> pluginConfigEntries, PluginConfigFactory cfgFactory, AllProjectsName allProjects, UiActions uiActions, DynamicMap<RestView<ProjectResource>> views) {
    ConfigInfo configInfo = new ConfigInfo();
    Project p = projectState.getProject();
    configInfo.description = Strings.emptyToNull(p.getDescription());
    ProjectState parentState = Iterables.getFirst(projectState.parents(), null);
    for (BooleanProjectConfig cfg : BooleanProjectConfig.values()) {
        InheritedBooleanInfo info = new InheritedBooleanInfo();
        info.configuredValue = p.getBooleanConfig(cfg);
        if (parentState != null) {
            info.inheritedValue = parentState.is(cfg);
        }
        BooleanProjectConfigTransformations.set(cfg, configInfo, info);
    }
    if (!serverEnableSignedPush) {
        configInfo.enableSignedPush = null;
        configInfo.requireSignedPush = null;
    }
    configInfo.maxObjectSizeLimit = getMaxObjectSizeLimit(projectState, p);
    configInfo.defaultSubmitType = new SubmitTypeInfo();
    configInfo.defaultSubmitType.value = projectState.getSubmitType();
    configInfo.defaultSubmitType.configuredValue = MoreObjects.firstNonNull(projectState.getConfig().getProject().getSubmitType(), Project.DEFAULT_SUBMIT_TYPE);
    ProjectState parent = projectState.isAllProjects() ? projectState : projectState.parents().get(0);
    configInfo.defaultSubmitType.inheritedValue = parent.getSubmitType();
    configInfo.submitType = configInfo.defaultSubmitType.value;
    configInfo.state = p.getState() != com.google.gerrit.extensions.client.ProjectState.ACTIVE ? p.getState() : null;
    configInfo.commentlinks = new LinkedHashMap<>();
    for (CommentLinkInfo cl : projectState.getCommentLinks()) {
        configInfo.commentlinks.put(cl.name, cl);
    }
    configInfo.pluginConfig = getPluginConfig(projectState, pluginConfigEntries, cfgFactory, allProjects);
    configInfo.actions = new TreeMap<>();
    for (UiAction.Description d : uiActions.from(views, new ProjectResource(projectState, user))) {
        configInfo.actions.put(d.getId(), new ActionInfo(d));
    }
    configInfo.extensionPanelNames = projectState.getConfig().getExtensionPanelSections();
    return configInfo;
}
Also used : ActionInfo(com.google.gerrit.extensions.common.ActionInfo) ConfigInfo(com.google.gerrit.extensions.api.projects.ConfigInfo) UiAction(com.google.gerrit.extensions.webui.UiAction) InheritedBooleanInfo(com.google.gerrit.extensions.api.projects.ConfigInfo.InheritedBooleanInfo) Project(com.google.gerrit.entities.Project) SubmitTypeInfo(com.google.gerrit.extensions.api.projects.ConfigInfo.SubmitTypeInfo) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig)

Aggregations

BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)4 Project (com.google.gerrit.entities.Project)4 CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)2 NotifyConfig (com.google.gerrit.entities.NotifyConfig)2 PluginConfig (com.google.gerrit.server.config.PluginConfig)2 ProjectState (com.google.gerrit.server.project.ProjectState)2 Config (org.eclipse.jgit.lib.Config)2 StoredConfig (org.eclipse.jgit.lib.StoredConfig)2 CommentLinkInfo (com.google.gerrit.extensions.api.projects.CommentLinkInfo)1 ConfigInfo (com.google.gerrit.extensions.api.projects.ConfigInfo)1 InheritedBooleanInfo (com.google.gerrit.extensions.api.projects.ConfigInfo.InheritedBooleanInfo)1 SubmitTypeInfo (com.google.gerrit.extensions.api.projects.ConfigInfo.SubmitTypeInfo)1 InheritableBoolean (com.google.gerrit.extensions.client.InheritableBoolean)1 ActionInfo (com.google.gerrit.extensions.common.ActionInfo)1 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)1 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)1 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)1 UiAction (com.google.gerrit.extensions.webui.UiAction)1 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)1 ProjectConfig (com.google.gerrit.server.project.ProjectConfig)1