Class ExecMojo
- All Implemented Interfaces:
org.apache.maven.plugin.ContextEnabled
,org.apache.maven.plugin.Mojo
- Since:
- 1.0
- Version:
- $Id$
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate List<?>
A list of arguments passed to theexecutable
, which should be of type<argument>
or<classpath>
.private boolean
If set to true the child process executes asynchronously and build execution continues in parallel.private boolean
If set to true, the asynchronous child process is destroyed upon JVM shutdown.private File
private File
static final String
private static final Pattern
Trying to recognize whether the givenexecutable
might be ajava
binary.private File
Environment script to be merged with environmentVariables This script is platform specifics, on Unix its must be Bourne shell format.Environment variables to pass to the executed program.private String
The executable.private boolean
Forces the plugin to recognize the given executable as java executable.private boolean
Program standard input, output and error streams will be inherited from the maven process.private boolean
If set to true the classpath and the main class will be written to a MANIFEST.MF file and wrapped into a jar.private boolean
If set to true the modulepath and the main class will be written as an @arg file Instead of '--module-path/-p MODULEPATH ' the exec plugin executes '@modulepath'.static final String
private File
Program standard and error output will be redirected to the file specified by this optional field.private org.apache.commons.exec.ProcessDestroyer
private boolean
When combined withexec.useMavenLogger=true
, prints all executed program output at debug level instead of the default info level to the Maven logger.private org.apache.maven.execution.MavenSession
The current build session instance.private int[]
Exit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).private int
Timeout in full milliseconds, default is0
.private String
The toolchain.private boolean
When enabled, program standard and error output will be redirected to the Maven logger as Info and Error level logs, respectively.private File
The current working directory.Fields inherited from class org.codehaus.mojo.exec.AbstractExecMojo
classpathScope, executableDependency, project
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static void
addToClasspath
(StringBuffer theClasspath, String toAdd) private String
computeClasspathString
(AbstractPath specifiedClasspath) Compute the classpath from the specified Classpath.computePath
(AbstractPath specifiedClasspath) Compute the classpath from the specified Classpath.private void
createArgFile
(String filePath, List<String> lines) createEnvs
(File envScriptFile) protected File
createEnvWrapperFile
(File envScript) private File
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<String, String> enviro, FileOutputStream outputFile) protected int
executeCommandLine
(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map<String, String> enviro, OutputStream out, OutputStream err) protected int
executeCommandLine
(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map<String, String> enviro, org.apache.commons.exec.PumpStreamHandler psh) private void
fillSuccessCodes
(org.apache.commons.exec.Executor exec) private List<org.apache.maven.artifact.Artifact>
filterArtifacts
(List<org.apache.maven.artifact.Artifact> artifacts, Collection<String> dependencies) (package private) static String
findExecutable
(String executable, List<String> paths) (package private) String
(package private) org.apache.commons.exec.CommandLine
getExecutablePath
(Map<String, String> enviro, File dir) getExecutablePaths
(Map<String, String> enviro) protected org.apache.commons.exec.ProcessDestroyer
int[]
protected String
getSystemProperty
(String key) private org.apache.maven.toolchain.Toolchain
private void
handleArguments
(List<String> commandArguments) private void
handleCommandLineArgs
(List<String> commandArguments) private void
handleSystemPropertyArguments
(String argsProp, List<String> commandArguments) private void
This is a convenient method to make the execute method a little bit more readable.private static boolean
hasExecutableExtension
(String exec) private static boolean
hasNativeExtension
(String exec) private boolean
Returnstrue
when a java binary is being executed.private boolean
private boolean
(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
(Integer... list) (package private) void
setWorkingDirectory
(File workingDir) (package private) void
setWorkingDirectory
(String workingDir) Methods inherited from class org.codehaus.mojo.exec.AbstractExecMojo
collectProjectArtifactsAndClasspath, findExecutableArtifact, getPluginDependencies, getSession, hasCommandlineArgs, isSkip, parseCommandlineArgs, registerSourceRoots
Methods inherited from class org.apache.maven.plugin.AbstractMojo
getLog, getPluginContext, setLog, setPluginContext
-
Field Details
-
ENDS_WITH_JAVA
Trying to recognize whether the givenexecutable
might be ajava
binary. -
executable
The executable. Can be a full path or the name of the executable. In the latter case, the executable must be in the PATH for the execution to work. Omit when using
executableDependency
.The plugin will search for the executable in the following order:
- relative to the root of the project
- as toolchain executable
- relative to the working directory (Windows only)
- relative to the directories specified in the system property PATH (Windows Only)
- Since:
- 1.0
-
timeout
@Parameter(property="exec.timeout", defaultValue="0") private int timeoutTimeout in full milliseconds, default is
0
.When set to a value larger than zero, the executable is forcefully terminated if it did not finish within this time, and the build will fail.
- Since:
- 3.0.0
-
toolchain
The toolchain. If omitted,
"jdk"
is assumed. -
workingDirectory
The current working directory. Optional. If not specified, basedir will be used.- Since:
- 1.0
-
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.
Note: Be aware thatSystem.out
andSystem.err
use buffering, so don't rely on the order!- Since:
- 1.1-beta-2
- See Also:
-
inheritIo
@Parameter(property="exec.inheritIo") private boolean inheritIoProgram standard input, output and error streams will be inherited from the maven process. This allow tighter control of the streams and the console.- Since:
- 3.0.1
- See Also:
-
useMavenLogger
@Parameter(property="exec.useMavenLogger", defaultValue="false") private boolean useMavenLoggerWhen enabled, program standard and error output will be redirected to the Maven logger as Info and Error level logs, respectively. If not enabled the traditional behavior of program output being directed to standard System.out and System.err is used.
NOTE: When enabled, to log the program standard out as Maven Debug level instead of Info level useexec.quietLogs=true
.
This option can be extremely helpful when combined with multithreaded builds for two reasons:
- Program output is suffixed with the owning thread name, making it easier to trace execution of a specific projects build thread.
- Program output will not get jumbled with other maven log messages.
exec:exec
to run a script to echo a count from 1 to 100 as:for i in {1..100} do echo "${project.artifactId} - $i" done
When this script is run multi-threaded on two modules,module1
andmodule2
, you might get output such as:[BuilderThread 1] [INFO] --- exec-maven-plugin:1.6.0:exec (test) @ module1 --- [BuilderThread 2] [INFO] --- exec-maven-plugin:1.6.0:exec (test) @ module2 --- ... module2 - 98 modu module1 - 97 module1 - le2 - 9899 ...
With this flag enabled, the output will instead come something similar to:... [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 98 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 97 [Exec Stream Pumper] [INFO] [BuilderThread 1] module1 - 98 [Exec Stream Pumper] [INFO] [BuilderThread 2] module2 - 99 ...
NOTE 1: To show the thread in the Maven log, configure the Maven installations conf/logging/simplelogger.properties option:org.slf4j.simpleLogger.showThreadName=true
NOTE 2: This option is ignored whenexec.outputFile
is specified.- Since:
- 3.0.0
- See Also:
-
quietLogs
@Parameter(property="exec.quietLogs", defaultValue="false") private boolean quietLogsWhen combined withexec.useMavenLogger=true
, prints all executed program output at debug level instead of the default info level to the Maven logger.- Since:
- 3.0.0
-
arguments
A list of arguments passed to the
executable
, which should be of type<argument>
or<classpath>
. Can be overridden by using theexec.args
environment variable.- Since:
- 1.0
-
basedir
- Since:
- 1.0
-
buildDirectory
@Parameter(readonly=true, required=true, defaultValue="${project.build.directory}") private File buildDirectory- Since:
- 3.0.0
-
environmentVariables
Environment variables to pass to the executed program. For example if you want to set the LANG var:
<environmentVariables> <LANG>en_US</LANG> </environmentVariables>
- Since:
- 1.1-beta-2
-
environmentScript
Environment script to be merged with environmentVariables This script is platform specifics, on Unix its must be Bourne shell format. Use this feature if you have a need to create environment variable dynamically such as invoking Visual Studio environment script file- Since:
- 1.4.0
-
session
@Parameter(defaultValue="${session}", readonly=true) private org.apache.maven.execution.MavenSession sessionThe current build session instance. This is used for toolchain manager API calls. -
successCodes
@Parameter private int[] successCodesExit codes to be resolved as successful execution for non-compliant applications (applications not returning 0 for success).- Since:
- 1.1.1
-
longClasspath
@Parameter(property="exec.longClasspath", defaultValue="false") private boolean longClasspathIf 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'.- Since:
- 1.1.2
-
longModulepath
@Parameter(property="exec.longModulepath", defaultValue="true") private boolean longModulepathIf set to true the modulepath and the main class will be written as an @arg file Instead of '--module-path/-p MODULEPATH ' the exec plugin executes '@modulepath'.- Since:
- 1.1.2
-
forceJava
@Parameter(property="exec.forceJava", defaultValue="false") private boolean forceJavaForces the plugin to recognize the given executable as java executable. This helps withlongClasspath
andlongModulepath
parameters.You shouldn't normally be needing this unless you renamed your java binary or are executing tools other than
java
which need modulepath or classpath parameters in a separate file.- Since:
- 3.1.1
-
async
@Parameter(property="exec.async", defaultValue="false") private boolean asyncIf set to true the child process executes asynchronously and build execution continues in parallel. -
asyncDestroyOnShutdown
@Parameter(property="exec.asyncDestroyOnShutdown", defaultValue="true") private boolean asyncDestroyOnShutdownIf set to true, the asynchronous child process is destroyed upon JVM shutdown. If set to false, asynchronous child process continues execution after JVM shutdown. Applies only to asynchronous processes; ignored for synchronous processes. -
CLASSPATH_TOKEN
- See Also:
-
MODULEPATH_TOKEN
- See Also:
-
processDestroyer
private org.apache.commons.exec.ProcessDestroyer processDestroyer
-
-
Constructor Details
-
ExecMojo
public ExecMojo()
-
-
Method Details
-
execute
public void execute() throws org.apache.maven.plugin.MojoExecutionExceptionpriority 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
-
handleSystemEnvVariables
private Map<String,String> handleSystemEnvVariables() throws org.apache.maven.plugin.MojoExecutionException- Throws:
org.apache.maven.plugin.MojoExecutionException
-
handleWorkingDirectory
private void handleWorkingDirectory() throws org.apache.maven.plugin.MojoExecutionExceptionThis is a convenient method to make the execute method a little bit more readable. It will define the workingDirectory to be the baseDir in case of workingDirectory is null. If the workingDirectory does not exist it will created.- Throws:
org.apache.maven.plugin.MojoExecutionException
-
handleSystemPropertyArguments
private void handleSystemPropertyArguments(String argsProp, List<String> commandArguments) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
handleCommandLineArgs
private void handleCommandLineArgs(List<String> commandArguments) throws org.apache.maven.plugin.MojoExecutionException, IOException - Throws:
org.apache.maven.plugin.MojoExecutionException
IOException
-
handleArguments
private void handleArguments(List<String> commandArguments) throws org.apache.maven.plugin.MojoExecutionException, IOException - Throws:
org.apache.maven.plugin.MojoExecutionException
IOException
-
fillSuccessCodes
private void fillSuccessCodes(org.apache.commons.exec.Executor exec) -
isResultCodeAFailure
boolean isResultCodeAFailure(int result) -
isLongClassPathArgument
-
isLongModulePathArgument
-
isJavaExec
private boolean isJavaExec()Returnstrue
when a java binary is being executed.- Returns:
true
when a java binary is being executed.
-
computeClasspathString
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 dependencies,null
otherwise (the default classpath will be used)- Returns:
- a platform specific String representation of the classpath
-
computePath
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 dependencies,null
otherwise (the default classpath will be used)- Returns:
- a list of class path elements
-
addToClasspath
-
filterArtifacts
private List<org.apache.maven.artifact.Artifact> filterArtifacts(List<org.apache.maven.artifact.Artifact> artifacts, Collection<String> dependencies) -
getExecutablePath
-
findExecutable
-
hasNativeExtension
-
hasExecutableExtension
-
getExecutableExtensions
-
getExecutablePaths
-
executeCommandLine
protected int executeCommandLine(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map<String, String> enviro, OutputStream out, OutputStream err) throws IOException- Throws:
IOException
-
executeCommandLine
protected int executeCommandLine(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map<String, String> enviro, FileOutputStream outputFile) throws IOException- Throws:
IOException
-
executeCommandLine
protected int executeCommandLine(org.apache.commons.exec.Executor exec, org.apache.commons.exec.CommandLine commandLine, Map<String, String> enviro, org.apache.commons.exec.PumpStreamHandler psh) throws IOException- Throws:
IOException
-
setExecutable
-
getExecutable
String getExecutable() -
setWorkingDirectory
-
setWorkingDirectory
-
setArguments
-
setBasedir
-
setProject
void setProject(org.apache.maven.project.MavenProject project) -
getSystemProperty
-
setSuccessCodes
-
getSuccessCodes
public int[] getSuccessCodes() -
getToolchain
private org.apache.maven.toolchain.Toolchain getToolchain() -
createJar
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
-
createArgFile
- Throws:
IOException
-
createEnvs
protected Map<String,String> createEnvs(File envScriptFile) throws org.apache.maven.plugin.MojoExecutionException - Throws:
org.apache.maven.plugin.MojoExecutionException
-
createEnvWrapperFile
- Throws:
IOException
-
getProcessDestroyer
protected org.apache.commons.exec.ProcessDestroyer getProcessDestroyer()
-