use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.
the class IntegrityDiffCommand method executeDiffCommand.
/**
* Since we can't arbitrarily apply the same start and end revisions to all files in the sandbox,
* this command will be adapted to show differences between the local version and the repository
*/
@Override
public DiffScmResult executeDiffCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
DiffScmResult result;
IntegrityScmProviderRepository iRepo = (IntegrityScmProviderRepository) repository;
APISession api = iRepo.getAPISession();
getLogger().info("Showing differences bettween local files in " + fileSet.getBasedir().getAbsolutePath() + " and server project " + iRepo.getConfigruationPath());
// Since the si diff command is not completely API ready, we will use the CLI for this command
Commandline shell = new Commandline();
shell.setWorkingDirectory(fileSet.getBasedir());
shell.setExecutable("si");
shell.createArg().setValue("diff");
shell.createArg().setValue("--hostname=" + api.getHostName());
shell.createArg().setValue("--port=" + api.getPort());
shell.createArg().setValue("--user=" + api.getUserName());
shell.createArg().setValue("-R");
shell.createArg().setValue("--filter=changed:all");
shell.createArg().setValue("--filter=format:text");
IntegrityDiffConsumer shellConsumer = new IntegrityDiffConsumer(getLogger());
try {
getLogger().debug("Executing: " + shell.getCommandline());
int exitCode = CommandLineUtils.executeCommandLine(shell, shellConsumer, new CommandLineUtils.StringStreamConsumer());
boolean success = (exitCode == 128 ? false : true);
ScmResult scmResult = new ScmResult(shell.getCommandline().toString(), "", "Exit Code: " + exitCode, success);
// a NPE in org.codehaus.plexus.util.FileUtils.fileWrite(FileUtils.java:426)
return new DiffScmResult(new ArrayList<ScmFile>(), new HashMap<String, CharSequence>(), "", scmResult);
} catch (CommandLineException cle) {
getLogger().error("Command Line Exception: " + cle.getMessage());
result = new DiffScmResult(shell.getCommandline().toString(), cle.getMessage(), "", false);
}
return result;
}
use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.
the class SvnDiffCommand method executeDiffCommand.
/**
* {@inheritDoc}
*/
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startVersion, ScmVersion endVersion) throws ScmException {
Commandline cl = createCommandLine((SvnScmProviderRepository) repo, fileSet.getBasedir(), startVersion, endVersion);
SvnDiffConsumer consumer = new SvnDiffConsumer(getLogger(), fileSet.getBasedir());
CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + SvnCommandLineUtils.cryptPassword(cl));
if (Os.isFamily(Os.FAMILY_WINDOWS)) {
getLogger().info("Working directory: " + cl.getWorkingDirectory().getAbsolutePath());
}
}
int exitCode;
try {
exitCode = SvnCommandLineUtils.execute(cl, consumer, stderr, getLogger());
} catch (CommandLineException ex) {
throw new ScmException("Error while executing command.", ex);
}
if (exitCode != 0) {
return new DiffScmResult(cl.toString(), "The svn command failed.", stderr.getOutput(), false);
}
return new DiffScmResult(cl.toString(), consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch());
}
use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.
the class StarteamScmProvider method diff.
/**
* {@inheritDoc}
*/
public DiffScmResult diff(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
fileSet = fixUpScmFileSetAbsoluteFilePath(fileSet);
StarteamDiffCommand command = new StarteamDiffCommand();
command.setLogger(getLogger());
return (DiffScmResult) command.execute(repository, fileSet, parameters);
}
use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.
the class DiffMojo method execute.
/**
* {@inheritDoc}
*/
public void execute() throws MojoExecutionException {
super.execute();
try {
ScmRepository repository = getScmRepository();
DiffScmResult result = getScmManager().diff(repository, getFileSet(), getScmVersion(startScmVersionType, startScmVersion), getScmVersion(endScmVersionType, endScmVersion));
checkResult(result);
getLog().info(result.getPatch());
try {
if (outputFile != null) {
FileUtils.fileWrite(outputFile.getAbsolutePath(), result.getPatch());
}
} catch (IOException e) {
throw new MojoExecutionException("Can't write patch file.", e);
}
} catch (IOException e) {
throw new MojoExecutionException("Cannot run diff command : ", e);
} catch (ScmException e) {
throw new MojoExecutionException("Cannot run diff command : ", e);
}
}
use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.
the class PerforceDiffCommand method executeDiffCommand.
/**
* {@inheritDoc}
*/
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet files, ScmVersion startRev, ScmVersion endRev) throws ScmException {
Commandline cl = createCommandLine((PerforceScmProviderRepository) repo, files.getBasedir(), startRev, endRev);
PerforceDiffConsumer consumer = new PerforceDiffConsumer();
if (getLogger().isInfoEnabled()) {
getLogger().info("Executing: " + PerforceScmProvider.clean(cl.toString()));
}
boolean success = false;
try {
CommandLineUtils.StringStreamConsumer err = new CommandLineUtils.StringStreamConsumer();
int exitCode = CommandLineUtils.executeCommandLine(cl, consumer, err);
if (exitCode != 0) {
String cmdLine = CommandLineUtils.toString(cl.getCommandline());
StringBuilder msg = new StringBuilder("Exit code: " + exitCode + " - " + err.getOutput());
msg.append('\n');
msg.append("Command line was:" + cmdLine);
throw new CommandLineException(msg.toString());
}
} catch (CommandLineException e) {
if (getLogger().isErrorEnabled()) {
getLogger().error("CommandLineException " + e.getMessage(), e);
}
}
return new DiffScmResult(cl.toString(), success ? "Diff successful" : "Unable to diff", consumer.getOutput(), success);
}
Aggregations