You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by bo...@apache.org on 2001/11/05 16:19:21 UTC
cvs commit: jakarta-ant/src/main/org/apache/tools/ant/types Commandline.java
bodewig 01/11/05 07:19:21
Modified: docs/manual/CoreTasks javac.html
src/main/org/apache/tools/ant/taskdefs Javac.java
src/main/org/apache/tools/ant/taskdefs/compilers
DefaultCompilerAdapter.java Gcj.java Jikes.java
Jvc.java Kjc.java
src/main/org/apache/tools/ant/types Commandline.java
Log:
Add a way to pass compiler specific command line arguments to <javac>.
PR: 4406
heavily based upon a Submission by: Stephen Anderson <an...@berbee.com>
Revision Changes Path
1.16 +37 -0 jakarta-ant/docs/manual/CoreTasks/javac.html
Index: javac.html
===================================================================
RCS file: /home/cvs/jakarta-ant/docs/manual/CoreTasks/javac.html,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- javac.html 2001/11/05 13:13:39 1.15
+++ javac.html 2001/11/05 15:19:20 1.16
@@ -244,6 +244,43 @@
<code><bootclasspath></code> and
<code><extdirs></code> elements, respectively.</p>
+<h4>compilerarg</h4>
+
+<p>You can specify additional command line arguments for the compiler
+with nested <code><compilerarg></code> elements. These elements
+are specified like <a href="../using.html#arg">Command-line
+Arguments</a> but have an additional attribute that can be used to
+enable arguments only if a given compiler implementation will be
+used.</p>
+<table border="1" cellpadding="2" cellspacing="0">
+<tr>
+ <td width="12%" valign="top"><b>Attribute</b></td>
+ <td width="78%" valign="top"><b>Description</b></td>
+ <td width="10%" valign="top"><b>Required</b></td>
+</tr>
+ <tr>
+ <td valign="top">value</td>
+ <td align="center" rowspan="4">See <a href="../using.html#arg">here</a></td>
+ <td align="center" rowspan="4">Exactly one of these.</td>
+ </tr>
+ <tr>
+ <td valign="top">line</td>
+ </tr>
+ <tr>
+ <td valign="top">file</td>
+ </tr>
+ <tr>
+ <td valign="top">path</td>
+ </tr>
+ <tr>
+ <td valign="top">implementation</td>
+ <td align="center">Only use this argument if the chosen
+ implementation matches this attribute. Possible choices are the
+ same as those of the build.compiler property.</td>
+ <td align="center">No.</td>
+ </tr>
+</table>
+
<h3>Examples</h3>
<pre> <javac srcdir="${src}"
destdir="${build}"
1.73 +88 -26 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java
Index: Javac.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v
retrieving revision 1.72
retrieving revision 1.73
diff -u -r1.72 -r1.73
--- Javac.java 2001/11/05 13:13:39 1.72
+++ Javac.java 2001/11/05 15:19:20 1.73
@@ -57,6 +57,7 @@
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.types.Path;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.util.GlobPatternMapper;
@@ -66,6 +67,8 @@
import org.apache.tools.ant.taskdefs.condition.Os;
import java.io.File;
+import java.util.Enumeration;
+import java.util.Vector;
/**
* Task to compile Java source files. This task can take the following
@@ -124,6 +127,7 @@
private boolean nowarn = false;
private String memoryInitialSize;
private String memoryMaximumSize;
+ private Vector implementationSpecificArgs = new Vector();
protected boolean failOnError = true;
protected File[] compileList = new File[0];
@@ -504,6 +508,36 @@
}
/**
+ * Adds an implementation specific command line argument.
+ */
+ public ImplementationSpecificArgument createCompilerArg() {
+ ImplementationSpecificArgument arg =
+ new ImplementationSpecificArgument();
+ implementationSpecificArgs.addElement(arg);
+ return arg;
+ }
+
+ /**
+ * Get the additional implementation specific command line arguments.
+ * @return array of command line arguments, guaranteed to be non-null.
+ */
+ public String[] getCurrentCompilerArgs() {
+ Vector args = new Vector();
+ for (Enumeration enum = implementationSpecificArgs.elements();
+ enum.hasMoreElements();
+ ) {
+ String[] curr =
+ ((ImplementationSpecificArgument) enum.nextElement()).getParts();
+ for (int i=0; i<curr.length; i++) {
+ args.addElement(curr[i]);
+ }
+ }
+ String[] res = new String[args.size()];
+ args.copyInto(res);
+ return res;
+ }
+
+ /**
* Executes the task.
*/
public void execute() throws BuildException {
@@ -539,33 +573,8 @@
// compile the source files
- String compiler = project.getProperty("build.compiler");
+ String compiler = determineCompiler();
- if (!"false".equals(fork)) {
- if (compiler != null) {
- if (isJdkCompiler(compiler)) {
- log("Since fork is true, ignoring build.compiler setting.",
- Project.MSG_WARN);
- compiler = "extJavac";
- }
- else {
- log("Since build.compiler setting isn't classic or modern, ignoring fork setting.", Project.MSG_WARN);
- }
- }
- else {
- compiler = "extJavac";
- }
- }
-
- if (compiler == null) {
- if (Project.getJavaVersion() != Project.JAVA_1_1 &&
- Project.getJavaVersion() != Project.JAVA_1_2) {
- compiler = "modern";
- } else {
- compiler = "classic";
- }
- }
-
if (compileList.length > 0) {
CompilerAdapter adapter = CompilerAdapterFactory.getCompiler(
@@ -653,4 +662,57 @@
}
}
+ private String determineCompiler() {
+ String compiler = project.getProperty("build.compiler");
+
+ if (!"false".equals(fork)) {
+ if (compiler != null) {
+ if (isJdkCompiler(compiler)) {
+ log("Since fork is true, ignoring build.compiler setting.",
+ Project.MSG_WARN);
+ compiler = "extJavac";
+ }
+ else {
+ log("Since build.compiler setting isn't classic or modern, ignoring fork setting.", Project.MSG_WARN);
+ }
+ }
+ else {
+ compiler = "extJavac";
+ }
+ }
+
+ if (compiler == null) {
+ if (Project.getJavaVersion() != Project.JAVA_1_1 &&
+ Project.getJavaVersion() != Project.JAVA_1_2) {
+ compiler = "modern";
+ } else {
+ compiler = "classic";
+ }
+ }
+ return compiler;
+ }
+
+ /**
+ * Adds an "implementation" attribute to Commandline$Attribute
+ * used to filter command line attributes based on the current
+ * implementation.
+ */
+ public class ImplementationSpecificArgument
+ extends Commandline.Argument {
+
+ private String impl;
+
+ public void setImplementation(String impl) {
+ this.impl = impl;
+ }
+
+ public String[] getParts() {
+ if (impl == null || impl.equals(determineCompiler())) {
+ return super.getParts();
+ } else {
+ return new String[0];
+ }
+ }
+ }
+
}
1.15 +10 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
Index: DefaultCompilerAdapter.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- DefaultCompilerAdapter.java 2001/11/02 16:36:49 1.14
+++ DefaultCompilerAdapter.java 2001/11/05 15:19:20 1.15
@@ -280,6 +280,9 @@
if (verbose) {
cmd.createArgument().setValue("-verbose");
}
+
+ addCurrentCompilerArgs(cmd);
+
return cmd;
}
@@ -432,6 +435,13 @@
fs.setIncludes("*");
classpath.addFileset(fs);
}
+ }
+
+ /**
+ * Adds the command line arguments specifc to the current implementation.
+ */
+ protected void addCurrentCompilerArgs(Commandline cmd) {
+ cmd.addArguments(getJavac().getCurrentCompilerArgs());
}
}
1.5 +3 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
Index: Gcj.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- Gcj.java 2001/10/28 21:27:51 1.4
+++ Gcj.java 2001/11/05 15:19:20 1.5
@@ -136,6 +136,9 @@
* gcj should be set for generate class.
*/
cmd.createArgument().setValue("-C");
+
+ addCurrentCompilerArgs(cmd);
+
return cmd;
}
}
1.4 +2 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java
Index: Jikes.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Jikes.java 2001/10/28 21:27:51 1.3
+++ Jikes.java 2001/11/05 15:19:20 1.4
@@ -210,6 +210,8 @@
cmd.createArgument().setValue("+F");
}
+ addCurrentCompilerArgs(cmd);
+
int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd);
1.4 +2 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java
Index: Jvc.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- Jvc.java 2001/10/28 21:27:51 1.3
+++ Jvc.java 2001/11/05 15:19:20 1.4
@@ -130,6 +130,8 @@
cmd.createArgument().setValue("/verbose");
}
+ addCurrentCompilerArgs(cmd);
+
int firstFileName = cmd.size();
logAndAddFilesToCompile(cmd);
1.3 +2 -0 jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java
Index: Kjc.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- Kjc.java 2001/10/28 21:27:51 1.2
+++ Kjc.java 2001/11/05 15:19:20 1.3
@@ -156,6 +156,8 @@
cmd.createArgument().setValue("-verbose");
}
+ addCurrentCompilerArgs(cmd);
+
logAndAddFilesToCompile(cmd);
return cmd;
}
1.16 +1 -1 jakarta-ant/src/main/org/apache/tools/ant/types/Commandline.java
Index: Commandline.java
===================================================================
RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/types/Commandline.java,v
retrieving revision 1.15
retrieving revision 1.16
diff -u -r1.15 -r1.16
--- Commandline.java 2001/01/03 14:18:46 1.15
+++ Commandline.java 2001/11/05 15:19:21 1.16
@@ -105,7 +105,7 @@
/**
* Used for nested xml command line definitions.
*/
- public class Argument {
+ public static class Argument {
private String[] parts;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>