Class AbstractExecMojo

  • All Implemented Interfaces:
    org.apache.maven.plugin.ContextEnabled, org.apache.maven.plugin.Mojo
    Direct Known Subclasses:
    ExecJavaMojo, ExecMojo

    public abstract class AbstractExecMojo
    extends org.apache.maven.plugin.AbstractMojo
    This class is used for unifying functionality between the 2 mojo exec plugins ('java' and 'exec'). It handles parsing the arguments and adding source/test folders.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean addOutputToClasspath
      Add project output directory to classpath.
      private boolean addResourcesToClasspath
      Add project resource directories to classpath.
      private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory  
      private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver  
      protected java.lang.String classpathScope
      Defines the scope of the classpath passed to the plugin.
      private java.lang.String commandlineArgs
      Arguments separated by space for the executed program.
      protected ExecutableDependency executableDependency
      If provided the ExecutableDependency identifies which of the plugin dependencies contains the executable class.
      private org.apache.maven.artifact.repository.ArtifactRepository localRepository  
      private org.apache.maven.artifact.metadata.ArtifactMetadataSource metadataSource  
      private java.util.List<org.apache.maven.artifact.Artifact> pluginDependencies  
      protected org.apache.maven.project.MavenProject project
      The enclosing project.
      private org.apache.maven.project.MavenProjectBuilder projectBuilder  
      private java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories  
      private boolean skip
      Skip the execution.
      private java.io.File sourceRoot
      This folder is added to the list of those folders containing source to be compiled.
      private java.io.File testSourceRoot
      This folder is added to the list of those folders containing source to be compiled for testing.
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void collectProjectArtifactsAndClasspath​(java.util.List<org.apache.maven.artifact.Artifact> artifacts, java.util.List<java.io.File> theClasspathFiles)
      Collects the project artifacts in the specified List and the project specific classpath (build output and build test output) Files in the specified List, depending on the plugin classpathScope value.
      protected org.apache.maven.artifact.Artifact findExecutableArtifact()
      Examine the plugin dependencies to find the executable artifact.
      protected boolean hasCommandlineArgs()  
      protected boolean isSkip()
      Check if the execution should be skipped
      protected java.lang.String[] parseCommandlineArgs()
      Parses the argument string given by the user.
      protected void registerSourceRoots()
      Register compile and compile tests source roots if necessary
      • 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
      • Methods inherited from interface org.apache.maven.plugin.Mojo

        execute
    • Field Detail

      • project

        @Parameter(defaultValue="${project}",
                   readonly=true)
        protected org.apache.maven.project.MavenProject project
        The enclosing project.
      • artifactResolver

        @Component
        private org.apache.maven.artifact.resolver.ArtifactResolver artifactResolver
      • artifactFactory

        @Component
        private org.apache.maven.artifact.factory.ArtifactFactory artifactFactory
      • projectBuilder

        @Component
        private org.apache.maven.project.MavenProjectBuilder projectBuilder
      • metadataSource

        @Component
        private org.apache.maven.artifact.metadata.ArtifactMetadataSource metadataSource
      • localRepository

        @Parameter(readonly=true,
                   required=true,
                   defaultValue="${localRepository}")
        private org.apache.maven.artifact.repository.ArtifactRepository localRepository
      • remoteRepositories

        @Parameter(readonly=true,
                   required=true,
                   defaultValue="${project.remoteArtifactRepositories}")
        private java.util.List<org.apache.maven.artifact.repository.ArtifactRepository> remoteRepositories
      • pluginDependencies

        @Parameter(readonly=true,
                   defaultValue="${plugin.artifacts}")
        private java.util.List<org.apache.maven.artifact.Artifact> pluginDependencies
      • executableDependency

        @Parameter
        protected ExecutableDependency executableDependency
        If provided the ExecutableDependency identifies which of the plugin dependencies contains the executable class. This will have the affect of only including plugin dependencies required by the identified ExecutableDependency.

        If includeProjectDependencies is set to true, all of the project dependencies will be included on the executable's classpath. Whether a particular project dependency is a dependency of the identified ExecutableDependency will be irrelevant to its inclusion in the classpath.

        Since:
        1.1-beta-1
      • sourceRoot

        @Parameter(property="sourceRoot")
        private java.io.File sourceRoot
        This folder is added to the list of those folders containing source to be compiled. Use this if your plugin generates source code.
      • testSourceRoot

        @Parameter(property="testSourceRoot")
        private java.io.File testSourceRoot
        This folder is added to the list of those folders containing source to be compiled for testing. Use this if your plugin generates test source code.
      • commandlineArgs

        @Parameter(property="exec.args")
        private java.lang.String commandlineArgs
        Arguments separated by space for the executed program. For example: "-j 20"
      • classpathScope

        @Parameter(property="exec.classpathScope",
                   defaultValue="runtime")
        protected java.lang.String classpathScope
        Defines the scope of the classpath passed to the plugin. Set to compile,test,runtime or system depending on your needs. Since 1.1.2, the default value is 'runtime' instead of 'compile'.
      • skip

        @Parameter(property="exec.skip",
                   defaultValue="false",
                   alias="skip")
        private boolean skip
        Skip the execution. Starting with version 1.4.0 the former name skip has been changed into exec.skip.
        Since:
        1.0.1
      • addResourcesToClasspath

        @Parameter(property="addResourcesToClasspath",
                   defaultValue="false")
        private boolean addResourcesToClasspath
        Add project resource directories to classpath. This is especially useful if the exec plugin is used for a code generator that reads its settings from the classpath.
        Since:
        1.5.1
      • addOutputToClasspath

        @Parameter(property="addOutputToClasspath",
                   defaultValue="true")
        private boolean addOutputToClasspath
        Add project output directory to classpath. This might be undesirable when the exec plugin is run before the compile step. Default is true.
        Since:
        1.5.1
    • Constructor Detail

      • AbstractExecMojo

        public AbstractExecMojo()
    • Method Detail

      • collectProjectArtifactsAndClasspath

        protected void collectProjectArtifactsAndClasspath​(java.util.List<org.apache.maven.artifact.Artifact> artifacts,
                                                           java.util.List<java.io.File> theClasspathFiles)
        Collects the project artifacts in the specified List and the project specific classpath (build output and build test output) Files in the specified List, depending on the plugin classpathScope value.
        Parameters:
        artifacts - the list where to collect the scope specific artifacts
        theClasspathFiles - the list where to collect the scope specific output directories
      • parseCommandlineArgs

        protected java.lang.String[] parseCommandlineArgs()
                                                   throws org.apache.maven.plugin.MojoExecutionException
        Parses the argument string given by the user. Strings are recognized as everything between STRING_WRAPPER. PARAMETER_DELIMITER is ignored inside a string. STRING_WRAPPER and PARAMETER_DELIMITER can be escaped using ESCAPE_CHAR.
        Returns:
        Array of String representing the arguments
        Throws:
        org.apache.maven.plugin.MojoExecutionException - for wrong formatted arguments
      • hasCommandlineArgs

        protected boolean hasCommandlineArgs()
        Returns:
        true of the mojo has command line arguments
      • registerSourceRoots

        protected void registerSourceRoots()
        Register compile and compile tests source roots if necessary
      • isSkip

        protected boolean isSkip()
        Check if the execution should be skipped
        Returns:
        true to skip
      • findExecutableArtifact

        protected org.apache.maven.artifact.Artifact findExecutableArtifact()
                                                                     throws org.apache.maven.plugin.MojoExecutionException
        Examine the plugin dependencies to find the executable artifact.
        Returns:
        an artifact which refers to the actual executable tool (not a POM)
        Throws:
        org.apache.maven.plugin.MojoExecutionException - if no executable artifact was found