Search in sources :

Example 1 with CachedProjectConfig

use of com.google.gerrit.entities.CachedProjectConfig in project gerrit by GerritCodeReview.

the class CustomLabelIT method customLabel_withBranch.

@Test
public void customLabel_withBranch() throws Exception {
    saveLabelConfig(LABEL.toBuilder().setRefPatterns(ImmutableList.of("master")));
    CachedProjectConfig cfg = projectCache.get(project).orElseThrow(illegalState(project)).getConfig();
    assertThat(cfg.getLabelSections().get(LABEL_NAME).getRefPatterns()).contains("master");
}
Also used : CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 2 with CachedProjectConfig

use of com.google.gerrit.entities.CachedProjectConfig in project gerrit by GerritCodeReview.

the class RenameGroupOp method run.

@Override
public void run() {
    Iterable<Project.NameKey> names = tryingAgain ? retryOn : projectCache.all();
    for (Project.NameKey projectName : names) {
        CachedProjectConfig config = projectCache.get(projectName).orElseThrow(illegalState(projectName)).getConfig();
        Optional<GroupReference> ref = config.getGroup(uuid);
        if (!ref.isPresent() || newName.equals(ref.get().getName())) {
            continue;
        }
        try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
            rename(md);
        } catch (RepositoryNotFoundException noProject) {
            continue;
        } catch (ConfigInvalidException | IOException err) {
            logger.atSevere().withCause(err).log("Cannot rename group %s in %s", oldName, projectName);
        }
    }
    // another attempt. If it doesn't update after that, give up.
    if (!retryOn.isEmpty() && !tryingAgain) {
        tryingAgain = true;
        @SuppressWarnings("unused") Future<?> possiblyIgnoredError = start(5, TimeUnit.MINUTES);
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) Project(com.google.gerrit.entities.Project) GroupReference(com.google.gerrit.entities.GroupReference) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate)

Example 3 with CachedProjectConfig

use of com.google.gerrit.entities.CachedProjectConfig in project gerrit by GerritCodeReview.

the class ProjectConfig method getCacheable.

/**
 * Returns an immutable, thread-safe representation of this object that can be cached.
 */
public CachedProjectConfig getCacheable() {
    CachedProjectConfig.Builder builder = CachedProjectConfig.builder().setProject(project).setAccountsSection(accountsSection).setBranchOrderSection(Optional.ofNullable(branchOrderSection)).setMimeTypes(mimeTypes).setRulesId(Optional.ofNullable(rulesId)).setRevision(Optional.ofNullable(getRevision())).setMaxObjectSizeLimit(maxObjectSizeLimit).setCheckReceivedObjects(checkReceivedObjects).setExtensionPanelSections(extensionPanelSections);
    groupList.byUUID().values().forEach(g -> builder.addGroup(g));
    contributorAgreements.values().forEach(c -> builder.addContributorAgreement(c));
    notifySections.values().forEach(n -> builder.addNotifySection(n));
    subscribeSections.values().forEach(s -> builder.addSubscribeSection(s));
    commentLinkSections.values().forEach(c -> builder.addCommentLinkSection(c));
    labelSections.values().forEach(l -> builder.addLabelSection(l));
    submitRequirementSections.values().forEach(sr -> builder.addSubmitRequirementSection(sr));
    pluginConfigs.entrySet().forEach(c -> builder.addPluginConfig(c.getKey(), c.getValue().toText()));
    projectLevelConfigs.entrySet().forEach(c -> builder.addProjectLevelConfig(c.getKey(), c.getValue().toText()));
    if (projectName.equals(allProjectsName)) {
        // Filter out permissions that aren't allowed to be set on All-Projects
        accessSections.values().forEach(a -> {
            List<Permission.Builder> copy = new ArrayList<>();
            for (Permission p : a.getPermissions()) {
                if (Permission.canBeOnAllProjects(a.getName(), p.getName())) {
                    copy.add(p.toBuilder());
                }
            }
            AccessSection section = AccessSection.builder(a.getName()).modifyPermissions(permissions -> permissions.addAll(copy)).build();
            builder.addAccessSection(section);
        });
    } else {
        accessSections.values().forEach(a -> builder.addAccessSection(a));
    }
    return builder.build();
}
Also used : GroupBackend(com.google.gerrit.server.account.GroupBackend) Arrays(java.util.Arrays) GlobalCapability(com.google.gerrit.common.data.GlobalCapability) Inject(com.google.inject.Inject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) Config(org.eclipse.jgit.lib.Config) Preconditions.checkArgument(com.google.common.base.Preconditions.checkArgument) VersionedMetaData(com.google.gerrit.server.git.meta.VersionedMetaData) LabelValue(com.google.gerrit.entities.LabelValue) LabelType(com.google.gerrit.entities.LabelType) ConfigUtil(com.google.gerrit.server.config.ConfigUtil) Locale(java.util.Locale) Map(java.util.Map) ContributorAgreement(com.google.gerrit.entities.ContributorAgreement) RefNames(com.google.gerrit.entities.RefNames) Splitter(com.google.common.base.Splitter) PluginConfig(com.google.gerrit.server.config.PluginConfig) EnumSet(java.util.EnumSet) Permission.isPermission(com.google.gerrit.entities.Permission.isPermission) ImmutableSet(com.google.common.collect.ImmutableSet) PatternSyntaxException(java.util.regex.PatternSyntaxException) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) AccessSection(com.google.gerrit.entities.AccessSection) Collection(java.util.Collection) Set(java.util.Set) Sets(com.google.common.collect.Sets) Preconditions.checkState(com.google.common.base.Preconditions.checkState) GroupReference(com.google.gerrit.entities.GroupReference) Objects(java.util.Objects) List(java.util.List) Nullable(com.google.gerrit.common.Nullable) AllProjectsName(com.google.gerrit.server.config.AllProjectsName) DEFAULT_SUBMIT_TYPE(com.google.gerrit.entities.Project.DEFAULT_SUBMIT_TYPE) ConfiguredMimeTypes(com.google.gerrit.entities.ConfiguredMimeTypes) NotifyConfig(com.google.gerrit.entities.NotifyConfig) BooleanProjectConfig(com.google.gerrit.entities.BooleanProjectConfig) Optional(java.util.Optional) Pattern(java.util.regex.Pattern) AllProjectsConfigProvider(com.google.gerrit.server.config.AllProjectsConfigProvider) FluentLogger(com.google.common.flogger.FluentLogger) Joiner(com.google.common.base.Joiner) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) Singleton(com.google.inject.Singleton) ValidationError(com.google.gerrit.server.git.ValidationError) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) Shorts(com.google.common.primitives.Shorts) SubmitRequirementExpression(com.google.gerrit.entities.SubmitRequirementExpression) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) LinkedHashMap(java.util.LinkedHashMap) Strings(com.google.common.base.Strings) PluginPermissionsUtil.isValidPluginPermission(com.google.gerrit.server.permissions.PluginPermissionsUtil.isValidPluginPermission) ImmutableList(com.google.common.collect.ImmutableList) GroupDescription(com.google.gerrit.entities.GroupDescription) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) Objects.requireNonNull(java.util.Objects.requireNonNull) LabelFunction(com.google.gerrit.entities.LabelFunction) PermissionRule(com.google.gerrit.entities.PermissionRule) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) UsedAt(com.google.gerrit.common.UsedAt) Address(com.google.gerrit.entities.Address) SubmitRequirement(com.google.gerrit.entities.SubmitRequirement) AccountGroup(com.google.gerrit.entities.AccountGroup) AccountsSection(com.google.gerrit.entities.AccountsSection) CharMatcher(com.google.common.base.CharMatcher) Permission(com.google.gerrit.entities.Permission) IOException(java.io.IOException) ProjectState(com.google.gerrit.extensions.client.ProjectState) Maps(com.google.common.collect.Maps) ObjectId(org.eclipse.jgit.lib.ObjectId) Consumer(java.util.function.Consumer) Collectors.toList(java.util.stream.Collectors.toList) NotifyType(com.google.gerrit.entities.NotifyConfig.NotifyType) SubscribeSection(com.google.gerrit.entities.SubscribeSection) Project(com.google.gerrit.entities.Project) StoredConfig(org.eclipse.jgit.lib.StoredConfig) VisibleForTesting(com.google.common.annotations.VisibleForTesting) StoredCommentLinkInfo(com.google.gerrit.entities.StoredCommentLinkInfo) BranchOrderSection(com.google.gerrit.entities.BranchOrderSection) Collections(java.util.Collections) Action(com.google.gerrit.entities.PermissionRule.Action) Repository(org.eclipse.jgit.lib.Repository) InvalidNameException(com.google.gerrit.exceptions.InvalidNameException) CommitBuilder(org.eclipse.jgit.lib.CommitBuilder) ArrayList(java.util.ArrayList) Permission.isPermission(com.google.gerrit.entities.Permission.isPermission) PluginPermissionsUtil.isValidPluginPermission(com.google.gerrit.server.permissions.PluginPermissionsUtil.isValidPluginPermission) Permission(com.google.gerrit.entities.Permission) CachedProjectConfig(com.google.gerrit.entities.CachedProjectConfig) AccessSection(com.google.gerrit.entities.AccessSection)

Aggregations

CachedProjectConfig (com.google.gerrit.entities.CachedProjectConfig)3 GroupReference (com.google.gerrit.entities.GroupReference)2 Project (com.google.gerrit.entities.Project)2 MetaDataUpdate (com.google.gerrit.server.git.meta.MetaDataUpdate)2 IOException (java.io.IOException)2 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 CharMatcher (com.google.common.base.CharMatcher)1 Joiner (com.google.common.base.Joiner)1 Preconditions.checkArgument (com.google.common.base.Preconditions.checkArgument)1 Preconditions.checkState (com.google.common.base.Preconditions.checkState)1 Splitter (com.google.common.base.Splitter)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Maps (com.google.common.collect.Maps)1 Sets (com.google.common.collect.Sets)1 FluentLogger (com.google.common.flogger.FluentLogger)1 Shorts (com.google.common.primitives.Shorts)1