diff --git a/docs/manual/CoreTasks/javac.html b/docs/manual/CoreTasks/javac.html index 7632c863b..e71127e9a 100644 --- a/docs/manual/CoreTasks/javac.html +++ b/docs/manual/CoreTasks/javac.html @@ -244,6 +244,43 @@ href="../using.html#path">path-like structures and can also be set via neste <bootclasspath> and <extdirs> elements, respectively.

+

compilerarg

+ +

You can specify additional command line arguments for the compiler +with nested <compilerarg> elements. These elements +are specified like Command-line +Arguments but have an additional attribute that can be used to +enable arguments only if a given compiler implementation will be +used.

+ + + + + + + + + + + + + + + + + + + + + + + + + +
AttributeDescriptionRequired
valueSee hereExactly one of these.
line
file
path
implementationOnly use this argument if the chosen + implementation matches this attribute. Possible choices are the + same as those of the build.compiler property.No.
+

Examples

  <javac srcdir="${src}"
          destdir="${build}"
diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java
index d12e1fd7c..d258070f3 100644
--- a/src/main/org/apache/tools/ant/taskdefs/Javac.java
+++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java
@@ -57,6 +57,7 @@ package org.apache.tools.ant.taskdefs;
 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.compilers.CompilerAdapterFactory;
 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 @@ public class Javac extends MatchingTask {
     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];
@@ -503,6 +507,36 @@ public class Javac extends MatchingTask {
         return nowarn;
     }
 
+    /**
+     * 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 0) {
 
@@ -653,4 +662,57 @@ public class Javac extends MatchingTask {
 	}
     }
     
+    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];
+            }
+        }
+    }
+
 }
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
index 63759ea8c..30ba0f151 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java
@@ -280,6 +280,9 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
         if (verbose) {
             cmd.createArgument().setValue("-verbose");
         }
+
+        addCurrentCompilerArgs(cmd);
+
         return cmd;
     }
 
@@ -434,5 +437,12 @@ public abstract class DefaultCompilerAdapter implements CompilerAdapter {
         }
     }
 
+    /**
+     * Adds the command line arguments specifc to the current implementation.
+     */
+    protected void addCurrentCompilerArgs(Commandline cmd) {
+        cmd.addArguments(getJavac().getCurrentCompilerArgs());
+    }
+
 }
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
index baa9f1e4c..fe92a0ce1 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
@@ -136,6 +136,9 @@ public class Gcj extends DefaultCompilerAdapter {
          *  gcj should be set for generate class.
          */
         cmd.createArgument().setValue("-C");
+
+        addCurrentCompilerArgs(cmd);
+
         return cmd;
     }
 }
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java
index 483e02626..4b4c12b04 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java
@@ -210,6 +210,8 @@ public class Jikes extends DefaultCompilerAdapter {
             cmd.createArgument().setValue("+F");
         }
 
+        addCurrentCompilerArgs(cmd);
+
         int firstFileName = cmd.size();
         logAndAddFilesToCompile(cmd);
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java
index 6085714e2..6818f0140 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java
@@ -130,6 +130,8 @@ public class Jvc extends DefaultCompilerAdapter {
             cmd.createArgument().setValue("/verbose");
         }
 
+        addCurrentCompilerArgs(cmd);
+
         int firstFileName = cmd.size();
         logAndAddFilesToCompile(cmd);
 
diff --git a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java
index 143d36d5c..2c571b824 100644
--- a/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java
+++ b/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java
@@ -156,6 +156,8 @@ public class Kjc extends DefaultCompilerAdapter {
             cmd.createArgument().setValue("-verbose");
         }
 
+        addCurrentCompilerArgs(cmd);
+
         logAndAddFilesToCompile(cmd);
         return cmd;
     }
diff --git a/src/main/org/apache/tools/ant/types/Commandline.java b/src/main/org/apache/tools/ant/types/Commandline.java
index 6ff65bc76..97ee1a50d 100644
--- a/src/main/org/apache/tools/ant/types/Commandline.java
+++ b/src/main/org/apache/tools/ant/types/Commandline.java
@@ -105,7 +105,7 @@ public class Commandline implements Cloneable {
     /**
      * Used for nested xml command line definitions.
      */
-    public class Argument {
+    public static class Argument {
 
         private String[] parts;