From f6af37217ec11e6f0e72a373dd6d0f4c5edda746 Mon Sep 17 00:00:00 2001 From: Jacobus Martinus Kruithof Date: Sun, 20 Nov 2005 18:06:25 +0000 Subject: [PATCH] PR 37546: Use alternative names for the compiler argument line. (If modern is specified in javac and javac1.5 is used, and for javac1.5 a command line is specified, but no command line is specified for modern, the javac1.5 command line will be used, if no javac has been specified and javac 1.4 is used and a comman line is specified for modern, the command line specified for modern will be used, etc.) git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@345766 13f79535-47bb-0310-9956-ffa450edef68 --- WHATSNEW | 3 + .../org/apache/tools/ant/taskdefs/Javac.java | 84 +++++++++++++++---- 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/WHATSNEW b/WHATSNEW index 5da586b2a..79e6730f5 100644 --- a/WHATSNEW +++ b/WHATSNEW @@ -4,6 +4,9 @@ Changes from current Ant 1.6.5 version to current CVS version Changes that could break older environments: -------------------------------------------- +* Use alternative names for the command line arguments in javac. Bugzilla + Report 37546. + * Use org.apache.log4j.Logger instead of org.apache.log4j.Category. Category has been deprecated for ~2 years and has been removed from the log4j code. Logger was introduced in log4j 1.2 so users of diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index bfead7142..3b4c8a451 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -69,6 +69,15 @@ public class Javac extends MatchingTask { private static final String FAIL_MSG = "Compile failed; see the compiler error output for details."; + private static final String JAVAC15 = "javac1.5"; + private static final String JAVAC14 = "javac1.4"; + private static final String JAVAC13 = "javac1.3"; + private static final String JAVAC12 = "javac1.2"; + private static final String JAVAC11 = "javac1.1"; + private static final String MODERN = "modern"; + private static final String CLASSIC = "classic"; + private static final String EXTJAVAC = "extJavac"; + private Path src; private File destDir; private Path compileClasspath; @@ -103,18 +112,22 @@ public class Javac extends MatchingTask { * Javac task for compilation of Java files. */ public Javac() { + facade = new FacadeTaskHelper(assumedJavaVersion()); + } + + private String assumedJavaVersion() { if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_1)) { - facade = new FacadeTaskHelper("javac1.1"); + return JAVAC11; } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_2)) { - facade = new FacadeTaskHelper("javac1.2"); + return JAVAC12; } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_3)) { - facade = new FacadeTaskHelper("javac1.3"); + return JAVAC13; } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_4)) { - facade = new FacadeTaskHelper("javac1.4"); + return JAVAC14; } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_5)) { - facade = new FacadeTaskHelper("javac1.5"); + return JAVAC15; } else { - facade = new FacadeTaskHelper("classic"); + return CLASSIC; } } @@ -700,15 +713,54 @@ public class Javac extends MatchingTask { */ public String[] getCurrentCompilerArgs() { String chosen = facade.getExplicitChoice(); - // make sure facade knows about magic properties and fork setting - facade.setImplementation(getCompiler()); try { - return facade.getArgs(); + // 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); } } + private String getAltCompilerName(String anImplementation) { + if (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 (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; + } + /** * Where Ant should place temporary files. * @@ -806,13 +858,13 @@ public class Javac extends MatchingTask { * "javac1.2", "javac1.3", "javac1.4" or "javac1.5". */ protected boolean isJdkCompiler(String compilerImpl) { - return "modern".equals(compilerImpl) - || "classic".equals(compilerImpl) - || "javac1.1".equals(compilerImpl) - || "javac1.2".equals(compilerImpl) - || "javac1.3".equals(compilerImpl) - || "javac1.4".equals(compilerImpl) - || "javac1.5".equals(compilerImpl); + return MODERN.equals(compilerImpl) + || CLASSIC.equals(compilerImpl) + || JAVAC15.equals(compilerImpl) + || JAVAC14.equals(compilerImpl) + || JAVAC13.equals(compilerImpl) + || JAVAC12.equals(compilerImpl) + || JAVAC11.equals(compilerImpl); } /**