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);
}
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;
}
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);
}
}
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;
}
Aggregations