Example usage for org.eclipse.jgit.lib PersonIdent PersonIdent

List of usage examples for org.eclipse.jgit.lib PersonIdent PersonIdent

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib PersonIdent PersonIdent.

Prototype

public PersonIdent(final String aName, final String aEmailAddress, final long aWhen, final int aTZ) 

Source Link

Document

Construct a org.eclipse.jgit.lib.PersonIdent .

Usage

From source file:com.binarybirchtree.contributionart.Repository.java

License:Open Source License

private PersonIdent identity(ZonedDateTime timestamp) {
    return new PersonIdent(name, email, Date.from(timestamp.toInstant()),
            TimeZone.getTimeZone(timestamp.getZone()));
}

From source file:com.google.gerrit.server.change.CommentsTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    @SuppressWarnings("unchecked")
    final DynamicMap<RestView<CommentResource>> commentViews = createMock(DynamicMap.class);
    final TypeLiteral<DynamicMap<RestView<CommentResource>>> commentViewsType = new TypeLiteral<DynamicMap<RestView<CommentResource>>>() {
    };/*from   w  ww . j a v  a2 s .  c o m*/
    @SuppressWarnings("unchecked")
    final DynamicMap<RestView<DraftCommentResource>> draftViews = createMock(DynamicMap.class);
    final TypeLiteral<DynamicMap<RestView<DraftCommentResource>>> draftViewsType = new TypeLiteral<DynamicMap<RestView<DraftCommentResource>>>() {
    };

    final AccountLoader.Factory alf = createMock(AccountLoader.Factory.class);
    db = createMock(ReviewDb.class);
    final FakeAccountCache accountCache = new FakeAccountCache();
    final PersonIdent serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(),
            TZ);
    project = new Project.NameKey("test-project");

    Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
    co.setFullName("Change Owner");
    co.setPreferredEmail("change@owner.com");
    accountCache.put(co);
    ownerId = co.getId();

    Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
    ou.setFullName("Other Account");
    ou.setPreferredEmail("other@account.com");
    accountCache.put(ou);
    Account.Id otherUserId = ou.getId();

    AbstractModule mod = new AbstractModule() {
        @Override
        protected void configure() {
            bind(commentViewsType).toInstance(commentViews);
            bind(draftViewsType).toInstance(draftViews);
            bind(AccountLoader.Factory.class).toInstance(alf);
            bind(ReviewDb.class).toInstance(db);
            bind(Realm.class).to(FakeRealm.class);
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(config);
            bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
            install(new GitModule());
            bind(GitRepositoryManager.class).to(InMemoryRepositoryManager.class);
            bind(InMemoryRepositoryManager.class).toInstance(new InMemoryRepositoryManager());
            bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
            bind(String.class).annotatedWith(AnonymousCowardName.class)
                    .toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(AccountCache.class).toInstance(accountCache);
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
            bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
        }

        @Provides
        @Singleton
        CurrentUser getCurrentUser(IdentifiedUser.GenericFactory userFactory) {
            return userFactory.create(ownerId);
        }
    };

    injector = Guice.createInjector(mod);
    injector.injectMembers(this);

    repoManager.createRepository(project);
    changeOwner = userFactory.create(ownerId);
    IdentifiedUser otherUser = userFactory.create(otherUserId);

    AccountLoader accountLoader = createMock(AccountLoader.class);
    accountLoader.fill();
    expectLastCall().anyTimes();
    expect(accountLoader.get(ownerId)).andReturn(new AccountInfo(ownerId.get())).anyTimes();
    expect(accountLoader.get(otherUserId)).andReturn(new AccountInfo(otherUserId.get())).anyTimes();
    expect(alf.create(true)).andReturn(accountLoader).anyTimes();
    replay(accountLoader, alf);

    repoManager.createRepository(allUsers.get());

    PatchLineCommentAccess plca = createMock(PatchLineCommentAccess.class);
    expect(db.patchComments()).andReturn(plca).anyTimes();

    Change change1 = newChange();
    PatchSet.Id psId1 = new PatchSet.Id(change1.getId(), 1);
    PatchSet ps1 = new PatchSet(psId1);
    PatchSet.Id psId2 = new PatchSet.Id(change1.getId(), 2);
    PatchSet ps2 = new PatchSet(psId2);

    Change change2 = newChange();
    PatchSet.Id psId3 = new PatchSet.Id(change2.getId(), 1);
    PatchSet ps3 = new PatchSet(psId3);

    long timeBase = TimeUtil.roundToSecond(TimeUtil.nowTs()).getTime();
    plc1 = newPatchLineComment(psId1, "Comment1", null, "FileOne.txt", Side.REVISION, 3, ownerId, timeBase,
            "First Comment", new CommentRange(1, 2, 3, 4));
    plc1.setRevId(new RevId("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"));
    plc2 = newPatchLineComment(psId1, "Comment2", "Comment1", "FileOne.txt", Side.REVISION, 3, otherUserId,
            timeBase + 1000, "Reply to First Comment", new CommentRange(1, 2, 3, 4));
    plc2.setRevId(new RevId("abcdabcdabcdabcdabcdabcdabcdabcdabcdabcd"));
    plc3 = newPatchLineComment(psId1, "Comment3", "Comment1", "FileOne.txt", Side.PARENT, 3, ownerId,
            timeBase + 2000, "First Parent Comment", new CommentRange(1, 2, 3, 4));
    plc3.setRevId(new RevId("cdefcdefcdefcdefcdefcdefcdefcdefcdefcdef"));
    plc4 = newPatchLineComment(psId2, "Comment4", null, "FileOne.txt", Side.REVISION, 3, ownerId,
            timeBase + 3000, "Second Comment", new CommentRange(1, 2, 3, 4), Status.DRAFT);
    plc4.setRevId(new RevId("bcdebcdebcdebcdebcdebcdebcdebcdebcdebcde"));
    plc5 = newPatchLineComment(psId2, "Comment5", null, "FileOne.txt", Side.REVISION, 5, ownerId,
            timeBase + 4000, "Third Comment", new CommentRange(3, 4, 5, 6), Status.DRAFT);
    plc5.setRevId(new RevId("bcdebcdebcdebcdebcdebcdebcdebcdebcdebcde"));
    plc6 = newPatchLineComment(psId3, "Comment6", null, "FileOne.txt", Side.REVISION, 5, ownerId,
            timeBase + 5000, "Sixth Comment", new CommentRange(3, 4, 5, 6), Status.DRAFT);
    plc6.setRevId(new RevId("1234123412341234123412341234123412341234"));

    List<PatchLineComment> commentsByOwner = Lists.newArrayList();
    commentsByOwner.add(plc1);
    commentsByOwner.add(plc3);
    List<PatchLineComment> commentsByReviewer = Lists.newArrayList();
    commentsByReviewer.add(plc2);
    List<PatchLineComment> drafts1 = Lists.newArrayList();
    drafts1.add(plc4);
    drafts1.add(plc5);
    List<PatchLineComment> drafts2 = Lists.newArrayList();
    drafts2.add(plc6);

    plca.upsert(commentsByOwner);
    expectLastCall().anyTimes();
    plca.upsert(commentsByReviewer);
    expectLastCall().anyTimes();
    plca.upsert(drafts1);
    expectLastCall().anyTimes();
    plca.upsert(drafts2);
    expectLastCall().anyTimes();

    expect(plca.publishedByPatchSet(psId1)).andAnswer(results(plc1, plc2, plc3)).anyTimes();
    expect(plca.publishedByPatchSet(psId2)).andAnswer(results()).anyTimes();
    expect(plca.draftByPatchSetAuthor(psId1, ownerId)).andAnswer(results()).anyTimes();
    expect(plca.draftByPatchSetAuthor(psId2, ownerId)).andAnswer(results(plc4, plc5)).anyTimes();
    expect(plca.byChange(change1.getId())).andAnswer(results(plc1, plc2, plc3, plc4, plc5)).anyTimes();
    expect(plca.draftByAuthor(ownerId)).andAnswer(results(plc4, plc5, plc6)).anyTimes();
    replay(db, plca);

    ChangeUpdate update = newUpdate(change1, changeOwner);
    update.setPatchSetId(psId1);
    plcUtil.upsertComments(db, update, commentsByOwner);
    update.commit();

    update = newUpdate(change1, otherUser);
    update.setPatchSetId(psId1);
    plcUtil.upsertComments(db, update, commentsByReviewer);
    update.commit();

    update = newUpdate(change1, changeOwner);
    update.setPatchSetId(psId2);
    plcUtil.upsertComments(db, update, drafts1);
    update.commit();

    update = newUpdate(change2, changeOwner);
    update.setPatchSetId(psId3);
    plcUtil.upsertComments(db, update, drafts2);
    update.commit();

    ChangeControl ctl = stubChangeControl(change1);
    revRes1 = new RevisionResource(new ChangeResource(ctl), ps1);
    revRes2 = new RevisionResource(new ChangeResource(ctl), ps2);
    revRes3 = new RevisionResource(new ChangeResource(stubChangeControl(change2)), ps3);
}

From source file:com.google.gerrit.server.IdentifiedUser.java

License:Apache License

public PersonIdent newRefLogIdent(final Date when, final TimeZone tz) {
    final Account ua = getAccount();

    String name = ua.getFullName();
    if (name == null || name.isEmpty()) {
        name = ua.getPreferredEmail();//w  w  w.j a  v  a2 s  .co  m
    }
    if (name == null || name.isEmpty()) {
        name = anonymousCowardName;
    }

    String user = getUserName();
    if (user == null) {
        user = "";
    }
    user = user + "|" + "account-" + ua.getId().toString();

    String host = null;
    if (remotePeerProvider != null) {
        final SocketAddress remotePeer = remotePeerProvider.get();
        if (remotePeer instanceof InetSocketAddress) {
            final InetSocketAddress sa = (InetSocketAddress) remotePeer;
            final InetAddress in = sa.getAddress();

            host = in != null ? getHost(in) : sa.getHostName();
        }
    }
    if (host == null || host.isEmpty()) {
        host = "unknown";
    }

    return new PersonIdent(name, user + "@" + host, when, tz);
}

From source file:com.google.gerrit.server.IdentifiedUser.java

License:Apache License

public PersonIdent newCommitterIdent(final Date when, final TimeZone tz) {
    final Account ua = getAccount();
    String name = ua.getFullName();
    String email = ua.getPreferredEmail();

    if (email == null || email.isEmpty()) {
        // No preferred email is configured. Use a generic identity so we
        // don't leak an address the user may have given us, but doesn't
        // necessarily want to publish through Git records.
        ////w  w w.  ja va  2 s.  c  o m
        String user = getUserName();
        if (user == null || user.isEmpty()) {
            user = "account-" + ua.getId().toString();
        }

        String host;
        if (canonicalUrl.get() != null) {
            try {
                host = new URL(canonicalUrl.get()).getHost();
            } catch (MalformedURLException e) {
                host = SystemReader.getInstance().getHostname();
            }
        } else {
            host = SystemReader.getInstance().getHostname();
        }

        email = user + "@" + host;
    }

    if (name == null || name.isEmpty()) {
        final int at = email.indexOf('@');
        if (0 < at) {
            name = email.substring(0, at);
        } else {
            name = anonymousCowardName;
        }
    }

    return new PersonIdent(name, email, when, tz);
}

From source file:com.google.gerrit.server.mail.FromAddressGeneratorProviderTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    config = new Config();
    ident = new PersonIdent("NAME", "e@email", 0, 0);
    accountCache = createStrictMock(AccountCache.class);
}

From source file:com.google.gerrit.server.notedb.AbstractChangeNotesTest.java

License:Apache License

@Before
public void setUp() throws Exception {
    setTimeForTesting();//from w ww  .j  a  v a  2s  . c o  m
    KeyUtil.setEncoderImpl(new StandardKeyEncoder());

    serverIdent = new PersonIdent("Gerrit Server", "noreply@gerrit.com", TimeUtil.nowTs(), TZ);
    project = new Project.NameKey("test-project");
    repoManager = new InMemoryRepositoryManager();
    repo = repoManager.createRepository(project);
    accountCache = new FakeAccountCache();
    Account co = new Account(new Account.Id(1), TimeUtil.nowTs());
    co.setFullName("Change Owner");
    co.setPreferredEmail("change@owner.com");
    accountCache.put(co);
    Account ou = new Account(new Account.Id(2), TimeUtil.nowTs());
    ou.setFullName("Other Account");
    ou.setPreferredEmail("other@account.com");
    accountCache.put(ou);

    injector = Guice.createInjector(new FactoryModule() {
        @Override
        public void configure() {
            install(new GitModule());
            bind(NotesMigration.class).toInstance(MIGRATION);
            bind(GitRepositoryManager.class).toInstance(repoManager);
            bind(ProjectCache.class).toProvider(Providers.<ProjectCache>of(null));
            bind(CapabilityControl.Factory.class).toProvider(Providers.<CapabilityControl.Factory>of(null));
            bind(Config.class).annotatedWith(GerritServerConfig.class).toInstance(new Config());
            bind(String.class).annotatedWith(AnonymousCowardName.class)
                    .toProvider(AnonymousCowardNameProvider.class);
            bind(String.class).annotatedWith(CanonicalWebUrl.class).toInstance("http://localhost:8080/");
            bind(Boolean.class).annotatedWith(DisableReverseDnsLookup.class).toInstance(Boolean.FALSE);
            bind(Realm.class).to(FakeRealm.class);
            bind(GroupBackend.class).to(SystemGroupBackend.class).in(SINGLETON);
            bind(AccountCache.class).toInstance(accountCache);
            bind(PersonIdent.class).annotatedWith(GerritPersonIdent.class).toInstance(serverIdent);
            bind(GitReferenceUpdated.class).toInstance(GitReferenceUpdated.DISABLED);
        }
    });

    injector.injectMembers(this);
    repoManager.createRepository(allUsers.get());
    changeOwner = userFactory.create(co.getId());
    otherUser = userFactory.create(ou.getId());
    otherUserId = otherUser.getAccountId();
}

From source file:com.google.gerrit.server.notedb.ChangeNotesParserTest.java

License:Apache License

@Test
public void parseAuthor() throws Exception {
    assertParseSucceeds("Update change\n" + "\n" + "Patch-Set: 1\n");
    assertParseFails(writeCommit("Update change\n" + "\n" + "Patch-Set: 1\n", new PersonIdent("Change Owner",
            "owner@example.com", serverIdent.getWhen(), serverIdent.getTimeZone())));
    assertParseFails(writeCommit("Update change\n" + "\n" + "Patch-Set: 1\n",
            new PersonIdent("Change Owner", "x@gerrit", serverIdent.getWhen(), serverIdent.getTimeZone())));
}

From source file:com.google.gerrit.server.notedb.ChangeNoteUtil.java

License:Apache License

static PersonIdent newIdent(Account author, Date when, PersonIdent serverIdent, String anonymousCowardName) {
    return new PersonIdent(new AccountInfo(author).getName(anonymousCowardName),
            author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST, when, serverIdent.getTimeZone());
}

From source file:com.google.gerrit.server.notedb.CommentsInNotesUtil.java

License:Apache License

private PersonIdent newIdent(Account author, Date when) {
    return new PersonIdent(new AccountInfo(author).getName(anonymousCowardName),
            author.getId().get() + "@" + GERRIT_PLACEHOLDER_HOST, when, serverIdent.getTimeZone());
}

From source file:com.google.gitiles.blame.BlameCacheImpl.java

License:Open Source License

private static List<Region> loadRegions(BlameGenerator gen) throws IOException {
    Map<ObjectId, PooledCommit> commits = Maps.newHashMap();
    Interner<String> strings = Interners.newStrongInterner();
    int lineCount = gen.getResultContents().size();

    List<Region> regions = Lists.newArrayList();
    while (gen.next()) {
        String path = gen.getSourcePath();
        PersonIdent author = gen.getSourceAuthor();
        ObjectId commit = gen.getSourceCommit();
        checkState(path != null && author != null && commit != null);

        PooledCommit pc = commits.get(commit);
        if (pc == null) {
            pc = new PooledCommit(commit.copy(), new PersonIdent(strings.intern(author.getName()),
                    strings.intern(author.getEmailAddress()), author.getWhen(), author.getTimeZone()));
            commits.put(pc.commit, pc);/* ww  w .j ava 2  s  .  c o m*/
        }
        path = strings.intern(path);
        commit = pc.commit;
        author = pc.author;
        regions.add(new Region(path, commit, author, gen.getResultStart(), gen.getResultEnd()));
    }
    Collections.sort(regions);

    // Fill in any gaps left by bugs in JGit, since rendering code assumes the
    // full set of contiguous regions.
    List<Region> result = Lists.newArrayListWithExpectedSize(regions.size());
    Region last = null;
    for (Region r : regions) {
        if (last != null) {
            checkState(last.getEnd() <= r.getStart());
            if (last.getEnd() < r.getStart()) {
                result.add(new Region(null, null, null, last.getEnd(), r.getStart()));
            }
        }
        result.add(r);
        last = r;
    }
    if (last != null && last.getEnd() != lineCount) {
        result.add(new Region(null, null, null, last.getEnd(), lineCount));
    }

    return ImmutableList.copyOf(result);
}