Search in sources :

Example 21 with ProjectInfo

use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.

the class SetParentCommand method getChildrenForReparenting.

/**
 * Returns the children of the specified parent project that should be reparented. The returned
 * list of child projects does not contain projects that were specified to be excluded from
 * reparenting.
 */
private List<Project.NameKey> getChildrenForReparenting(ProjectState parent) throws Exception {
    final List<Project.NameKey> childProjects = new ArrayList<>();
    final List<Project.NameKey> excluded = new ArrayList<>(excludedChildren.size());
    for (ProjectState excludedChild : excludedChildren) {
        excluded.add(excludedChild.getProject().getNameKey());
    }
    final List<Project.NameKey> automaticallyExcluded = new ArrayList<>(excludedChildren.size());
    if (newParentKey != null) {
        automaticallyExcluded.addAll(getAllParents(newParentKey));
    }
    for (ProjectInfo child : listChildProjects.apply(new ProjectResource(parent, user)).value()) {
        final Project.NameKey childName = Project.nameKey(child.name);
        if (!excluded.contains(childName)) {
            if (!automaticallyExcluded.contains(childName)) {
                childProjects.add(childName);
            } else {
                stdout.println("Automatically excluded '" + childName + "' " + "from reparenting because it is in the parent " + "line of the new parent '" + newParentKey + "'.");
            }
        }
    }
    return childProjects;
}
Also used : Project(com.google.gerrit.entities.Project) ArrayList(java.util.ArrayList) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) ProjectResource(com.google.gerrit.server.project.ProjectResource)

Example 22 with ProjectInfo

use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.

the class Index method apply.

@Override
public Response.Accepted apply(ProjectResource rsrc, IndexProjectInput input) throws Exception {
    String response = "Project " + rsrc.getName() + " submitted for reindexing";
    reindex(rsrc.getNameKey(), input.async);
    if (Boolean.TRUE.equals(input.indexChildren)) {
        for (ProjectInfo child : listChildProjectsProvider.get().withRecursive(true).apply(rsrc).value()) {
            reindex(Project.nameKey(child.name), input.async);
        }
        response += " (indexing children recursively)";
    }
    return Response.accepted(response);
}
Also used : ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo)

Example 23 with ProjectInfo

use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.

the class ProjectIT method createProjectWithPluginConfigs.

@Test
public void createProjectWithPluginConfigs() throws Exception {
    String name = name("foo");
    ProjectInput input = new ProjectInput();
    input.name = name;
    input.description = "foo description";
    input.pluginConfigValues = newPluginConfigValues();
    ProjectInfo info = gApi.projects().create(input).get();
    assertThat(info.description).isEqualTo(input.description);
}
Also used : ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 24 with ProjectInfo

use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.

the class ProjectIT method getProjectThatHasLabelDefinitionWithDuplicateValues.

@Test
public void getProjectThatHasLabelDefinitionWithDuplicateValues() throws Exception {
    // Update the definition of the Code-Review label so that it has the value "+1 LGTM" twice.
    // This update bypasses all validation checks so that the duplicate label value doesn't get
    // rejected.
    projectOperations.project(allProjects).forInvalidation().addProjectConfigUpdater(cfg -> cfg.setStringList("label", LabelId.CODE_REVIEW, "value", ImmutableList.of("+1 LGTM", "1 LGTM", "0 No Value", "-1 Looks Bad"))).invalidate();
    // Verify that project info can be retrieved and that the label value "+1 LGTM" appears only
    // once.
    ProjectInfo projectInfo = gApi.projects().name(allProjects.get()).get();
    assertThat(projectInfo.labels.keySet()).containsExactly(LabelId.CODE_REVIEW);
    assertThat(projectInfo.labels.get(LabelId.CODE_REVIEW).values).containsExactly("+1", "LGTM", " 0", "No Value", "-1", "Looks Bad");
}
Also used : ChangeIndexedListener(com.google.gerrit.extensions.events.ChangeIndexedListener) Module(com.google.inject.Module) Arrays(java.util.Arrays) ProjectConfig(com.google.gerrit.server.project.ProjectConfig) Inject(com.google.inject.Inject) RestResponse(com.google.gerrit.acceptance.RestResponse) SystemGroupBackend(com.google.gerrit.server.group.SystemGroupBackend) REGISTERED_USERS(com.google.gerrit.server.group.SystemGroupBackend.REGISTERED_USERS) BadRequestException(com.google.gerrit.extensions.restapi.BadRequestException) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) InheritableBoolean(com.google.gerrit.extensions.client.InheritableBoolean) Config(org.eclipse.jgit.lib.Config) Registration(com.google.gerrit.acceptance.ExtensionRegistry.Registration) ConfigInput(com.google.gerrit.extensions.api.projects.ConfigInput) ConfigInfo(com.google.gerrit.extensions.api.projects.ConfigInfo) Map(java.util.Map) RefNames(com.google.gerrit.entities.RefNames) AuthException(com.google.gerrit.extensions.restapi.AuthException) AtomicLongMap(com.google.common.util.concurrent.AtomicLongMap) CommentLinkInfo(com.google.gerrit.extensions.api.projects.CommentLinkInfo) TestProjectUpdate.allow(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.allow) Collectors.toSet(java.util.stream.Collectors.toSet) INHERITED_FROM_PARENT(com.google.gerrit.server.project.ProjectState.INHERITED_FROM_PARENT) ImmutableMap(com.google.common.collect.ImmutableMap) SubmitType(com.google.gerrit.extensions.client.SubmitType) ProjectConfigEntry(com.google.gerrit.server.config.ProjectConfigEntry) Set(java.util.Set) ProjectIndexedListener(com.google.gerrit.extensions.events.ProjectIndexedListener) BranchNameKey(com.google.gerrit.entities.BranchNameKey) RequestScopeOperations(com.google.gerrit.acceptance.testsuite.request.RequestScopeOperations) GroupReference(com.google.gerrit.entities.GroupReference) List(java.util.List) PushResult(org.eclipse.jgit.transport.PushResult) ProjectInput(com.google.gerrit.extensions.api.projects.ProjectInput) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Optional(java.util.Optional) GerritJUnit.assertThrows(com.google.gerrit.testing.GerritJUnit.assertThrows) Exports(com.google.gerrit.extensions.annotations.Exports) OVERRIDDEN_BY_GLOBAL(com.google.gerrit.server.project.ProjectState.OVERRIDDEN_BY_GLOBAL) Mockito.mock(org.mockito.Mockito.mock) MetaDataUpdate(com.google.gerrit.server.git.meta.MetaDataUpdate) TestProjectUpdate.block(com.google.gerrit.acceptance.testsuite.project.TestProjectUpdate.block) BranchInput(com.google.gerrit.extensions.api.projects.BranchInput) Status(org.eclipse.jgit.transport.RemoteRefUpdate.Status) LabelId(com.google.gerrit.entities.LabelId) RevCommit(org.eclipse.jgit.revwalk.RevCommit) InMemoryRepository(org.eclipse.jgit.internal.storage.dfs.InMemoryRepository) UnprocessableEntityException(com.google.gerrit.extensions.restapi.UnprocessableEntityException) CommentLinkInput(com.google.gerrit.extensions.api.projects.CommentLinkInput) HashMap(java.util.HashMap) Lists(com.google.common.collect.Lists) GroupInfo(com.google.gerrit.extensions.common.GroupInfo) ImmutableList(com.google.common.collect.ImmutableList) Change(com.google.gerrit.entities.Change) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) GitUtil(com.google.gerrit.acceptance.GitUtil) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) ExtensionRegistry(com.google.gerrit.acceptance.ExtensionRegistry) AccountGroup(com.google.gerrit.entities.AccountGroup) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) INHERITED_FROM_GLOBAL(com.google.gerrit.server.project.ProjectState.INHERITED_FROM_GLOBAL) TestRepository(org.eclipse.jgit.junit.TestRepository) Permission(com.google.gerrit.entities.Permission) Mockito.times(org.mockito.Mockito.times) Test(org.junit.Test) ProjectState(com.google.gerrit.extensions.client.ProjectState) Truth.assertThat(com.google.common.truth.Truth.assertThat) ConfigValue(com.google.gerrit.extensions.api.projects.ConfigValue) Mockito.verify(org.mockito.Mockito.verify) R_HEADS(org.eclipse.jgit.lib.Constants.R_HEADS) DescriptionInput(com.google.gerrit.extensions.api.projects.DescriptionInput) OVERRIDDEN_BY_PARENT(com.google.gerrit.server.project.ProjectState.OVERRIDDEN_BY_PARENT) ProjectOperations(com.google.gerrit.acceptance.testsuite.project.ProjectOperations) ResourceConflictException(com.google.gerrit.extensions.restapi.ResourceConflictException) GerritConfig(com.google.gerrit.acceptance.config.GerritConfig) Project(com.google.gerrit.entities.Project) R_TAGS(org.eclipse.jgit.lib.Constants.R_TAGS) Collections(java.util.Collections) AbstractModule(com.google.inject.AbstractModule) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Example 25 with ProjectInfo

use of com.google.gerrit.extensions.common.ProjectInfo in project gerrit by GerritCodeReview.

the class ParentProjectPredicate method predicates.

protected static ImmutableList<Predicate<ChangeData>> predicates(ProjectCache projectCache, ChildProjects childProjects, String value) {
    Optional<ProjectState> projectState = projectCache.get(Project.nameKey(value));
    if (!projectState.isPresent()) {
        return ImmutableList.of();
    }
    ImmutableList.Builder<Predicate<ChangeData>> r = ImmutableList.builder();
    r.add(ChangePredicates.project(projectState.get().getNameKey()));
    try {
        for (ProjectInfo p : childProjects.list(projectState.get().getNameKey())) {
            r.add(ChangePredicates.project(Project.nameKey(p.name)));
        }
    } catch (PermissionBackendException e) {
        logger.atWarning().withCause(e).log("cannot check permissions to expand child projects");
    }
    return r.build();
}
Also used : ImmutableList(com.google.common.collect.ImmutableList) ProjectInfo(com.google.gerrit.extensions.common.ProjectInfo) ProjectState(com.google.gerrit.server.project.ProjectState) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) Predicate(com.google.gerrit.index.query.Predicate) OrPredicate(com.google.gerrit.index.query.OrPredicate)

Aggregations

ProjectInfo (com.google.gerrit.extensions.common.ProjectInfo)38 Test (org.junit.Test)25 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)15 ProjectAssert.assertProjectInfo (com.google.gerrit.acceptance.rest.project.ProjectAssert.assertProjectInfo)10 ProjectState (com.google.gerrit.server.project.ProjectState)10 Project (com.google.gerrit.entities.Project)8 ProjectInput (com.google.gerrit.extensions.api.projects.ProjectInput)5 ImmutableList (com.google.common.collect.ImmutableList)3 BadRequestException (com.google.gerrit.extensions.restapi.BadRequestException)3 Project (com.google.gerrit.reviewdb.client.Project)3 ProjectResource (com.google.gerrit.server.project.ProjectResource)3 ArrayList (java.util.ArrayList)3 Truth.assertThat (com.google.common.truth.Truth.assertThat)2 RestResponse (com.google.gerrit.acceptance.RestResponse)2 AccountGroup (com.google.gerrit.entities.AccountGroup)2 ConfigInput (com.google.gerrit.extensions.api.projects.ConfigInput)2 LabelTypeInfo (com.google.gerrit.extensions.common.LabelTypeInfo)2 WebLinkInfo (com.google.gerrit.extensions.common.WebLinkInfo)2 PermissionBackend (com.google.gerrit.server.permissions.PermissionBackend)2 PermissionBackendException (com.google.gerrit.server.permissions.PermissionBackendException)2