| Method from org.apache.tools.ant.taskdefs.Javac Detail: |
protected void checkParameters() throws BuildException {
if (src == null) {
throw new BuildException("srcdir attribute must be set!",
getLocation());
}
if (src.size() == 0) {
throw new BuildException("srcdir attribute must be set!",
getLocation());
}
if (destDir != null && !destDir.isDirectory()) {
throw new BuildException("destination directory \""
+ destDir
+ "\" does not exist "
+ "or is not a directory", getLocation());
}
}
Check that all required attributes have been set and nothing
silly has been entered. |
protected void compile() {
String compilerImpl = getCompiler();
if (compileList.length > 0) {
log("Compiling " + compileList.length + " source file"
+ (compileList.length == 1 ? "" : "s")
+ (destDir != null ? " to " + destDir : ""));
if (listFiles) {
for (int i = 0; i < compileList.length; i++) {
String filename = compileList[i].getAbsolutePath();
log(filename);
}
}
CompilerAdapter adapter =
CompilerAdapterFactory.getCompiler(compilerImpl, this);
// now we need to populate the compiler adapter
adapter.setJavac(this);
// finally, lets execute the compiler!!
if (adapter.execute()) {
// Success - check
for (Iterator i = updateDirList.iterator(); i.hasNext();) {
File file = (File) i.next();
file.setLastModified(System.currentTimeMillis());
}
} else {
// Fail path
this.taskSuccess = false;
if (errorProperty != null) {
getProject().setNewProperty(
errorProperty, "true");
}
if (failOnError) {
throw new BuildException(FAIL_MSG, getLocation());
} else {
log(FAIL_MSG, Project.MSG_ERR);
}
}
}
}
|
public Path createBootclasspath() {
if (bootclasspath == null) {
bootclasspath = new Path(getProject());
}
return bootclasspath.createPath();
}
Adds a path to the bootclasspath. |
public Path createClasspath() {
if (compileClasspath == null) {
compileClasspath = new Path(getProject());
}
return compileClasspath.createPath();
}
Adds a path to the classpath. |
public Javac.ImplementationSpecificArgument createCompilerArg() {
ImplementationSpecificArgument arg =
new ImplementationSpecificArgument();
facade.addImplementationArgument(arg);
return arg;
}
Adds an implementation specific command-line argument. |
public Path createExtdirs() {
if (extdirs == null) {
extdirs = new Path(getProject());
}
return extdirs.createPath();
}
|
public Path createSourcepath() {
if (compileSourcepath == null) {
compileSourcepath = new Path(getProject());
}
return compileSourcepath.createPath();
}
Adds a path to sourcepath. |
public Path createSrc() {
if (src == null) {
src = new Path(getProject());
}
return src.createPath();
}
Adds a path for source compilation. |
public void execute() throws BuildException {
checkParameters();
resetFileLists();
// scan source directories and dest directory to build up
// compile lists
String[] list = src.list();
for (int i = 0; i < list.length; i++) {
File srcDir = getProject().resolveFile(list[i]);
if (!srcDir.exists()) {
throw new BuildException("srcdir \""
+ srcDir.getPath()
+ "\" does not exist!", getLocation());
}
DirectoryScanner ds = this.getDirectoryScanner(srcDir);
String[] files = ds.getIncludedFiles();
scanDir(srcDir, destDir != null ? destDir : srcDir, files);
}
compile();
if (updatedProperty != null
&& taskSuccess
&& compileList.length != 0) {
getProject().setNewProperty(updatedProperty, "true");
}
}
|
public Path getBootclasspath() {
return bootclasspath;
}
Gets the bootclasspath that will be used to compile the classes
against. |
public Path getClasspath() {
return compileClasspath;
}
Gets the classpath to be used for this compilation. |
public String getCompiler() {
String compilerImpl = getCompilerVersion();
if (fork) {
if (isJdkCompiler(compilerImpl)) {
compilerImpl = "extJavac";
} else {
log("Since compiler setting isn't classic or modern,"
+ "ignoring fork setting.", Project.MSG_WARN);
}
}
return compilerImpl;
}
The implementation for this particular task.
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. |
public String getCompilerVersion() {
facade.setMagicValue(getProject().getProperty("build.compiler"));
return facade.getImplementation();
}
The implementation for this particular task.
Defaults to the build.compiler property but can be overridden
via the compiler attribute.
This method does not take the fork attribute into
account. |
public String[] getCurrentCompilerArgs() {
String chosen = facade.getExplicitChoice();
try {
// make sure facade knows about magic properties and fork setting
String appliedCompiler = getCompiler();
facade.setImplementation(appliedCompiler);
String[] result = facade.getArgs();
String altCompilerName = getAltCompilerName(facade.getImplementation());
if (result.length == 0 && altCompilerName != null) {
facade.setImplementation(altCompilerName);
result = facade.getArgs();
}
return result;
} finally {
facade.setImplementation(chosen);
}
}
Get the additional implementation specific command line arguments. |
public boolean getDebug() {
return debug;
}
|
public String getDebugLevel() {
return debugLevel;
}
Get the value of debugLevel. |
public boolean getDepend() {
return depend;
}
|
public boolean getDeprecation() {
return deprecation;
}
Gets the deprecation flag. |
public File getDestdir() {
return destDir;
}
Gets the destination directory into which the java source files
should be compiled. |
public String getEncoding() {
return encoding;
}
Gets the java source file encoding name. |
public String getExecutable() {
return forkedExecutable;
}
The value of the executable attribute, if any. |
public Path getExtdirs() {
return extdirs;
}
Gets the extension directories that will be used during the
compilation. |
public boolean getFailonerror() {
return failOnError;
}
Gets the failonerror flag. |
public File[] getFileList() {
return compileList;
}
Gets the list of files to be compiled. |
public boolean getIncludeantruntime() {
return includeAntRuntime;
}
Gets whether or not the ant classpath is to be included in the classpath. |
public boolean getIncludejavaruntime() {
return includeJavaRuntime;
}
Gets whether or not the java runtime should be included in this
task's classpath. |
public String getJavacExecutable() {
if (forkedExecutable == null && isForkedJavac()) {
forkedExecutable = getSystemJavac();
} else if (forkedExecutable != null && !isForkedJavac()) {
forkedExecutable = null;
}
return forkedExecutable;
}
The name of the javac executable to use in fork-mode.
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() {
return listFiles;
}
|
public String getMemoryInitialSize() {
return memoryInitialSize;
}
Gets the memoryInitialSize flag. |
public String getMemoryMaximumSize() {
return memoryMaximumSize;
}
Gets the memoryMaximumSize flag. |
public boolean getNowarn() {
return nowarn;
}
Should the -nowarn option be used. |
public boolean getOptimize() {
return optimize;
}
|
public String getSource() {
return source != null
? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);
}
|
public Path getSourcepath() {
return compileSourcepath;
}
Gets the sourcepath to be used for this compilation. |
public Path getSrcdir() {
return src;
}
Gets the source dirs to find the source java files. |
protected String getSystemJavac() {
return JavaEnvUtils.getJdkExecutable("javac");
}
|
public String getTarget() {
return targetAttribute != null
? targetAttribute
: getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET);
}
Gets the target VM that the classes will be compiled for. |
public boolean getTaskSuccess() {
return taskSuccess;
}
Get the result of the javac task (success or failure). |
public File getTempdir() {
return tmpDir;
}
Where Ant should place temporary files. |
public boolean getVerbose() {
return verbose;
}
|
public boolean isForkedJavac() {
return fork || "extJavac".equals(getCompiler());
}
Is this a forked invocation of JDK's javac? |
public boolean isIncludeDestClasses() {
return includeDestClasses;
}
Get the value of the includeDestClasses property. |
protected boolean isJdkCompiler(String compilerImpl) {
return MODERN.equals(compilerImpl)
|| CLASSIC.equals(compilerImpl)
|| JAVAC16.equals(compilerImpl)
|| JAVAC15.equals(compilerImpl)
|| JAVAC14.equals(compilerImpl)
|| JAVAC13.equals(compilerImpl)
|| JAVAC12.equals(compilerImpl)
|| JAVAC11.equals(compilerImpl);
}
Is the compiler implementation a jdk compiler |
protected Path recreateSrc() {
src = null;
return createSrc();
}
|
protected void resetFileLists() {
compileList = new File[0];
}
Clear the list of files to be compiled and copied.. |
protected void scanDir(File srcDir,
File destDir,
String[] files) {
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("*.java");
m.setTo("*.class");
SourceFileScanner sfs = new SourceFileScanner(this);
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
newFiles = removePackageInfoFiles(newFiles, srcDir, destDir);
if (newFiles.length > 0) {
File[] newCompileList
= new File[compileList.length + newFiles.length];
System.arraycopy(compileList, 0, newCompileList, 0,
compileList.length);
System.arraycopy(newFiles, 0, newCompileList,
compileList.length, newFiles.length);
compileList = newCompileList;
}
}
Scans the directory looking for source files to be compiled.
The results are returned in the class variable compileList |
public void setBootClasspathRef(Reference r) {
createBootclasspath().setRefid(r);
}
Adds a reference to a classpath defined elsewhere. |
public void setBootclasspath(Path bootclasspath) {
if (this.bootclasspath == null) {
this.bootclasspath = bootclasspath;
} else {
this.bootclasspath.append(bootclasspath);
}
}
Sets the bootclasspath that will be used to compile the classes
against. |
public void setClasspath(Path classpath) {
if (compileClasspath == null) {
compileClasspath = classpath;
} else {
compileClasspath.append(classpath);
}
}
Set the classpath to be used for this compilation. |
public void setClasspathRef(Reference r) {
createClasspath().setRefid(r);
}
Adds a reference to a classpath defined elsewhere. |
public void setCompiler(String compiler) {
facade.setImplementation(compiler);
}
Choose the implementation for this particular task. |
public void setDebug(boolean debug) {
this.debug = debug;
}
Indicates whether source should be compiled
with debug information; defaults to off. |
public void setDebugLevel(String v) {
this.debugLevel = v;
}
Keyword list to be appended to the -g command-line switch.
This will be ignored by all implementations except modern
and classic(ver >= 1.2). Legal values are none or a
comma-separated list of the following keywords: lines, vars,
and source. If debuglevel is not specified, by default, :none
will be appended to -g. If debug is not turned on, this attribute
will be ignored. |
public void setDepend(boolean depend) {
this.depend = depend;
}
Enables dependency-tracking for compilers
that support this (jikes and classic). |
public void setDeprecation(boolean deprecation) {
this.deprecation = deprecation;
}
Indicates whether source should be
compiled with deprecation information; defaults to off. |
public void setDestdir(File destDir) {
this.destDir = destDir;
}
Set the destination directory into which the Java source
files should be compiled. |
public void setEncoding(String encoding) {
this.encoding = encoding;
}
Set the Java source file encoding name. |
public void setErrorProperty(String errorProperty) {
this.errorProperty = errorProperty;
}
The property to set on compliation failure.
This property will be set if the compilation
fails. |
public void setExecutable(String forkExec) {
forkedExecutable = forkExec;
}
|
public void setExtdirs(Path extdirs) {
if (this.extdirs == null) {
this.extdirs = extdirs;
} else {
this.extdirs.append(extdirs);
}
}
Sets the extension directories that will be used during the
compilation. |
public void setFailonerror(boolean fail) {
failOnError = fail;
}
Indicates whether the build will continue
even if there are compilation errors; defaults to true. |
public void setFork(boolean f) {
fork = f;
}
If true, forks the javac compiler. |
public void setIncludeDestClasses(boolean includeDestClasses) {
this.includeDestClasses = includeDestClasses;
}
This property controls whether to include the
destination classes directory in the classpath
given to the compiler.
The default value is "true". |
public void setIncludeantruntime(boolean include) {
includeAntRuntime = include;
}
If true, includes Ant's own classpath in the classpath. |
public void setIncludejavaruntime(boolean include) {
includeJavaRuntime = include;
}
If true, includes the Java runtime libraries in the classpath. |
public void setListfiles(boolean list) {
listFiles = list;
}
If true, list the source files being handed off to the compiler. |
public void setMemoryInitialSize(String memoryInitialSize) {
this.memoryInitialSize = memoryInitialSize;
}
The initial size of the memory for the underlying VM
if javac is run externally; ignored otherwise.
Defaults to the standard VM memory setting.
(Examples: 83886080, 81920k, or 80m) |
public void setMemoryMaximumSize(String memoryMaximumSize) {
this.memoryMaximumSize = memoryMaximumSize;
}
The maximum size of the memory for the underlying VM
if javac is run externally; ignored otherwise.
Defaults to the standard VM memory setting.
(Examples: 83886080, 81920k, or 80m) |
public void setNowarn(boolean flag) {
this.nowarn = flag;
}
If true, enables the -nowarn option. |
public void setOptimize(boolean optimize) {
this.optimize = optimize;
}
If true, compiles with optimization enabled. |
public void setProceed(boolean proceed) {
failOnError = !proceed;
}
|
public void setSource(String v) {
this.source = v;
}
Value of the -source command-line switch; will be ignored
by all implementations except modern and jikes.
If you use this attribute together with jikes, you must make
sure that your version of jikes supports the -source switch.
Legal values are 1.3, 1.4, 1.5, and 5 - by default, no
-source argument will be used at all. |
public void setSourcepath(Path sourcepath) {
if (compileSourcepath == null) {
compileSourcepath = sourcepath;
} else {
compileSourcepath.append(sourcepath);
}
}
Set the sourcepath to be used for this compilation. |
public void setSourcepathRef(Reference r) {
createSourcepath().setRefid(r);
}
Adds a reference to a source path defined elsewhere. |
public void setSrcdir(Path srcDir) {
if (src == null) {
src = srcDir;
} else {
src.append(srcDir);
}
}
Set the source directories to find the source Java files. |
public void setTarget(String target) {
this.targetAttribute = target;
}
Sets the target VM that the classes will be compiled for. Valid
values depend on the compiler, for jdk 1.4 the valid values are
"1.1", "1.2", "1.3", "1.4", "1.5", "1.6", "5" and "6". |
public void setTempdir(File tmpDir) {
this.tmpDir = tmpDir;
}
Where Ant should place temporary files. |
public void setUpdatedProperty(String updatedProperty) {
this.updatedProperty = updatedProperty;
}
The property to set on compliation success.
This property will not be set if the compilation
fails, or if there are no files to compile. |
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
If true, asks the compiler for verbose output. |