package com.perforce.maven.mojo.shelve;
/**
* Copyright (c) 2010 Perforce Software. All rights reserved.
*/
import java.io.IOException;
import java.util.Date;
import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.ScmFileSet;
import org.apache.maven.scm.ScmResult;
import org.apache.maven.scm.repository.ScmRepository;
import com.perforce.maven.mojo.P4Mojo;
import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository;
import com.perforce.maven.scm.provider.p4.util.P4Utils;
import com.perforce.p4java.client.IClient;
import com.perforce.p4java.core.ChangelistStatus;
import com.perforce.p4java.core.IChangelist;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.impl.generic.core.Changelist;
import com.perforce.p4java.impl.mapbased.server.Server;
import com.perforce.p4java.option.client.ReopenFilesOptions;
import com.perforce.p4java.option.client.ShelveFilesOptions;
import com.perforce.p4java.server.IOptionsServer;
/**
* Perforce shelve command.
*/
@Mojo( name = "shelve", aggregator = true )
public class P4ShelveMojo
extends P4Mojo
{
/** The Constant command. */
public static final String command = "Perforce shelve command";
/**
* Changelist number to shelve to, default is IChangelist.DEFAULT
*/
@Parameter ( property = "p4mojo.changeListId")
private int changelistId = 0;
/**
* Changelist description
*/
@Parameter( property = "p4mojo.changeListDesc", defaultValue = "Open Files" )
private String changelistDesc;
public void execute()
throws MojoExecutionException, MojoFailureException
{
try
{
ScmRepository repository = getScmRepository();
P4ScmProviderRepository providerRepository = (P4ScmProviderRepository) repository.getProviderRepository();
ScmFileSet fileSet = this.getFileSet();
if ( fileSet.getFileList().isEmpty() )
{
this.getLog().warn( "No files to shelve." );
return;
}
executeShelveCommand( providerRepository, fileSet );
// return scmResult;
}
catch ( ScmException e )
{
throw new MojoExecutionException( "Couldn't shelve files.", e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Problem occurred while shelving files.", e );
}
}
protected ScmResult executeShelveCommand( P4ScmProviderRepository p4Repo, ScmFileSet files )
throws ScmException
{
P4ShelveResult p4Result = new P4ShelveResult();
IClient client = p4ClientManager.getClient( p4Repo, files.getBasedir() );
IOptionsServer server = (IOptionsServer) client.getServer();
List<IFileSpec> fileSpecs = P4Utils.scmFileSet2P4FileSpecs( files );
List<IFileSpec> changelistFileSpecs = null;
try
{
IChangelist changelist = server.getChangelist( changelistId );
changelistFileSpecs = changelist.getFiles( true );
if ( changelistFileSpecs != null && !changelistFileSpecs.isEmpty() )
{
if ( changelistId == IChangelist.DEFAULT )
{
Changelist newChangelistImpl =
new Changelist( IChangelist.UNKNOWN, client.getName(), p4Repo.getUser(), ChangelistStatus.NEW,
new Date(), changelistDesc, false, (Server) server );
IChangelist retChangelist = client.createChangelist( newChangelistImpl );
ReopenFilesOptions reopenFilesOptions = new ReopenFilesOptions();
reopenFilesOptions.setChangelistId( retChangelist.getId() );
List<IFileSpec> retFileSpecs = client.reopenFiles( changelistFileSpecs, reopenFilesOptions );
if ( retChangelist.canRefresh() )
{
retChangelist.refresh();
}
changelistId = retChangelist.getId();
}
ShelveFilesOptions options = new ShelveFilesOptions();
List<IFileSpec> retFileSpecs = client.shelveFiles( fileSpecs, changelistId, options );
p4Result.process( retFileSpecs );
// convenient properties for next goal to use if needed
project.getProperties().put( P4Mojo.P4_SHELVED_CHANGELIST_PROPERTY, Integer.toString( changelistId ) );
}
}
catch ( P4JavaException e )
{
throw new ScmException( e.getLocalizedMessage(), e );
}
getLog().info( p4Result.getCommandOutput() );
return new ScmResult( command, p4Result.isSuccess() ? "Shelve successful" : "Unable to shelve",
p4Result.getCommandOutput(), p4Result.isSuccess() );
}
}
# |
Change |
User |
Description |
Committed |
|
#2
|
19967 |
jkovisto |
Pull over numerous changes from @dantran's branch from change 16716. |
|
|
#1
|
10055 |
Matt Attaway |
Pull over numerous changes from @dantran's branch. |
|
|
//guest/perforce_software/p4maven/main/com.perforce.maven.mojo/src/main/java/com/perforce/maven/mojo/shelve/P4ShelveMojo.java |
#1
|
8496 |
Matt Attaway |
Move P4Ant and P4Maven into their proper homes |
|
|
//public/perforce/p4maven/main/com.perforce.maven.mojo/src/main/java/com/perforce/maven/mojo/shelve/P4ShelveMojo.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|