@Mojo(name="java", threadSafe=true, requiresDependencyResolution=TEST) public class ExecJavaMojo extends AbstractExecMojo
Modifier and Type | Class and Description |
---|---|
(package private) class |
ExecJavaMojo.IsolatedThreadGroup
a ThreadGroup to isolate execution and collect exceptions.
|
Modifier and Type | Field and Description |
---|---|
private java.util.List<java.lang.String> |
additionalClasspathElements
Additional elements to be appended to the classpath.
|
private java.lang.String[] |
arguments
The class arguments.
|
private org.apache.maven.artifact.factory.ArtifactFactory |
artifactFactory |
private org.apache.maven.artifact.resolver.ArtifactResolver |
artifactResolver |
private boolean |
cleanupDaemonThreads
Whether to interrupt/join and possibly stop the daemon threads upon quitting.
|
private long |
daemonThreadJoinTimeout
This defines the number of milliseconds to wait for daemon threads to quit following their interruption.
This is only taken into account if cleanupDaemonThreads is true . |
private boolean |
includePluginDependencies
Indicates if this plugin's dependencies should be used when executing the main class.
|
private boolean |
includeProjectDependencies
Indicates if the project dependencies should be used when executing the main class.
|
private boolean |
keepAlive
Deprecated.
since 1.1-alpha-1
|
private long |
killAfter
Deprecated.
since 1.1-alpha-1
|
private org.apache.maven.artifact.repository.ArtifactRepository |
localRepository |
private java.lang.String |
mainClass
The main class to execute.
|
private org.apache.maven.artifact.metadata.ArtifactMetadataSource |
metadataSource |
private java.util.Properties |
originalSystemProperties |
private java.util.List<org.apache.maven.artifact.Artifact> |
pluginDependencies |
private org.apache.maven.project.MavenProjectBuilder |
projectBuilder |
private java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> |
remoteRepositories |
private boolean |
stopUnresponsiveDaemonThreads
Wether to call
Thread.stop() following a timing out of waiting for an interrupted thread to finish. |
private Property[] |
systemProperties
A list of system properties to be passed.
|
classpathScope, executableDependency, project
Constructor and Description |
---|
ExecJavaMojo() |
Modifier and Type | Method and Description |
---|---|
private void |
addAdditionalClasspathElements(java.util.List<java.net.URL> path) |
private void |
addRelevantPluginDependenciesToClasspath(java.util.List<java.net.URL> path)
Add any relevant project dependencies to the classpath.
|
private void |
addRelevantProjectDependenciesToClasspath(java.util.List<java.net.URL> path)
Add any relevant project dependencies to the classpath.
|
private java.util.Set<org.apache.maven.artifact.Artifact> |
determineRelevantPluginDependencies()
Determine all plugin dependencies relevant to the executable.
|
void |
execute()
Execute goal.
|
private java.util.Collection<java.lang.Thread> |
getActiveThreads(java.lang.ThreadGroup threadGroup) |
private java.lang.ClassLoader |
getClassLoader()
Set up a classloader for the execution of the main class.
|
private org.apache.maven.artifact.Artifact |
getExecutablePomArtifact(org.apache.maven.artifact.Artifact executableArtifact)
Get the artifact which refers to the POM of the executable artifact.
|
private void |
joinNonDaemonThreads(java.lang.ThreadGroup threadGroup) |
private void |
joinThread(java.lang.Thread thread,
long timeoutMsecs) |
private java.util.Set<org.apache.maven.artifact.Artifact> |
resolveExecutableDependencies(org.apache.maven.artifact.Artifact executablePomArtifact)
Resolve the executable dependencies for the specified project
|
private void |
setSystemProperties()
Pass any given system properties to the java system properties.
|
private void |
terminateThreads(java.lang.ThreadGroup threadGroup) |
private void |
waitFor(long millis)
Stop program execution for nn millis.
|
collectProjectArtifactsAndClasspath, findExecutableArtifact, hasCommandlineArgs, isSkip, parseCommandlineArgs, registerSourceRoots
@Component private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
@Component private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
@Component private org.apache.maven.artifact.metadata.ArtifactMetadataSource metadataSource
@Parameter(readonly=true, required=true, defaultValue="${localRepository}") private org.apache.maven.artifact.repository.ArtifactRepository localRepository
@Parameter(readonly=true, required=true, defaultValue="${project.remoteArtifactRepositories}") private java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories
@Component private org.apache.maven.project.MavenProjectBuilder projectBuilder
@Parameter(readonly=true, defaultValue="${plugin.artifacts}") private java.util.List<org.apache.maven.artifact.Artifact> pluginDependencies
@Parameter(required=true, property="exec.mainClass") private java.lang.String mainClass
@Parameter(property="exec.arguments") private java.lang.String[] arguments
@Parameter private Property[] systemProperties
@Parameter(property="exec.keepAlive", defaultValue="false") @Deprecated private boolean keepAlive
@Parameter(property="exec.includeProjectDependencies", defaultValue="true") private boolean includeProjectDependencies
@Parameter(property="exec.includePluginsDependencies", defaultValue="false") private boolean includePluginDependencies
@Parameter(property="exec.cleanupDaemonThreads", defaultValue="true") private boolean cleanupDaemonThreads
false
, maven does nothing about the daemon threads. When maven has no more work to do,
the VM will normally terminate any remaining daemon threads.
In certain cases (in particular if maven is embedded), you might need to keep this enabled to make sure threads
are properly cleaned up to ensure they don't interfere with subsequent activity. In that case, see
daemonThreadJoinTimeout
and stopUnresponsiveDaemonThreads
for further tuning.
@Parameter(property="exec.daemonThreadJoinTimeout", defaultValue="15000") private long daemonThreadJoinTimeout
cleanupDaemonThreads
is true
. A value <=0 means to
not timeout (i.e. wait indefinitely for threads to finish). Following a timeout, a warning will be logged.
Note: properly coded threads should terminate upon interruption but some threads may prove problematic: as the VM does interrupt daemon threads, some code may not have been written to handle interruption properly. For example java.util.Timer is known to not handle interruptions in JDK <= 1.6. So it is not possible for us to infinitely wait by default otherwise maven could hang. A sensible default value has been chosen, but this default value may change in the future based on user feedback.
@Parameter(property="exec.stopUnresponsiveDaemonThreads", defaultValue="false") private boolean stopUnresponsiveDaemonThreads
Thread.stop()
following a timing out of waiting for an interrupted thread to finish. This
is only taken into account if cleanupDaemonThreads
is true
and the
daemonThreadJoinTimeout
threshold has been reached for an uncooperative thread. If this is
false
, or if Thread.stop()
fails to get the thread to stop, then a warning is logged and
Maven will continue on while the affected threads (and related objects in memory) linger on. Consider setting
this to true
if you are invoking problematic code that you can't fix. An example is
Timer
which doesn't respond to interruption. To have Timer
fixed, vote for
this bug.@Parameter(property="exec.killAfter", defaultValue="-1") @Deprecated private long killAfter
private java.util.Properties originalSystemProperties
@Parameter private java.util.List<java.lang.String> additionalClasspathElements
public void execute() throws org.apache.maven.plugin.MojoExecutionException, org.apache.maven.plugin.MojoFailureException
org.apache.maven.plugin.MojoExecutionException
- execution of the main class or one of the threads it generated failed.org.apache.maven.plugin.MojoFailureException
- something bad happened...private void joinNonDaemonThreads(java.lang.ThreadGroup threadGroup)
private void joinThread(java.lang.Thread thread, long timeoutMsecs)
private void terminateThreads(java.lang.ThreadGroup threadGroup)
private java.util.Collection<java.lang.Thread> getActiveThreads(java.lang.ThreadGroup threadGroup)
private void setSystemProperties()
private java.lang.ClassLoader getClassLoader() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
- if a problem happensprivate void addAdditionalClasspathElements(java.util.List<java.net.URL> path)
private void addRelevantPluginDependenciesToClasspath(java.util.List<java.net.URL> path) throws org.apache.maven.plugin.MojoExecutionException
path
- classpath of URL
objectsorg.apache.maven.plugin.MojoExecutionException
- if a problem happensprivate void addRelevantProjectDependenciesToClasspath(java.util.List<java.net.URL> path) throws org.apache.maven.plugin.MojoExecutionException
path
- classpath of URL
objectsorg.apache.maven.plugin.MojoExecutionException
- if a problem happensprivate java.util.Set<org.apache.maven.artifact.Artifact> determineRelevantPluginDependencies() throws org.apache.maven.plugin.MojoExecutionException
org.apache.maven.plugin.MojoExecutionException
- if a problem happens resolving the plufin dependenciesprivate org.apache.maven.artifact.Artifact getExecutablePomArtifact(org.apache.maven.artifact.Artifact executableArtifact)
executableArtifact
- this artifact refers to the actual assembly.private java.util.Set<org.apache.maven.artifact.Artifact> resolveExecutableDependencies(org.apache.maven.artifact.Artifact executablePomArtifact) throws org.apache.maven.plugin.MojoExecutionException
executablePomArtifact
- the project's POMorg.apache.maven.plugin.MojoExecutionException
- if a failure happensprivate void waitFor(long millis)
millis
- the number of millis-seconds to wait for, 0
stops program forever.