public class Javac extends MatchingTask
When this task executes, it will recursively scan the sourcedir and destdir looking for Java source files to compile. This task makes its compile decision based on timestamp.
Modifier and Type | Class and Description |
---|---|
class |
Javac.ImplementationSpecificArgument
Adds an "compiler" attribute to Commandline$Attribute used to
filter command line attributes based on the current
implementation.
|
Modifier and Type | Field and Description |
---|---|
protected File[] |
compileList |
protected boolean |
failOnError |
protected boolean |
listFiles |
fileset
Constructor and Description |
---|
Javac()
Javac task for compilation of Java files.
|
Modifier and Type | Method and Description |
---|---|
void |
add(CompilerAdapter adapter)
Set the compiler adapter explicitly.
|
protected void |
checkParameters()
Check that all required attributes have been set and nothing
silly has been entered.
|
protected void |
compile()
Perform the compilation.
|
Path |
createBootclasspath()
Adds a path to the bootclasspath.
|
Path |
createClasspath()
Adds a path to the classpath.
|
Javac.ImplementationSpecificArgument |
createCompilerArg()
Adds an implementation specific command-line argument.
|
Path |
createCompilerClasspath()
The classpath to use when loading the compiler implementation
if it is not a built-in one.
|
Path |
createExtdirs()
Adds a path to extdirs.
|
Path |
createModulepath()
Adds a path to the modulepath.
|
Path |
createModulesourcepath()
Adds a path to modulesourcepath.
|
Path |
createSourcepath()
Adds a path to sourcepath.
|
Path |
createSrc()
Adds a path for source compilation.
|
Path |
createUpgrademodulepath()
Adds a path to the upgrademodulepath.
|
void |
execute()
Executes the task.
|
Path |
getBootclasspath()
Gets the bootclasspath that will be used to compile the classes
against.
|
Path |
getClasspath()
Gets the classpath to be used for this compilation.
|
String |
getCompiler()
The implementation for this particular task.
|
String |
getCompilerVersion()
The implementation for this particular task.
|
String[] |
getCurrentCompilerArgs()
Get the additional implementation specific command line arguments.
|
boolean |
getDebug()
Gets the debug flag.
|
String |
getDebugLevel()
Get the value of debugLevel.
|
boolean |
getDepend()
Gets the depend flag.
|
boolean |
getDeprecation()
Gets the deprecation flag.
|
File |
getDestdir()
Gets the destination directory into which the java source files
should be compiled.
|
String |
getEncoding()
Gets the java source file encoding name.
|
String |
getExecutable()
The value of the executable attribute, if any.
|
Path |
getExtdirs()
Gets the extension directories that will be used during the
compilation.
|
boolean |
getFailonerror()
Gets the failonerror flag.
|
File[] |
getFileList()
Gets the list of files to be compiled.
|
boolean |
getIncludeantruntime()
Gets whether or not the ant classpath is to be included in the classpath.
|
boolean |
getIncludejavaruntime()
Gets whether or not the java runtime should be included in this
task's classpath.
|
String |
getJavacExecutable()
The name of the javac executable to use in fork-mode.
|
boolean |
getListfiles()
Get the listfiles flag.
|
String |
getMemoryInitialSize()
Gets the memoryInitialSize flag.
|
String |
getMemoryMaximumSize()
Gets the memoryMaximumSize flag.
|
Path |
getModulepath()
Gets the modulepath to be used for this compilation.
|
Path |
getModulesourcepath()
Gets the modulesourcepath to be used for this compilation.
|
File |
getNativeHeaderDir()
Gets the destination directory into which the generated native
header files should be placed.
|
boolean |
getNowarn()
Should the -nowarn option be used.
|
boolean |
getOptimize()
Gets the optimize flag.
|
String |
getRelease()
Gets the version to use for the
--release switch that
combines source , target and setting the
bootclasspath. |
String |
getSource()
Get the value of source.
|
Path |
getSourcepath()
Gets the sourcepath to be used for this compilation.
|
Path |
getSrcdir()
Gets the source dirs to find the source java files.
|
protected String |
getSystemJavac() |
String |
getTarget()
Gets the target VM that the classes will be compiled for.
|
boolean |
getTaskSuccess()
Get the result of the javac task (success or failure).
|
File |
getTempdir()
Where Ant should place temporary files.
|
Path |
getUpgrademodulepath()
Gets the upgrademodulepath to be used for this compilation.
|
boolean |
getVerbose()
Gets the verbose flag.
|
boolean |
isForkedJavac()
Is this a forked invocation of JDK's javac?
|
boolean |
isIncludeDestClasses()
Get the value of the includeDestClasses property.
|
protected boolean |
isJdkCompiler(String compilerImpl)
Is the compiler implementation a jdk compiler
|
protected Path |
recreateSrc()
Recreate src.
|
protected void |
resetFileLists()
Clear the list of files to be compiled and copied..
|
protected void |
scanDir(File srcDir,
File destDir,
String[] files)
Scans the directory looking for source files to be compiled.
|
void |
setBootclasspath(Path bootclasspath)
Sets the bootclasspath that will be used to compile the classes
against.
|
void |
setBootClasspathRef(Reference r)
Adds a reference to a classpath defined elsewhere.
|
void |
setClasspath(Path classpath)
Set the classpath to be used for this compilation.
|
void |
setClasspathRef(Reference r)
Adds a reference to a classpath defined elsewhere.
|
void |
setCompiler(String compiler)
Choose the implementation for this particular task.
|
void |
setCreateMissingPackageInfoClass(boolean b)
Whether package-info.class files will be created by Ant
matching package-info.java files that have been compiled but
didn't create class files themselves.
|
void |
setDebug(boolean debug)
Indicates whether source should be compiled
with debug information; defaults to off.
|
void |
setDebugLevel(String v)
Keyword list to be appended to the -g command-line switch.
|
void |
setDepend(boolean depend)
Enables dependency-tracking for compilers
that support this (jikes and classic).
|
void |
setDeprecation(boolean deprecation)
Indicates whether source should be
compiled with deprecation information; defaults to off.
|
void |
setDestdir(File destDir)
Set the destination directory into which the Java source
files should be compiled.
|
void |
setEncoding(String encoding)
Set the Java source file encoding name.
|
void |
setErrorProperty(String errorProperty)
The property to set on compilation failure.
|
void |
setExecutable(String forkExec)
Sets the name of the javac executable.
|
void |
setExtdirs(Path extdirs)
Sets the extension directories that will be used during the
compilation.
|
void |
setFailonerror(boolean fail)
Indicates whether the build will continue
even if there are compilation errors; defaults to true.
|
void |
setFork(boolean f)
If true, forks the javac compiler.
|
void |
setIncludeantruntime(boolean include)
If true, includes Ant's own classpath in the classpath.
|
void |
setIncludeDestClasses(boolean includeDestClasses)
This property controls whether to include the
destination classes directory in the classpath
given to the compiler.
|
void |
setIncludejavaruntime(boolean include)
If true, includes the Java runtime libraries in the classpath.
|
void |
setListfiles(boolean list)
If true, list the source files being handed off to the compiler.
|
void |
setMemoryInitialSize(String memoryInitialSize)
The initial size of the memory for the underlying VM
if javac is run externally; ignored otherwise.
|
void |
setMemoryMaximumSize(String memoryMaximumSize)
The maximum size of the memory for the underlying VM
if javac is run externally; ignored otherwise.
|
void |
setModulepath(Path mp)
Set the modulepath to be used for this compilation.
|
void |
setModulepathRef(Reference r)
Adds a reference to a modulepath defined elsewhere.
|
void |
setModulesourcepath(Path msp)
Set the modulesourcepath to be used for this compilation.
|
void |
setModulesourcepathRef(Reference r)
Adds a reference to a modulesourcepath defined elsewhere.
|
void |
setNativeHeaderDir(File nhDir)
Set the destination directory into which the generated native
header files should be placed.
|
void |
setNowarn(boolean flag)
If true, enables the -nowarn option.
|
void |
setOptimize(boolean optimize)
If true, compiles with optimization enabled.
|
void |
setProceed(boolean proceed) |
void |
setRelease(String release)
Sets the version to use for the
--release switch that
combines source , target and setting the
bootclasspath. |
void |
setSource(String v)
Value of the -source command-line switch; will be ignored by
all implementations except modern, jikes and gcj (gcj uses
-fsource).
|
void |
setSourcepath(Path sourcepath)
Set the sourcepath to be used for this compilation.
|
void |
setSourcepathRef(Reference r)
Adds a reference to a source path defined elsewhere.
|
void |
setSrcdir(Path srcDir)
Set the source directories to find the source Java files.
|
void |
setTarget(String target)
Sets the target VM that the classes will be compiled for.
|
void |
setTempdir(File tmpDir)
Where Ant should place temporary files.
|
void |
setUpdatedProperty(String updatedProperty)
The property to set on compilation success.
|
void |
setUpgrademodulepath(Path ump)
Set the upgrademodulepath to be used for this compilation.
|
void |
setUpgrademodulepathRef(Reference r)
Adds a reference to the upgrademodulepath defined elsewhere.
|
void |
setVerbose(boolean verbose)
If true, asks the compiler for verbose output.
|
add, addAnd, addContains, addContainsRegexp, addCustom, addDate, addDepend, addDepth, addDifferent, addFilename, addMajority, addModified, addNone, addNot, addOr, addPresent, addSelector, addSize, addType, appendSelector, createExclude, createExcludesFile, createInclude, createIncludesFile, createPatternSet, getDirectoryScanner, getImplicitFileSet, getSelectors, hasSelectors, selectorCount, selectorElements, setCaseSensitive, setDefaultexcludes, setExcludes, setExcludesfile, setFollowSymlinks, setIncludes, setIncludesfile, setProject, XsetIgnore, XsetItems
bindToOwner, getOwningTarget, getRuntimeConfigurableWrapper, getTaskName, getTaskType, getWrapper, handleErrorFlush, handleErrorOutput, handleFlush, handleInput, handleOutput, init, isInvalid, log, log, log, log, maybeConfigure, perform, reconfigure, setOwningTarget, setRuntimeConfigurableWrapper, setTaskName, setTaskType
clone, getDescription, getLocation, getProject, setDescription, setLocation
protected File[] compileList
protected boolean failOnError
protected boolean listFiles
public void add(CompilerAdapter adapter)
protected void checkParameters() throws BuildException
BuildException
- if an error occursprotected void compile()
public Path createBootclasspath()
public Path createClasspath()
public Javac.ImplementationSpecificArgument createCompilerArg()
public Path createCompilerClasspath()
public Path createExtdirs()
public Path createModulepath()
public Path createModulesourcepath()
public Path createSourcepath()
public Path createSrc()
public Path createUpgrademodulepath()
public void execute() throws BuildException
execute
in class Task
BuildException
- if an error occurspublic Path getBootclasspath()
public Path getClasspath()
public String getCompiler()
Defaults to the build.compiler property but can be overridden via the compiler and fork attributes.
If fork has been set to true, the result will be extJavac and not classic or java1.2 - no matter what the compiler attribute looks like.
getCompilerVersion()
public String getCompilerVersion()
Defaults to the build.compiler property but can be overridden via the compiler attribute.
This method does not take the fork attribute into account.
getCompiler()
public String[] getCurrentCompilerArgs()
public boolean getDebug()
public String getDebugLevel()
public boolean getDepend()
public boolean getDeprecation()
public File getDestdir()
public String getEncoding()
public String getExecutable()
public Path getExtdirs()
public boolean getFailonerror()
public File[] getFileList()
public boolean getIncludeantruntime()
public boolean getIncludejavaruntime()
public String getJavacExecutable()
This is either the name specified with the executable attribute or the full path of the javac compiler of the VM Ant is currently running in - guessed by Ant.
You should not invoke this method if you
want to get the value of the executable command - use getExecutable
for this.
public boolean getListfiles()
public String getMemoryInitialSize()
public String getMemoryMaximumSize()
public Path getModulepath()
public Path getModulesourcepath()
public File getNativeHeaderDir()
public boolean getNowarn()
public boolean getOptimize()
public String getRelease()
--release
switch that
combines source
, target
and setting the
bootclasspath.public String getSource()
public Path getSourcepath()
public Path getSrcdir()
protected String getSystemJavac()
public String getTarget()
public boolean getTaskSuccess()
public File getTempdir()
public Path getUpgrademodulepath()
public boolean getVerbose()
public boolean isForkedJavac()
public boolean isIncludeDestClasses()
protected boolean isJdkCompiler(String compilerImpl)
compilerImpl
- the name of the compiler implementationprotected Path recreateSrc()
protected void resetFileLists()
protected void scanDir(File srcDir, File destDir, String[] files)
srcDir
- The source directorydestDir
- The destination directoryfiles
- An array of filenamespublic void setBootclasspath(Path bootclasspath)
bootclasspath
- a path to use as a boot class path (may be more
than one)public void setBootClasspathRef(Reference r)
r
- a reference to a classpathpublic void setClasspath(Path classpath)
classpath
- an Ant Path object containing the compilation classpath.public void setClasspathRef(Reference r)
r
- a reference to a classpathpublic void setCompiler(String compiler)
compiler
- the name of the compilerpublic void setCreateMissingPackageInfoClass(boolean b)
public void setDebug(boolean debug)
debug
- if true compile with debug informationpublic void setDebugLevel(String v)
v
- Value to assign to debugLevel.public void setDepend(boolean depend)
depend
- if true enable dependency-trackingpublic void setDeprecation(boolean deprecation)
deprecation
- if true turn on deprecation informationpublic void setDestdir(File destDir)
destDir
- the destination directorpublic void setEncoding(String encoding)
encoding
- the source file encodingpublic void setErrorProperty(String errorProperty)
errorProperty
- the property name to use.public void setExecutable(String forkExec)
Ignored unless fork is true or extJavac has been specified as the compiler.
forkExec
- the name of the executablepublic void setExtdirs(Path extdirs)
extdirs
- a pathpublic void setFailonerror(boolean fail)
fail
- if true halt the build on failurepublic void setFork(boolean f)
f
- "true|false|on|off|yes|no"public void setIncludeantruntime(boolean include)
include
- if true, includes Ant's own classpath in the classpathpublic void setIncludeDestClasses(boolean includeDestClasses)
includeDestClasses
- the value to use.public void setIncludejavaruntime(boolean include)
include
- if true, includes the Java runtime libraries in the classpathpublic void setListfiles(boolean list)
list
- if true list the source filespublic void setMemoryInitialSize(String memoryInitialSize)
memoryInitialSize
- string to pass to VMpublic void setMemoryMaximumSize(String memoryMaximumSize)
memoryMaximumSize
- string to pass to VMpublic void setModulepath(Path mp)
mp
- an Ant Path object containing the modulepath.public void setModulepathRef(Reference r)
r
- a reference to a modulepathpublic void setModulesourcepath(Path msp)
msp
- the modulesourcepathpublic void setModulesourcepathRef(Reference r)
r
- a reference to a modulesourcepathpublic void setNativeHeaderDir(File nhDir)
nhDir
- where to place generated native header filespublic void setNowarn(boolean flag)
flag
- if true, enable the -nowarn optionpublic void setOptimize(boolean optimize)
optimize
- if true compile with optimization enabledpublic void setProceed(boolean proceed)
proceed
- inverse of failoferrorpublic void setRelease(String release)
--release
switch that
combines source
, target
and setting the
bootclasspath.
Values depend on the compiler, for jdk 9 the valid values are
"6", "7", "8", "9".release
- the value of the release attributepublic void setSource(String v)
If you use this attribute together with jikes or gcj, you must make sure that your version of jikes supports the -source switch.
Legal values are 1.3, 1.4, 1.5, 1.6, 1.7, 1.8, 1.9, and 5, 6, 7, 8 and 9 - by default, no -source argument will be used at all.
v
- Value to assign to source.public void setSourcepath(Path sourcepath)
sourcepath
- the source pathpublic void setSourcepathRef(Reference r)
r
- a reference to a source pathpublic void setSrcdir(Path srcDir)
srcDir
- the source directories as a pathpublic void setTarget(String target)
target
- the target VMpublic void setTempdir(File tmpDir)
tmpDir
- the temporary directorypublic void setUpdatedProperty(String updatedProperty)
updatedProperty
- the property name to use.public void setUpgrademodulepath(Path ump)
ump
- an Ant Path object containing the upgrademodulepath.public void setUpgrademodulepathRef(Reference r)
r
- a reference to an upgrademodulepathpublic void setVerbose(boolean verbose)
verbose
- if true, asks the compiler for verbose output