org.codehaus.mojo.exec
Class ExecMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.codehaus.mojo.exec.AbstractExecMojo
          extended by org.codehaus.mojo.exec.ExecMojo
All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
Direct Known Subclasses:
EclipseFormatterMojo

public class ExecMojo
extends AbstractExecMojo

A Plugin for executing external programs.

Since:
1.0
Version:
$Id: ExecMojo.java 12386 2010-07-16 22:10:38Z rfscholte $
Author:
Jerome Lacoste

Field Summary
private  List arguments
          Can be of type <argument> or <classpath> Can be overridden using "exec.args" env.
private  File basedir
           
static String CLASSPATH_TOKEN
           
private  Map environmentVariables
          Environment variables to pass to the executed program.
private  String executable
          The executable.
private  boolean longClasspath
          If set to true the classpath and the main class will be written to a MANIFEST.MF file and wrapped into a jar.
private  File outputFile
          Program standard and error output will be redirected to the file specified by this optional field.
private  org.apache.maven.execution.MavenSession session
          The current build session instance.
private  List successCodes
          Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).
private  File workingDirectory
          The current working directory.
 
Fields inherited from class org.codehaus.mojo.exec.AbstractExecMojo
classpathScope, project
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
ExecMojo()
           
 
Method Summary
private static void addToClasspath(StringBuffer theClasspath, String toAdd)
           
private  List computeClasspath(Classpath specifiedClasspath)
          Compute the classpath from the specified Classpath.
private  String computeClasspathString(Classpath specifiedClasspath)
          Compute the classpath from the specified Classpath.
private  File createJar(List classPath, String mainClass)
          Create a jar with just a manifest containing a Main-Class entry for SurefireBooter and a Class-Path entry for all classpath elements.
 void execute()
          priority in the execute method will be to use System properties arguments over the pom specification.
protected  int executeCommandLine(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map enviro, OutputStream out, OutputStream err)
           
private  List filterArtifacts(List artifacts, Collection dependencies)
           
private  org.apache.maven.plugin.logging.Log getExecOutputLog()
           
(package private)  String getExecutable()
           
(package private)  org.apache.commons.exec.CommandLine getExecutablePath(Map enviro, File dir)
           
protected  org.apache.commons.exec.Executor getExecutor()
           
 List getSuccessCodes()
           
protected  String getSystemProperty(String key)
           
private  org.apache.maven.toolchain.Toolchain getToolchain()
           
private static boolean isEmpty(String string)
           
private  boolean isLongClassPathArgument(String arg)
           
(package private)  boolean isResultCodeAFailure(int result)
           
(package private)  void setArguments(List arguments)
           
(package private)  void setBasedir(File basedir)
           
(package private)  void setExecutable(String executable)
           
(package private)  void setProject(org.apache.maven.project.MavenProject project)
           
 void setSuccessCodes(List list)
           
(package private)  void setWorkingDirectory(File workingDir)
           
(package private)  void setWorkingDirectory(String workingDir)
           
 
Methods inherited from class org.codehaus.mojo.exec.AbstractExecMojo
collectProjectArtifactsAndClasspath, hasCommandlineArgs, isSkip, parseCommandlineArgs, registerSourceRoots
 
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

executable

private String executable
The executable. Can be a full path or a the name executable. In the latter case, the executable must be in the PATH for the execution to work.


workingDirectory

private File workingDirectory
The current working directory. Optional. If not specified, basedir will be used.


outputFile

private File outputFile
Program standard and error output will be redirected to the file specified by this optional field. If not specified the standard maven logging is used.


arguments

private List arguments
Can be of type <argument> or <classpath> Can be overridden using "exec.args" env. variable


basedir

private File basedir
Since:
1.0

environmentVariables

private Map environmentVariables
Environment variables to pass to the executed program.


session

private org.apache.maven.execution.MavenSession session
The current build session instance. This is used for toolchain manager API calls.


successCodes

private List successCodes
Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).


longClasspath

private boolean longClasspath
If set to true the classpath and the main class will be written to a MANIFEST.MF file and wrapped into a jar. Instead of '-classpath/-cp CLASSPATH mainClass' the exec plugin executes '-jar maven-exec.jar'.


CLASSPATH_TOKEN

public static final String CLASSPATH_TOKEN
See Also:
Constant Field Values
Constructor Detail

ExecMojo

public ExecMojo()
Method Detail

execute

public void execute()
             throws org.apache.maven.plugin.MojoExecutionException
priority in the execute method will be to use System properties arguments over the pom specification.

Throws:
org.apache.maven.plugin.MojoExecutionException - if a failure happens

getExecutor

protected org.apache.commons.exec.Executor getExecutor()

isResultCodeAFailure

boolean isResultCodeAFailure(int result)

isLongClassPathArgument

private boolean isLongClassPathArgument(String arg)

getExecOutputLog

private org.apache.maven.plugin.logging.Log getExecOutputLog()

computeClasspathString

private String computeClasspathString(Classpath specifiedClasspath)
Compute the classpath from the specified Classpath. The computed classpath is based on the classpathScope. The plugin cannot know from maven the phase it is executed in. So we have to depend on the user to tell us he wants the scope in which the plugin is expected to be executed.

Parameters:
specifiedClasspath - Non null when the user restricted the dependenceis, null otherwise (the default classpath will be used)
Returns:
a platform specific String representation of the classpath

computeClasspath

private List computeClasspath(Classpath specifiedClasspath)
Compute the classpath from the specified Classpath. The computed classpath is based on the classpathScope. The plugin cannot know from maven the phase it is executed in. So we have to depend on the user to tell us he wants the scope in which the plugin is expected to be executed.

Parameters:
specifiedClasspath - Non null when the user restricted the dependenceis, null otherwise (the default classpath will be used)
Returns:
a list of class path elements

addToClasspath

private static void addToClasspath(StringBuffer theClasspath,
                                   String toAdd)

filterArtifacts

private List filterArtifacts(List artifacts,
                             Collection dependencies)

getExecutablePath

org.apache.commons.exec.CommandLine getExecutablePath(Map enviro,
                                                      File dir)

isEmpty

private static boolean isEmpty(String string)

executeCommandLine

protected int executeCommandLine(org.apache.commons.exec.Executor exec,
                                 org.apache.commons.exec.CommandLine commandLine,
                                 Map enviro,
                                 OutputStream out,
                                 OutputStream err)
                          throws IOException
Throws:
IOException

setExecutable

void setExecutable(String executable)

getExecutable

String getExecutable()

setWorkingDirectory

void setWorkingDirectory(String workingDir)

setWorkingDirectory

void setWorkingDirectory(File workingDir)

setArguments

void setArguments(List arguments)

setBasedir

void setBasedir(File basedir)

setProject

void setProject(org.apache.maven.project.MavenProject project)

getSystemProperty

protected String getSystemProperty(String key)

setSuccessCodes

public void setSuccessCodes(List list)

getSuccessCodes

public List getSuccessCodes()

getToolchain

private org.apache.maven.toolchain.Toolchain getToolchain()

createJar

private File createJar(List classPath,
                       String mainClass)
                throws IOException
Create a jar with just a manifest containing a Main-Class entry for SurefireBooter and a Class-Path entry for all classpath elements. Copied from surefire (ForkConfiguration#createJar())

Parameters:
classPath - List<String> of all classpath elements.
Returns:
Throws:
IOException


Copyright © 2004-2011 The Kuali Foundation. All Rights Reserved.