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