org.apache.maven.plugin.compiler
Class AbstractCompilerMojo

java.lang.Object
  extended by org.apache.maven.plugin.AbstractMojo
      extended by org.apache.maven.plugin.compiler.AbstractCompilerMojo
All Implemented Interfaces:
ContextEnabled, Mojo
Direct Known Subclasses:
AbstractCompilerMojo, CompilerMojo, TestCompilerMojo

public abstract class AbstractCompilerMojo
extends 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.

Since:
2.0
Version:
$Id: AbstractCompilerMojo.java 1410034 2012-11-15 21:40:58Z olamy $
Author:
others, Trygve Laugstøl

Field Summary
protected  String compilerArgument
           Sets the unformatted single argument string to be passed to the compiler if fork is set to true.
protected  Map<String,String> compilerArguments
           Sets the arguments to be passed to the compiler (prepending a dash) if fork is set to true.
protected  MavenSession mavenSession
          We need this to determine the start timestamp of the build.
protected  String source
          The -source argument for the Java compiler.
protected  String target
          The -target argument for the Java compiler.
 
Fields inherited from interface org.apache.maven.plugin.Mojo
ROLE
 
Constructor Summary
AbstractCompilerMojo()
           
 
Method Summary
protected  CompilerResult convertToCompilerResult(List<CompilerError> compilerErrors)
           
 void execute()
           
protected  Date getBuildStartTime()
           
protected abstract  List<String> getClasspathElements()
           
protected abstract  String getCompilerArgument()
           
protected abstract  Map<String,String> getCompilerArguments()
           
protected abstract  List<String> getCompileSourceRoots()
           
protected abstract  File getGeneratedSourcesDirectory()
           
protected abstract  File getOutputDirectory()
           
protected  int getRequestThreadCount()
          try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependant
protected abstract  String getSource()
           
protected abstract  SourceInclusionScanner getSourceInclusionScanner(int staleMillis)
           
protected abstract  SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding)
           
protected abstract  String getTarget()
           
protected  boolean isDependencyChanged()
          We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own generated classes and if we got a file which is >= the buid-started timestamp, then we catched a file which got changed during this build.
 
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

source

@Parameter(property="maven.compiler.source",
           defaultValue="1.5")
protected String source
The -source argument for the Java compiler.


target

@Parameter(property="maven.compiler.target",
           defaultValue="1.5")
protected String target
The -target argument for the Java compiler.


compilerArguments

@Parameter
protected Map<String,String> compilerArguments

Sets the 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.

To pass -Xmaxerrs 1000 -Xlint -Xlint:-path -Averbose=true you should include the following:

 <compilerArguments>
   <Xmaxerrs>1000</Xmaxerrs>
   <Xlint/>
   <Xlint:-path/>
   <Averbose>true</Averbose>
 </compilerArguments>
 

Since:
2.0.1

compilerArgument

@Parameter
protected String compilerArgument

Sets the unformatted single argument string to be passed to the compiler if fork is set to true. To pass multiple arguments such as -Xmaxerrs 1000 (which are actually two arguments) you have to use compilerArguments.

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


mavenSession

@Component
protected MavenSession mavenSession
We need this to determine the start timestamp of the build.

Since:
2.6
Constructor Detail

AbstractCompilerMojo

public AbstractCompilerMojo()
Method Detail

getSourceInclusionScanner

protected abstract SourceInclusionScanner getSourceInclusionScanner(int staleMillis)

getSourceInclusionScanner

protected abstract SourceInclusionScanner getSourceInclusionScanner(String inputFileEnding)

getClasspathElements

protected abstract List<String> getClasspathElements()

getCompileSourceRoots

protected abstract List<String> getCompileSourceRoots()

getOutputDirectory

protected abstract File getOutputDirectory()

getSource

protected abstract String getSource()

getTarget

protected abstract String getTarget()

getCompilerArgument

protected abstract String getCompilerArgument()

getCompilerArguments

protected abstract Map<String,String> getCompilerArguments()

getGeneratedSourcesDirectory

protected abstract File getGeneratedSourcesDirectory()

execute

public void execute()
             throws MojoExecutionException,
                    CompilationFailureException
Throws:
MojoExecutionException
CompilationFailureException

convertToCompilerResult

protected CompilerResult convertToCompilerResult(List<CompilerError> compilerErrors)

getRequestThreadCount

protected int getRequestThreadCount()
try to get thread count if a Maven 3 build, using reflection as the plugin must not be maven3 api dependant

Returns:
number of thread for this build or 1 if not multi-thread build

getBuildStartTime

protected Date getBuildStartTime()

isDependencyChanged

protected boolean isDependencyChanged()
We just compare the timestamps of all local dependency files (inter-module dependency classpath) and the own generated classes and if we got a file which is >= the buid-started timestamp, then we catched a file which got changed during this build.

Returns:
true if at least one single dependency has changed.


Copyright © 2001-2012 The Apache Software Foundation. All Rights Reserved.