Methods Summary |
---|
private java.lang.String | assumedJavaVersion()
if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) {
return JAVAC12;
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) {
return JAVAC13;
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) {
return JAVAC14;
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) {
return JAVAC15;
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_6)) {
return JAVAC16;
} else {
return CLASSIC;
}
|
protected void | checkParameters()Check that all required attributes have been set and nothing
silly has been entered.
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());
}
|
protected void | compile()Perform the compilation.
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()) {
if (failOnError) {
throw new BuildException(FAIL_MSG, getLocation());
} else {
log(FAIL_MSG, Project.MSG_ERR);
}
}
}
|
public org.apache.tools.ant.types.Path | createBootclasspath()Adds a path to the bootclasspath.
if (bootclasspath == null) {
bootclasspath = new Path(getProject());
}
return bootclasspath.createPath();
|
public org.apache.tools.ant.types.Path | createClasspath()Adds a path to the classpath.
if (compileClasspath == null) {
compileClasspath = new Path(getProject());
}
return compileClasspath.createPath();
|
public org.apache.tools.ant.taskdefs.Javac$ImplementationSpecificArgument | createCompilerArg()Adds an implementation specific command-line argument.
ImplementationSpecificArgument arg =
new ImplementationSpecificArgument();
facade.addImplementationArgument(arg);
return arg;
|
public org.apache.tools.ant.types.Path | createExtdirs()Adds a path to extdirs.
if (extdirs == null) {
extdirs = new Path(getProject());
}
return extdirs.createPath();
|
public org.apache.tools.ant.types.Path | createSourcepath()Adds a path to sourcepath.
if (compileSourcepath == null) {
compileSourcepath = new Path(getProject());
}
return compileSourcepath.createPath();
|
public org.apache.tools.ant.types.Path | createSrc()Adds a path for source compilation.
if (src == null) {
src = new Path(getProject());
}
return src.createPath();
|
public void | execute()Executes the task.
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();
|
private java.lang.String | getAltCompilerName(java.lang.String anImplementation)
if (JAVAC16.equalsIgnoreCase(anImplementation)
|| JAVAC15.equalsIgnoreCase(anImplementation)
|| JAVAC14.equalsIgnoreCase(anImplementation)
|| JAVAC13.equalsIgnoreCase(anImplementation)) {
return MODERN;
}
if (JAVAC12.equalsIgnoreCase(anImplementation)
|| JAVAC11.equalsIgnoreCase(anImplementation)) {
return CLASSIC;
}
if (MODERN.equalsIgnoreCase(anImplementation)) {
String nextSelected = assumedJavaVersion();
if (JAVAC16.equalsIgnoreCase(nextSelected)
|| JAVAC15.equalsIgnoreCase(nextSelected)
|| JAVAC14.equalsIgnoreCase(nextSelected)
|| JAVAC13.equalsIgnoreCase(nextSelected)) {
return nextSelected;
}
}
if (CLASSIC.equals(anImplementation)) {
return assumedJavaVersion();
}
if (EXTJAVAC.equalsIgnoreCase(anImplementation)) {
return assumedJavaVersion();
}
return null;
|
public org.apache.tools.ant.types.Path | getBootclasspath()Gets the bootclasspath that will be used to compile the classes
against.
return bootclasspath;
|
public org.apache.tools.ant.types.Path | getClasspath()Gets the classpath to be used for this compilation.
return compileClasspath;
|
public java.lang.String | getCompiler()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.
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;
|
public java.lang.String | getCompilerVersion()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.
facade.setMagicValue(getProject().getProperty("build.compiler"));
return facade.getImplementation();
|
public java.lang.String[] | getCurrentCompilerArgs()Get the additional implementation specific command line arguments.
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);
}
|
public boolean | getDebug()Gets the debug flag.
return debug;
|
public java.lang.String | getDebugLevel()Get the value of debugLevel.
return debugLevel;
|
public boolean | getDepend()Gets the depend flag.
return depend;
|
public boolean | getDeprecation()Gets the deprecation flag.
return deprecation;
|
public java.io.File | getDestdir()Gets the destination directory into which the java source files
should be compiled.
return destDir;
|
public java.lang.String | getEncoding()Gets the java source file encoding name.
return encoding;
|
public java.lang.String | getExecutable()The value of the executable attribute, if any.
return forkedExecutable;
|
public org.apache.tools.ant.types.Path | getExtdirs()Gets the extension directories that will be used during the
compilation.
return extdirs;
|
public boolean | getFailonerror()Gets the failonerror flag.
return failOnError;
|
public java.io.File[] | getFileList()Gets the list of files to be compiled.
return compileList;
|
public boolean | getIncludeantruntime()Gets whether or not the ant classpath is to be included in the classpath.
return includeAntRuntime;
|
public boolean | getIncludejavaruntime()Gets whether or not the java runtime should be included in this
task's classpath.
return includeJavaRuntime;
|
public java.lang.String | getJavacExecutable()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 {@link
#getExecutable getExecutable} for this.
if (forkedExecutable == null && isForkedJavac()) {
forkedExecutable = getSystemJavac();
} else if (forkedExecutable != null && !isForkedJavac()) {
forkedExecutable = null;
}
return forkedExecutable;
|
public boolean | getListfiles()Get the listfiles flag.
return listFiles;
|
public java.lang.String | getMemoryInitialSize()Gets the memoryInitialSize flag.
return memoryInitialSize;
|
public java.lang.String | getMemoryMaximumSize()Gets the memoryMaximumSize flag.
return memoryMaximumSize;
|
public boolean | getNowarn()Should the -nowarn option be used.
return nowarn;
|
public boolean | getOptimize()Gets the optimize flag.
return optimize;
|
public java.lang.String | getSource()Get the value of source.
return source != null
? source : getProject().getProperty(MagicNames.BUILD_JAVAC_SOURCE);
|
public org.apache.tools.ant.types.Path | getSourcepath()Gets the sourcepath to be used for this compilation.
return compileSourcepath;
|
public org.apache.tools.ant.types.Path | getSrcdir()Gets the source dirs to find the source java files.
return src;
|
protected java.lang.String | getSystemJavac()
return JavaEnvUtils.getJdkExecutable("javac");
|
public java.lang.String | getTarget()Gets the target VM that the classes will be compiled for.
return targetAttribute != null
? targetAttribute
: getProject().getProperty(MagicNames.BUILD_JAVAC_TARGET);
|
public java.io.File | getTempdir()Where Ant should place temporary files.
return tmpDir;
|
public boolean | getVerbose()Gets the verbose flag.
return verbose;
|
public boolean | isForkedJavac()Is this a forked invocation of JDK's javac?
return fork || "extJavac".equals(getCompiler());
|
protected boolean | isJdkCompiler(java.lang.String compilerImpl)Is the compiler implementation a jdk compiler
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);
|
protected org.apache.tools.ant.types.Path | recreateSrc()Recreate src.
src = null;
return createSrc();
|
protected void | resetFileLists()Clear the list of files to be compiled and copied..
compileList = new File[0];
|
protected void | scanDir(java.io.File srcDir, java.io.File destDir, java.lang.String[] files)Scans the directory looking for source files to be compiled.
The results are returned in the class variable compileList
GlobPatternMapper m = new GlobPatternMapper();
m.setFrom("*.java");
m.setTo("*.class");
SourceFileScanner sfs = new SourceFileScanner(this);
File[] newFiles = sfs.restrictAsFiles(files, srcDir, destDir, m);
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;
}
|
public void | setBootClasspathRef(org.apache.tools.ant.types.Reference r)Adds a reference to a classpath defined elsewhere.
createBootclasspath().setRefid(r);
|
public void | setBootclasspath(org.apache.tools.ant.types.Path bootclasspath)Sets the bootclasspath that will be used to compile the classes
against.
if (this.bootclasspath == null) {
this.bootclasspath = bootclasspath;
} else {
this.bootclasspath.append(bootclasspath);
}
|
public void | setClasspath(org.apache.tools.ant.types.Path classpath)Set the classpath to be used for this compilation.
if (compileClasspath == null) {
compileClasspath = classpath;
} else {
compileClasspath.append(classpath);
}
|
public void | setClasspathRef(org.apache.tools.ant.types.Reference r)Adds a reference to a classpath defined elsewhere.
createClasspath().setRefid(r);
|
public void | setCompiler(java.lang.String compiler)Choose the implementation for this particular task.
facade.setImplementation(compiler);
|
public void | setDebug(boolean debug)Indicates whether source should be compiled
with debug information; defaults to off.
this.debug = debug;
|
public void | setDebugLevel(java.lang.String 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.
this.debugLevel = v;
|
public void | setDepend(boolean depend)Enables dependency-tracking for compilers
that support this (jikes and classic).
this.depend = depend;
|
public void | setDeprecation(boolean deprecation)Indicates whether source should be
compiled with deprecation information; defaults to off.
this.deprecation = deprecation;
|
public void | setDestdir(java.io.File destDir)Set the destination directory into which the Java source
files should be compiled.
this.destDir = destDir;
|
public void | setEncoding(java.lang.String encoding)Set the Java source file encoding name.
this.encoding = encoding;
|
public void | setExecutable(java.lang.String forkExec)Sets the name of the javac executable.
Ignored unless fork is true or extJavac has been specified
as the compiler.
forkedExecutable = forkExec;
|
public void | setExtdirs(org.apache.tools.ant.types.Path extdirs)Sets the extension directories that will be used during the
compilation.
if (this.extdirs == null) {
this.extdirs = extdirs;
} else {
this.extdirs.append(extdirs);
}
|
public void | setFailonerror(boolean fail)Indicates whether the build will continue
even if there are compilation errors; defaults to true.
failOnError = fail;
|
public void | setFork(boolean f)If true, forks the javac compiler.
fork = f;
|
public void | setIncludeantruntime(boolean include)If true, includes Ant's own classpath in the classpath.
includeAntRuntime = include;
|
public void | setIncludejavaruntime(boolean include)If true, includes the Java runtime libraries in the classpath.
includeJavaRuntime = include;
|
public void | setListfiles(boolean list)If true, list the source files being handed off to the compiler.
listFiles = list;
|
public void | setMemoryInitialSize(java.lang.String 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)
this.memoryInitialSize = memoryInitialSize;
|
public void | setMemoryMaximumSize(java.lang.String 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)
this.memoryMaximumSize = memoryMaximumSize;
|
public void | setNowarn(boolean flag)If true, enables the -nowarn option.
this.nowarn = flag;
|
public void | setOptimize(boolean optimize)If true, compiles with optimization enabled.
this.optimize = optimize;
|
public void | setProceed(boolean proceed)
failOnError = !proceed;
|
public void | setSource(java.lang.String 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.
this.source = v;
|
public void | setSourcepath(org.apache.tools.ant.types.Path sourcepath)Set the sourcepath to be used for this compilation.
if (compileSourcepath == null) {
compileSourcepath = sourcepath;
} else {
compileSourcepath.append(sourcepath);
}
|
public void | setSourcepathRef(org.apache.tools.ant.types.Reference r)Adds a reference to a source path defined elsewhere.
createSourcepath().setRefid(r);
|
public void | setSrcdir(org.apache.tools.ant.types.Path srcDir)Set the source directories to find the source Java files.
if (src == null) {
src = srcDir;
} else {
src.append(srcDir);
}
|
public void | setTarget(java.lang.String 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".
this.targetAttribute = target;
|
public void | setTempdir(java.io.File tmpDir)Where Ant should place temporary files.
this.tmpDir = tmpDir;
|
public void | setVerbose(boolean verbose)If true, asks the compiler for verbose output.
this.verbose = verbose;
|