Search in sources :

Example 11 with BlameScmResult

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

the class IntegrityBlameCommand method doShellAnnotate.

/**
 * Execute 'si annotate' command in current shell and process output as {@link BlameScmResult} instance.
 *
 * @param iRepo            the Integrity repository instance.
 * @param workingDirectory the SCM working directory.
 * @param filename         the file name.
 * @return the {@link BlameScmResult} instance.
 */
private BlameScmResult doShellAnnotate(IntegrityScmProviderRepository iRepo, ScmFileSet workingDirectory, String filename) {
    BlameScmResult result;
    Commandline shell = new Commandline();
    shell.setWorkingDirectory(workingDirectory.getBasedir());
    shell.setExecutable("si");
    shell.createArg().setValue("annotate");
    shell.createArg().setValue("--hostname=" + iRepo.getHost());
    shell.createArg().setValue("--port=" + iRepo.getPort());
    shell.createArg().setValue("--user=" + iRepo.getUser());
    shell.createArg().setValue("--fields=date,revision,author");
    shell.createArg().setValue('"' + filename + '"');
    IntegrityBlameConsumer shellConsumer = new IntegrityBlameConsumer(getLogger());
    try {
        getLogger().debug("Executing: " + CommandLineUtils.toString(shell.getCommandline()));
        int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
        boolean success = (exitCode == 0 ? true : false);
        ScmResult scmResult = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
        return new BlameScmResult(shellConsumer.getBlameList(), scmResult);
    } catch (CommandLineException cle) {
        getLogger().error("Command Line Exception: " + cle.getMessage());
        result = new BlameScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
    }
    return result;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) ScmResult(org.apache.maven.scm.ScmResult) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException)

Example 12 with BlameScmResult

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

the class JGitBlameCommand method executeBlameCommand.

@Override
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    Git git = null;
    File basedir = workingDirectory.getBasedir();
    try {
        git = JGitUtils.openRepo(basedir);
        BlameResult blameResult = git.blame().setFilePath(filename).call();
        List<BlameLine> lines = new ArrayList<BlameLine>();
        int i = 0;
        while ((i = blameResult.computeNext()) != -1) {
            lines.add(new BlameLine(blameResult.getSourceAuthor(i).getWhen(), blameResult.getSourceCommit(i).getName(), blameResult.getSourceAuthor(i).getName(), blameResult.getSourceCommitter(i).getName()));
        }
        return new BlameScmResult("JGit blame", lines);
    } catch (Exception e) {
        throw new ScmException("JGit blame failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) BlameResult(org.eclipse.jgit.blame.BlameResult) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) ArrayList(java.util.ArrayList) File(java.io.File) ScmException(org.apache.maven.scm.ScmException)

Example 13 with BlameScmResult

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

the class GitBlameCommand method executeBlameCommand.

/**
 * {@inheritDoc}
 */
public BlameScmResult executeBlameCommand(ScmProviderRepository repo, ScmFileSet workingDirectory, String filename) throws ScmException {
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.FILE, filename);
    commandParameters.setString(CommandParameter.IGNORE_WHITESPACE, Boolean.FALSE.toString());
    return (BlameScmResult) execute(repo, workingDirectory, commandParameters);
}
Also used : BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandParameters(org.apache.maven.scm.CommandParameters)

Example 14 with BlameScmResult

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

the class AccuRevBlameCommandTest method testBlame.

@Test
public void testBlame() throws Exception {
    final File file = new File("src/main/java/Foo.java");
    final ScmFileSet testFileSet = new ScmFileSet(basedir, file);
    final Date date = new Date();
    final BlameLine blameLine = new BlameLine(date, "12", "theAuthor");
    when(accurev.annotate(basedir, file)).thenReturn(Collections.singletonList(blameLine));
    AccuRevBlameCommand command = new AccuRevBlameCommand(getLogger());
    CommandParameters commandParameters = new CommandParameters();
    commandParameters.setString(CommandParameter.FILE, file.getPath());
    BlameScmResult result = command.blame(repo, testFileSet, commandParameters);
    assertThat(result.isSuccess(), is(true));
    assertThat(result.getLines().size(), is(1));
    assertThat(((BlameLine) result.getLines().get(0)), is(blameLine));
}
Also used : BlameLine(org.apache.maven.scm.command.blame.BlameLine) ScmFileSet(org.apache.maven.scm.ScmFileSet) BlameScmResult(org.apache.maven.scm.command.blame.BlameScmResult) CommandParameters(org.apache.maven.scm.CommandParameters) File(java.io.File) Date(java.util.Date) Test(org.junit.Test) AbstractAccuRevCommandTest(org.apache.maven.scm.provider.accurev.command.AbstractAccuRevCommandTest)

Example 15 with BlameScmResult

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

the class BazaarScmProvider method blame.

/**
 * {@inheritDoc}
 */
protected BlameScmResult blame(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    BazaarBlameCommand command = new BazaarBlameCommand();
    command.setLogger(getLogger());
    return (BlameScmResult) command.execute(repository, fileSet, parameters);
}
Also used : BazaarBlameCommand(org.apache.maven.scm.provider.bazaar.command.blame.BazaarBlameCommand) 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