use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class RenameGroupOp method rename.
private void rename(MetaDataUpdate md) throws IOException, ConfigInvalidException {
boolean success = false;
for (int attempts = 0; !success && attempts < MAX_TRIES; attempts++) {
ProjectConfig config = projectConfigFactory.read(md);
// The group isn't referenced, or its name has been fixed already.
//
GroupReference ref = config.getGroup(uuid);
if (ref == null || newName.equals(ref.getName())) {
projectCache.evictAndReindex(config.getProject());
return;
}
config.renameGroup(uuid, newName);
md.getCommitBuilder().setAuthor(author);
md.setMessage("Rename group " + oldName + " to " + newName + "\n");
try {
config.commit(md);
projectCache.evictAndReindex(config.getProject());
success = true;
} catch (IOException e) {
logger.atSevere().withCause(e).log("Could not commit rename of group %s to %s in %s", oldName, newName, md.getProjectName().get());
try {
Thread.sleep(25);
} catch (InterruptedException wakeUp) {
continue;
}
}
}
if (!success) {
if (tryingAgain) {
logger.atWarning().log("Could not rename group %s to %s in %s", oldName, newName, md.getProjectName().get());
} else {
retryOn.add(md.getProjectName());
}
}
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class PushPermissionsIT method setUp.
@Before
public void setUp() throws Exception {
try (ProjectConfigUpdate u = updateProject(allProjects)) {
ProjectConfig cfg = u.getConfig();
// Remove push-related permissions, so they can be added back individually by test methods.
removeAllBranchPermissions(cfg, Permission.ADD_PATCH_SET, Permission.CREATE, Permission.DELETE, Permission.PUSH, Permission.PUSH_MERGE, Permission.SUBMIT);
removeAllGlobalCapabilities(cfg, GlobalCapability.ADMINISTRATE_SERVER);
u.save();
}
// Include some auxiliary permissions.
projectOperations.allProjectsForUpdate().add(allow(Permission.FORGE_AUTHOR).ref("refs/*").group(REGISTERED_USERS)).add(allow(Permission.FORGE_COMMITTER).ref("refs/*").group(REGISTERED_USERS)).update();
}
use of com.google.gerrit.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method allowSubmoduleSubscription.
protected void allowSubmoduleSubscription(Project.NameKey submodule, String subBranch, Project.NameKey superproject, String superBranch, boolean match) throws Exception {
try (MetaDataUpdate md = metaDataUpdateFactory.create(submodule)) {
md.setMessage("Added superproject subscription");
SubscribeSection.Builder s;
ProjectConfig pc = projectConfigFactory.read(md);
if (pc.getSubscribeSections().containsKey(superproject)) {
s = pc.getSubscribeSections().get(superproject).toBuilder();
} else {
s = SubscribeSection.builder(superproject);
}
String refspec;
if (superBranch == null) {
refspec = subBranch;
} else {
refspec = subBranch + ":" + superBranch;
}
if (match) {
s.addMatchingRefSpec(refspec);
} else {
s.addMultiMatchRefSpec(refspec);
}
pc.addSubscribeSection(s.build());
ObjectId oldId = pc.getRevision();
ObjectId newId = pc.commit(md);
assertThat(newId).isNotEqualTo(oldId);
projectCache.evictAndReindex(pc.getProject());
}
}
use of com.google.gerrit.server.project.ProjectConfig 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.server.project.ProjectConfig in project gerrit by GerritCodeReview.
the class PutConfig method updateCommentLinks.
private void updateCommentLinks(ProjectConfig projectConfig, Map<String, CommentLinkInput> input) {
for (Map.Entry<String, CommentLinkInput> e : input.entrySet()) {
String name = e.getKey();
CommentLinkInput value = e.getValue();
if (value != null) {
// Add or update the commentlink section
Config cfg = new Config();
cfg.setString(COMMENTLINK, name, KEY_MATCH, value.match);
cfg.setString(COMMENTLINK, name, KEY_LINK, value.link);
cfg.setBoolean(COMMENTLINK, name, KEY_ENABLED, value.enabled == null || value.enabled);
projectConfig.addCommentLinkSection(ProjectConfig.buildCommentLink(cfg, name, false));
} else {
// Delete the commentlink section
projectConfig.removeCommentLinkSection(name);
}
}
}
Aggregations