Search in sources :

Example 1 with DiffScmResult

use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.

the class BazaarDiffCommand method executeDiffCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeDiffCommand(ScmProviderRepository repo, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    String[] diffCmd;
    if (startRevision != null && StringUtils.isNotEmpty(startRevision.getName())) {
        String revArg = startRevision.getName();
        if (endRevision != null && StringUtils.isNotEmpty(endRevision.getName())) {
            revArg += ".." + endRevision.getName();
        }
        diffCmd = new String[] { BazaarConstants.DIFF_CMD, BazaarConstants.REVISION_OPTION, revArg };
    } else {
        diffCmd = new String[] { BazaarConstants.DIFF_CMD };
    }
    diffCmd = BazaarUtils.expandCommandLine(diffCmd, fileSet);
    BazaarDiffConsumer consumer = new BazaarDiffConsumer(getLogger(), fileSet.getBasedir());
    ScmResult result = BazaarUtils.execute(consumer, getLogger(), fileSet.getBasedir(), diffCmd);
    return new DiffScmResult(consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch(), result);
}
Also used : ScmResult(org.apache.maven.scm.ScmResult) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 2 with DiffScmResult

use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.

the class JGitDiffCommand method callDiff.

public DiffScmResult callDiff(Git git, ScmVersion startRevision, ScmVersion endRevision) throws IOException, GitAPIException, ScmException {
    AbstractTreeIterator oldTree = null;
    if (startRevision != null && StringUtils.isNotEmpty(startRevision.getName().trim())) {
        String startRev = startRevision.getName().trim();
        oldTree = getTreeIterator(git.getRepository(), startRev);
    }
    AbstractTreeIterator newTree = null;
    if (endRevision != null && StringUtils.isNotEmpty(endRevision.getName().trim())) {
        String endRev = endRevision.getName().trim();
        newTree = getTreeIterator(git.getRepository(), endRev);
    }
    OutputStream out = new ByteArrayOutputStream();
    git.diff().setOutputStream(out).setOldTree(oldTree).setNewTree(newTree).setCached(false).call();
    git.diff().setOutputStream(out).setOldTree(oldTree).setNewTree(newTree).setCached(true).call();
    out.flush();
    GitDiffConsumer consumer = new GitDiffConsumer(getLogger(), null);
    String fullDiff = out.toString();
    out.close();
    String[] lines = fullDiff.split("\n");
    for (String aLine : lines) {
        consumer.consumeLine(aLine);
    }
    return new DiffScmResult("JGit diff", consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch());
}
Also used : AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) GitDiffConsumer(org.apache.maven.scm.provider.git.command.diff.GitDiffConsumer) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 3 with DiffScmResult

use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.

the class JGitDiffCommand method executeDiffCommand.

@Override
protected DiffScmResult executeDiffCommand(ScmProviderRepository repository, ScmFileSet fileSet, ScmVersion startRevision, ScmVersion endRevision) throws ScmException {
    Git git = null;
    try {
        git = JGitUtils.openRepo(fileSet.getBasedir());
        DiffScmResult diff = callDiff(git, startRevision, endRevision);
        git.getRepository().close();
        return diff;
    } catch (Exception e) {
        throw new ScmException("JGit diff failure!", e);
    } finally {
        JGitUtils.closeRepo(git);
    }
}
Also used : ScmException(org.apache.maven.scm.ScmException) Git(org.eclipse.jgit.api.Git) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult) GitAPIException(org.eclipse.jgit.api.errors.GitAPIException) IOException(java.io.IOException) ScmException(org.apache.maven.scm.ScmException)

Example 4 with DiffScmResult

use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.

the class HgScmProvider method diff.

/**
 * {@inheritDoc}
 */
public DiffScmResult diff(ScmProviderRepository repository, ScmFileSet fileSet, CommandParameters parameters) throws ScmException {
    HgDiffCommand command = new HgDiffCommand();
    command.setLogger(getLogger());
    return (DiffScmResult) command.execute(repository, fileSet, parameters);
}
Also used : HgDiffCommand(org.apache.maven.scm.provider.hg.command.diff.HgDiffCommand) DiffScmResult(org.apache.maven.scm.command.diff.DiffScmResult)

Example 5 with DiffScmResult

use of org.apache.maven.scm.command.diff.DiffScmResult in project maven-scm by apache.

the class CvsExeDiffCommand method executeCvsCommand.

/**
 * {@inheritDoc}
 */
protected DiffScmResult executeCvsCommand(Commandline cl) throws ScmException {
    CvsDiffConsumer consumer = new CvsDiffConsumer(getLogger(), cl.getWorkingDirectory());
    CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
    try {
        CommandLineUtils.executeCommandLine(cl, consumer, stderr);
    } catch (CommandLineException ex) {
        throw new ScmException("Error while executing command.", ex);
    }
    return new DiffScmResult(cl.toString(), consumer.getChangedFiles(), consumer.getDifferences(), consumer.getPatch());
}
Also used : CvsDiffConsumer(org.apache.maven.scm.provider.cvslib.command.diff.CvsDiffConsumer) ScmException(org.apache.maven.scm.ScmException) 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