Search in sources :

Example 51 with Project

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");
}
Also used : Project(com.google.gerrit.entities.Project) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 52 with 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");
}
Also used : Project(com.google.gerrit.entities.Project) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Config(org.eclipse.jgit.lib.Config) StoredConfig(org.eclipse.jgit.lib.StoredConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 53 with 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);
}
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 54 with Project

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;
}
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 55 with Project

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());
        }
    }
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) AllUsersName(com.google.gerrit.server.config.AllUsersName) Iterables(com.google.common.collect.Iterables) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ProjectCache(com.google.gerrit.server.project.ProjectCache) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) GerritConfigListener(com.google.gerrit.server.config.GerritConfigListener) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) Inject(com.google.inject.Inject) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) Multimap(com.google.common.collect.Multimap) Response(com.google.gerrit.extensions.restapi.Response) PermissionBackend(com.google.gerrit.server.permissions.PermissionBackend) ConfigUpdateEntry(com.google.gerrit.server.config.ConfigUpdatedEvent.ConfigUpdateEntry) RestModifyView(com.google.gerrit.extensions.restapi.RestModifyView) Strings(com.google.common.base.Strings) Config(org.eclipse.jgit.lib.Config) ParentInput(com.google.gerrit.extensions.api.projects.ParentInput) Objects.requireNonNull(java.util.Objects.requireNonNull) AuthException(com.google.gerrit.extensions.restapi.AuthException) ConfigUpdatedEvent(com.google.gerrit.server.config.ConfigUpdatedEvent) GlobalPermission(com.google.gerrit.server.permissions.GlobalPermission) GerritServerConfig(com.google.gerrit.server.config.GerritServerConfig) ProjectState(com.google.gerrit.server.project.ProjectState) MoreObjects(com.google.common.base.MoreObjects) ProjectResource(com.google.gerrit.server.project.ProjectResource) IOException(java.io.IOException) UpdateResult(com.google.gerrit.server.config.ConfigUpdatedEvent.UpdateResult) ConfigKey(com.google.gerrit.server.config.ConfigKey) ProjectPermission(com.google.gerrit.server.permissions.ProjectPermission) Provider(com.google.inject.Provider) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) IdentifiedUser(com.google.gerrit.server.IdentifiedUser) Project(com.google.gerrit.entities.Project) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Singleton(com.google.inject.Singleton) Project(com.google.gerrit.entities.Project) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) ProjectState(com.google.gerrit.server.project.ProjectState)

Aggregations

Project (com.google.gerrit.entities.Project)184 Test (org.junit.Test)109 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)67 Change (com.google.gerrit.entities.Change)43 Repository (org.eclipse.jgit.lib.Repository)34 ChangeInfo (com.google.gerrit.extensions.common.ChangeInfo)33 PushOneCommit (com.google.gerrit.acceptance.PushOneCommit)32 InMemoryRepository (org.eclipse.jgit.internal.storage.dfs.InMemoryRepository)31 BranchNameKey (com.google.gerrit.entities.BranchNameKey)30 Config (org.eclipse.jgit.lib.Config)26 ObjectId (org.eclipse.jgit.lib.ObjectId)26 IOException (java.io.IOException)25 ChangeNotes (com.google.gerrit.server.notedb.ChangeNotes)24 ProjectState (com.google.gerrit.server.project.ProjectState)23 Inject (com.google.inject.Inject)23 List (java.util.List)23 AuthException (com.google.gerrit.extensions.restapi.AuthException)22 ChangeData (com.google.gerrit.server.query.change.ChangeData)22 RevCommit (org.eclipse.jgit.revwalk.RevCommit)22 PatchSet (com.google.gerrit.entities.PatchSet)20