package com.perforce.maven.mojo; import java.io.File; import java.io.IOException; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; import org.apache.maven.scm.ScmFileSet; import org.apache.maven.scm.log.ScmLogDispatcher; import org.apache.maven.scm.manager.NoSuchScmProviderException; import org.apache.maven.scm.manager.ScmManager; import org.apache.maven.scm.provider.ScmProviderRepositoryWithHost; import org.apache.maven.scm.repository.ScmRepository; import org.apache.maven.scm.repository.ScmRepositoryException; import org.apache.maven.settings.Server; import org.apache.maven.settings.Settings; import org.codehaus.plexus.util.StringUtils; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcher; import org.sonatype.plexus.components.sec.dispatcher.SecDispatcherException; import com.perforce.maven.scm.provider.p4.manager.P4ClientManager; /** * Super class for Perforce Mojos. * * @requiresProject */ public abstract class P4Mojo extends AbstractMojo { /** The Constant P4_CHANGELIST_PROPERTY. */ public static final String P4_SHELVED_CHANGELIST_PROPERTY = "p4.shelved.changelist"; /** * @parameter expression="${project.scm.developerConnection}" * @readonly */ @Parameter( defaultValue = "${project.scm.developerConnection}", required = true ) protected String urlScm; /** * The username that is used when connecting to the SCM system. */ @Parameter( property = "username" ) protected String username; /** * The password that is used when connecting to the SCM system. */ @Parameter( property = "password" ) protected String password; /** * The includes that is used to include files with that pattern. */ @Parameter( property = "includes" ) protected String includes; /** * The excludes that is used to exclude files with that pattern. */ @Parameter( property = "excludes" ) protected String excludes; /** * Local directory to be used to issue SCM actions */ @Parameter( defaultValue = "${project.basedir}" ) protected File scmDirectory; @Component protected ScmManager scmManager; /** * The maven project. */ @Parameter( defaultValue = "${project}", readonly = true ) protected MavenProject project; /** * When this plugin requires Maven 3.0 as minimum, this component can be removed and o.a.m.s.c.SettingsDecrypter be * used instead. */ @Component( hint = "mng-4384" ) private SecDispatcher secDispatcher; @Parameter( defaultValue = "${settings}", readonly = true ) private Settings settings; @Component protected P4ClientManager p4ClientManager; protected ScmLogDispatcher logger; protected ScmRepository getScmRepository() throws MojoExecutionException, ScmRepositoryException, NoSuchScmProviderException { ScmRepository repository = scmManager.makeScmRepository( urlScm ); ScmProviderRepositoryWithHost scmRepo = (ScmProviderRepositoryWithHost) repository.getProviderRepository(); loadInfosFromSettings( scmRepo ); if ( !StringUtils.isEmpty( username ) ) { scmRepo.setUser( username ); } if ( !StringUtils.isEmpty( password ) ) { scmRepo.setPassword( password ); } return repository; } private String decrypt( String str, String server ) throws MojoExecutionException { try { return secDispatcher.decrypt( str ); } catch ( SecDispatcherException e ) { throw new MojoExecutionException( "Failed to decrypt password/passphrase for server", e ); } } /** * Load username password from settings if user has not set them in JVM properties * * @param repo not null */ private void loadInfosFromSettings( ScmProviderRepositoryWithHost repo ) throws MojoExecutionException { if ( username == null || password == null ) { String host = repo.getHost(); int port = repo.getPort(); if ( port > 0 ) { host += ":" + port; } Server server = this.settings.getServer( host ); if ( server != null ) { if ( username == null ) { username = server.getUsername(); } if ( password == null ) { password = decrypt( server.getPassword(), host ); } } } } protected ScmFileSet getFileSet() throws IOException { if ( includes != null || excludes != null ) { return new ScmFileSet( scmDirectory, includes, excludes ); } else { return new ScmFileSet( scmDirectory ); } } }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#7 | 14124 | dantran | Handle empty excludes/includes ScmFileList | ||
#6 | 9618 | dantran | cleanup | ||
#5 | 9605 | dantran | refactoy to use MOJO parameter instead of system properties | ||
#4 | 9533 | dantran | source format | ||
#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/P4Mojo.java | |||||
#4 | 9513 | dantran | add provider doc, deploy site:jar, support external charset config | ||
#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/P4Mojo.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/P4Mojo.java | |||||
#1 | 8270 | Matt Attaway | Initial add of P4Maven source code |