Search in sources :

Example 6 with IFileHistoryProvider

use of org.eclipse.team.core.history.IFileHistoryProvider in project pmd-eclipse-plugin by pmd.

the class RepositoryUtil method authorNameFor.

/**
 * Returns the name of the resource author if the resource was parked in a
 * repository or null if it wasn't.
 *
 * @param resource
 * @return String
 */
public static String authorNameFor(IResource resource) {
    IProject project = resource.getProject();
    String authorName = null;
    try {
        RepositoryProvider provider = RepositoryProvider.getProvider(project);
        if (provider == null) {
            return null;
        }
        IFileHistoryProvider fhProvider = provider.getFileHistoryProvider();
        if (fhProvider == null) {
            return null;
        }
        IFileRevision revision = fhProvider.getWorkspaceFileRevision(resource);
        authorName = revision.getAuthor();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return authorName;
}
Also used : IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) RepositoryProvider(org.eclipse.team.core.RepositoryProvider) IProject(org.eclipse.core.resources.IProject)

Example 7 with IFileHistoryProvider

use of org.eclipse.team.core.history.IFileHistoryProvider in project egit by eclipse.

the class HistoryTest method testDeepHistory_B.

@Test
public void testDeepHistory_B() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/B.txt"), IFileHistoryProvider.NONE, new NullProgressMonitor());
    IFileRevision[] fileRevisions = fileHistory.getFileRevisions();
    assertEquals(2, fileRevisions.length);
    assertEquals("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f", fileRevisions[0].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
    assertEquals("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359", fileRevisions[1].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 8 with IFileHistoryProvider

use of org.eclipse.team.core.history.IFileHistoryProvider in project egit by eclipse.

the class HistoryTest method testSingleRevision_3.

@Test
public void testSingleRevision_3() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/B.txt"), IFileHistoryProvider.SINGLE_LINE_OF_DESCENT, new NullProgressMonitor());
    IFileRevision fileRevision = fileHistory.getFileRevision("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f");
    assertEquals("fd5a571c8a3a4a152e4c413d09d3ecb7d41e1e5f", fileRevision.getContentIdentifier());
    assertEquals("J. Author", fileRevision.getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Example 9 with IFileHistoryProvider

use of org.eclipse.team.core.history.IFileHistoryProvider in project egit by eclipse.

the class HistoryTest method testDeepHistory_A.

@Test
public void testDeepHistory_A() {
    GitProvider provider = (GitProvider) RepositoryProvider.getProvider(project.project);
    assertNotNull(provider);
    IFileHistoryProvider fileHistoryProvider = provider.getFileHistoryProvider();
    IFileHistory fileHistory = fileHistoryProvider.getFileHistoryFor(project.getProject().getWorkspace().getRoot().findMember("Project-1/A.txt"), IFileHistoryProvider.NONE, new NullProgressMonitor());
    IFileRevision[] fileRevisions = fileHistory.getFileRevisions();
    assertEquals(1, fileRevisions.length);
    assertEquals("60f0d7917fe2aed5c92b5bc35dfb55b9b8ada359", fileRevisions[0].getContentIdentifier());
    assertEquals("J. Author", fileRevisions[0].getAuthor());
}
Also used : IFileHistory(org.eclipse.team.core.history.IFileHistory) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFileHistoryProvider(org.eclipse.team.core.history.IFileHistoryProvider) IFileRevision(org.eclipse.team.core.history.IFileRevision) GitProvider(org.eclipse.egit.core.GitProvider) Test(org.junit.Test)

Aggregations

IFileHistoryProvider (org.eclipse.team.core.history.IFileHistoryProvider)9 IFileRevision (org.eclipse.team.core.history.IFileRevision)9 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)8 GitProvider (org.eclipse.egit.core.GitProvider)8 IFileHistory (org.eclipse.team.core.history.IFileHistory)8 Test (org.junit.Test)8 IStorage (org.eclipse.core.resources.IStorage)2 IProject (org.eclipse.core.resources.IProject)1 RepositoryProvider (org.eclipse.team.core.RepositoryProvider)1