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 |
|
#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/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 |
|
|