Compile Java source files using the Java 6 javac API:s.
Task package: | org.schmant.task.base |
Java package: | org.schmant.task.jdk.javac.jdk6 |
Category: | Compiling tasks |
Since: | 0.5 |
EntityFS-aware? | Yes* |
Implements: | ActionTaskFactory GeneratorTaskFactory ProcessTaskFactory |
See also: | ExtJavacTF |
Description:
Use the Java 6 javac API:s to compile Java source files.
The task assumes that the source files are encoded in the platform's default character encoding. If they are not, set the encoding property.
If a property is not set, javac
's default value for that property is used.
Note: there is a bug in the compiler in early versions of Sun's JDK 6 that sometimes causes the compiler to fail on autoboxing constructs in the code that it compiles if running multiple compile threads simultaneously. The simplest workaround for the bug is to upgrade to a newer JDK.
Required properties
Properties
annotationProcessingMode | top |
Set the mode for annotation processing.
This corresponds
to javac
's -proc
option.
- Setter method:
setAnnotationProcessingMode(JavacAnnotationProcessingMode m)
parameters:m
– The annotation processing mode.
annotationProcessor | top |
A list of fully qualified class names of the annotation
processors to use. This corresponds to javac
's
-processor
option.
- Setter method:
addAnnotationProcessor(String n)
Add one annotation processor class.parameters:n
– The fully qualified name of an annotation processor class.- Setter method:
addAnnotationProcessors(Object o)
Add one or several annotation processor classes.parameters:o
– One or an array or collection of fully qualified class names of annotation processors (strings).- Setter method:
clearAnnotationProcessors()
Clear the list of annotation processors.
annotationProcessorOptions | top |
Annotation processor options.
Corresponds to
javac
's -A
option.
- Setter method:
addAnnotationProcessorOption(String key, String value)
Add one annotation processor option.parameters:key
– The option name.value
– The option value.- Setter method:
addAnnotationProcessorOptions(Map<String, String> m)
Add all annotation processor options from aparameters:Map
.m
– The option map.- Setter method:
clearAnnotationProcessorOptions()
Clear the list of annotation processor options.
annotationProcessorPath | top |
A path where annotation processors can be found.
This
corresponds to javac
's -processorpath
option.
- Setter method:
setAnnotationProcessorPath(Object o)
parameters:
arguments | top |
Arguments (options) to the compiler. See the
javac
documentation for the compiler version used for a list of
accepted values. The arguments are given to the compiler in the order that they
were added.
- Setter method:
addArgument(String s)
Add one compiler option.parameters:s
– Ajavac
option.- Setter method:
addArguments(Object o)
Add one or several compiler options.parameters:o
– One compiler option or an array or collection of compiler options (strings).- Setter method:
clearArguments()
Clear the list of compiler options.
classpathDecorators | top |
A collection of
PathDecorator:s that are used
to add entries to the classpath. The decorators are run in the order that they
are added to this property. Classpath decorator entries are added to the classpath after all entries added
manually to the classpathEntries
property.
- Setter method:
addClasspathDecorator(PathDecorator pd)
Add one classpath decorator to the end of the list.parameters:pd
– A classpath decorator.- Setter method:
addClasspathDecorators(Object o)
Add one or several classpath decorators.parameters:- Setter method:
clearClasspathDecorators()
Clear the list of classpath decorators.- See also:
- classpathEntries
classpathEntries | top |
Manually set classpath entries. An entry must be a Jar file or a class file directory.
- Setter method:
addClasspathEntries(Object o)
Add one or several classpath entries.parameters:o
– One or an array or collection of entries to add to the class path.
Interpreted byInterpretAsFileStrategy
.- Setter method:
addClasspathEntry(Object o)
Add one entry to the end of the class path.parameters:- Setter method:
clearClasspathEntries()
Clear the list of classpath entries.- See also:
- classpathDecorators
debugOptions | top |
This option decides what debug information to include in the compiled classes. Set it to JavacDebugKeyword.ALL to include all debug information.
This corresponds to javac
's -g
option.
- Setter method:
addDebugOption(JavacDebugKeyword o)
Add one debug option.parameters:o
– The debug option.- Setter method:
addDebugOptions(Object o)
Add one debug option or an array or collection of debug options.parameters:- Setter method:
clearDebugOptions()
Clear the list of debug options.- Default value:
- Not set (use
javac
's default).
deprecation | top |
Should detailed deprecation information be displayed?
This
corresponds to javac
's -deprecation
flag.
- Setter method:
setDeprecation(boolean b)
parameters:b
– Should detailed deprecation information be displayed?
encoding | top |
The name of the character encoding of the source files.
- Setter method:
setEncoding(String s)
parameters:s
– The name of the encoding, e.g.UTF-8
.- Default value:
- The platform's default character encoding.
implicitClassFileGeneration | top |
Should class files be generated for implicitly loaded source files?
This corresponds to javac
's -implicit
option.
- Setter method:
setImplicitClassFileGeneration(JavacImplicitClassFileGeneration j)
parameters:j
– Should class files for implicitly loaded source files be generated?- Default value:
false
(implicit class files are not generated).
logFooter | top |
The message that is logged to info
level
after the task has been successfully run.
- Setter method:
setLogFooter(String s)
parameters:s
– The footer message.- Default value:
- Empty (no footer message is logged.)
- See also:
- logHeader
logHeader | top |
The message that is logged to info
level
before the task is run.
- Setter method:
setLogHeader(String s)
parameters:s
– The header message.- Default value:
- A task class specific message.
- See also:
- logFooter
noWarn | top |
Should warning messages from javac
be
disabled? This corresponds to javac
's -nowarn
flag.
- Setter method:
setNoWarn(boolean b)
parameters:b
– Disable warnings?
overwriteStrategy | top |
The overwrite strategy decides how the task will react if there already is an entity (file or directory) in a location where it wants to create a new entity.
If the strategy is to not overwrite existing entities, the task will fail when it cannot create the entities that it wants to create.
Non-empty directories are never overwritten, regardless of the chosen strategy.
- Setter method:
setOverwrite(boolean b)
Setting this to a value ofparameters:true
means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.b
– Should an existing entity be overwritten?- Setter method:
setOverwriteStrategy(OverwriteStrategy strat)
Set the overwrite strategy.parameters:strat
– The overwrite strategy.- Default value:
- DontOverwriteAndThrowException
- See also:
- target
reportLevel | top |
This property is used to change the Report level for all task created by this task factory. The report level is changed for the thread running the task when the it is run, and is restored to its previous level when the it is done.
- Setter method:
setReportLevel(Level l)
Set the report levelparameters:l
– The new report level.
sourceCodeVersion | top |
The source code version accepted.
- Setter method:
setSourceCodeVersion(String release)
parameters:release
– The source code version accepted. See thejavac
documentation for the compiler version used for a list of accepted values.
sourceFilesDir | top |
The directory where generated source files will be put.
This corresponds to javac
's -s
option.
- Setter method:
setSourceFilesDir(Object o)
parameters:
sources (required) | top |
The source directories for Java files.
There are two ways that EntityFilter:s can be used to exclude source files from being compiled:
- Using a DirectoryView as source: This task will only compile files that match the view's filter. Furthermore, it will only recurse down into child directories that match the filter.
- Using a DirectoryAndFilter as source: This task will only compile files that match the view's filter. It will however recurse down into all child directories of a processed directory.
- Setter method:
addSource(Object o)
Add one or several source directories.parameters:- Setter method:
addSources(Object o)
Add one or several source directories.parameters:- Setter method:
clearSources()
Discard all source paths.- Setter method:
setSource(Object o)
Set one or several source directories, discarding previously set directories.parameters:- Setter method:
setSources(Object o)
Set one or several source directories, discarding previously set directories.parameters:
target (required) | top |
The target directory to put compiled classes in.
- Setter method:
setTarget(Object o)
parameters:- See also:
- overwriteStrategy
targetVersion | top |
The target Java version for generated class files. The class files will only run on the targeted and later versions of Java.
- Setter method:
setTargetVersion(String version)
parameters:version
– The target Java version for generated class files. See thejavac
documentation for the compiler version used for a list of accepted values.
traceLogging | top |
If trace logging is enabled for a task, it reports its configuration before it is run.
Trace logging may also be enabled globally for all tasks by calling TraceMode.setTraceMode(boolean).
- Setter method:
setTraceLogging(boolean b)
Enable or disable trace logging.parameters:b
– Enable trace logging?
Examples
Example 1
Compile source files in the directory hierarchy under
src
. Put the class files in a directory hierarchy under
bin
.
JavaScript
Example 2
Compile all Java projects from the
ProjectRepository eWos
(in this case, an
EclipseWorkspace under the Directory
wosDir
). Put all class files under bin
. The compile
tasks are run by the TaskExecutor te
.
Groovy
JavaScript
JRuby
Jython
* An EntityFS-aware task is implemented using EntityFS. This means that it uses the filter settings of DirectoryView:s and also that it often can work with other file system implementations than File-based, such as the RAM file system.