diff --git a/src/main/org/apache/tools/ant/IntrospectionHelper.java b/src/main/org/apache/tools/ant/IntrospectionHelper.java index 9361e35bf..21e5dcba7 100644 --- a/src/main/org/apache/tools/ant/IntrospectionHelper.java +++ b/src/main/org/apache/tools/ant/IntrospectionHelper.java @@ -64,6 +64,7 @@ import java.lang.reflect.Constructor; import java.io.File; import java.util.Enumeration; import java.util.Hashtable; +import java.util.Locale; /** * Helper class that collects the methods a task or nested element @@ -628,7 +629,7 @@ public class IntrospectionHelper implements BuildListener { */ private String getPropertyName(String methodName, String prefix) { int start = prefix.length(); - return methodName.substring(start).toLowerCase(); + return methodName.substring(start).toLowerCase(Locale.US); } private interface NestedCreator { diff --git a/src/main/org/apache/tools/ant/ProjectHelper.java b/src/main/org/apache/tools/ant/ProjectHelper.java index c6ec2fd03..878077f64 100644 --- a/src/main/org/apache/tools/ant/ProjectHelper.java +++ b/src/main/org/apache/tools/ant/ProjectHelper.java @@ -61,6 +61,7 @@ import java.io.IOException; import java.util.Hashtable; import java.util.Vector; import java.util.Enumeration; +import java.util.Locale; import org.xml.sax.Locator; import org.xml.sax.InputSource; import org.xml.sax.HandlerBase; @@ -553,11 +554,12 @@ public class ProjectHelper { IntrospectionHelper.getHelper(parentClass); try { + String elementName = propType.toLowerCase(Locale.US); if (parent instanceof UnknownElement) { - child = new UnknownElement(propType.toLowerCase()); + child = new UnknownElement(elementName); ((UnknownElement) parent).addChild((UnknownElement) child); } else { - child = ih.createElement(project, parent, propType.toLowerCase()); + child = ih.createElement(project, parent, elementName); } configureId(child, attrs); @@ -568,7 +570,7 @@ public class ProjectHelper { parentWrapper.addChild(childWrapper); } else { configure(child, attrs, project); - ih.storeElement(project, parent, child, propType.toLowerCase()); + ih.storeElement(project, parent, child, elementName); } } catch (BuildException exc) { throw new SAXParseException(exc.getMessage(), locator, exc); @@ -665,7 +667,7 @@ public class ProjectHelper { project.getProperties() ); try { ih.setAttribute(project, target, - attrs.getName(i).toLowerCase(), value); + attrs.getName(i).toLowerCase(Locale.US), value); } catch (BuildException be) { // id attribute must be set externally diff --git a/src/main/org/apache/tools/ant/RuntimeConfigurable.java b/src/main/org/apache/tools/ant/RuntimeConfigurable.java index 893883ef7..6e7153a98 100644 --- a/src/main/org/apache/tools/ant/RuntimeConfigurable.java +++ b/src/main/org/apache/tools/ant/RuntimeConfigurable.java @@ -55,6 +55,7 @@ package org.apache.tools.ant; import java.util.Enumeration; +import java.util.Locale; import java.util.Vector; import org.xml.sax.AttributeList; import org.xml.sax.helpers.AttributeListImpl; @@ -152,7 +153,7 @@ public class RuntimeConfigurable { while (enum.hasMoreElements()) { RuntimeConfigurable child = (RuntimeConfigurable) enum.nextElement(); child.maybeConfigure(p); - ProjectHelper.storeChild(p, wrappedObject, child.wrappedObject, child.getElementTag().toLowerCase()); + ProjectHelper.storeChild(p, wrappedObject, child.wrappedObject, child.getElementTag().toLowerCase(Locale.US)); } if (id != null) { diff --git a/src/main/org/apache/tools/ant/taskdefs/DependSet.java b/src/main/org/apache/tools/ant/taskdefs/DependSet.java index 12ab61c40..8a5c382f9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/DependSet.java +++ b/src/main/org/apache/tools/ant/taskdefs/DependSet.java @@ -61,6 +61,7 @@ import java.util.Date; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; +import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.FileList; @@ -170,8 +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) */ - String osname = System.getProperty("os.name").toLowerCase(); - if ( osname.indexOf("windows") >= 0 ) { + if ((new Os("windows")).eval()) { 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 15354d5fa..5d45cb162 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Execute.java +++ b/src/main/org/apache/tools/ant/taskdefs/Execute.java @@ -58,6 +58,7 @@ import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; import org.apache.tools.ant.types.Commandline; +import org.apache.tools.ant.taskdefs.condition.Os; import java.io.File; import java.io.IOException; @@ -68,6 +69,7 @@ import java.io.StringReader; import java.io.ByteArrayOutputStream; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.util.Locale; import java.util.Vector; /** @@ -109,17 +111,17 @@ public class Execute { // Ignore and keep try } - String osname = System.getProperty("os.name").toLowerCase(); - if ( osname.indexOf("mac os") >= 0 ) { + if ( (new Os("mac")).eval() ) { // Mac shellLauncher = new MacCommandLauncher(new CommandLauncher()); } - else if ( osname.indexOf("os/2") >= 0 ) { + else if ( (new Os("os/2")).eval() ) { // OS/2 - use same mechanism as Windows 2000 shellLauncher = new WinNTCommandLauncher(new CommandLauncher()); } - else if ( osname.indexOf("windows") >= 0 ) { + else if ( (new Os("windows")).eval() ) { // Windows. Need to determine which JDK we're running in + CommandLauncher baseLauncher; if ( System.getProperty("java.version").startsWith("1.1") ) { // JDK 1.1 @@ -131,6 +133,9 @@ public class Execute { } // Determine if we're running under 2000/NT or 98/95 + String osname = + System.getProperty("os.name").toLowerCase(Locale.US); + if ( osname.indexOf("nt") >= 0 || osname.indexOf("2000") >= 0 ) { // Windows 2000/NT shellLauncher = new WinNTCommandLauncher(baseLauncher); @@ -198,35 +203,15 @@ public class Execute { } private static String[] getProcEnvCommand() { - String osname = System.getProperty("os.name").toLowerCase(); - if ( osname.indexOf("mac os") >= 0 ) { - // Mac - // Determine if we are running under OS X - try { - String version = System.getProperty("os.version"); - int majorVersion = - Integer.parseInt(version.substring(0, version.indexOf('.'))); - - if (majorVersion >= 10) { - // OS X - just line UNIX - String[] cmd = {"/usr/bin/env"}; - return cmd; - } - } catch (NumberFormatException e) { - // fall through to OS 9 - } - // OS 9 and previous - // TODO: I have no idea how to get it, someone must fix it - String[] cmd = null; - return cmd; - } - else if ( osname.indexOf("os/2") >= 0 ) { + if ( (new Os("os/2")).eval() ) { // OS/2 - use same mechanism as Windows 2000 // Not sure String[] cmd = {"cmd", "/c", "set" }; return cmd; } - else if ( osname.indexOf("indows") >= 0 ) { + else if ( (new Os("windows")).eval() ) { + String osname = + System.getProperty("os.name").toLowerCase(Locale.US); // Determine if we're running under 2000/NT or 98/95 if ( osname.indexOf("nt") >= 0 || osname.indexOf("2000") >= 0 ) { // Windows 2000/NT @@ -239,12 +224,18 @@ public class Execute { return cmd; } } - else { + else if ( (new Os("unix")).eval() ) { // Generic UNIX // Alternatively one could use: /bin/sh -c env String[] cmd = {"/usr/bin/env"}; return cmd; } + else { + // MAC OS 9 and previous, Netware + // 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 3650732d6..8993f74f3 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javadoc.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javadoc.java @@ -67,6 +67,7 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.ProjectHelper; 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; @@ -1158,13 +1159,7 @@ public class Javadoc extends Task { { // This is the most common extension case - exe for windows and OS/2, // nothing for *nix. - String os = System.getProperty("os.name").toLowerCase(); - boolean dosBased = - os.indexOf("windows") >= 0 || os.indexOf("os/2") >= 0; - // for NetWare, we do not want an extension either, so we will be - // "non dosBased". If this variable is ever used for other logic - // besides the extension, we may need to revisit this code. - String extension = dosBased? ".exe" : ""; + String extension = (new Os("dos")).eval() ? ".exe" : ""; // Look for javadoc in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, 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 d5768404f..4d53f9709 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/Cab.java @@ -59,6 +59,7 @@ import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.ExecTask; +import org.apache.tools.ant.taskdefs.condition.Os; import org.apache.tools.ant.types.FileSet; import org.apache.tools.ant.types.Commandline; @@ -91,13 +92,8 @@ public class Cab extends MatchingTask { protected String archiveType = "cab"; private static String myos; - private static boolean isWindows; + private static boolean isWindows = (new Os("windows")).eval(); - static { - myos = System.getProperty("os.name"); - isWindows = myos.toLowerCase().indexOf("windows") >= 0; - } - /** * This is the name/location of where to * create the .cab file. diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java index cd868fd8a..cd9c310a9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java @@ -74,6 +74,7 @@ import java.io.FileWriter; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; +import java.util.Locale; import java.util.Vector; /** @@ -346,26 +347,27 @@ public class FTP */ public void setAction(String action) throws BuildException { - if (action.toLowerCase().equals("send") || - action.toLowerCase().equals("put")) + String actionL = action.toLowerCase(Locale.US); + if (actionL.equals("send") || + actionL.equals("put")) { this.action = SEND_FILES; } - else if (action.toLowerCase().equals("recv") || - action.toLowerCase().equals("get")) + else if (actionL.equals("recv") || + actionL.equals("get")) { this.action = GET_FILES; } - else if (action.toLowerCase().equals("del") || - action.toLowerCase().equals("delete" )) + else if (actionL.equals("del") || + actionL.equals("delete" )) { this.action = DEL_FILES; } - else if (action.toLowerCase().equals("list")) + else if (actionL.equals("list")) { this.action = LIST_FILES; } - else if (action.toLowerCase().equals("mkdir")) + else if (actionL.equals("mkdir")) { this.action = MK_DIR; } diff --git a/src/main/org/apache/tools/ant/types/CommandlineJava.java b/src/main/org/apache/tools/ant/types/CommandlineJava.java index e4fe4f0f5..64c353b4a 100644 --- a/src/main/org/apache/tools/ant/types/CommandlineJava.java +++ b/src/main/org/apache/tools/ant/types/CommandlineJava.java @@ -59,6 +59,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; /** * A representation of a Java command line that is nothing more @@ -346,10 +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 os = System.getProperty("os.name").toLowerCase(); - boolean dosBased = - os.indexOf("windows") >= 0 || os.indexOf("os/2") >= 0; - String extension = dosBased? ".exe" : ""; + String extension = (new Os("dos")).eval() ? ".exe" : ""; // Look for java in the java.home/../bin directory. Unfortunately // on Windows java.home doesn't always refer to the correct location, diff --git a/src/main/org/apache/tools/ant/util/SourceFileScanner.java b/src/main/org/apache/tools/ant/util/SourceFileScanner.java index 9378cd3b7..489ef7719 100644 --- a/src/main/org/apache/tools/ant/util/SourceFileScanner.java +++ b/src/main/org/apache/tools/ant/util/SourceFileScanner.java @@ -56,6 +56,7 @@ package org.apache.tools.ant.util; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; +import org.apache.tools.ant.taskdefs.condition.Os; import java.io.File; import java.util.Vector; @@ -106,8 +107,7 @@ public class SourceFileScanner { be able to check file modification times. (Windows has a max resolution of two secs for modification times) */ - String osname = System.getProperty("os.name").toLowerCase(); - if ( osname.indexOf("windows") >= 0 ) { + if ((new Os("windows")).eval()) { now += 2000; } diff --git a/src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java b/src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java index 7d221a013..70d7cd7e3 100644 --- a/src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java +++ b/src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java @@ -424,10 +424,10 @@ public class IntrospectionHelperTest extends TestCase { public void setTen(File f) { if (isUnixStyle) { assertEquals("/tmp/2", f.getAbsolutePath()); - } else if (System.getProperty("os.name").toLowerCase().equals("netware")) { - assertEquals("\\tmp\\2", f.getAbsolutePath().toLowerCase()); + } else if (System.getProperty("os.name").toLowerCase(Locale.US).equals("netware")) { + assertEquals("\\tmp\\2", f.getAbsolutePath().toLowerCase(Locale.US)); } else { - assertEquals(":\\tmp\\2", f.getAbsolutePath().toLowerCase().substring(1)); + assertEquals(":\\tmp\\2", f.getAbsolutePath().toLowerCase(Locale.US).substring(1)); } } diff --git a/src/testcases/org/apache/tools/ant/types/PathTest.java b/src/testcases/org/apache/tools/ant/types/PathTest.java index bec4624e5..9a2268201 100644 --- a/src/testcases/org/apache/tools/ant/types/PathTest.java +++ b/src/testcases/org/apache/tools/ant/types/PathTest.java @@ -61,6 +61,7 @@ import junit.framework.TestCase; import junit.framework.AssertionFailedError; import java.io.File; +import java.util.Locale; /** * JUnit 3 testcases for org.apache.tools.ant.types.Path @@ -71,7 +72,7 @@ import java.io.File; public class PathTest extends TestCase { public static boolean isUnixStyle = File.pathSeparatorChar == ':'; - public static boolean isNetWare = (System.getProperty("os.name").toLowerCase().indexOf("netware") > -1); + public static boolean isNetWare = (System.getProperty("os.name").toLowerCase(Locale.US).indexOf("netware") > -1); private Project project; @@ -140,10 +141,10 @@ public class PathTest extends TestCase { assertEquals("/test", l[1]); } else if (isNetWare) { assertEquals("volumes on NetWare", 1, l.length); - assertEquals("c:\\test", l[0].toLowerCase()); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); } else { assertEquals("drives on DOS", 1, l.length); - assertEquals("c:\\test", l[0].toLowerCase()); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); } p = new Path(project, "c:/test"); @@ -155,10 +156,10 @@ public class PathTest extends TestCase { assertEquals("/test", l[1]); } else if (isNetWare) { assertEquals("volumes on NetWare", 1, l.length); - assertEquals("c:\\test", l[0].toLowerCase()); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); } else { assertEquals("drives on DOS", 1, l.length); - assertEquals("c:\\test", l[0].toLowerCase()); + assertEquals("c:\\test", l[0].toLowerCase(Locale.US)); } }