Search in sources :

Example 36 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class ChangeBundleTest method diffChangesTakesMaxEntityTimestampFromReviewDb.

@Test
public void diffChangesTakesMaxEntityTimestampFromReviewDb() throws Exception {
    Change c1 = TestChanges.newChange(new Project.NameKey("project"), new Account.Id(100));
    PatchSet ps = new PatchSet(c1.currentPatchSetId());
    ps.setRevision(new RevId("deadbeefdeadbeefdeadbeefdeadbeefdeadbeef"));
    ps.setUploader(accountId);
    ps.setCreatedOn(TimeUtil.nowTs());
    PatchSetApproval a = new PatchSetApproval(new PatchSetApproval.Key(c1.currentPatchSetId(), accountId, new LabelId("Code-Review")), (short) 1, TimeUtil.nowTs());
    Change c2 = clone(c1);
    c2.setLastUpdatedOn(a.getGranted());
    // Both ReviewDb, exact match required.
    ChangeBundle b1 = new ChangeBundle(c1, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
    ChangeBundle b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), REVIEW_DB);
    assertDiffs(b1, b2, "effective last updated time differs for Change.Id " + c1.getId() + ":" + " {2009-09-30 17:00:00.0} != {2009-09-30 17:00:12.0}");
    // NoteDb allows latest timestamp from all entities in bundle.
    b2 = new ChangeBundle(c2, messages(), patchSets(ps), approvals(a), comments(), reviewers(), NOTE_DB);
    assertNoDiffs(b1, b2);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Account(com.google.gerrit.reviewdb.client.Account) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) LabelId(com.google.gerrit.reviewdb.client.LabelId) RevId(com.google.gerrit.reviewdb.client.RevId) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) Test(org.junit.Test)

Example 37 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class AdminSetParent method run.

@Override
protected void run() throws Failure {
    if (oldParent == null && children.isEmpty()) {
        throw die("child projects have to be specified as " + "arguments or the --children-of option has to be set");
    }
    if (oldParent == null && !excludedChildren.isEmpty()) {
        throw die("--exclude can only be used together with --children-of");
    }
    final StringBuilder err = new StringBuilder();
    final Set<Project.NameKey> grandParents = new HashSet<>();
    grandParents.add(allProjectsName);
    if (newParent != null) {
        newParentKey = newParent.getProject().getNameKey();
        // Catalog all grandparents of the "parent", we want to
        // catch a cycle in the parent pointers before it occurs.
        //
        Project.NameKey gp = newParent.getProject().getParent();
        while (gp != null && grandParents.add(gp)) {
            final ProjectState s = projectCache.get(gp);
            if (s != null) {
                gp = s.getProject().getParent();
            } else {
                break;
            }
        }
    }
    final List<Project.NameKey> childProjects = new ArrayList<>();
    for (final ProjectControl pc : children) {
        childProjects.add(pc.getProject().getNameKey());
    }
    if (oldParent != null) {
        try {
            childProjects.addAll(getChildrenForReparenting(oldParent));
        } catch (PermissionBackendException e) {
            throw new Failure(1, "permissions unavailable", e);
        }
    }
    for (final Project.NameKey nameKey : childProjects) {
        final String name = nameKey.get();
        if (allProjectsName.equals(nameKey)) {
            // Don't allow the wild card project to have a parent.
            //
            err.append("error: Cannot set parent of '").append(name).append("'\n");
            continue;
        }
        if (grandParents.contains(nameKey) || nameKey.equals(newParentKey)) {
            // Try to avoid creating a cycle in the parent pointers.
            //
            err.append("error: Cycle exists between '").append(name).append("' and '").append(newParentKey != null ? newParentKey.get() : allProjectsName.get()).append("'\n");
            continue;
        }
        try (MetaDataUpdate md = metaDataUpdateFactory.create(nameKey)) {
            ProjectConfig config = ProjectConfig.read(md);
            config.getProject().setParentName(newParentKey);
            md.setMessage("Inherit access from " + (newParentKey != null ? newParentKey.get() : allProjectsName.get()) + "\n");
            config.commit(md);
        } catch (RepositoryNotFoundException notFound) {
            err.append("error: Project ").append(name).append(" not found\n");
        } catch (IOException | ConfigInvalidException e) {
            final String msg = "Cannot update project " + name;
            log.error(msg, e);
            err.append("error: ").append(msg).append("\n");
        }
        projectCache.evict(nameKey);
    }
    if (err.length() > 0) {
        while (err.charAt(err.length() - 1) == '\n') {
            err.setLength(err.length() - 1);
        }
        throw die(err.toString());
    }
}
Also used : ConfigInvalidException(org.eclipse.jgit.errors.ConfigInvalidException) ArrayList(java.util.ArrayList) PermissionBackendException(com.google.gerrit.server.permissions.PermissionBackendException) RepositoryNotFoundException(org.eclipse.jgit.errors.RepositoryNotFoundException) IOException(java.io.IOException) ProjectControl(com.google.gerrit.server.project.ProjectControl) ProjectConfig(com.google.gerrit.server.git.ProjectConfig) Project(com.google.gerrit.reviewdb.client.Project) ProjectState(com.google.gerrit.server.project.ProjectState) HashSet(java.util.HashSet) MetaDataUpdate(com.google.gerrit.server.git.MetaDataUpdate)

Example 38 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class TestChanges method stubChangeControl.

private static ChangeControl stubChangeControl(AbstractChangeNotes.Args args, Change c, CurrentUser user) throws OrmException {
    ChangeControl ctl = EasyMock.createMock(ChangeControl.class);
    expect(ctl.getChange()).andStubReturn(c);
    expect(ctl.getProject()).andStubReturn(new Project(c.getProject()));
    expect(ctl.getUser()).andStubReturn(user);
    ChangeNotes notes = new ChangeNotes(args, c).load();
    expect(ctl.getNotes()).andStubReturn(notes);
    expect(ctl.getId()).andStubReturn(c.getId());
    EasyMock.replay(ctl);
    return ctl;
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) ChangeControl(com.google.gerrit.server.project.ChangeControl) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) AbstractChangeNotes(com.google.gerrit.server.notedb.AbstractChangeNotes)

Example 39 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SubmitOnPushIT method mergeOnPushToBranchWithOldPatchset.

@Test
public void mergeOnPushToBranchWithOldPatchset() throws Exception {
    grant(project, "refs/heads/master", Permission.PUSH);
    PushOneCommit.Result r = pushTo("refs/for/master");
    r.assertOkStatus();
    RevCommit c1 = r.getCommit();
    PatchSet.Id psId1 = r.getPatchSetId();
    String changeId = r.getChangeId();
    assertThat(psId1.get()).isEqualTo(1);
    r = amendChange(changeId);
    ChangeData cd = r.getChange();
    PatchSet.Id psId2 = cd.change().currentPatchSetId();
    assertThat(psId2.getParentKey()).isEqualTo(psId1.getParentKey());
    assertThat(psId2.get()).isEqualTo(2);
    testRepo.reset(c1);
    assertPushOk(pushHead(testRepo, "refs/heads/master", false), "refs/heads/master");
    cd = changeDataFactory.create(db, project, psId1.getParentKey());
    Change c = cd.change();
    assertThat(c.getStatus()).isEqualTo(Change.Status.MERGED);
    assertThat(c.currentPatchSetId()).isEqualTo(psId1);
    assertThat(cd.patchSets().stream().map(ps -> ps.getId()).collect(toList())).containsExactly(psId1, psId2);
}
Also used : Iterables(com.google.common.collect.Iterables) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Change(com.google.gerrit.reviewdb.client.Change) Inject(com.google.inject.Inject) RevObject(org.eclipse.jgit.revwalk.RevObject) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) PatchSetApproval(com.google.gerrit.reviewdb.client.PatchSetApproval) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTag(org.eclipse.jgit.revwalk.RevTag) Project(com.google.gerrit.reviewdb.client.Project) GitUtil.pushHead(com.google.gerrit.acceptance.GitUtil.pushHead) RefSpec(org.eclipse.jgit.transport.RefSpec) Permission(com.google.gerrit.common.data.Permission) ChangeNotes(com.google.gerrit.server.notedb.ChangeNotes) Test(org.junit.Test) Truth.assertThat(com.google.common.truth.Truth.assertThat) ApprovalsUtil(com.google.gerrit.server.ApprovalsUtil) ObjectId(org.eclipse.jgit.lib.ObjectId) NoHttpd(com.google.gerrit.acceptance.NoHttpd) Collectors.toList(java.util.stream.Collectors.toList) ChangeData(com.google.gerrit.server.query.change.ChangeData) RefNames(com.google.gerrit.reviewdb.client.RefNames) Ref(org.eclipse.jgit.lib.Ref) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) GitUtil.assertPushOk(com.google.gerrit.acceptance.GitUtil.assertPushOk) Repository(org.eclipse.jgit.lib.Repository) PatchSet(com.google.gerrit.reviewdb.client.PatchSet) Change(com.google.gerrit.reviewdb.client.Change) ChangeData(com.google.gerrit.server.query.change.ChangeData) PushOneCommit(com.google.gerrit.acceptance.PushOneCommit) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest)

Example 40 with Project

use of com.google.gerrit.reviewdb.client.Project in project gerrit by GerritCodeReview.

the class SubmoduleSectionParserIT method withSubProjectFound.

@Test
public void withSubProjectFound() throws Exception {
    Project.NameKey p1 = createProject("a/b");
    Project.NameKey p2 = createProject("b");
    Config cfg = new Config();
    cfg.fromText("\n" + "[submodule \"a/b\"]\n" + "path = a/b\n" + "url = ssh://localhost/" + p1.get() + "\n" + "branch = .\n" + "[submodule \"b\"]\n" + "path = b\n" + "url = http://localhost/" + p2.get() + "\n" + "branch = .\n");
    Branch.NameKey targetBranch = new Branch.NameKey(new Project.NameKey("project"), "master");
    Set<SubmoduleSubscription> res = new SubmoduleSectionParser(cfg, THIS_SERVER, targetBranch).parseAllSections();
    Set<SubmoduleSubscription> expected = Sets.newHashSet(new SubmoduleSubscription(targetBranch, new Branch.NameKey(p2, "master"), "b"), new SubmoduleSubscription(targetBranch, new Branch.NameKey(p1, "master"), "a/b"));
    assertThat(res).containsExactlyElementsIn(expected);
}
Also used : Project(com.google.gerrit.reviewdb.client.Project) Config(org.eclipse.jgit.lib.Config) Branch(com.google.gerrit.reviewdb.client.Branch) SubmoduleSubscription(com.google.gerrit.reviewdb.client.SubmoduleSubscription) SubmoduleSectionParser(com.google.gerrit.server.util.SubmoduleSectionParser) AbstractDaemonTest(com.google.gerrit.acceptance.AbstractDaemonTest) Test(org.junit.Test)

Aggregations

Project (com.google.gerrit.reviewdb.client.Project)93 Test (org.junit.Test)37 Change (com.google.gerrit.reviewdb.client.Change)26 AbstractDaemonTest (com.google.gerrit.acceptance.AbstractDaemonTest)22 Branch (com.google.gerrit.reviewdb.client.Branch)21 Account (com.google.gerrit.reviewdb.client.Account)19 Config (org.eclipse.jgit.lib.Config)18 SubmoduleSubscription (com.google.gerrit.reviewdb.client.SubmoduleSubscription)17 Repository (org.eclipse.jgit.lib.Repository)17 ResourceConflictException (com.google.gerrit.extensions.restapi.ResourceConflictException)15 SubmoduleSectionParser (com.google.gerrit.server.util.SubmoduleSectionParser)14 IOException (java.io.IOException)14 MetaDataUpdate (com.google.gerrit.server.git.MetaDataUpdate)13 ProjectConfig (com.google.gerrit.server.git.ProjectConfig)13 ConfigInvalidException (org.eclipse.jgit.errors.ConfigInvalidException)13 ObjectId (org.eclipse.jgit.lib.ObjectId)13 ResourceNotFoundException (com.google.gerrit.extensions.restapi.ResourceNotFoundException)12 PatchSet (com.google.gerrit.reviewdb.client.PatchSet)12 RepositoryNotFoundException (org.eclipse.jgit.errors.RepositoryNotFoundException)12 RevCommit (org.eclipse.jgit.revwalk.RevCommit)12