Class AbstractCompilerMojo

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

    public abstract class AbstractCompilerMojo
    extends org.apache.maven.plugin.AbstractMojo
    TODO: At least one step could be optimized, currently the plugin will do two scans of all the source code if the compiler has to have the entire set of sources. This is currently the case for at least the C# compiler and most likely all the other .NET compilers too.
    Version:
    $Id: AbstractCompilerMojo.java 210 2007-02-20 03:02:41Z jvanzyl $
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.lang.String[] annotationProcessors
      Qualified class names of annotation processors to run.
      private java.io.File basedir
      The directory to run the compiler from if fork is true.
      private java.io.File buildDirectory
      The target directory of the compiler if fork is true.
      private java.util.List<java.lang.String> compilerArgs
      Arguments to be passed to the compiler.
      private java.lang.String compilerArgument
      Unformatted argument string to be passed to the compiler if fork is set to true.
      private java.util.Map<java.lang.String,​java.lang.String> compilerArguments
      Deprecated.
      use compilerArgs instead.
      private java.lang.String compilerId
      The compiler id of the compiler to use.
      private org.codehaus.plexus.compiler.manager.CompilerManager compilerManager
      Plexus compiler manager.
      private java.lang.String compilerVersion
      Version of the compiler to use, ex.
      private boolean debug
      Whether to include debugging information in the compiled class files.
      static java.lang.String DEFAULT_SOURCE_VERSION  
      static java.lang.String DEFAULT_TARGET_VERSION  
      private java.lang.String encoding
      The -encoding argument for the Java compiler
      private java.lang.String executable
      The executable of the compiler to use when fork is true.
      private boolean failOnWarning
      Fail on warnings
      private boolean fork
      Allows running the compiler in a separate process.
      private java.io.File generatedSourcesDirectory
      The directory where source files generated by annotation processors will be created.
      private java.lang.String mavenCompilerEncoding
      Deprecated.
      private java.lang.String maxmem
      maximum size, in megabytes, of the memory allocation pool, ex.
      private java.lang.String meminitial
      Initial size, in megabytes, of the memory allocation pool, ex.
      private boolean optimize
      Optimize compiled code using the compiler's optimization methods
      private java.lang.String outputFileName
      Used to control the name of the output file when compiling a set of sources to a single file.
      private java.lang.String proc
      If only is specified, the annotation processors will run but no compilation will be performed.
      protected java.lang.String release
      The -release argument for the Java compiler
      private boolean showDeprecation
      Output source locations where deprecated APIs are used
      private boolean showWarnings
      Output warnings
      protected java.lang.String source
      The -source argument for the Java compiler
      private int staleMillis
      The granularity in milliseconds of the last modification date for testing whether a source needs recompilation
      protected java.lang.String target
      The -target argument for the Java compiler
      private boolean verbose
      Whether to output messages about what the compiler is doing
      • Fields inherited from interface org.apache.maven.plugin.Mojo

        ROLE
    • Method Summary

      All Methods Static Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      private java.util.Set<java.io.File> computeStaleSources​(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration, org.codehaus.plexus.compiler.Compiler compiler, org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner scanner)  
      void execute()  
      protected abstract java.util.List<java.lang.String> getClasspathElements()  
      protected org.codehaus.plexus.compiler.CompilerConfiguration getCompilerConfiguration​(java.util.List<java.lang.String> compileSourceRoots, java.util.List<java.lang.String> compileSourceExcludes)  
      protected abstract java.util.List<java.lang.String> getCompileSourceExcludePaths()  
      protected abstract java.util.List<java.lang.String> getCompileSourceRoots()  
      private java.lang.String getEncoding()  
      private java.lang.String getMemoryValue​(java.lang.String setting)  
      protected abstract java.io.File getOutputDirectory()  
      protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(int staleMillis)  
      protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(java.lang.String inputFileEnding)  
      private boolean isDigits​(java.lang.String string)  
      protected static java.util.List<java.lang.String> removeEmptyCompileSourceRoots​(java.util.List<java.lang.String> compileSourceRootsList)  
      • 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

      • DEFAULT_SOURCE_VERSION

        public static final java.lang.String DEFAULT_SOURCE_VERSION
        See Also:
        Constant Field Values
      • DEFAULT_TARGET_VERSION

        public static final java.lang.String DEFAULT_TARGET_VERSION
        See Also:
        Constant Field Values
      • debug

        @Parameter(property="maven.compiler.debug",
                   defaultValue="true")
        private boolean debug
        Whether to include debugging information in the compiled class files. The default value is true.
      • verbose

        @Parameter(property="maven.compiler.verbose",
                   defaultValue="false")
        private boolean verbose
        Whether to output messages about what the compiler is doing
      • showDeprecation

        @Parameter(property="maven.compiler.showDeprecation",
                   defaultValue="false")
        private boolean showDeprecation
        Output source locations where deprecated APIs are used
      • optimize

        @Parameter(property="maven.compiler.optimize",
                   defaultValue="false")
        private boolean optimize
        Optimize compiled code using the compiler's optimization methods
      • showWarnings

        @Parameter(property="maven.compiler.showWarnings",
                   defaultValue="false")
        private boolean showWarnings
        Output warnings
      • failOnWarning

        @Parameter(property="maven.compiler.failOnWarning",
                   defaultValue="false")
        private boolean failOnWarning
        Fail on warnings
      • source

        @Parameter(property="maven.compiler.source")
        protected java.lang.String source
        The -source argument for the Java compiler
      • target

        @Parameter(property="maven.compiler.target")
        protected java.lang.String target
        The -target argument for the Java compiler
      • release

        @Parameter(property="maven.compiler.release")
        protected java.lang.String release
        The -release argument for the Java compiler
      • mavenCompilerEncoding

        @Parameter(property="maven.compiler.encoding",
                   readonly=true)
        private java.lang.String mavenCompilerEncoding
        Deprecated.
        The -encoding argument for the Java compiler (kept for backwards compatibility)
      • encoding

        @Parameter(property="project.build.sourceEncoding")
        private java.lang.String encoding
        The -encoding argument for the Java compiler
      • staleMillis

        @Parameter(property="lastModGranularityMs",
                   defaultValue="0")
        private int staleMillis
        The granularity in milliseconds of the last modification date for testing whether a source needs recompilation
      • compilerId

        @Parameter(property="maven.compiler.compilerId",
                   defaultValue="jdt")
        private java.lang.String compilerId
        The compiler id of the compiler to use.
      • compilerVersion

        @Parameter(property="maven.compiler.compilerVersion")
        private java.lang.String compilerVersion
        Version of the compiler to use, ex. "1.3", "1.5", if fork is set to true
      • fork

        @Parameter(defaultValue="false")
        private boolean fork
        Allows running the compiler in a separate process. If "false" it uses the built in compiler, while if "true" it will use an executable.
      • meminitial

        @Parameter(property="maven.compiler.meminitial")
        private java.lang.String meminitial
        Initial size, in megabytes, of the memory allocation pool, ex. "64", "64m" if fork is set to true
      • maxmem

        @Parameter(property="maven.compiler.maxmem")
        private java.lang.String maxmem
        maximum size, in megabytes, of the memory allocation pool, ex. "128", "128m" if fork is set to true
      • executable

        @Parameter(property="maven.compiler.executable")
        private java.lang.String executable
        The executable of the compiler to use when fork is true.
      • proc

        @Parameter
        private java.lang.String proc
        If only is specified, the annotation processors will run but no compilation will be performed. If none is specified, annotation processors will not be discovered or run; compilation will proceed as if no annotation processors were found. By default the compiler must search the classpath for annotation processors, so specifying none may speed compilation if annotation processing is not required. This parameter requires a 1.6 VM or above and is used only if the compliance is 1.6
        Since:
        0.16.0
      • annotationProcessors

        @Parameter
        private java.lang.String[] annotationProcessors
        Qualified class names of annotation processors to run. If specified, the normal processor discovery process will be skipped. This parameter requires a 1.6 VM or above and is used only if the compliance is 1.6
        Since:
        0.16.0
      • generatedSourcesDirectory

        @Parameter(defaultValue="${project.build.directory}/generated-sources/annotations")
        private java.io.File generatedSourcesDirectory
        The directory where source files generated by annotation processors will be created. This parameter requires a 1.6 VM or above and is used only if the compliance is 1.6.
        Since:
        0.16.0
      • compilerArguments

        @Parameter
        private java.util.Map<java.lang.String,​java.lang.String> compilerArguments
        Deprecated.
        use compilerArgs instead.

        Arguments to be passed to the compiler (prepending a dash) if fork is set to true.

        This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.

      • compilerArgs

        @Parameter
        private java.util.List<java.lang.String> compilerArgs
        Arguments to be passed to the compiler.
        Since:
        0.17.0
      • compilerArgument

        @Parameter
        private java.lang.String compilerArgument

        Unformatted argument string to be passed to the compiler if fork is set to true.

        This is because the list of valid arguments passed to a Java compiler varies based on the compiler version.

      • outputFileName

        @Parameter(property="project.build.finalName")
        private java.lang.String outputFileName
        Used to control the name of the output file when compiling a set of sources to a single file.
      • basedir

        @Parameter(property="basedir",
                   required=true,
                   readonly=true)
        private java.io.File basedir
        The directory to run the compiler from if fork is true.
      • buildDirectory

        @Parameter(property="project.build.directory",
                   readonly=true,
                   required=true)
        private java.io.File buildDirectory
        The target directory of the compiler if fork is true.
      • compilerManager

        @Component
        private org.codehaus.plexus.compiler.manager.CompilerManager compilerManager
        Plexus compiler manager.
    • Constructor Detail

      • AbstractCompilerMojo

        public AbstractCompilerMojo()
    • Method Detail

      • getSourceInclusionScanner

        protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(int staleMillis)
      • getSourceInclusionScanner

        protected abstract org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner getSourceInclusionScanner​(java.lang.String inputFileEnding)
      • getClasspathElements

        protected abstract java.util.List<java.lang.String> getClasspathElements()
                                                                          throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getCompileSourceRoots

        protected abstract java.util.List<java.lang.String> getCompileSourceRoots()
                                                                           throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getCompileSourceExcludePaths

        protected abstract java.util.List<java.lang.String> getCompileSourceExcludePaths()
                                                                                  throws org.apache.maven.plugin.MojoExecutionException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
      • getOutputDirectory

        protected abstract java.io.File getOutputDirectory()
      • execute

        public void execute()
                     throws org.apache.maven.plugin.MojoExecutionException,
                            org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • getCompilerConfiguration

        protected org.codehaus.plexus.compiler.CompilerConfiguration getCompilerConfiguration​(java.util.List<java.lang.String> compileSourceRoots,
                                                                                              java.util.List<java.lang.String> compileSourceExcludes)
                                                                                       throws org.apache.maven.plugin.MojoExecutionException,
                                                                                              org.apache.maven.plugin.MojoFailureException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.apache.maven.plugin.MojoFailureException
      • getEncoding

        private java.lang.String getEncoding()
      • getMemoryValue

        private java.lang.String getMemoryValue​(java.lang.String setting)
      • isDigits

        private boolean isDigits​(java.lang.String string)
      • computeStaleSources

        private java.util.Set<java.io.File> computeStaleSources​(org.codehaus.plexus.compiler.CompilerConfiguration compilerConfiguration,
                                                                org.codehaus.plexus.compiler.Compiler compiler,
                                                                org.codehaus.plexus.compiler.util.scan.SourceInclusionScanner scanner)
                                                         throws org.apache.maven.plugin.MojoExecutionException,
                                                                org.codehaus.plexus.compiler.CompilerException
        Throws:
        org.apache.maven.plugin.MojoExecutionException
        org.codehaus.plexus.compiler.CompilerException
      • removeEmptyCompileSourceRoots

        protected static java.util.List<java.lang.String> removeEmptyCompileSourceRoots​(java.util.List<java.lang.String> compileSourceRootsList)