Search in sources :

Example 16 with DiffScmResult

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;
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) ScmResult(org.apache.maven.scm.ScmResult) IntegrityScmProviderRepository(org.apache.maven.scm.provider.integrity.repository.IntegrityScmProviderRepository) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) ScmFile(org.apache.maven.scm.ScmFile) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) APISession(org.apache.maven.scm.provider.integrity.APISession) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 17 with DiffScmResult

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());
}
Also used : ScmException(org.apache.maven.scm.ScmException) Commandline(org.codehaus.plexus.util.cli.Commandline) SvnDiffConsumer(org.apache.maven.scm.provider.svn.command.diff.SvnDiffConsumer) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) SvnCommandLineUtils(org.apache.maven.scm.provider.svn.svnexe.command.SvnCommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 18 with DiffScmResult

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);
}
Also used : StarteamDiffCommand(org.apache.maven.scm.provider.starteam.command.diff.StarteamDiffCommand) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 19 with DiffScmResult

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);
    }
}
Also used : ScmRepository(org.apache.maven.scm.repository.ScmRepository) ScmException(org.apache.maven.scm.ScmException) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) IOException(java.io.IOException) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 20 with DiffScmResult

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);
}
Also used : Commandline(org.codehaus.plexus.util.cli.Commandline) CommandLineUtils(org.codehaus.plexus.util.cli.CommandLineUtils) CommandLineException(org.codehaus.plexus.util.cli.CommandLineException) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Aggregations

DiffScmResult (org.apache.maven.scm.command.diff.DiffScmResult)21 ScmException (org.apache.maven.scm.ScmException)6 CommandLineUtils (org.codehaus.plexus.util.cli.CommandLineUtils)6 Commandline (org.codehaus.plexus.util.cli.Commandline)5 ScmFile (org.apache.maven.scm.ScmFile)4 CommandLineException (org.codehaus.plexus.util.cli.CommandLineException)4 File (java.io.File)3 ScmResult (org.apache.maven.scm.ScmResult)3 ScmRepository (org.apache.maven.scm.repository.ScmRepository)3 IOException (java.io.IOException)2 ScmFileSet (org.apache.maven.scm.ScmFileSet)2 ScmProvider (org.apache.maven.scm.provider.ScmProvider)2 CvsDiffConsumer (org.apache.maven.scm.provider.cvslib.command.diff.CvsDiffConsumer)2 GitDiffConsumer (org.apache.maven.scm.provider.git.command.diff.GitDiffConsumer)2 BufferedReader (java.io.BufferedReader)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStreamReader (java.io.InputStreamReader)1 OutputStream (java.io.OutputStream)1 HashMap (java.util.HashMap)1