/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
package com.perforce.maven.scm.provider.p4.command.update;
import java.util.List;
import org.apache.maven.scm.CommandParameter;
import org.apache.maven.scm.CommandParameters;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmVersion;
import org.apache.maven.scm.command.changelog.ChangeLogCommand;
import org.apache.maven.scm.command.checkout.CheckOutScmResult;
import org.apache.maven.scm.command.update.AbstractUpdateCommand;
import org.apache.maven.scm.command.update.UpdateScmResult;
import org.apache.maven.scm.command.update.UpdateScmResultWithRevision;
import org.apache.maven.scm.provider.ScmProviderRepository;
import com.perforce.maven.scm.provider.p4.command.P4Command;
import com.perforce.maven.scm.provider.p4.command.changelog.P4ChangeLogCommand;
import com.perforce.maven.scm.provider.p4.command.checkout.P4CheckOutCommand;
import com.perforce.p4java.client.IClient;
import com.perforce.p4java.core.IChangelist;
import com.perforce.p4java.core.IChangelistSummary;
import com.perforce.p4java.core.file.FileSpecBuilder;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.option.server.GetChangelistsOptions;
import com.perforce.p4java.server.IOptionsServer;
/**
* Use Perforce sync command to update files from the repository.
*/
public class P4UpdateCommand
extends AbstractUpdateCommand
implements P4Command
{
/** The Constant command. */
public static final String command = "Perforce sync command";
private IClient client;
public void setClient( IClient client )
{
this.client = client;
}
/**
* @see org.apache.maven.scm.command.update.AbstractUpdateCommand
* executeUpdateCommand(org.apache.maven.scm.provider.ScmProviderRepository, org.apache.maven.scm.ScmFileSet,
* org.apache.maven.scm.ScmVersion)
*/
protected UpdateScmResult executeUpdateCommand( ScmProviderRepository repo, ScmFileSet files, ScmVersion scmVersion )
throws ScmException
{
// Update is the same as checkout in Perforce
P4CheckOutCommand command = new P4CheckOutCommand();
command.setLogger( getLogger() );
command.setClient( client );
CommandParameters params = new CommandParameters();
params.setScmVersion( CommandParameter.SCM_VERSION, scmVersion );
CheckOutScmResult checkOutScmResult = (CheckOutScmResult) command.execute( repo, files, params );
if ( !checkOutScmResult.isSuccess() )
{
return new UpdateScmResult( checkOutScmResult.getCommandLine(), checkOutScmResult.getProviderMessage(),
checkOutScmResult.getCommandOutput(), false );
}
// get latest revision, expected by scm:update goal
int revision = 0;
try
{
GetChangelistsOptions getChangelistsOptions = new GetChangelistsOptions();
getChangelistsOptions.setMaxMostRecent( 1 );
getChangelistsOptions.setType( IChangelist.Type.SUBMITTED );
String fileSpec = "//" + client.getName() + "/...#have";
List<IFileSpec> fileSpecs = FileSpecBuilder.makeFileSpecList( fileSpec );
IOptionsServer server = (IOptionsServer) client.getServer();
List<IChangelistSummary> retChangelistSummaries = server.getChangelists( fileSpecs, getChangelistsOptions );
if ( retChangelistSummaries != null )
{
for ( IChangelistSummary changelistSummary : retChangelistSummaries )
{
revision = changelistSummary.getId();
break;
}
}
}
catch ( P4JavaException e )
{
throw new ScmException( e.getLocalizedMessage(), e );
}
return new UpdateScmResultWithRevision( checkOutScmResult.getCheckedOutFiles(), null,
String.valueOf( revision ), checkOutScmResult );
// AbstractUpdateCommand will handle ChangeSet after this
}
/**
* @see org.apache.maven.scm.command.update.AbstractUpdateCommand#getChangeLogCommand ()
*/
protected ChangeLogCommand getChangeLogCommand()
{
P4ChangeLogCommand command = new P4ChangeLogCommand();
command.setLogger( getLogger() );
command.setClient( client );
return command;
}
}
# |
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/update/P4UpdateCommand.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/update/P4UpdateCommand.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|