Search in sources :

Example 1 with ProjectState

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

the class CreateProjectIT method withValidGroupName.

@Test
public void withValidGroupName() throws Exception {
    String newGroupName = "newGroup";
    adminRestSession.put("/groups/" + newGroupName);
    String newProjectName = "newProject";
    adminSshSession.exec("gerrit create-project --branch master --owner " + newGroupName + " " + newProjectName);
    assert_().withFailureMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isFalse();
    ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
    assertThat(projectState).isNotNull();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 2 with ProjectState

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

the class CreateProjectIT method withInvalidGroupName.

@Test
public void withInvalidGroupName() throws Exception {
    String newGroupName = "newGroup";
    adminRestSession.put("/groups/" + newGroupName);
    String wrongGroupName = "newG";
    String newProjectName = "newProject";
    adminSshSession.exec("gerrit create-project --branch master --owner " + wrongGroupName + " " + newProjectName);
    assert_().withFailureMessage(adminSshSession.getError()).that(adminSshSession.hasError()).isTrue();
    ProjectState projectState = projectCache.get(new Project.NameKey(newProjectName));
    assertThat(projectState).isNull();
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ProjectState(com.google.gerrit.server.project.ProjectState) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 3 with ProjectState

use of com.google.gerrit.server.project.ProjectState 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 4 with ProjectState

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

the class FixReplacementInterpreter method toTreeModifications.

/**
   * Transforms the given {@code FixReplacement}s into {@code TreeModification}s.
   *
   * @param repository the affected Git repository
   * @param projectState the affected project
   * @param patchSetCommitId the patch set which should be modified
   * @param fixReplacements the replacements which should be applied
   * @return a list of {@code TreeModification}s representing the given replacements
   * @throws ResourceNotFoundException if a file to which one of the replacements refers doesn't
   *     exist
   * @throws ResourceConflictException if the replacements can't be transformed into {@code
   *     TreeModification}s
   */
public List<TreeModification> toTreeModifications(Repository repository, ProjectState projectState, ObjectId patchSetCommitId, List<FixReplacement> fixReplacements) throws ResourceNotFoundException, IOException, ResourceConflictException {
    checkNotNull(fixReplacements, "Fix replacements must not be null");
    Map<String, List<FixReplacement>> fixReplacementsPerFilePath = fixReplacements.stream().collect(Collectors.groupingBy(fixReplacement -> fixReplacement.path));
    List<TreeModification> treeModifications = new ArrayList<>();
    for (Map.Entry<String, List<FixReplacement>> entry : fixReplacementsPerFilePath.entrySet()) {
        TreeModification treeModification = toTreeModification(repository, projectState, patchSetCommitId, entry.getKey(), entry.getValue());
        treeModifications.add(treeModification);
    }
    return treeModifications;
}
Also used : ResourceNotFoundException(com.google.gerrit.extensions.restapi.ResourceNotFoundException) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) Inject(com.google.inject.Inject) Preconditions.checkNotNull(com.google.common.base.Preconditions.checkNotNull) RawInputUtil(com.google.gerrit.common.RawInputUtil) ChangeFileContentModification(com.google.gerrit.server.edit.tree.ChangeFileContentModification) ProjectState(com.google.gerrit.server.project.ProjectState) FixReplacement(com.google.gerrit.reviewdb.client.FixReplacement) IOException(java.io.IOException) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) ObjectId(org.eclipse.jgit.lib.ObjectId) Comment(com.google.gerrit.reviewdb.client.Comment) BinaryResult(com.google.gerrit.extensions.restapi.BinaryResult) List(java.util.List) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) FileContentUtil(com.google.gerrit.server.change.FileContentUtil) Map(java.util.Map) Comparator(java.util.Comparator) Repository(org.eclipse.jgit.lib.Repository) Singleton(com.google.inject.Singleton) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) TreeModification(com.google.gerrit.server.edit.tree.TreeModification) Map(java.util.Map)

Example 5 with ProjectState

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

the class EventBroker method isVisibleTo.

protected boolean isVisibleTo(Branch.NameKey branchName, CurrentUser user) {
    ProjectState pe = projectCache.get(branchName.getParentKey());
    if (pe == null) {
        return false;
    }
    ProjectControl pc = pe.controlFor(user);
    return pc.controlForRef(branchName).isVisible();
}
Also used : ProjectState(com.google.gerrit.server.project.ProjectState) ProjectControl(com.google.gerrit.server.project.ProjectControl)

Aggregations

ProjectState (com.google.gerrit.server.project.ProjectState)86 Project (com.google.gerrit.entities.Project)20 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)19 IOException (java.io.IOException)18 Repository (org.eclipse.jgit.lib.Repository)18 AuthException (com.google.gerrit.extensions.restapi.AuthException)16 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)14 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)14 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)13 Change (com.google.gerrit.entities.Change)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 Test (org.junit.Test)13 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)12 ChangeData (com.google.gerrit.server.query.change.ChangeData)11 Inject (com.google.inject.Inject)10 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)10 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)10 StorageException (com.google.gerrit.exceptions.StorageException)9 ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)9 ProjectResource (com.google.gerrit.server.project.ProjectResource)9