Search in sources :

Example 6 with NoSuchProjectException

use of com.google.gerrit.server.project.NoSuchProjectException in project gerrit by GerritCodeReview.

the class SubmoduleOp method getDestinationBranches.

private Collection<Branch.NameKey> getDestinationBranches(Branch.NameKey src, SubscribeSection s) throws IOException {
    Collection<Branch.NameKey> ret = new HashSet<>();
    logDebug("Inspecting SubscribeSection " + s);
    for (RefSpec r : s.getMatchingRefSpecs()) {
        logDebug("Inspecting [matching] ref " + r);
        if (!r.matchSource(src.get())) {
            continue;
        }
        if (r.isWildcard()) {
            // refs/heads/*[:refs/somewhere/*]
            ret.add(new Branch.NameKey(s.getProject(), r.expandFromSource(src.get()).getDestination()));
        } else {
            // e.g. refs/heads/master[:refs/heads/stable]
            String dest = r.getDestination();
            if (dest == null) {
                dest = r.getSource();
            }
            ret.add(new Branch.NameKey(s.getProject(), dest));
        }
    }
    for (RefSpec r : s.getMultiMatchRefSpecs()) {
        logDebug("Inspecting [all] ref " + r);
        if (!r.matchSource(src.get())) {
            continue;
        }
        OpenRepo or;
        try {
            or = orm.getRepo(s.getProject());
        } catch (NoSuchProjectException e) {
            // thrown.
            continue;
        }
        for (Ref ref : or.repo.getRefDatabase().getRefs(RefNames.REFS_HEADS).values()) {
            if (r.getDestination() != null && !r.matchDestination(ref.getName())) {
                continue;
            }
            Branch.NameKey b = new Branch.NameKey(s.getProject(), ref.getName());
            if (!ret.contains(b)) {
                ret.add(b);
            }
        }
    }
    logDebug("Returning possible branches: " + ret + "for project " + s.getProject());
    return ret;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) RefSpec(org.eclipse.jgit.transport.RefSpec) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) Branch(com.google.gerrit.reviewdb.client.Branch) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet)

Example 7 with NoSuchProjectException

use of com.google.gerrit.server.project.NoSuchProjectException in project gerrit by GerritCodeReview.

the class SubmoduleOp method superProjectSubscriptionsForSubmoduleBranch.

public Collection<SubmoduleSubscription> superProjectSubscriptionsForSubmoduleBranch(Branch.NameKey srcBranch) throws IOException {
    logDebug("Calculating possible superprojects for " + srcBranch);
    Collection<SubmoduleSubscription> ret = new ArrayList<>();
    Project.NameKey srcProject = srcBranch.getParentKey();
    ProjectConfig cfg = projectCache.get(srcProject).getConfig();
    for (SubscribeSection s : projectStateFactory.create(cfg).getSubscribeSections(srcBranch)) {
        logDebug("Checking subscribe section " + s);
        Collection<Branch.NameKey> branches = getDestinationBranches(srcBranch, s);
        for (Branch.NameKey targetBranch : branches) {
            Project.NameKey targetProject = targetBranch.getParentKey();
            try {
                OpenRepo or = orm.getRepo(targetProject);
                ObjectId id = or.repo.resolve(targetBranch.get());
                if (id == null) {
                    logDebug("The branch " + targetBranch + " doesn't exist.");
                    continue;
                }
            } catch (NoSuchProjectException e) {
                logDebug("The project " + targetProject + " doesn't exist");
                continue;
            }
            GitModules m = branchGitModules.get(targetBranch);
            if (m == null) {
                m = gitmodulesFactory.create(targetBranch, orm);
                branchGitModules.put(targetBranch, m);
            }
            ret.addAll(m.subscribedTo(srcBranch));
        }
    }
    logDebug("Calculated superprojects for " + srcBranch + " are " + ret);
    return ret;
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ArrayList(java.util.ArrayList) SubscribeSection(com.google.gerrit.common.data.SubscribeSection) Project(com.google.gerrit.reviewdb.client.Project) Branch(com.google.gerrit.reviewdb.client.Branch) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) SubmoduleSubscription(com.google.gerrit.reviewdb.client.SubmoduleSubscription)

Example 8 with NoSuchProjectException

use of com.google.gerrit.server.project.NoSuchProjectException in project gerrit by GerritCodeReview.

the class MergeOpRepoManager method getRepo.

public OpenRepo getRepo(Project.NameKey project) throws NoSuchProjectException, IOException {
    if (openRepos.containsKey(project)) {
        return openRepos.get(project);
    }
    ProjectState projectState = projectCache.get(project);
    if (projectState == null) {
        throw new NoSuchProjectException(project);
    }
    try {
        OpenRepo or = new OpenRepo(repoManager.openRepository(project), projectState);
        openRepos.put(project, or);
        return or;
    } catch (RepositoryNotFoundException e) {
        throw new NoSuchProjectException(project, e);
    }
}
Also used : NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) ProjectState(com.google.gerrit.server.project.ProjectState) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException)

Example 9 with NoSuchProjectException

use of com.google.gerrit.server.project.NoSuchProjectException in project gerrit by GerritCodeReview.

the class MergeSuperSet method getRepo.

private OpenRepo getRepo(Project.NameKey project) throws IOException {
    if (orm == null) {
        orm = repoManagerProvider.get();
        closeOrm = true;
    }
    try {
        OpenRepo or = orm.getRepo(project);
        checkState(or.rw.hasRevSort(RevSort.TOPO));
        return or;
    } catch (NoSuchProjectException e) {
        throw new IOException(e);
    }
}
Also used : NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) OpenRepo(com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo) IOException(java.io.IOException)

Example 10 with NoSuchProjectException

use of com.google.gerrit.server.project.NoSuchProjectException in project gerrit by GerritCodeReview.

the class ProjectAccessHandler method call.

@Override
public final T call() throws NoSuchProjectException, IOException, ConfigInvalidException, InvalidNameException, NoSuchGroupException, OrmException, UpdateParentFailedException, PermissionDeniedException, PermissionBackendException {
    final ProjectControl projectControl = projectControlFactory.controlFor(projectName);
    Capable r = projectControl.canPushToAtLeastOneRef();
    if (r != Capable.OK) {
        throw new PermissionDeniedException(r.getMessage());
    }
    try (MetaDataUpdate md = metaDataUpdateFactory.create(projectName)) {
        ProjectConfig config = ProjectConfig.read(md, base);
        Set<String> toDelete = scanSectionNames(config);
        for (AccessSection section : mergeSections(sectionList)) {
            String name = section.getName();
            if (AccessSection.GLOBAL_CAPABILITIES.equals(name)) {
                if (checkIfOwner && !projectControl.isOwner()) {
                    continue;
                }
                replace(config, toDelete, section);
            } else if (AccessSection.isValid(name)) {
                if (checkIfOwner && !projectControl.controlForRef(name).isOwner()) {
                    continue;
                }
                RefPattern.validate(name);
                replace(config, toDelete, section);
            }
        }
        for (String name : toDelete) {
            if (AccessSection.GLOBAL_CAPABILITIES.equals(name)) {
                if (!checkIfOwner || projectControl.isOwner()) {
                    config.remove(config.getAccessSection(name));
                }
            } else if (!checkIfOwner || projectControl.controlForRef(name).isOwner()) {
                config.remove(config.getAccessSection(name));
            }
        }
        boolean parentProjectUpdate = false;
        if (!config.getProject().getNameKey().equals(allProjects) && !config.getProject().getParent(allProjects).equals(parentProjectName)) {
            parentProjectUpdate = true;
            try {
                setParent.get().validateParentUpdate(projectControl, MoreObjects.firstNonNull(parentProjectName, allProjects).get(), checkIfOwner);
            } catch (AuthException e) {
                throw new UpdateParentFailedException("You are not allowed to change the parent project since you are " + "not an administrator. You may save the modifications for review " + "so that an administrator can approve them.", e);
            } catch (ResourceConflictException | UnprocessableEntityException e) {
                throw new UpdateParentFailedException(e.getMessage(), e);
            }
            config.getProject().setParentName(parentProjectName);
        }
        if (message != null && !message.isEmpty()) {
            if (!message.endsWith("\n")) {
                message += "\n";
            }
            md.setMessage(message);
        } else {
            md.setMessage("Modify access rules\n");
        }
        return updateProjectConfig(projectControl, config, md, parentProjectUpdate);
    } catch (RepositoryNotFoundException notFound) {
        throw new NoSuchProjectException(projectName);
    }
}
Also used : UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) NoSuchProjectException(com.google.gerrit.server.project.NoSuchProjectException) UpdateParentFailedException(com.google.gerrit.common.errors.UpdateParentFailedException) AuthException(com.google.gerrit.extensions.restapi.AuthException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) ProjectControl(com.google.gerrit.server.project.ProjectControl) AccessSection(com.google.gerrit.common.data.AccessSection) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) Capable(com.google.gerrit.common.data.Capable) PermissionDeniedException(com.google.gerrit.common.errors.PermissionDeniedException) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Aggregations

NoSuchProjectException (com.google.gerrit.server.project.NoSuchProjectException)15 OpenRepo (com.google.gerrit.server.git.MergeOpRepoManager.OpenRepo)8 IOException (java.io.IOException)7 Branch (com.google.gerrit.reviewdb.client.Branch)4 Project (com.google.gerrit.reviewdb.client.Project)3 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)3 ProjectControl (com.google.gerrit.server.project.ProjectControl)3 ObjectId (org.eclipse.jgit.lib.ObjectId)3 Ref (org.eclipse.jgit.lib.Ref)3 NoSuchGroupException (com.google.gerrit.common.errors.NoSuchGroupException)2 AuthException (com.google.gerrit.extensions.restapi.AuthException)2 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)2 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)2 UnprocessableEntityException (com.google.gerrit.extensions.restapi.UnprocessableEntityException)2 Account (com.google.gerrit.reviewdb.client.Account)2 UpdateException (com.google.gerrit.server.update.UpdateException)2 HashSet (java.util.HashSet)2 LinkedHashSet (java.util.LinkedHashSet)2 DirCache (org.eclipse.jgit.dircache.DirCache)2 DirCacheEditor (org.eclipse.jgit.dircache.DirCacheEditor)2