DO NOT REPLY TO THIS EMAIL, BUT PLEASE POST YOUR BUG RELATED COMMENTS THROUGH THE WEB INTERFACE AVAILABLE AT <http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4406>. ANY REPLY MADE TO THIS MESSAGE WILL NOT BE COLLECTED AND INSERTED IN THE BUG DATABASE.
http://nagoya.apache.org/bugzilla/show_bug.cgi?id=4406 Proposed flexible, compiler specific "flags" target in javac Summary: Proposed flexible, compiler specific "flags" target in javac Product: Ant Version: 1.5 alpha (nightly) Platform: All OS/Version: All Status: NEW Severity: Enhancement Priority: Other Component: Core tasks AssignedTo: [EMAIL PROTECTED] ReportedBy: [EMAIL PROTECTED] Some java compilers, such as Jikes have very unique arguments that are not appropriate to other java compilers. Diane Holt suggested the following on [email protected]: ----------------------------------------------------------------------- How about a nested <flags> element that takes a "compiler" and "args" attribute, and only uses those that are for the compiler currently being used? For example: <flags compiler="jikes" args="+Z"/> <flags compiler="modern" args="-g:lines"/> ----------------------------------------------------------------------- I have coded up a patch per her proposal, for your consideration. Thanks! -Steve- Here are the cvs diff's for the patch: Index: src/main/org/apache/tools/ant/taskdefs/Javac.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Javac.java,v retrieving revision 1.70 diff -u -b -B -r1.70 Javac.java --- src/main/org/apache/tools/ant/taskdefs/Javac.java 2001/09/30 13:21:53 1.70 +++ src/main/org/apache/tools/ant/taskdefs/Javac.java 2001/10/24 22:50:07 @@ -62,6 +62,8 @@ import org.apache.tools.ant.taskdefs.compilers.*; import java.io.File; +import java.util.Enumeration; +import java.util.Vector; /** * Task to compile Java source files. This task can take the following @@ -119,6 +121,7 @@ private boolean nowarn = false; private String memoryInitialSize; private String memoryMaximumSize; + private Vector compilerSpecificFlags = new Vector(); protected boolean failOnError = true; protected File[] compileList = new File[0]; @@ -514,33 +517,8 @@ // compile the source files - String compiler = project.getProperty("build.compiler"); + String compiler = this.determineCompiler(); - if (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( @@ -608,4 +586,79 @@ "javac1.4".equals(compiler); } + private String determineCompiler() { + String compiler = project.getProperty("build.compiler"); + + if (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); + } + + public Flags createFlags() { + Flags newFlags = new Flags(); + compilerSpecificFlags.add(newFlags); + return(newFlags); + } + + public String getFlagsForCurrentCompiler() { + String compiler = this.determineCompiler(); + Enumeration e = this.compilerSpecificFlags.elements(); + + while(e.hasMoreElements()) { + Flags flag = (Flags)e.nextElement(); + String targetCompiler = flag.getCompiler(); + + if((targetCompiler != null) && (targetCompiler.equals(compiler))) { + return(flag.getArgs()); + } + } + return(null); + } + + static public class Flags extends DataType { + private String compiler = null; + private String args = null; + + public Flags() { + super(); + } + + public void setCompiler(String targetCompiler) { + this.compiler = targetCompiler; + } + + public String getCompiler() { + return(this.compiler); + } + + public void setArgs(String targetArgs) { + this.args = targetArgs; + } + + public String getArgs() { + return(this.args); + } + } } Index: src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java,v retrieving revision 1.9 diff -u -b -B -r1.9 DefaultCompilerAdapter.java --- src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java 2001/09/30 13:21:54 1.9 +++ src/main/org/apache/tools/ant/taskdefs/compilers/DefaultCompilerAdapter.java 2001/10/24 22:50:07 @@ -310,8 +310,21 @@ if (verbose) { cmd.createArgument().setValue("-verbose"); } + + handleCompilerSpecificFlags(cmd); return cmd; } + + /** + * handleCompilerSpecificFlags + **/ + protected Commandline handleCompilerSpecificFlags(Commandline cmd) { + String flagsForThisCompiler = attributes.getFlagsForCurrentCompiler(); + if (flagsForThisCompiler != null) { + cmd.createArgument().setValue(flagsForThisCompiler); + } + return(cmd); + } /** * Does the command line argument processing common to classic and Index: src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java,v retrieving revision 1.3 diff -u -b -B -r1.3 Gcj.java --- src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java 2001/10/12 08:14:08 1.3 +++ src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java 2001/10/24 22:50:07 @@ -76,6 +76,7 @@ Commandline cmd; attributes.log("Using gcj compiler", Project.MSG_VERBOSE); cmd = setupGCJCommand(); + handleCompilerSpecificFlags(cmd); int firstFileName = cmd.size(); logAndAddFilesToCompile(cmd); Index: src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java,v retrieving revision 1.2 diff -u -b -B -r1.2 Jikes.java --- src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java 2001/08/18 14:59:39 1.2 +++ src/main/org/apache/tools/ant/taskdefs/compilers/Jikes.java 2001/10/24 22:50:07 @@ -208,6 +209,8 @@ if (fullDependProperty != null && Project.toBoolean(fullDependProperty)) { cmd.createArgument().setValue("+F"); } + + handleCompilerSpecificFlags(cmd); int firstFileName = cmd.size(); logAndAddFilesToCompile(cmd); Index: src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java,v retrieving revision 1.2 diff -u -b -B -r1.2 Jvc.java --- src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java 2001/01/26 08:43:02 1.2 +++ src/main/org/apache/tools/ant/taskdefs/compilers/Jvc.java 2001/10/24 22:50:07 @@ -129,6 +129,8 @@ cmd.createArgument().setValue("/verbose"); } + handleCompilerSpecificFlags(cmd); + int firstFileName = cmd.size(); logAndAddFilesToCompile(cmd); Index: src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java =================================================================== RCS file: /home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java,v retrieving revision 1.1 diff -u -b -B -r1.1 Kjc.java --- src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java 2001/08/01 15:54:24 1.1 +++ src/main/org/apache/tools/ant/taskdefs/compilers/Kjc.java 2001/10/24 22:50:07 @@ -75,6 +75,7 @@ public boolean execute() throws BuildException { attributes.log("Using kjc compiler", Project.MSG_VERBOSE); Commandline cmd = setupKjcCommand(); + handleCompilerSpecificFlags(cmd); try { Class c = Class.forName("at.dms.kjc.Main");
