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 = new ScmFileSet( scmDirectory, includes, excludes ); 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 | |
---|---|---|---|---|---|
#10 | 14124 | dantran | Handle empty excludes/includes ScmFileList | ||
#9 | 14103 | dantran | Ugrade p4java, externalize p4mojo | ||
#8 | 9626 | dantran | rework on job goal | ||
#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/shelve/P4ShelveMojo.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/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 |