package com.perforce.maven.mojo.validate;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.scm.ScmException;
import org.apache.maven.scm.repository.ScmRepository;
import com.perforce.maven.mojo.P4Mojo;
import com.perforce.maven.scm.provider.p4.repository.P4ScmProviderRepository;
/**
* Use this goal to validate current client workspace, useful during release:prepare
*/
@Mojo( name = "validate", requiresProject = true, threadSafe = true, defaultPhase = LifecyclePhase.INITIALIZE, aggregator = true )
public class P4ValidateMojo
extends P4Mojo
{
public void execute()
throws MojoExecutionException, MojoFailureException
{
try
{
// construct the repo base on the value found under project scm's element
ScmRepository repository = getScmRepository();
if ( !( repository.getProviderRepository() instanceof P4ScmProviderRepository ) )
{
this.getLog().warn( "Skipping current client workspace validation since SCM settings are not Perforce P4Java provider" );
return;
}
P4ScmProviderRepository providerRepository = (P4ScmProviderRepository) repository.getProviderRepository();
// use the repo to discover a existing client name that match with basedir and project's scm. If found, we
// got a match
String clientName = p4ClientManager.discoverClientName( providerRepository, this.project.getBasedir() );
if ( null == clientName )
{
throw new MojoExecutionException(
"Unable to discover Perforce client. Please check the validity of project scm configuration." );
}
this.getLog().info( "Found client name: " + clientName );
}
catch ( ScmException e )
{
throw new MojoExecutionException(
"Unable to discover Perforce client. Please check the validity of project scm configuration.",
e );
}
}
}