git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1585981 13f79535-47bb-0310-9956-ffa450edef68master
@@ -80,6 +80,7 @@ public class Javac extends MatchingTask { | |||||
private static final String FAIL_MSG | private static final String FAIL_MSG | ||||
= "Compile failed; see the compiler error output for details."; | = "Compile failed; see the compiler error output for details."; | ||||
private static final String JAVAC19 = "javac1.9"; | |||||
private static final String JAVAC18 = "javac1.8"; | private static final String JAVAC18 = "javac1.8"; | ||||
private static final String JAVAC17 = "javac1.7"; | private static final String JAVAC17 = "javac1.7"; | ||||
private static final String JAVAC16 = "javac1.6"; | private static final String JAVAC16 = "javac1.6"; | ||||
@@ -152,6 +153,8 @@ public class Javac extends MatchingTask { | |||||
return JAVAC17; | return JAVAC17; | ||||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | } else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_8)) { | ||||
return JAVAC18; | return JAVAC18; | ||||
} else if (JavaEnvUtils.isJavaVersion(JavaEnvUtils.JAVA_1_9)) { | |||||
return JAVAC19; | |||||
} else { | } else { | ||||
return CLASSIC; | return CLASSIC; | ||||
} | } | ||||
@@ -767,8 +770,9 @@ public class Javac extends MatchingTask { | |||||
} | } | ||||
private String getAltCompilerName(String anImplementation) { | private String getAltCompilerName(String anImplementation) { | ||||
if (JAVAC17.equalsIgnoreCase(anImplementation) | |||||
if (JAVAC19.equalsIgnoreCase(anImplementation) | |||||
|| JAVAC18.equalsIgnoreCase(anImplementation) | || JAVAC18.equalsIgnoreCase(anImplementation) | ||||
|| JAVAC17.equalsIgnoreCase(anImplementation) | |||||
|| JAVAC16.equalsIgnoreCase(anImplementation) | || JAVAC16.equalsIgnoreCase(anImplementation) | ||||
|| JAVAC15.equalsIgnoreCase(anImplementation) | || JAVAC15.equalsIgnoreCase(anImplementation) | ||||
|| JAVAC14.equalsIgnoreCase(anImplementation) | || JAVAC14.equalsIgnoreCase(anImplementation) | ||||
@@ -781,8 +785,9 @@ public class Javac extends MatchingTask { | |||||
} | } | ||||
if (MODERN.equalsIgnoreCase(anImplementation)) { | if (MODERN.equalsIgnoreCase(anImplementation)) { | ||||
String nextSelected = assumedJavaVersion(); | String nextSelected = assumedJavaVersion(); | ||||
if (JAVAC17.equalsIgnoreCase(nextSelected) | |||||
if (JAVAC19.equalsIgnoreCase(nextSelected) | |||||
|| JAVAC18.equalsIgnoreCase(nextSelected) | || JAVAC18.equalsIgnoreCase(nextSelected) | ||||
|| JAVAC17.equalsIgnoreCase(nextSelected) | |||||
|| JAVAC16.equalsIgnoreCase(nextSelected) | || JAVAC16.equalsIgnoreCase(nextSelected) | ||||
|| JAVAC15.equalsIgnoreCase(nextSelected) | || JAVAC15.equalsIgnoreCase(nextSelected) | ||||
|| JAVAC14.equalsIgnoreCase(nextSelected) | || JAVAC14.equalsIgnoreCase(nextSelected) | ||||
@@ -1013,12 +1018,13 @@ public class Javac extends MatchingTask { | |||||
* | * | ||||
* @param compilerImpl the name of the compiler implementation | * @param compilerImpl the name of the compiler implementation | ||||
* @return true if compilerImpl is "modern", "classic", | * @return true if compilerImpl is "modern", "classic", | ||||
* "javac1.1", "javac1.2", "javac1.3", "javac1.4", "javac1.5" or | |||||
* "javac1.6". | |||||
* "javac1.1", "javac1.2", "javac1.3", "javac1.4", "javac1.5", | |||||
* "javac1.6", "javac1.7", "javac1.8" or "javac1.9". | |||||
*/ | */ | ||||
protected boolean isJdkCompiler(String compilerImpl) { | protected boolean isJdkCompiler(String compilerImpl) { | ||||
return MODERN.equals(compilerImpl) | return MODERN.equals(compilerImpl) | ||||
|| CLASSIC.equals(compilerImpl) | || CLASSIC.equals(compilerImpl) | ||||
|| JAVAC19.equals(compilerImpl) | |||||
|| JAVAC18.equals(compilerImpl) | || JAVAC18.equals(compilerImpl) | ||||
|| JAVAC17.equals(compilerImpl) | || JAVAC17.equals(compilerImpl) | ||||
|| JAVAC16.equals(compilerImpl) | || JAVAC16.equals(compilerImpl) | ||||
@@ -1243,6 +1249,7 @@ public class Javac extends MatchingTask { | |||||
} | } | ||||
} | } | ||||
} | } | ||||
private static final byte[] PACKAGE_INFO_CLASS_HEADER = { | private static final byte[] PACKAGE_INFO_CLASS_HEADER = { | ||||
(byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, 0x00, 0x00, 0x00, | (byte) 0xca, (byte) 0xfe, (byte) 0xba, (byte) 0xbe, 0x00, 0x00, 0x00, | ||||
0x31, 0x00, 0x07, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06, 0x01, 0x00, 0x0a, | 0x31, 0x00, 0x07, 0x07, 0x00, 0x05, 0x07, 0x00, 0x06, 0x01, 0x00, 0x0a, | ||||
@@ -1250,6 +1257,7 @@ public class Javac extends MatchingTask { | |||||
0x11, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66, | 0x11, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66, | ||||
0x6f, 0x2e, 0x6a, 0x61, 0x76, 0x61, 0x01 | 0x6f, 0x2e, 0x6a, 0x61, 0x76, 0x61, 0x01 | ||||
}; | }; | ||||
private static final byte[] PACKAGE_INFO_CLASS_FOOTER = { | private static final byte[] PACKAGE_INFO_CLASS_FOOTER = { | ||||
0x2f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66, | 0x2f, 0x70, 0x61, 0x63, 0x6b, 0x61, 0x67, 0x65, 0x2d, 0x69, 0x6e, 0x66, | ||||
0x6f, 0x01, 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, | 0x6f, 0x01, 0x00, 0x10, 0x6a, 0x61, 0x76, 0x61, 0x2f, 0x6c, 0x61, 0x6e, | ||||
@@ -17,11 +17,12 @@ | |||||
*/ | */ | ||||
package org.apache.tools.ant.util; | package org.apache.tools.ant.util; | ||||
import java.io.BufferedWriter; | |||||
import java.io.File; | import java.io.File; | ||||
import java.io.IOException; | |||||
import java.io.FileWriter; | import java.io.FileWriter; | ||||
import java.io.BufferedWriter; | |||||
import java.io.IOException; | |||||
import java.util.Vector; | import java.util.Vector; | ||||
import org.apache.tools.ant.taskdefs.condition.Os; | import org.apache.tools.ant.taskdefs.condition.Os; | ||||
/** | /** | ||||
@@ -99,6 +100,11 @@ public final class JavaEnvUtils { | |||||
/** Number Version constant for Java 1.8 */ | /** Number Version constant for Java 1.8 */ | ||||
public static final int VERSION_1_8 = 18; | public static final int VERSION_1_8 = 18; | ||||
/** Version constant for Java 1.9 */ | |||||
public static final String JAVA_1_9 = "1.9"; | |||||
/** Number Version constant for Java 1.9 */ | |||||
public static final int VERSION_1_9 = 19; | |||||
/** Whether this is the Kaffe VM */ | /** Whether this is the Kaffe VM */ | ||||
private static boolean kaffeDetected; | private static boolean kaffeDetected; | ||||
@@ -152,6 +158,9 @@ public final class JavaEnvUtils { | |||||
Class.forName("java.lang.reflect.Executable"); | Class.forName("java.lang.reflect.Executable"); | ||||
javaVersion = JAVA_1_8; | javaVersion = JAVA_1_8; | ||||
javaVersionNumber++; | javaVersionNumber++; | ||||
checkForJava9(); | |||||
javaVersion = JAVA_1_9; | |||||
javaVersionNumber++; | |||||
} catch (Throwable t) { | } catch (Throwable t) { | ||||
// swallow as we've hit the max class version that | // swallow as we've hit the max class version that | ||||
// we have | // we have | ||||
@@ -196,6 +205,24 @@ public final class JavaEnvUtils { | |||||
/** | /** | ||||
* Checks for a give Java 9 runtime. | |||||
* At the time of writing the actual version of the JDK was 1.9.0_b06. | |||||
* Searching for new classes gave no hits, so we need another aproach. | |||||
* Searching for changes (grep -r -i -n "@since 1.9" .) in the sources gave | |||||
* only one hit: a new constant in the class SourceVersion. | |||||
* So we have to check that ... | |||||
* | |||||
* @throws An exception if we can't load the class or don't find the new constant. | |||||
* This is the behavior when searching for new features on older versions. | |||||
* @since Ant 1.9.4 | |||||
*/ | |||||
private static void checkForJava9() throws Exception { | |||||
Class<?> clazz = Class.forName("javax.lang.model.SourceVersion"); | |||||
clazz.getDeclaredField("RELEASE_9"); | |||||
} | |||||
/** | |||||
* Returns the version of Java this class is running under. | * Returns the version of Java this class is running under. | ||||
* This number can be used for comparisons; it will always be | * This number can be used for comparisons; it will always be | ||||
* @return the version of Java as a number 10x the major/minor, | * @return the version of Java as a number 10x the major/minor, | ||||
@@ -398,6 +425,7 @@ public final class JavaEnvUtils { | |||||
private static void buildJrePackages() { | private static void buildJrePackages() { | ||||
jrePackages = new Vector<String>(); | jrePackages = new Vector<String>(); | ||||
switch(javaVersionNumber) { | switch(javaVersionNumber) { | ||||
case VERSION_1_9: | |||||
case VERSION_1_8: | case VERSION_1_8: | ||||
case VERSION_1_7: | case VERSION_1_7: | ||||
case VERSION_1_6: | case VERSION_1_6: | ||||
@@ -446,20 +474,22 @@ public final class JavaEnvUtils { | |||||
* Testing helper method; kept here for unification of changes. | * Testing helper method; kept here for unification of changes. | ||||
* @return a list of test classes depending on the java version. | * @return a list of test classes depending on the java version. | ||||
*/ | */ | ||||
public static Vector getJrePackageTestCases() { | |||||
Vector tests = new Vector(); | |||||
public static Vector<String> getJrePackageTestCases() { | |||||
Vector<String> tests = new Vector<String>(); | |||||
tests.addElement("java.lang.Object"); | tests.addElement("java.lang.Object"); | ||||
switch(javaVersionNumber) { | switch(javaVersionNumber) { | ||||
case VERSION_1_9: | |||||
case VERSION_1_8: | case VERSION_1_8: | ||||
case VERSION_1_7: | case VERSION_1_7: | ||||
case VERSION_1_6: | case VERSION_1_6: | ||||
case VERSION_1_5: | case VERSION_1_5: | ||||
tests.addElement( | tests.addElement( | ||||
"com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl "); | "com.sun.org.apache.xerces.internal.jaxp.datatype.DatatypeFactoryImpl "); | ||||
// Fall tru | |||||
// Fall through | |||||
case VERSION_1_4: | case VERSION_1_4: | ||||
tests.addElement("sun.audio.AudioPlayer"); | tests.addElement("sun.audio.AudioPlayer"); | ||||
if (javaVersionNumber == VERSION_1_4) { | if (javaVersionNumber == VERSION_1_4) { | ||||
// only for 1.4, not for higher versions which fall through | |||||
tests.addElement("org.apache.crimson.parser.ContentModel"); | tests.addElement("org.apache.crimson.parser.ContentModel"); | ||||
tests.addElement("org.apache.xalan.processor.ProcessorImport"); | tests.addElement("org.apache.xalan.processor.ProcessorImport"); | ||||
tests.addElement("org.apache.xml.utils.URI"); | tests.addElement("org.apache.xml.utils.URI"); | ||||
@@ -19,8 +19,8 @@ | |||||
package org.apache.tools.ant.util.facade; | package org.apache.tools.ant.util.facade; | ||||
import java.util.ArrayList; | import java.util.ArrayList; | ||||
import java.util.Iterator; | |||||
import java.util.List; | import java.util.List; | ||||
import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
import org.apache.tools.ant.types.Path; | import org.apache.tools.ant.types.Path; | ||||
@@ -37,7 +37,7 @@ public class FacadeTaskHelper { | |||||
/** | /** | ||||
* Command line arguments. | * Command line arguments. | ||||
*/ | */ | ||||
private List args = new ArrayList(); | |||||
private List<ImplementationSpecificArgument> args = new ArrayList<ImplementationSpecificArgument>(); | |||||
/** | /** | ||||
* The explicitly chosen implementation. | * The explicitly chosen implementation. | ||||
@@ -126,10 +126,8 @@ public class FacadeTaskHelper { | |||||
* @return an array of command line arguments. | * @return an array of command line arguments. | ||||
*/ | */ | ||||
public String[] getArgs() { | public String[] getArgs() { | ||||
List tmp = new ArrayList(args.size()); | |||||
for (Iterator e = args.iterator(); e.hasNext();) { | |||||
ImplementationSpecificArgument arg = | |||||
((ImplementationSpecificArgument) e.next()); | |||||
List<String> tmp = new ArrayList<String>(args.size()); | |||||
for (ImplementationSpecificArgument arg : args) { | |||||
String[] curr = arg.getParts(getImplementation()); | String[] curr = arg.getParts(getImplementation()); | ||||
if (curr != null) { | if (curr != null) { | ||||
for (int i = 0; i < curr.length; i++) { | for (int i = 0; i < curr.length; i++) { | ||||
@@ -136,5 +136,5 @@ public class JavaEnvUtilsTest extends TestCase { | |||||
"In case the current java version is higher than 9.0 definitely a new algorithem will be needed", | "In case the current java version is higher than 9.0 definitely a new algorithem will be needed", | ||||
JavaEnvUtils.isAtLeastJavaVersion("9.0")); | JavaEnvUtils.isAtLeastJavaVersion("9.0")); | ||||
} | } | ||||
} | } |