Search in sources :

Example 26 with BlameLine

use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.

the class GitBlameConsumerTest method testConsumerWithDifferentAuthor.

/**
 * Test a case where the committer and author are different persons
 */
public void testConsumerWithDifferentAuthor() throws Exception {
    GitBlameConsumer consumer = consumeFile("/src/test/resources/git/blame/git-blame-different-author.out");
    Assert.assertEquals(93, consumer.getLines().size());
    BlameLine blameLine = consumer.getLines().get(0);
    Assert.assertNotNull(blameLine);
    Assert.assertEquals("39574726d20f62023d39311e6032c7ab0a9d3cdb", blameLine.getRevision());
    Assert.assertEquals("Mark Struberg", blameLine.getAuthor());
    Assert.assertEquals("Mark Struberg", blameLine.getCommitter());
    blameLine = consumer.getLines().get(12);
    Assert.assertNotNull(blameLine);
    Assert.assertEquals("41e5bc05953781a5702f597a1a36c55371b517d3", blameLine.getRevision());
    Assert.assertEquals("Another User", blameLine.getAuthor());
    Assert.assertEquals("Mark Struberg", blameLine.getCommitter());
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine)

Example 27 with BlameLine

use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.

the class GitBlameConsumerTest method testConsumerEasy.

public void testConsumerEasy() throws Exception {
    GitBlameConsumer consumer = consumeFile("/src/test/resources/git/blame/git-blame-3.out");
    Assert.assertEquals(36, consumer.getLines().size());
    BlameLine blameLine = consumer.getLines().get(11);
    Assert.assertEquals("e670863b2b03e158c59f34af1fee20f91b2bd852", blameLine.getRevision());
    Assert.assertEquals("Mark Struberg", blameLine.getAuthor());
    Assert.assertNotNull(blameLine.getDate());
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine)

Example 28 with BlameLine

use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.

the class GitBlameConsumerTest method testConsumerCompareWithOriginal.

/**
 * This unit test compares the output of our new parsing with a
 * simplified git blame output.
 */
public void testConsumerCompareWithOriginal() throws Exception {
    GitBlameConsumer consumer = consumeFile("/src/test/resources/git/blame/git-blame-2.out");
    Assert.assertNotNull(consumer);
    List<BlameLine> consumerLines = consumer.getLines();
    Iterator<BlameLine> consumerLineIt = consumerLines.iterator();
    File compareWithFile = getTestFile("/src/test/resources/git/blame/git-blame-2.orig");
    Assert.assertNotNull(compareWithFile);
    BufferedReader r = new BufferedReader(new FileReader(compareWithFile));
    String line;
    SimpleDateFormat blameDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    blameDateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
    int lineNr = 0;
    while ((line = r.readLine()) != null && line.trim().length() > 0) {
        if (!consumerLineIt.hasNext()) {
            fail("GitBlameConsumer lines do not match the original output!");
        }
        BlameLine blameLine = consumerLineIt.next();
        Assert.assertNotNull(blameLine);
        String[] parts = line.split("\t");
        Assert.assertEquals(3, parts.length);
        Assert.assertEquals("error in line " + lineNr, parts[0], blameLine.getRevision());
        Assert.assertEquals("error in line " + lineNr, parts[1], blameLine.getAuthor());
        Assert.assertEquals("error in line " + lineNr, parts[2], blameDateFormat.format(blameLine.getDate()));
        lineNr++;
    }
    if (consumerLineIt.hasNext()) {
        fail("GitBlameConsumer found more lines than in the original output!");
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) BufferedReader(java.io.BufferedReader) FileReader(java.io.FileReader) File(java.io.File) SimpleDateFormat(java.text.SimpleDateFormat)

Example 29 with BlameLine

use of org.apache.maven.scm.command.blame.BlameLine in project maven-scm by apache.

the class GitBlameConsumer method consumeLine.

public void consumeLine(String line) {
    if (line == null) {
        return;
    }
    if (expectRevisionLine) {
        // this is the revision line
        String[] parts = line.split("\\s", 4);
        if (parts.length >= 1) {
            revision = parts[0];
            BlameLine oldLine = commitInfo.get(revision);
            if (oldLine != null) {
                // restore the commit info
                author = oldLine.getAuthor();
                committer = oldLine.getCommitter();
                time = oldLine.getDate();
            }
            expectRevisionLine = false;
        }
    } else {
        if (line.startsWith(GIT_AUTHOR)) {
            author = line.substring(GIT_AUTHOR.length());
            return;
        }
        if (line.startsWith(GIT_COMMITTER)) {
            committer = line.substring(GIT_COMMITTER.length());
            return;
        }
        if (line.startsWith(GIT_COMMITTER_TIME)) {
            String timeStr = line.substring(GIT_COMMITTER_TIME.length());
            time = new Date(Long.parseLong(timeStr) * 1000L);
            return;
        }
        if (line.startsWith("\t")) {
            // this is the content line.
            // we actually don't need the content, but this is the right time to add the blame line
            BlameLine blameLine = new BlameLine(time, revision, author, committer);
            getLines().add(blameLine);
            // keep commitinfo for this sha-1
            commitInfo.put(revision, blameLine);
            if (getLogger().isDebugEnabled()) {
                DateFormat df = SimpleDateFormat.getDateTimeInstance();
                getLogger().debug(author + " " + df.format(time));
            }
            expectRevisionLine = true;
        }
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) Date(java.util.Date)

Aggregations

BlameLine (org.apache.maven.scm.command.blame.BlameLine)29 Date (java.util.Date)11 Matcher (java.util.regex.Matcher)7 File (java.io.File)5 BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)5 DefaultLog (org.apache.maven.scm.log.DefaultLog)4 BufferedReader (java.io.BufferedReader)3 InputStreamReader (java.io.InputStreamReader)2 SimpleDateFormat (java.text.SimpleDateFormat)2 ArrayList (java.util.ArrayList)2 ScmException (org.apache.maven.scm.ScmException)2 ScmFileSet (org.apache.maven.scm.ScmFileSet)2 Test (org.junit.Test)2 FileInputStream (java.io.FileInputStream)1 FileReader (java.io.FileReader)1 InputStream (java.io.InputStream)1 DateFormat (java.text.DateFormat)1 CommandParameters (org.apache.maven.scm.CommandParameters)1 BlameScmRequest (org.apache.maven.scm.command.blame.BlameScmRequest)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1