Search in sources :

Example 21 with BlameScmResult

use of org.apache.maven.scm.command.blame.BlameScmResult 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 22 with BlameScmResult

use of org.apache.maven.scm.command.blame.BlameScmResult 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 23 with BlameScmResult

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

the class PerforceScmProvider method blame.

protected BlameScmResult blame(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters params) throws ScmException {
    PerforceBlameCommand command = new PerforceBlameCommand();
    command.setLogger(getLogger());
    return (BlameScmResult) command.execute(repository, fileSet, params);
}
Also used : BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) PerforceBlameCommand(org.apache.maven.scm.provider.perforce.command.blame.PerforceBlameCommand)

Example 24 with BlameScmResult

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

the class GitBlameCommand method executeCommand.

@Override
protected ScmResult executeCommand(ScmProviderRepository repository, ScmFileSet workingDirectory, CommandParameters parameters) throws ScmException {
    String filename = parameters.getString(CommandParameter.FILE);
    Commandline cl = createCommandLine(workingDirectory.getBasedir(), filename, parameters.getBoolean(CommandParameter.IGNORE_WHITESPACE, false));
    GitBlameConsumer consumer = new GitBlameConsumer(getLogger());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    int exitCode = GitCommandLineUtils.execute(cl, consumer, stderr, getLogger());
    if (exitCode != 0) {
        return new BlameScmResult(cl.toString(), "The git blame command failed.", stderr.getOutput(), false);
    }
    return new BlameScmResult(cl.toString(), consumer.getLines());
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) GitCommandLineUtils(org.apache.maven.scm.provider.git.gitexe.command.GitCommandLineUtils) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult)

Aggregations

BlameScmResult (org.apache.maven.scm.command.blame.BlameScmResult)24 ScmException (org.apache.maven.scm.ScmException)7 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)7 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)6 Commandline (org.codehaus.plexus.util.cli.Commandline)6 BlameLine (org.apache.maven.scm.command.blame.BlameLine)5 File (java.io.File)3 ScmResult (org.apache.maven.scm.ScmResult)3 Date (java.util.Date)2 CommandParameters (org.apache.maven.scm.CommandParameters)2 ScmFileSet (org.apache.maven.scm.ScmFileSet)2 CvsBlameConsumer (org.apache.maven.scm.provider.cvslib.command.blame.CvsBlameConsumer)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStreamReader (java.io.InputStreamReader)1 ArrayList (java.util.ArrayList)1 BlameScmRequest (org.apache.maven.scm.command.blame.BlameScmRequest)1 CheckInScmResult (org.apache.maven.scm.command.checkin.CheckInScmResult)1 ScmManager (org.apache.maven.scm.manager.ScmManager)1 ScmProvider (org.apache.maven.scm.provider.ScmProvider)1