package com.perforce.maven.mojo.unshelve; /** * Copyright (c) 2010 Perforce Software. All rights reserved. */ import java.io.IOException; 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.provider.ScmProviderRepository; 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.IChangelist; import com.perforce.p4java.core.file.IFileSpec; import com.perforce.p4java.exception.P4JavaException; import com.perforce.p4java.option.client.ShelveFilesOptions; import com.perforce.p4java.option.client.UnshelveFilesOptions; /** * Perforce unshelve command. */ @Mojo( name = "unshelve", aggregator = true ) public class P4UnShelveMojo extends P4Mojo { /** The Constant command. */ public static final String command = "Perforce unshelve command"; /** * Changelist number to shelve to, default is IChangelist.DEFAULT */ @Parameter( property = "p4mojo.fromChangelistId", required = true ) private int fromChangelistId = 0; /** * Changelist number to unshelve to, default is IChangelist.DEFAULT */ @Parameter( property = "p4mojo.toChangelistId" ) private int toChangelistId = 0; /** * Remove the shelve after successfully unshelved */ @Parameter( property = "p4mojo.deleteShelvedFilesAfterUnshelved", defaultValue = "false" ) private boolean deleteShelvedFilesAfterUnshelved; /** * Remove the shelve after successfully unshelved */ @Parameter( property = "p4mojo.deleteChangelistAfterUnshelved", defaultValue = "false" ) private boolean deleteChangelistAfterUnshelved; public void execute() throws MojoExecutionException, MojoFailureException { if ( fromChangelistId == 0 ) { this.getLog().warn( "Skip unshelve task due to empty changelist: 0" ); return; } try { ScmRepository repository = getScmRepository(); P4ScmProviderRepository providerRepository = (P4ScmProviderRepository) repository.getProviderRepository(); ScmFileSet fileSet = this.getFileSet(); ScmResult scmResult = executeUnShelveCommand( providerRepository, fileSet ); // return scmResult; } catch ( ScmException e ) { throw new MojoExecutionException( "Couldn't unshelve files.", e ); } catch ( IOException e ) { throw new MojoExecutionException( "Problem occurred while unshelving files.", e ); } } protected ScmResult executeUnShelveCommand( ScmProviderRepository repo, ScmFileSet files ) throws ScmException { P4UnShelveResult p4Result = new P4UnShelveResult(); P4ScmProviderRepository p4Repo = (P4ScmProviderRepository) repo; IClient client = p4ClientManager.getClient( p4Repo, files.getBasedir() ); if ( fromChangelistId != IChangelist.DEFAULT ) { try { UnshelveFilesOptions options = new UnshelveFilesOptions(); options.setForceUnshelve( true ); options.setImmutable( true ); // unshelve everything List<IFileSpec> retFileSpecs = client.unshelveFiles( null, fromChangelistId, toChangelistId, options ); p4Result.process( retFileSpecs ); if ( p4Result.isSuccess() && deleteShelvedFilesAfterUnshelved ) { List<IFileSpec> fileSpecs = P4Utils.scmFileSet2P4FileSpecs( files ); ShelveFilesOptions shelveOptions = new ShelveFilesOptions(); shelveOptions.setDeleteFiles( true ); client.shelveFiles( fileSpecs, fromChangelistId, shelveOptions ); // check for error? if ( deleteChangelistAfterUnshelved ) { client.getServer().deletePendingChangelist( fromChangelistId ); } } } catch ( P4JavaException e ) { throw new ScmException( e.getLocalizedMessage(), e ); } } getLog().info( p4Result.getCommandOutput() ); return new ScmResult( command, p4Result.isSuccess() ? "Unshelve successful" : "Unable to Unshelve", p4Result.getCommandOutput(), p4Result.isSuccess() ); } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#12 | 16491 | dantran | skip p4mojo:unshelve when changelist is 0, upgrade p4java, and a number of maven plugin | ||
#11 | 16484 | dantran | skip p4mojo:unshelve when changelist is 0, upgrade p4java, and a number of maven plugin | ||
#10 | 14124 | dantran | Handle empty excludes/includes ScmFileList | ||
#9 | 14103 | dantran | Ugrade p4java, externalize p4mojo | ||
#8 | 9625 | dantran | add option to remove changelist after unshelved | ||
#7 | 9618 | dantran | cleanup | ||
#6 | 9605 | dantran | refactoy to use MOJO parameter instead of system properties | ||
#5 | 9603 | dantran | cleanup | ||
#4 | 9602 | dantran |
shelve mojo is now working. Add basic IT |
||
#3 | 9527 | dantran |
Cleanup with - Source format - Remove all unused code - There is no reason for mojo to pickup maven-scm-plugin's config which is not recommend from Maven best practice. If needed, user need to do it himself use project <properties> |
||
#2 | 9526 | dantran | Remove P4Executor, use P4ClientManager instead | ||
#1 | 9520 | dantran | folder rename to match with its artifactId | ||
//guest/dantran/p4maven/com.perforce.maven.mojo/src/main/java/com/perforce/maven/mojo/unshelve/P4UnShelveMojo.java | |||||
#3 | 9191 | dantran |
jobs,shelve, and unshelve should run as aggregate, there is no need to tranverse. Ensure extracting credential from settings.xml working |
||
#2 | 9190 | dantran | Migrate to java annotation, add loading credential from settings.xml if not given | ||
#1 | 9167 | dantran |
Populate //guest/dantran/p4maven/... from //guest/perforce_software/p4maven/main/.... |
||
//guest/perforce_software/p4maven/main/com.perforce.maven.mojo/src/main/java/com/perforce/maven/mojo/unshelve/P4UnShelveMojo.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/unshelve/P4UnShelveMojo.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |