Jdk6JavacTF

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

annotationProcessingModetop

Set the mode for annotation processing.

This corresponds to javac's -proc option.

Setter method:
setAnnotationProcessingMode(JavacAnnotationProcessingMode m)
parameters:
m – The annotation processing mode.
annotationProcessortop

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.
annotationProcessorOptionstop

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 a Map.
parameters:
m – The option map.
Setter method:
clearAnnotationProcessorOptions()
Clear the list of annotation processor options.
annotationProcessorPathtop

A path where annotation processors can be found.

This corresponds to javac's -processorpath option.

Setter method:
setAnnotationProcessorPath(Object o)
parameters:
o – The path.
Interpreted by InterpretAsFileStrategy.
argumentstop

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 – A javac 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.
classpathDecoratorstop

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:
o – One or an array or collection of classpath decorators (PathDecorator objects).
Setter method:
clearClasspathDecorators()
Clear the list of classpath decorators.
See also:
classpathEntries
classpathEntriestop

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 by InterpretAsFileStrategy.
Setter method:
addClasspathEntry(Object o)
Add one entry to the end of the class path.
parameters:
o – The entry to add to the class path.
Interpreted by InterpretAsFileStrategy.
Setter method:
clearClasspathEntries()
Clear the list of classpath entries.
See also:
classpathDecorators
debugOptionstop

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:
o – One debug option or an array or collection of debug options (JavacDebugKeyword objects).
Setter method:
clearDebugOptions()
Clear the list of debug options.
Default value:
Not set (use javac's default).
deprecationtop

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?
encodingtop

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.
implicitClassFileGenerationtop

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).
logFootertop

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
logHeadertop

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
noWarntop

Should warning messages from javac be disabled? This corresponds to javac's -nowarn flag.

Setter method:
setNoWarn(boolean b)
parameters:
b – Disable warnings?
overwriteStrategytop

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 of true means that the DoOverwriteAndLogWarning strategy is used. A value of false gives the DontOverwriteAndThrowException strategy.
parameters:
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
reportLeveltop

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 level
parameters:
l – The new report level.
sourceCodeVersiontop

The source code version accepted.

Setter method:
setSourceCodeVersion(String release)
parameters:
release – The source code version accepted. See the javac documentation for the compiler version used for a list of accepted values.
sourceFilesDirtop

The directory where generated source files will be put.

This corresponds to javac's -s option.

Setter method:
setSourceFilesDir(Object o)
parameters:
o – The directory for generated source files.
Interpreted by InterpretAsFileDirectoryStrategy.
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:

  1. 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.
  2. 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:
o – One or several source directories.
Interpreted by InterpretAsReadOnlyDirectoryStrategy.
Setter method:
addSources(Object o)
Add one or several source directories.
parameters:
o – One or several source directories.
Interpreted by InterpretAsReadOnlyDirectoryStrategy.
Setter method:
clearSources()
Discard all source paths.
Setter method:
setSource(Object o)
Set one or several source directories, discarding previously set directories.
parameters:
o – One or several source directories.
Interpreted by InterpretAsReadOnlyDirectoryStrategy.
Setter method:
setSources(Object o)
Set one or several source directories, discarding previously set directories.
parameters:
o – One or several source directories.
Interpreted by InterpretAsReadOnlyDirectoryStrategy.
target (required)top

The target directory to put compiled classes in.

Setter method:
setTarget(Object o)
parameters:
o – The target directory.
Interpreted by InterpretAsFutureEntityStrategy.
See also:
overwriteStrategy
targetVersiontop

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 the javac documentation for the compiler version used for a list of accepted values.
traceLoggingtop

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.

new Jdk6JavacTF(). addSource(src). setTarget(bin).run();

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.

import org.entityfs.util.* import org.schmant.project.eclipse.* import org.schmant.run.TaskExecutor import org.schmant.task.jdk.javac.jdk6.Jdk6JavacTF import org.schmant.task.project.JavaWorkspaceBuilderTF // This is a classpath variable used by some of the Eclipse Java projects. // wosLibDir is a Directory variable for a library directory in the Eclipse // workspace. def settings = new EclipseWorkspaceSettings(). addClasspathVariable( "ENTITYFS", Directories.getFileMatching(wosLibDir, "entityfs-*.jar")) // Create the ProjectRepository (an EclipseWorkspace in this example) def eWos = new EclipseWorkspace(wosDir, settings) // Create a task executor and start it def te = new TaskExecutor(). setNumberOfThreads(2). start() try { // Use a JavaWorkspaceBuilderTF to build the workspace new JavaWorkspaceBuilderTF(). setWorkspace(eWos). // // Set the task executor. The task will use the task executor to run the // tasks that it creates for compiling all projects in the workspace setTaskExecutor(te). // // Set a custom factory for the compilation tasks. setCompileTaskFactory( new Jdk6JavacTF(). setTargetVersion("6")). setTarget(bin).run() // Wait for all compilation tasks to complete te.waitFor() } finally { te.shutdown() }


* 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.