From ab9f91736afcdd65e4ca1da6c627f4df71f5289a Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 2 Nov 2001 07:56:53 +0000 Subject: [PATCH] Take care of NetWare when searching for "java" and "javadoc", add NetWare case for . Simplify OS based decisions. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269851 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Chmod.java | 7 ++----- .../apache/tools/ant/taskdefs/DependSet.java | 2 +- .../apache/tools/ant/taskdefs/Execute.java | 18 ++++++++++------- .../apache/tools/ant/taskdefs/Javadoc.java | 10 ++++++---- .../tools/ant/taskdefs/condition/Os.java | 20 +++++++++++++++---- .../tools/ant/taskdefs/optional/Cab.java | 3 +-- .../tools/ant/types/CommandlineJava.java | 7 +++++-- .../tools/ant/util/SourceFileScanner.java | 2 +- 8 files changed, 43 insertions(+), 26 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Chmod.java b/src/main/org/apache/tools/ant/taskdefs/Chmod.java index 12bab8c57..df87eb489 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Chmod.java +++ b/src/main/org/apache/tools/ant/taskdefs/Chmod.java @@ -55,6 +55,7 @@ package org.apache.tools.ant.taskdefs; import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.PatternSet; @@ -202,10 +203,6 @@ public class Chmod extends ExecuteOn { } protected boolean isValidOs() { - // XXX if OS=unix - return System.getProperty("path.separator").equals(":") - && (!System.getProperty("os.name").startsWith("Mac") - || System.getProperty("os.name").endsWith("X")) - && super.isValidOs(); + return Os.isFamily("unix") && super.isValidOs(); } } diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java index 8a5c382f9..c045bad29 100644 --- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java @@ -171,7 +171,7 @@ public class DependSet extends MatchingTask { be able to check file modification times. (Windows has a max resolution of two secs for modification times) */ - if ((new Os("windows")).eval()) { + if (Os.isFamily("windows")) { now += 2000; } diff --git a/src/main/org/apache/tools/ant/taskdefs/Execute.java b/src/main/org/apache/tools/ant/taskdefs/Execute.java index 5d45cb162..b55d3a510 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -111,15 +111,15 @@ public class Execute { // Ignore and keep try } - if ( (new Os("mac")).eval() ) { + if ( Os.isFamily("mac") ) { // Mac shellLauncher = new MacCommandLauncher(new CommandLauncher()); } - else if ( (new Os("os/2")).eval() ) { + else if ( Os.isFamily("os/2") ) { // OS/2 - use same mechanism as Windows 2000 shellLauncher = new WinNTCommandLauncher(new CommandLauncher()); } - else if ( (new Os("windows")).eval() ) { + else if ( Os.isFamily("windows") ) { // Windows. Need to determine which JDK we're running in CommandLauncher baseLauncher; @@ -203,13 +203,13 @@ public class Execute { } private static String[] getProcEnvCommand() { - if ( (new Os("os/2")).eval() ) { + if ( Os.isFamily("os/2") ) { // OS/2 - use same mechanism as Windows 2000 // Not sure String[] cmd = {"cmd", "/c", "set" }; return cmd; } - else if ( (new Os("windows")).eval() ) { + else if ( Os.isFamily("windows") ) { String osname = System.getProperty("os.name").toLowerCase(Locale.US); // Determine if we're running under 2000/NT or 98/95 @@ -224,14 +224,18 @@ public class Execute { return cmd; } } - else if ( (new Os("unix")).eval() ) { + else if ( Os.isFamily("unix") ) { // Generic UNIX // Alternatively one could use: /bin/sh -c env String[] cmd = {"/usr/bin/env"}; return cmd; + } + else if ( Os.isFamily("netware") ) { + String[] cmd = {"env"}; + return cmd; } else { - // MAC OS 9 and previous, Netware + // MAC OS 9 and previous // TODO: I have no idea how to get it, someone must fix it String[] cmd = null; return cmd; diff --git a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java index 8993f74f3..9e6f00979 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -1159,7 +1159,7 @@ public class Javadoc extends Task { { // This is the most common extension case - exe for windows and OS/2, // nothing for *nix. - String extension = (new Os("dos")).eval() ? ".exe" : ""; + String extension = Os.isFamily("dos") ? ".exe" : ""; // Look for javadoc in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, @@ -1168,14 +1168,16 @@ public class Javadoc extends Task { File jdocExecutable = new File( System.getProperty("java.home") + "/../bin/javadoc" + extension ); - if (jdocExecutable.exists()) + if (jdocExecutable.exists() && !Os.isFamily("netware")) { return jdocExecutable.getAbsolutePath(); } else { - log( "Unable to locate " + jdocExecutable.getAbsolutePath() + - ". Using \"javadoc\" instead.", Project.MSG_VERBOSE ); + if (!Os.isFamily("netware")) { + log( "Unable to locate " + jdocExecutable.getAbsolutePath() + + ". Using \"javadoc\" instead.", Project.MSG_VERBOSE ); + } return "javadoc"; } } diff --git a/src/main/org/apache/tools/ant/taskdefs/condition/Os.java b/src/main/org/apache/tools/ant/taskdefs/condition/Os.java index 8023d424f..7fc7fbfb8 100644 --- a/src/main/org/apache/tools/ant/taskdefs/condition/Os.java +++ b/src/main/org/apache/tools/ant/taskdefs/condition/Os.java @@ -65,6 +65,10 @@ import java.util.Locale; * @version $Revision$ */ public class Os implements Condition { + private static final String osName = + System.getProperty("os.name").toLowerCase(Locale.US); + private static final String pathSep = System.getProperty("path.separator"); + private String family; public Os() {} @@ -93,8 +97,16 @@ public class Os implements Condition { * @see Os#setFamily(String) */ public boolean eval() throws BuildException { - String osName = System.getProperty("os.name").toLowerCase(Locale.US); - String pathSep = System.getProperty("path.separator"); + return isFamily(family); + } + + /** + * Determines if the OS on which Ant is executing matches the + * given OS family. + * + * @since 1.5 + */ + public static boolean isFamily(String family) { if (family != null) { if (family.equals("windows")) { return osName.indexOf("windows") > -1; @@ -103,12 +115,12 @@ public class Os implements Condition { } else if (family.equals("netware")) { return osName.indexOf("netware") > -1; } else if (family.equals("dos")) { - return pathSep.equals(";"); + return pathSep.equals(";") && !isFamily("netware"); } else if (family.equals("mac")) { return osName.indexOf("mac") > -1; } else if (family.equals("unix")) { return pathSep.equals(":") - && (!osName.startsWith("mac") || osName.endsWith("x")); + && (!isFamily("mac") || osName.endsWith("x")); } throw new BuildException("Don\'t know how to detect os family \"" + family + "\""); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java index 4d53f9709..127d4c5ab 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -92,7 +92,6 @@ public class Cab extends MatchingTask { protected String archiveType = "cab"; private static String myos; - private static boolean isWindows = (new Os("windows")).eval(); /** * This is the name/location of where to @@ -310,7 +309,7 @@ public class Cab extends MatchingTask { log("Building "+ archiveType +": "+ cabFile.getAbsolutePath()); // we must be on Windows to continue - if (!isWindows) { + if (Os.isFamily("windows")) { log("Using listcab/libcabinet", Project.MSG_VERBOSE); StringBuffer sb = new StringBuffer(); diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index 64c353b4a..4ea491a58 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -347,7 +347,7 @@ public class CommandlineJava implements Cloneable { private String getJavaExecutableName() { // This is the most common extension case - exe for windows and OS/2, // nothing for *nix. - String extension = (new Os("dos")).eval() ? ".exe" : ""; + String extension = Os.isFamily("dos") ? ".exe" : ""; // Look for java in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, @@ -357,7 +357,10 @@ public class CommandlineJava implements Cloneable { new java.io.File(System.getProperty("java.home") + "/../bin/java" + extension ); - if (jExecutable.exists()) { + 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 + // return jExecutable.getAbsolutePath(); } else { return "java"; diff --git a/src/main/org/apache/tools/ant/util/SourceFileScanner.java b/src/main/org/apache/tools/ant/util/SourceFileScanner.java index 489ef7719..9a21f91ad 100644 --- a/src/main/org/apache/tools/ant/util/SourceFileScanner.java +++ b/src/main/org/apache/tools/ant/util/SourceFileScanner.java @@ -107,7 +107,7 @@ public class SourceFileScanner { be able to check file modification times. (Windows has a max resolution of two secs for modification times) */ - if ((new Os("windows")).eval()) { + if (Os.isFamily("windows")) { now += 2000; }