use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectOperationsImplTest method getProjectConfig.
@Test
public void getProjectConfig() throws Exception {
Project.NameKey key = projectOperations.newProject().create();
assertThat(projectOperations.project(key).getProjectConfig().getProject().getDescription()).isEmpty();
ConfigInput input = new ConfigInput();
input.description = "my fancy project";
gApi.projects().name(key.get()).config(input);
assertThat(projectOperations.project(key).getProjectConfig().getProject().getDescription()).isEqualTo("my fancy project");
}
use of com.google.gerrit.entities.Project in project gerrit by GerritCodeReview.
the class ProjectOperationsImplTest method getConfig.
@Test
public void getConfig() throws Exception {
Project.NameKey key = projectOperations.newProject().create();
Config config = projectOperations.project(key).getConfig();
assertThat(config).isNotInstanceOf(StoredConfig.class);
assertThat(config).text().isEmpty();
ConfigInput input = new ConfigInput();
input.description = "my fancy project";
gApi.projects().name(key.get()).config(input);
config = projectOperations.project(key).getConfig();
assertThat(config).isNotInstanceOf(StoredConfig.class);
assertThat(config).sections().containsExactly("project");
assertThat(config).subsections("project").isEmpty();
assertThat(config).sectionValues("project").containsExactly("description", "my fancy project");
}
use of com.google.gerrit.entities.Project 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.Project 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.Project in project gerrit by GerritCodeReview.
the class SetParent method validateParentUpdate.
public void validateParentUpdate(Project.NameKey project, IdentifiedUser user, String newParent, boolean checkIfAdmin) throws AuthException, ResourceConflictException, UnprocessableEntityException, PermissionBackendException, BadRequestException {
if (checkIfAdmin) {
if (allowProjectOwnersToChangeParent) {
permissionBackend.user(user).project(project).check(ProjectPermission.WRITE_CONFIG);
} else {
permissionBackend.user(user).check(GlobalPermission.ADMINISTRATE_SERVER);
}
}
if (project.equals(allUsers) && !allProjects.get().equals(newParent)) {
throw new BadRequestException(String.format("%s must inherit from %s", allUsers.get(), allProjects.get()));
}
if (project.equals(allProjects)) {
throw new ResourceConflictException("cannot set parent of " + allProjects.get());
}
if (allUsers.get().equals(newParent)) {
throw new ResourceConflictException(String.format("Cannot inherit from '%s' project", allUsers.get()));
}
newParent = Strings.emptyToNull(newParent);
if (newParent != null) {
Project.NameKey newParentNameKey = Project.nameKey(newParent);
ProjectState parent = cache.get(newParentNameKey).orElseThrow(() -> new UnprocessableEntityException("parent project " + newParentNameKey + " not found"));
if (parent.getName().equals(project.get())) {
throw new ResourceConflictException("cannot set parent to self");
}
if (Iterables.tryFind(parent.tree(), p -> p.getNameKey().equals(project)).isPresent()) {
throw new ResourceConflictException("cycle exists between " + project.get() + " and " + parent.getName());
}
}
}
Aggregations