installation: * Moved JVM version detection code from Project to the new class. * Unified the "find executable" methods and factored them into the new class. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272069 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -68,6 +68,7 @@ import java.lang.reflect.Modifier; | |||
| import org.apache.tools.ant.types.FilterSet; | |||
| import org.apache.tools.ant.types.FilterSetCollection; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /** | |||
| * Central representation of an Ant project. This class defines an | |||
| @@ -108,19 +109,16 @@ public class Project { | |||
| */ | |||
| private final static String VISITED = "VISITED"; | |||
| /** Version of currently running VM. */ | |||
| private static String javaVersion; | |||
| /** Version constant for Java 1.0 */ | |||
| public final static String JAVA_1_0 = "1.0"; | |||
| public final static String JAVA_1_0 = JavaEnvUtils.JAVA_1_0; | |||
| /** Version constant for Java 1.1 */ | |||
| public final static String JAVA_1_1 = "1.1"; | |||
| public final static String JAVA_1_1 = JavaEnvUtils.JAVA_1_1; | |||
| /** Version constant for Java 1.2 */ | |||
| public final static String JAVA_1_2 = "1.2"; | |||
| public final static String JAVA_1_2 = JavaEnvUtils.JAVA_1_2; | |||
| /** Version constant for Java 1.3 */ | |||
| public final static String JAVA_1_3 = "1.3"; | |||
| public final static String JAVA_1_3 = JavaEnvUtils.JAVA_1_3; | |||
| /** Version constant for Java 1.4 */ | |||
| public final static String JAVA_1_4 = "1.4"; | |||
| public final static String JAVA_1_4 = JavaEnvUtils.JAVA_1_4; | |||
| /** Default filter start token. */ | |||
| public final static String TOKEN_START = FilterSet.DEFAULT_TOKEN_START; | |||
| @@ -183,31 +181,6 @@ public class Project { | |||
| /** Records the latest task to be executed on a thread (Thread to Task). */ | |||
| private Hashtable threadTasks = new Hashtable(); | |||
| static { | |||
| // Determine the Java version by looking at available classes | |||
| // java.lang.CharSequence was introduced in JDK 1.4 | |||
| // java.lang.StrictMath was introduced in JDK 1.3 | |||
| // java.lang.ThreadLocal was introduced in JDK 1.2 | |||
| // java.lang.Void was introduced in JDK 1.1 | |||
| // Count up version until a NoClassDefFoundError ends the try | |||
| try { | |||
| javaVersion = JAVA_1_0; | |||
| Class.forName("java.lang.Void"); | |||
| javaVersion = JAVA_1_1; | |||
| Class.forName("java.lang.ThreadLocal"); | |||
| javaVersion = JAVA_1_2; | |||
| Class.forName("java.lang.StrictMath"); | |||
| javaVersion = JAVA_1_3; | |||
| Class.forName("java.lang.CharSequence"); | |||
| javaVersion = JAVA_1_4; | |||
| } catch (ClassNotFoundException cnfe) { | |||
| // swallow as we've hit the max class version that | |||
| // we have | |||
| } | |||
| } | |||
| /** Instance of a utility class to use for file operations. */ | |||
| private FileUtils fileUtils; | |||
| @@ -728,9 +701,10 @@ public class Project { | |||
| /** | |||
| * Returns the version of Java this class is running under. | |||
| * @return the version of Java as a String, e.g. "1.1" | |||
| * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion | |||
| */ | |||
| public static String getJavaVersion() { | |||
| return javaVersion; | |||
| return JavaEnvUtils.getJavaVersion(); | |||
| } | |||
| /** | |||
| @@ -741,13 +715,14 @@ public class Project { | |||
| * | |||
| * @exception BuildException if this Java version is not supported | |||
| * | |||
| * @see #getJavaVersion() | |||
| * @see org.apache.tools.ant.util.JavaEnvUtils#getJavaVersion | |||
| */ | |||
| public void setJavaVersionProperty() throws BuildException { | |||
| String javaVersion = JavaEnvUtils.getJavaVersion(); | |||
| setPropertyInternal("ant.java.version", javaVersion); | |||
| // sanity check | |||
| if (javaVersion == JAVA_1_0) { | |||
| if (javaVersion == JavaEnvUtils.JAVA_1_0) { | |||
| throw new BuildException("Ant cannot work on Java 1.0"); | |||
| } | |||
| @@ -1477,7 +1452,7 @@ public class Project { | |||
| */ | |||
| public void setFileLastModified(File file, long time) | |||
| throws BuildException { | |||
| if (getJavaVersion() == JAVA_1_1) { | |||
| if (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1) { | |||
| log("Cannot change the modification time of " + file | |||
| + " in JDK 1.1", Project.MSG_WARN); | |||
| return; | |||
| @@ -61,10 +61,10 @@ 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; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| import org.apache.tools.ant.util.SourceFileScanner; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapter; | |||
| import org.apache.tools.ant.taskdefs.compilers.CompilerAdapterFactory; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import java.io.File; | |||
| import java.util.Enumeration; | |||
| @@ -697,34 +697,7 @@ public class Javac extends MatchingTask { | |||
| } | |||
| protected String getSystemJavac() { | |||
| // This is the most common extension case - exe for windows and OS/2, | |||
| // nothing for *nix. | |||
| String extension = Os.isFamily("dos") ? ".exe" : ""; | |||
| File jExecutable = null; | |||
| // On AIX using IBM's JDK 1.2 the javac executable is in | |||
| // the java.home/../../sh directory | |||
| if (Os.isName("aix")) { | |||
| jExecutable = new File(System.getProperty("java.home") + | |||
| "/../../sh/javac" + extension); | |||
| } | |||
| if (jExecutable == null || !jExecutable.exists()) { | |||
| // Look for javac in the java.home/../bin directory. | |||
| jExecutable = new File(System.getProperty("java.home") + | |||
| "/../bin/javac" + extension); | |||
| } | |||
| // Unfortunately | |||
| // on Windows java.home doesn't always refer to the correct location, | |||
| // so we need to fall back to assuming java is somewhere on the | |||
| // PATH. | |||
| if (jExecutable.exists() && !Os.isFamily("netware")) { | |||
| return jExecutable.getAbsolutePath(); | |||
| } else { | |||
| return "javac" + extension; | |||
| } | |||
| return JavaEnvUtils.getJdkExecutable("javac"); | |||
| } | |||
| /** | |||
| @@ -767,8 +740,8 @@ public class Javac extends MatchingTask { | |||
| } | |||
| if (compilerImpl == null) { | |||
| if (Project.getJavaVersion() != Project.JAVA_1_1 && | |||
| Project.getJavaVersion() != Project.JAVA_1_2) { | |||
| if (JavaEnvUtils.getJavaVersion() != Project.JAVA_1_1 && | |||
| JavaEnvUtils.getJavaVersion() != Project.JAVA_1_2) { | |||
| compilerImpl = "modern"; | |||
| } else { | |||
| compilerImpl = "classic"; | |||
| @@ -67,13 +67,13 @@ import org.apache.tools.ant.DirectoryScanner; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.Task; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.types.Path; | |||
| import org.apache.tools.ant.types.Reference; | |||
| import org.apache.tools.ant.types.EnumeratedAttribute; | |||
| import org.apache.tools.ant.types.Commandline; | |||
| import org.apache.tools.ant.types.FileSet; | |||
| import org.apache.tools.ant.util.FileUtils; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /** | |||
| * This task makes it easy to generate Javadoc documentation for a collection | |||
| @@ -223,12 +223,12 @@ public class Javadoc extends Task { | |||
| private Commandline cmd = new Commandline(); | |||
| private static boolean javadoc1 = | |||
| (Project.getJavaVersion() == Project.JAVA_1_1); | |||
| (JavaEnvUtils.getJavaVersion() == Project.JAVA_1_1); | |||
| private static boolean javadoc4 = | |||
| (Project.getJavaVersion() != Project.JAVA_1_1 && | |||
| Project.getJavaVersion() != Project.JAVA_1_2 && | |||
| Project.getJavaVersion() != Project.JAVA_1_3); | |||
| (JavaEnvUtils.getJavaVersion() != Project.JAVA_1_1 && | |||
| JavaEnvUtils.getJavaVersion() != Project.JAVA_1_2 && | |||
| JavaEnvUtils.getJavaVersion() != Project.JAVA_1_3); | |||
| private void addArgIf(boolean b, String arg) { | |||
| if (b) { | |||
| @@ -921,7 +921,7 @@ public class Javadoc extends Task { | |||
| } | |||
| Commandline toExecute = (Commandline)cmd.clone(); | |||
| toExecute.setExecutable( getJavadocExecutableName() ); | |||
| toExecute.setExecutable(JavaEnvUtils.getJdkExecutable("javadoc")); | |||
| // ------------------------------------------------ general javadoc arguments | |||
| if (classpath == null) { | |||
| @@ -1337,42 +1337,4 @@ public class Javadoc extends Task { | |||
| return project.replaceProperties(content); | |||
| } | |||
| private String getJavadocExecutableName() | |||
| { | |||
| // This is the most common extension case - exe for windows and OS/2, | |||
| // nothing for *nix. | |||
| String extension = Os.isFamily("dos") ? ".exe" : ""; | |||
| File jdocExecutable = null; | |||
| // On AIX using IBM's JDK 1.2 the javadoc executable is in | |||
| // the java.home/../sh directory | |||
| if (Os.isName("aix")) { | |||
| jdocExecutable = new File(System.getProperty("java.home") + | |||
| "/../sh/javadoc" + extension); | |||
| } | |||
| if (jdocExecutable == null || !jdocExecutable.exists()) { | |||
| // Look for javadoc in the java.home/../bin directory. | |||
| jdocExecutable = new File(System.getProperty("java.home") + | |||
| "/../bin/javadoc" + extension); | |||
| } | |||
| // Unfortunately | |||
| // on Windows java.home doesn't always refer to the correct location, | |||
| // so we need to fall back to assuming java is somewhere on the | |||
| // PATH. | |||
| if (jdocExecutable.exists() && !Os.isFamily("netware")) { | |||
| return jdocExecutable.getAbsolutePath(); | |||
| } else { | |||
| if (!Os.isFamily("netware")) { | |||
| log( "Unable to locate " + jdocExecutable.getAbsolutePath() | |||
| + ". Using \"javadoc" + extension | |||
| + "\" instead.", Project.MSG_VERBOSE ); | |||
| } | |||
| return "javadoc" + extension; | |||
| } | |||
| } | |||
| } | |||
| @@ -60,7 +60,7 @@ import java.util.Enumeration; | |||
| import java.util.Vector; | |||
| import org.apache.tools.ant.Project; | |||
| import org.apache.tools.ant.BuildException; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import org.apache.tools.ant.util.JavaEnvUtils; | |||
| /** | |||
| * A representation of a Java command line that is nothing more | |||
| @@ -151,8 +151,8 @@ public class CommandlineJava implements Cloneable { | |||
| } | |||
| public CommandlineJava() { | |||
| setVm(getJavaExecutableName()); | |||
| setVmversion(Project.getJavaVersion()); | |||
| setVm(JavaEnvUtils.getJreExecutable("java")); | |||
| setVmversion(JavaEnvUtils.getJavaVersion()); | |||
| } | |||
| public Commandline.Argument createArgument() { | |||
| @@ -358,39 +358,4 @@ public class CommandlineJava implements Cloneable { | |||
| javaCommand.clearArgs(); | |||
| } | |||
| private String getJavaExecutableName() { | |||
| // This is the most common extension case - exe for windows and OS/2, | |||
| // nothing for *nix. | |||
| String extension = Os.isFamily("dos") ? ".exe" : ""; | |||
| File jExecutable = null; | |||
| // On AIX using IBM's JDK 1.2 the java executable is in | |||
| // the java.home/../sh directory | |||
| if (Os.isName("aix")) { | |||
| jExecutable = new File(System.getProperty("java.home") + | |||
| "/../sh/java" + extension); | |||
| } | |||
| if (jExecutable == null || !jExecutable.exists()) { | |||
| // Look for java in the java.home/../bin directory. | |||
| jExecutable = new File(System.getProperty("java.home") + | |||
| "/../bin/java" + extension); | |||
| } | |||
| // Unfortunately | |||
| // on Windows java.home doesn't always refer to the correct location, | |||
| // so we need to fall back to assuming java is somewhere on the | |||
| // PATH. | |||
| if (jExecutable.exists() && !Os.isFamily("netware")) { | |||
| // NetWare may have a "java" in that directory, but 99% of | |||
| // the time, you don't want to execute it -- Jeff Tulley | |||
| // <JTULLEY@novell.com> | |||
| return jExecutable.getAbsolutePath(); | |||
| } else { | |||
| return "java" + extension; | |||
| } | |||
| } | |||
| } | |||
| @@ -0,0 +1,235 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2002 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.util; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| import java.io.File; | |||
| /** | |||
| * A set of helper methods related to locating executables or checking | |||
| * conditons of a given Java installation. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| * | |||
| * @since Ant 1.5 | |||
| */ | |||
| public class JavaEnvUtils { | |||
| /** Are we on a DOS-based system */ | |||
| private static final boolean isDos = Os.isFamily("dos"); | |||
| /** Are we on Novell NetWare */ | |||
| private static final boolean isNetware = Os.isName("netware"); | |||
| /** Are we on AIX */ | |||
| private static final boolean isAix = Os.isName("aix"); | |||
| /** shortcut for System.getProperty("java.home") */ | |||
| private static final String javaHome = System.getProperty("java.home"); | |||
| /** FileUtils instance for path normalization */ | |||
| private static final FileUtils fileUtils = FileUtils.newFileUtils(); | |||
| /** Version of currently running VM. */ | |||
| private static String javaVersion; | |||
| /** Version constant for Java 1.0 */ | |||
| public final static String JAVA_1_0 = "1.0"; | |||
| /** Version constant for Java 1.1 */ | |||
| public final static String JAVA_1_1 = "1.1"; | |||
| /** Version constant for Java 1.2 */ | |||
| public final static String JAVA_1_2 = "1.2"; | |||
| /** Version constant for Java 1.3 */ | |||
| public final static String JAVA_1_3 = "1.3"; | |||
| /** Version constant for Java 1.4 */ | |||
| public final static String JAVA_1_4 = "1.4"; | |||
| static { | |||
| // Determine the Java version by looking at available classes | |||
| // java.lang.CharSequence was introduced in JDK 1.4 | |||
| // java.lang.StrictMath was introduced in JDK 1.3 | |||
| // java.lang.ThreadLocal was introduced in JDK 1.2 | |||
| // java.lang.Void was introduced in JDK 1.1 | |||
| // Count up version until a NoClassDefFoundError ends the try | |||
| try { | |||
| javaVersion = JAVA_1_0; | |||
| Class.forName("java.lang.Void"); | |||
| javaVersion = JAVA_1_1; | |||
| Class.forName("java.lang.ThreadLocal"); | |||
| javaVersion = JAVA_1_2; | |||
| Class.forName("java.lang.StrictMath"); | |||
| javaVersion = JAVA_1_3; | |||
| Class.forName("java.lang.CharSequence"); | |||
| javaVersion = JAVA_1_4; | |||
| } catch (ClassNotFoundException cnfe) { | |||
| // swallow as we've hit the max class version that | |||
| // we have | |||
| } | |||
| } | |||
| /** | |||
| * Returns the version of Java this class is running under. | |||
| * @return the version of Java as a String, e.g. "1.1" | |||
| */ | |||
| public static String getJavaVersion() { | |||
| return javaVersion; | |||
| } | |||
| /** | |||
| * Finds an executable that is part of a JRE installation based on | |||
| * the java.home system property. | |||
| * | |||
| * <p><code>java</code>, <code>keytool</code>, | |||
| * <code>policytool</code>, <code>orbd</code>, <code>rmid</code>, | |||
| * <code>rmiregistry</code>, <code>servertool</code> and | |||
| * <code>tnameserv</code> are JRE executables on Sun based | |||
| * JRE's.</p> | |||
| * | |||
| * <p>You typically find them in <code>JAVA_HOME/jre/bin</code> if | |||
| * <code>JAVA_HOME</code> points to your JDK installation. JDK | |||
| * < 1.2 has them in the same directory as the JDK | |||
| * executables.</p> | |||
| * | |||
| * @since Ant 1.5 | |||
| */ | |||
| public static String getJreExecutable(String command) { | |||
| if (isNetware) { | |||
| // Extrapolating from: | |||
| // "NetWare may have a "java" in that directory, but 99% of | |||
| // the time, you don't want to execute it" -- Jeff Tulley | |||
| // <JTULLEY@novell.com> | |||
| return command; | |||
| } | |||
| File jExecutable = findInDir(javaHome + "/bin", command); | |||
| if (jExecutable == null && isAix) { | |||
| // On IBM's JDK 1.2 the directory layout is different, 1.3 follows | |||
| // Sun's layout. | |||
| jExecutable = findInDir(javaHome + "/sh", command); | |||
| } | |||
| if (jExecutable != null) { | |||
| return jExecutable.getAbsolutePath(); | |||
| } else { | |||
| // Unfortunately on Windows java.home doesn't always refer | |||
| // to the correct location, so we need to fall back to | |||
| // assuming java is somewhere on the PATH. | |||
| return addExtension(command); | |||
| } | |||
| } | |||
| /** | |||
| * Finds an executable that is part of a JDK installation based on | |||
| * the java.home system property. | |||
| * | |||
| * <p>You typically find them in <code>JAVA_HOME/bin</code> if | |||
| * <code>JAVA_HOME</code> points to your JDK installation.</p> | |||
| * | |||
| * @since Ant 1.5 | |||
| */ | |||
| public static String getJdkExecutable(String command) { | |||
| if (isNetware) { | |||
| // Extrapolating from: | |||
| // "NetWare may have a "java" in that directory, but 99% of | |||
| // the time, you don't want to execute it" -- Jeff Tulley | |||
| // <JTULLEY@novell.com> | |||
| return command; | |||
| } | |||
| File jExecutable = findInDir(javaHome + "/../bin", command); | |||
| if (jExecutable == null && isAix) { | |||
| // On IBM's JDK 1.2 the directory layout is different, 1.3 follows | |||
| // Sun's layout. | |||
| jExecutable = findInDir(javaHome + "/../sh", command); | |||
| } | |||
| if (jExecutable != null) { | |||
| return jExecutable.getAbsolutePath(); | |||
| } else { | |||
| // fall back to JRE bin directory, also catches JDK 1.0 and 1.1 | |||
| // where java.home points to the root of the JDK | |||
| return getJreExecutable(command); | |||
| } | |||
| } | |||
| /** | |||
| * Adds a system specific extension to the name of an executable. | |||
| * | |||
| * @since Ant 1.5 | |||
| */ | |||
| private static String addExtension(String command) { | |||
| // This is the most common extension case - exe for windows and OS/2, | |||
| // nothing for *nix. | |||
| return command + (isDos ? ".exe" : ""); | |||
| } | |||
| /** | |||
| * Look for an executable in a given directory. | |||
| * | |||
| * @return null if the executable cannot be found. | |||
| */ | |||
| private static File findInDir(String dirName, String commandName) { | |||
| File dir = fileUtils.normalize(dirName); | |||
| File executable = null; | |||
| if (dir.exists()) { | |||
| executable = new File(dir, addExtension(commandName)); | |||
| if (!executable.exists()) { | |||
| executable = null; | |||
| } | |||
| } | |||
| return executable; | |||
| } | |||
| } | |||
| @@ -0,0 +1,174 @@ | |||
| /* | |||
| * The Apache Software License, Version 1.1 | |||
| * | |||
| * Copyright (c) 2002 The Apache Software Foundation. All rights | |||
| * reserved. | |||
| * | |||
| * Redistribution and use in source and binary forms, with or without | |||
| * modification, are permitted provided that the following conditions | |||
| * are met: | |||
| * | |||
| * 1. Redistributions of source code must retain the above copyright | |||
| * notice, this list of conditions and the following disclaimer. | |||
| * | |||
| * 2. Redistributions in binary form must reproduce the above copyright | |||
| * notice, this list of conditions and the following disclaimer in | |||
| * the documentation and/or other materials provided with the | |||
| * distribution. | |||
| * | |||
| * 3. The end-user documentation included with the redistribution, if | |||
| * any, must include the following acknowlegement: | |||
| * "This product includes software developed by the | |||
| * Apache Software Foundation (http://www.apache.org/)." | |||
| * Alternately, this acknowlegement may appear in the software itself, | |||
| * if and wherever such third-party acknowlegements normally appear. | |||
| * | |||
| * 4. The names "The Jakarta Project", "Ant", and "Apache Software | |||
| * Foundation" must not be used to endorse or promote products derived | |||
| * from this software without prior written permission. For written | |||
| * permission, please contact apache@apache.org. | |||
| * | |||
| * 5. Products derived from this software may not be called "Apache" | |||
| * nor may "Apache" appear in their names without prior written | |||
| * permission of the Apache Group. | |||
| * | |||
| * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED | |||
| * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES | |||
| * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | |||
| * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR | |||
| * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |||
| * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |||
| * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF | |||
| * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | |||
| * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | |||
| * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT | |||
| * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |||
| * SUCH DAMAGE. | |||
| * ==================================================================== | |||
| * | |||
| * This software consists of voluntary contributions made by many | |||
| * individuals on behalf of the Apache Software Foundation. For more | |||
| * information on the Apache Software Foundation, please see | |||
| * <http://www.apache.org/>. | |||
| */ | |||
| package org.apache.tools.ant.util; | |||
| import java.io.File; | |||
| import junit.framework.AssertionFailedError; | |||
| import junit.framework.TestCase; | |||
| import org.apache.tools.ant.taskdefs.condition.Os; | |||
| /** | |||
| * TestCase for JavaEnvUtils. | |||
| * | |||
| * @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> | |||
| */ | |||
| public class JavaEnvUtilsTest extends TestCase { | |||
| public JavaEnvUtilsTest(String s) { | |||
| super(s); | |||
| } | |||
| public void testGetExecutableNetware() { | |||
| if (Os.isName("netware")) { | |||
| assertEquals("java", JavaEnvUtils.getJreExecutable("java")); | |||
| assertEquals("javac", JavaEnvUtils.getJdkExecutable("javac")); | |||
| assertEquals("foo", JavaEnvUtils.getJreExecutable("foo")); | |||
| assertEquals("foo", JavaEnvUtils.getJdkExecutable("foo")); | |||
| } | |||
| } | |||
| public void testGetExecutableWindows() { | |||
| if (Os.isFamily("windows")) { | |||
| FileUtils fileUtils = FileUtils.newFileUtils(); | |||
| String javaHome = | |||
| fileUtils.normalize(System.getProperty("java.home")) | |||
| .getAbsolutePath(); | |||
| String j = JavaEnvUtils.getJreExecutable("java"); | |||
| assertTrue(j.endsWith(".exe")); | |||
| assertTrue(j+" is absolute", (new File(j)).isAbsolute()); | |||
| try { | |||
| assertTrue(j+" is normalized and in the JRE dir", | |||
| j.startsWith(javaHome)); | |||
| } catch (AssertionFailedError e) { | |||
| // java.home is bogus | |||
| assertEquals("java.exe", j); | |||
| } | |||
| j = JavaEnvUtils.getJdkExecutable("javac"); | |||
| assertTrue(j.endsWith(".exe")); | |||
| assertTrue(j+" is absolute", (new File(j)).isAbsolute()); | |||
| try { | |||
| String javaHomeParent = | |||
| fileUtils.normalize(javaHome+"/..").getAbsolutePath(); | |||
| assertTrue(j+" is normalized and in the JDK dir", | |||
| j.startsWith(javaHomeParent)); | |||
| if (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_0 || | |||
| JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1) { | |||
| assertTrue(j+" is normalized and in the JRE dir", | |||
| j.startsWith(javaHome)); | |||
| } else { | |||
| assertTrue(j+" is normalized and not in the JRE dir", | |||
| !j.startsWith(javaHome)); | |||
| } | |||
| } catch (AssertionFailedError e) { | |||
| // java.home is bogus | |||
| assertEquals("javac.exe", j); | |||
| } | |||
| assertEquals("foo.exe", JavaEnvUtils.getJreExecutable("foo")); | |||
| assertEquals("foo.exe", JavaEnvUtils.getJdkExecutable("foo")); | |||
| } | |||
| } | |||
| public void testGetExecutableMostPlatforms() { | |||
| if (!Os.isName("netware") && !Os.isFamily("windows")) { | |||
| FileUtils fileUtils = FileUtils.newFileUtils(); | |||
| String javaHome = | |||
| fileUtils.normalize(System.getProperty("java.home")) | |||
| .getAbsolutePath(); | |||
| // could still be OS/2 | |||
| String extension = Os.isFamily("dos") ? ".exe" : ""; | |||
| String j = JavaEnvUtils.getJreExecutable("java"); | |||
| if (!extension.equals("")) { | |||
| assertTrue(j.endsWith(extension)); | |||
| } | |||
| assertTrue(j+" is absolute", (new File(j)).isAbsolute()); | |||
| assertTrue(j+" is normalized and in the JRE dir", | |||
| j.startsWith(javaHome)); | |||
| j = JavaEnvUtils.getJdkExecutable("javac"); | |||
| if (!extension.equals("")) { | |||
| assertTrue(j.endsWith(extension)); | |||
| } | |||
| assertTrue(j+" is absolute", (new File(j)).isAbsolute()); | |||
| String javaHomeParent = | |||
| fileUtils.normalize(javaHome+"/..").getAbsolutePath(); | |||
| assertTrue(j+" is normalized and in the JDK dir", | |||
| j.startsWith(javaHomeParent)); | |||
| if (JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_0 || | |||
| JavaEnvUtils.getJavaVersion() == JavaEnvUtils.JAVA_1_1) { | |||
| assertTrue(j+" is normalized and in the JRE dir", | |||
| j.startsWith(javaHome)); | |||
| } else { | |||
| assertTrue(j+" is normalized and not in the JRE dir", | |||
| !j.startsWith(javaHome)); | |||
| } | |||
| assertEquals("foo"+extension, | |||
| JavaEnvUtils.getJreExecutable("foo")); | |||
| assertEquals("foo"+extension, | |||
| JavaEnvUtils.getJdkExecutable("foo")); | |||
| } | |||
| } | |||
| } | |||