Search in sources :

Example 6 with ProjectConfig

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());
        }
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) GroupReference(com.google.gerrit.entities.GroupReference) IOException(java.io.IOException)

Example 7 with ProjectConfig

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();
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Before(org.junit.Before)

Example 8 with ProjectConfig

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());
    }
}
Also used : ProjectConfig(com.google.gerrit.server.project.ProjectConfig) AnyObjectId(org.eclipse.jgit.lib.AnyObjectId) ObjectId(org.eclipse.jgit.lib.ObjectId) SubscribeSection(com.google.gerrit.entities.SubscribeSection) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 9 with ProjectConfig

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);
    }
}
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 10 with ProjectConfig

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);
        }
    }
}
Also used : CommentLinkInput(com.google.gerrit.extensions.api.projects.CommentLinkInput) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Config(org.eclipse.jgit.lib.Config) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) Map(java.util.Map) DynamicMap(com.google.gerrit.extensions.registration.DynamicMap)

Aggregations

ProjectConfig (com.google.gerrit.server.project.ProjectConfig)39 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)26 AuthException (com.google.gerrit.extensions.restapi.AuthException)8 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)8 Project (com.google.gerrit.entities.Project)7 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)7 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)7 Test (org.junit.Test)7 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)6 AccessSection (com.google.gerrit.entities.AccessSection)6 BooleanProjectConfig (com.google.gerrit.entities.BooleanProjectConfig)6 LabelType (com.google.gerrit.entities.LabelType)6 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)6 Repository (org.eclipse.jgit.lib.Repository)6 GroupReference (com.google.gerrit.entities.GroupReference)5 Permission (com.google.gerrit.entities.Permission)5 IOException (java.io.IOException)5 ProjectState (com.google.gerrit.server.project.ProjectState)4 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)4 TestRepository (org.eclipse.jgit.junit.TestRepository)4