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());
}
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());
}
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!");
}
}
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;
}
}
}
Aggregations