package com.perforce.maven.mojo.jobs;
/**
* 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.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.IJob;
import com.perforce.p4java.core.file.IFileSpec;
import com.perforce.p4java.exception.P4JavaException;
import com.perforce.p4java.option.server.GetJobsOptions;
import com.perforce.p4java.server.IOptionsServer;
/**
* Perforce jobs command.
*/
@Mojo( name = "jobs", aggregator = true )
public class P4JobsMojo
extends P4Mojo
{
/** The Constant command. */
public static final String command = "Perforce jobs command";
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 for job goal." );
return;
}
ScmResult scmResult = executeJobsCommand( providerRepository, fileSet );
// return scmResult;
}
catch ( ScmException e )
{
throw new MojoExecutionException( "Couldn't run jobs.", e );
}
catch ( IOException e )
{
throw new MojoExecutionException( "Problem occurred while running jobs.", e );
}
}
protected ScmResult executeJobsCommand( P4ScmProviderRepository p4Repo, ScmFileSet files )
throws ScmException
{
P4JobsResult p4Result = new P4JobsResult();
IClient client = p4ClientManager.getClient( p4Repo, files.getBasedir() );
IOptionsServer server = (IOptionsServer) client.getServer();
List<IFileSpec> fileSpecs = P4Utils.scmFileSet2P4FileSpecs( files );
try
{
GetJobsOptions getJobsOptions = new GetJobsOptions();
List<IJob> retJobs = server.getJobs( fileSpecs, getJobsOptions );
( (P4JobsResult) p4Result ).processJobs( retJobs );
}
catch ( P4JavaException e )
{
throw new ScmException( e.getLocalizedMessage(), e );
}
getLog().info( p4Result.getCommandOutput() );
return new ScmResult( command, p4Result.isSuccess() ? "Jobs command successful" : "Unable to run jobs",
p4Result.getCommandOutput(), p4Result.isSuccess() );
}
}
# |
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/jobs/P4JobsMojo.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/jobs/P4JobsMojo.java |
#1
|
8270 |
Matt Attaway |
Initial add of P4Maven source code |
|
|