/** * 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.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() + "..." + start ); IFileSpec fileSpec2 = new FileSpec( files.getBasedir() + "..." + 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 getFileDiffsOptions = new GetFileDiffsOptions(); P4DiffResult p4Result = new P4DiffResult( server.getFileDiffs( fileSpec1, fileSpec2, null, getFileDiffsOptions ) ); 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 | |
---|---|---|---|---|---|
#4 | 9519 | dantran | folder rename to match with its artifactId | ||
#3 | 9471 | dantran |
- cleanup diff command - simplify branch command and full compliant with maven-scm-test - add checkout with branch - add repo's path as client manager lookup key in addition to p4port and rootdir so that we can handle mutiple clients on the same rootdir |
||
#2 | 9250 | dantran | caching client across mutiple commands | ||
#1 | 9167 | dantran |
Populate //guest/dantran/p4maven/... from //guest/perforce_software/p4maven/main/.... |
||
//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 |