/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.maven.scm.provider.p4.command.diff;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.diff.AbstractDiffCommand;
import org.apache.maven.scm.command.diff.DiffScmResult;
import org.apache.maven.scm.provider.ScmProviderRepository;
import org.codehaus.plexus.util.StringUtils;
import com.perforce.maven.scm.provider.p4.command.P4Command;
import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository;
import com.perforce.p4java.client.IClient;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.impl.generic.core.file.FileSpec;
import com.perforce.p4java.option.server.GetFileDiffsOptions;
import com.perforce.p4java.server.IOptionsServer;
/**
* The class uses the Perforce diff2 command to diff of two depot files.
*/
public class P4DiffCommand
extends AbstractDiffCommand
implements P4Command
{
/** The Constant command. */
public static final String command = "Perforce diff2 command";
private IClient client;
private IOptionsServer server;
public void setClient( IClient client )
{
this.client = client;
server = (IOptionsServer) this.client.getServer();
}
/**
* @see org.apache.maven.scm.command.diff.AbstractDiffCommand#executeDiffCommand
* (org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet,
* org.apache.maven.scm.ScmVersion, org.apache.maven.scm.ScmVersion)
*/
protected DiffScmResult executeDiffCommand( ScmProviderRepository repo, ScmFileSet files, ScmVersion startRev,
ScmVersion endRev )
throws ScmException
{
// Assume revisions are labels
String start = startRev != null && StringUtils.isNotEmpty( startRev.getName() ) ? "@" + startRev.getName() : "";
String end = endRev != null && StringUtils.isNotEmpty( endRev.getName() ) ? "@" + endRev.getName() : "@now";
IFileSpec fileSpec1 = new FileSpec( files.getBasedir().getAbsolutePath() + "/..." + start );
IFileSpec fileSpec2 = new FileSpec( ((P4ScmProviderRepository)repo).getPath() + "/..." + end );
// fixme handle case where both start and env revision are null
// where we need to get the get diff between local workspace and remote server
try
{
GetFileDiffsOptions options = new GetFileDiffsOptions();
options.setQuiet( true );
options.setUnifiedDiff( 0 );
P4DiffResult p4Result =
new P4DiffResult( server.getFileDiffs( fileSpec1, fileSpec2, null, options ) );
if ( !p4Result.isSuccess() )
{
return new DiffScmResult( command, "The diff2 command failed.", p4Result.getFileDiffOutput(),
p4Result.isSuccess() );
}
return new DiffScmResult( command, p4Result.getChangedFiles(), p4Result.getDifferences(),
p4Result.getPatch() );
}
catch ( P4JavaException e )
{
throw new ScmException( e.getLocalizedMessage(), e );
}
}
}
# |
Change |
User |
Description |
Committed |
|
#1
|
10055 |
Matt Attaway |
Pull over numerous changes from @dantran's branch. |
|
|
//guest/perforce_software/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/diff/P4DiffCommand.java |
#1
|
8496 |
Matt Attaway |
Move P4Ant and P4Maven into their proper homes |
|
|
//public/perforce/p4maven/main/com.perforce.maven/src/main/java/com/perforce/maven/scm/provider/p4/command/diff/P4DiffCommand.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|