Search in sources :

Example 1 with BlameLine

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

the class SvnBlameConsumer method consumeLine.

public void consumeLine(String line) {
    Matcher matcher;
    if ((matcher = LINE_PATTERN.matcher(line)).find()) {
        String lineNumberStr = matcher.group(1);
        lineNumber = Integer.parseInt(lineNumberStr);
    } else if ((matcher = REVISION_PATTERN.matcher(line)).find()) {
        revision = matcher.group(1);
    } else if ((matcher = AUTHOR_PATTERN.matcher(line)).find()) {
        author = matcher.group(1);
    } else if ((matcher = DATE_PATTERN.matcher(line)).find()) {
        String date = matcher.group(1);
        String time = matcher.group(2);
        Date dateTime = parseDateTime(date + " " + time);
        lines.add(new BlameLine(dateTime, revision, author));
        if (getLogger().isDebugEnabled()) {
            getLogger().debug("Author of line " + lineNumber + ": " + author + " (" + date + ")");
        }
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) Matcher(java.util.regex.Matcher) Date(java.util.Date)

Example 2 with BlameLine

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

the class PerforceBlameCommand method executeBlameCommand.

public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    // Call annotate command
    PerforceScmProviderRepository p4repo = (PerforceScmProviderRepository) repo;
    String clientspec = PerforceScmProvider.getClientspecName(getLogger(), p4repo, workingDirectory.getBasedir());
    Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
    PerforceBlameConsumer blameConsumer = new PerforceBlameConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode;
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, blameConsumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
    }
    // Call filelog command
    cl = createFilelogCommandLine((PerforceScmProviderRepository) repo, workingDirectory.getBasedir(), filename, clientspec);
    PerforceFilelogConsumer filelogConsumer = new PerforceFilelogConsumer(getLogger());
    try {
        exitCode = CommandLineUtils.executeCommandLine(cl, filelogConsumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The perforce command failed.", stderr.getOutput(), false);
    }
    // Combine results
    List<BlameLine> lines = blameConsumer.getLines();
    for (int i = 0; i < lines.size(); i++) {
        BlameLine line = lines.get(i);
        String revision = line.getRevision();
        line.setAuthor(filelogConsumer.getAuthor(revision));
        line.setDate(filelogConsumer.getDate(revision));
    }
    return new BlameScmResult(cl.toString(), lines);
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) BlameLine(org.apache.maven.scm.command.blame.BlameLine) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) PerforceScmProviderRepository(org.apache.maven.scm.provider.perforce.repository.PerforceScmProviderRepository)

Example 3 with BlameLine

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

the class BazaarBlameCommandTckTest method verifyResult.

protected void verifyResult(BlameScmResult result) {
    List<BlameLine> lines = result.getLines();
    assertEquals("Expected 1 line in blame", 1, lines.size());
    BlameLine line = lines.get(0);
    assertEquals("1", line.getRevision());
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine)

Example 4 with BlameLine

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

the class AnnotateConsumerTest method testParse.

@Test
public void testParse() throws Exception {
    List<BlameLine> consumedLines = new ArrayList<BlameLine>();
    AnnotateConsumer consumer = new AnnotateConsumer(consumedLines, new DefaultLog());
    AccuRevJUnitUtil.consume("/annotate.txt", consumer);
    Assert.assertEquals(12, consumer.getLines().size());
    BlameLine line1 = (BlameLine) consumer.getLines().get(0);
    Assert.assertEquals("2", line1.getRevision());
    Assert.assertEquals("godin", line1.getAuthor());
    assertThat(line1.getDate(), is(AccuRev.ACCUREV_TIME_SPEC.parse("2008/10/26 16:26:44")));
    BlameLine line12 = (BlameLine) consumer.getLines().get(11);
    Assert.assertEquals("1", line12.getRevision());
    Assert.assertEquals("godin", line12.getAuthor());
    assertThat(line12.getDate(), is(AccuRev.ACCUREV_TIME_SPEC.parse("2008/10/17 11:41:50")));
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) DefaultLog(org.apache.maven.scm.log.DefaultLog) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 5 with BlameLine

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

the class AnnotateConsumer method consumeLine.

public void consumeLine(String line) {
    final Matcher matcher = LINE_PATTERN.matcher(line);
    if (matcher.matches()) {
        String revision = matcher.group(1).trim();
        String author = matcher.group(2).trim();
        String dateStr = matcher.group(3).trim();
        Date date = parseDate(dateStr, null, AccuRev.ACCUREV_TIME_FORMAT_STRING);
        lines.add(new BlameLine(date, revision, author));
    } else {
        throw new RuntimeException("Unable to parse annotation from line: " + line);
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) Matcher(java.util.regex.Matcher) 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