Search in sources :

Example 66 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class ProjectConfig method loadSubscribeSections.

private void loadSubscribeSections(Config rc) throws ConfigInvalidException {
    Set<String> subsections = rc.getSubsections(SUBSCRIBE_SECTION);
    subscribeSections = new HashMap<>();
    try {
        for (String projectName : subsections) {
            Project.NameKey p = new Project.NameKey(projectName);
            SubscribeSection ss = new SubscribeSection(p);
            for (String s : rc.getStringList(SUBSCRIBE_SECTION, projectName, SUBSCRIBE_MULTI_MATCH_REFS)) {
                ss.addMultiMatchRefSpec(s);
            }
            for (String s : rc.getStringList(SUBSCRIBE_SECTION, projectName, SUBSCRIBE_MATCH_REFS)) {
                ss.addMatchingRefSpec(s);
            }
            subscribeSections.put(p, ss);
        }
    } catch (IllegalArgumentException e) {
        throw new ConfigInvalidException(e.getMessage());
    }
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) SubscribeSection(com.google.gerrit.common.data.SubscribeSection)

Example 67 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException 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) {
        ProjectConfig config = projectCache.get(projectName).getConfig();
        GroupReference ref = config.getGroup(uuid);
        if (ref == null || newName.equals(ref.getName())) {
            continue;
        }
        try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
            rename(md);
        } catch (RepositoryNotFoundException noProject) {
            continue;
        } catch (ConfigInvalidException | IOException err) {
            log.error("Cannot rename group " + oldName + " in " + projectName, err);
        }
    }
    // 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) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) Project(com.google.gerrit.reviewdb.client.Project) GroupReference(com.google.gerrit.common.data.GroupReference)

Example 68 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method query.

@Operator
public Predicate<ChangeData> query(String name) throws QueryParseException {
    try (Repository git = args.repoManager.openRepository(args.allUsersName)) {
        VersionedAccountQueries q = VersionedAccountQueries.forUser(self());
        q.load(git);
        String query = q.getQueryList().getQuery(name);
        if (query != null) {
            return parse(query);
        }
    } catch (RepositoryNotFoundException e) {
        throw new QueryParseException("Unknown named query (no " + args.allUsersName + " repo): " + name, e);
    } catch (IOException | ConfigInvalidException e) {
        throw new QueryParseException("Error parsing named query: " + name, e);
    }
    throw new QueryParseException("Unknown named query: " + name);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) VersionedAccountQueries(com.google.gerrit.server.account.VersionedAccountQueries) QueryParseException(com.google.gerrit.server.query.QueryParseException)

Example 69 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class ChangeQueryBuilder method destination.

@Operator
public Predicate<ChangeData> destination(String name) throws QueryParseException {
    try (Repository git = args.repoManager.openRepository(args.allUsersName)) {
        VersionedAccountDestinations d = VersionedAccountDestinations.forUser(self());
        d.load(git);
        Set<Branch.NameKey> destinations = d.getDestinationList().getDestinations(name);
        if (destinations != null) {
            return new DestinationPredicate(destinations, name);
        }
    } catch (RepositoryNotFoundException e) {
        throw new QueryParseException("Unknown named destination (no " + args.allUsersName + " repo): " + name, e);
    } catch (IOException | ConfigInvalidException e) {
        throw new QueryParseException("Error parsing named destination: " + name, e);
    }
    throw new QueryParseException("Unknown named destination: " + name);
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) VersionedAccountDestinations(com.google.gerrit.server.account.VersionedAccountDestinations) QueryParseException(com.google.gerrit.server.query.QueryParseException)

Example 70 with ConfigInvalidException

use of org.eclipse.jgit.errors.ConfigInvalidException in project gerrit by GerritCodeReview.

the class PutConfig method apply.

public ConfigInfo apply(ProjectControl ctrl, ConfigInput input) throws ResourceNotFoundException, BadRequestException, ResourceConflictException {
    Project.NameKey projectName = ctrl.getProject().getNameKey();
    if (input == null) {
        throw new BadRequestException("config is required");
    }
    try (MetaDataUpdate md = metaDataUpdateFactory.get().create(projectName)) {
        ProjectConfig projectConfig = ProjectConfig.read(md);
        Project p = projectConfig.getProject();
        p.setDescription(Strings.emptyToNull(input.description));
        if (input.useContributorAgreements != null) {
            p.setUseContributorAgreements(input.useContributorAgreements);
        }
        if (input.useContentMerge != null) {
            p.setUseContentMerge(input.useContentMerge);
        }
        if (input.useSignedOffBy != null) {
            p.setUseSignedOffBy(input.useSignedOffBy);
        }
        if (input.createNewChangeForAllNotInTarget != null) {
            p.setCreateNewChangeForAllNotInTarget(input.createNewChangeForAllNotInTarget);
        }
        if (input.requireChangeId != null) {
            p.setRequireChangeID(input.requireChangeId);
        }
        if (serverEnableSignedPush) {
            if (input.enableSignedPush != null) {
                p.setEnableSignedPush(input.enableSignedPush);
            }
            if (input.requireSignedPush != null) {
                p.setRequireSignedPush(input.requireSignedPush);
            }
        }
        if (input.rejectImplicitMerges != null) {
            p.setRejectImplicitMerges(input.rejectImplicitMerges);
        }
        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.enableReviewerByEmail != null) {
            p.setEnableReviewerByEmail(input.enableReviewerByEmail);
        }
        if (input.pluginConfigValues != null) {
            setPluginConfigValues(ctrl.getProjectState(), projectConfig, input.pluginConfigValues);
        }
        md.setMessage("Modified project settings\n");
        try {
            projectConfig.commit(md);
            projectCache.evict(projectConfig.getProject());
            md.getRepository().setGitwebDescription(p.getDescription());
        } catch (IOException e) {
            if (e.getCause() instanceof ConfigInvalidException) {
                throw new ResourceConflictException("Cannot update " + projectName + ": " + e.getCause().getMessage());
            }
            log.warn(String.format("Failed to update config of project %s.", projectName), e);
            throw new ResourceConflictException("Cannot update " + projectName);
        }
        ProjectState state = projectStateFactory.create(projectConfig);
        return new ConfigInfoImpl(serverEnableSignedPush, state.controlFor(user.get()), config, pluginConfigEntries, cfgFactory, allProjects, uiActions, views);
    } catch (RepositoryNotFoundException notFound) {
        throw new ResourceNotFoundException(projectName.get());
    } catch (ConfigInvalidException err) {
        throw new ResourceConflictException("Cannot read project " + projectName, err);
    } catch (IOException err) {
        throw new ResourceConflictException("Cannot update project " + projectName, err);
    }
}
Also used : ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) IOException(java.io.IOException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)73 IOException (java.io.IOException)43 OrmException (com.google.gwtorm.server.OrmException)30 Repository (org.eclipse.jgit.lib.Repository)24 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)18 Project (com.google.gerrit.reviewdb.client.Project)15 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)14 Account (com.google.gerrit.reviewdb.client.Account)13 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)12 RevWalk (org.eclipse.jgit.revwalk.RevWalk)12 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)10 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)10 ObjectId (org.eclipse.jgit.lib.ObjectId)10 ExternalId (com.google.gerrit.server.account.externalids.ExternalId)9 Inject (com.google.inject.Inject)9 ArrayList (java.util.ArrayList)9 Provider (com.google.inject.Provider)8 Map (java.util.Map)8 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)7 HashMap (java.util.HashMap)7