Search in sources :

Example 21 with BlameLine

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

the class CvsBlameConsumer method consumeLine.

public void consumeLine(String line) {
    if (line != null && line.indexOf(':') > 0) {
        String annotation = line.substring(0, line.indexOf(':'));
        Matcher matcher = LINE_PATTERN.matcher(annotation);
        if (matcher.matches()) {
            String revision = matcher.group(1).trim();
            String author = matcher.group(2).trim();
            String dateTimeStr = matcher.group(3).trim();
            Date dateTime = parseDate(dateTimeStr, null, CVS_TIMESTAMP_PATTERN, Locale.US);
            lines.add(new BlameLine(dateTime, revision, author));
            if (getLogger().isDebugEnabled()) {
                getLogger().debug(author + " " + dateTimeStr);
            }
        }
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) Matcher(java.util.regex.Matcher) Date(java.util.Date)

Example 22 with BlameLine

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

the class BlameCommandTckTest method testBlameCommand.

public void testBlameCommand() throws Exception {
    ScmRepository repository = getScmRepository();
    ScmManager manager = getScmManager();
    ScmProvider provider = manager.getProviderByRepository(getScmRepository());
    ScmFileSet fileSet = new ScmFileSet(getWorkingCopy());
    BlameScmResult result;
    BlameLine line;
    // === readme.txt ===
    BlameScmRequest blameScmRequest = new BlameScmRequest(repository, fileSet);
    blameScmRequest.setFilename("readme.txt");
    // result = manager.blame( repository, fileSet, "readme.txt" );
    result = manager.blame(blameScmRequest);
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    assertEquals("Expected 1 line in blame", 1, result.getLines().size());
    line = result.getLines().get(0);
    String initialRevision = line.getRevision();
    // Make a timestamp that we know are after initial revision but before the second
    // Current time
    Date timeBeforeSecond = new Date();
    // pause a couple seconds...
    Thread.sleep(2000);
    // Make a change to the readme.txt and commit the change
    this.edit(getWorkingCopy(), "readme.txt", null, getScmRepository());
    ScmTestCase.makeFile(getWorkingCopy(), "/readme.txt", "changed readme.txt");
    CheckInScmResult checkInResult = provider.checkIn(getScmRepository(), fileSet, COMMIT_MSG);
    assertTrue("Unable to checkin changes to the repository", checkInResult.isSuccess());
    result = manager.blame(repository, fileSet, "readme.txt");
    // pause a couple seconds...
    Thread.sleep(2000);
    // Current time
    Date timeAfterSecond = new Date();
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    assertEquals("Expected 1 line in blame", 1, result.getLines().size());
    line = result.getLines().get(0);
    assertNotNull("Expected not null author", line.getAuthor());
    assertNotNull("Expected not null revision", line.getRevision());
    assertNotNull("Expected not null date", line.getDate());
    assertTrue("Expected another revision", !initialRevision.equals(line.getRevision()));
    if (isTestDateTime()) {
        assertDateBetween(timeBeforeSecond, timeAfterSecond, line.getDate());
    }
    // === pom.xml ===
    result = manager.blame(repository, fileSet, "pom.xml");
    assertNotNull("The command returned a null result.", result);
    assertResultIsSuccess(result);
    verifyResult(result);
}
Also used : ScmProvider(org.apache.maven.scm.provider.ScmProvider) BlameLine(org.apache.maven.scm.command.blame.BlameLine) ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmFileSet(org.apache.maven.scm.ScmFileSet) BlameScmRequest(org.apache.maven.scm.command.blame.BlameScmRequest) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) ScmManager(org.apache.maven.scm.manager.ScmManager) CheckInScmResult(org.apache.maven.scm.command.checkin.CheckInScmResult) Date(java.util.Date)

Example 23 with BlameLine

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

the class AccuRevBlameCommand method executeAccurevCommand.

@Override
protected BlameScmResult executeAccurevCommand(AccuRevScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException, AccuRevException {
    AccuRev accuRev = repository.getAccuRev();
    File file = new File(parameters.getString(CommandParameter.FILE));
    List<BlameLine> lines = accuRev.annotate(fileSet.getBasedir(), file);
    if (lines != null) {
        return new BlameScmResult(accuRev.getCommandLines(), lines);
    } else {
        return new BlameScmResult(accuRev.getCommandLines(), "AccuRev Error", accuRev.getErrorOutput(), false);
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) AccuRev(org.apache.maven.scm.provider.accurev.AccuRev) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) File(java.io.File)

Example 24 with BlameLine

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

the class PerforceBlameConsumer method consumeLine.

/**
 * {@inheritDoc}
 */
public void consumeLine(String line) {
    Matcher matcher = LINE_PATTERN.matcher(line);
    if (matcher.find()) {
        String revision = matcher.group(1).trim();
        lines.add(new BlameLine(null, revision, null));
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) Matcher(java.util.regex.Matcher)

Example 25 with BlameLine

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

the class PerforceBlameConsumerTest method testParse.

public void testParse() throws IOException {
    File testFile = getTestFile("src/test/resources/perforce/annotatelog.txt");
    PerforceBlameConsumer consumer = new PerforceBlameConsumer(new DefaultLog());
    FileInputStream fis = new FileInputStream(testFile);
    BufferedReader in = new BufferedReader(new InputStreamReader(fis));
    String s = in.readLine();
    while (s != null) {
        consumer.consumeLine(s);
        s = in.readLine();
    }
    Assert.assertEquals(2, consumer.getLines().size());
    BlameLine line1 = (BlameLine) consumer.getLines().get(0);
    Assert.assertEquals("1", line1.getRevision());
    BlameLine line2 = (BlameLine) consumer.getLines().get(1);
    Assert.assertEquals("2", line2.getRevision());
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) DefaultLog(org.apache.maven.scm.log.DefaultLog)

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