Browse Source

Use locale independent methods to identify OS or match attributes and

elements in build files.

PR: 4100


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@269847 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 23 years ago
parent
commit
d17f3c4f2a
12 changed files with 59 additions and 72 deletions
  1. +2
    -1
      src/main/org/apache/tools/ant/IntrospectionHelper.java
  2. +6
    -4
      src/main/org/apache/tools/ant/ProjectHelper.java
  3. +2
    -1
      src/main/org/apache/tools/ant/RuntimeConfigurable.java
  4. +2
    -2
      src/main/org/apache/tools/ant/taskdefs/DependSet.java
  5. +20
    -29
      src/main/org/apache/tools/ant/taskdefs/Execute.java
  6. +2
    -7
      src/main/org/apache/tools/ant/taskdefs/Javadoc.java
  7. +2
    -6
      src/main/org/apache/tools/ant/taskdefs/optional/Cab.java
  8. +10
    -8
      src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java
  9. +2
    -4
      src/main/org/apache/tools/ant/types/CommandlineJava.java
  10. +2
    -2
      src/main/org/apache/tools/ant/util/SourceFileScanner.java
  11. +3
    -3
      src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java
  12. +6
    -5
      src/testcases/org/apache/tools/ant/types/PathTest.java

+ 2
- 1
src/main/org/apache/tools/ant/IntrospectionHelper.java View File

@@ -64,6 +64,7 @@ import java.lang.reflect.Constructor;
import java.io.File; import java.io.File;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Locale;


/** /**
* Helper class that collects the methods a task or nested element * 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) { private String getPropertyName(String methodName, String prefix) {
int start = prefix.length(); int start = prefix.length();
return methodName.substring(start).toLowerCase();
return methodName.substring(start).toLowerCase(Locale.US);
} }


private interface NestedCreator { private interface NestedCreator {


+ 6
- 4
src/main/org/apache/tools/ant/ProjectHelper.java View File

@@ -61,6 +61,7 @@ import java.io.IOException;
import java.util.Hashtable; import java.util.Hashtable;
import java.util.Vector; import java.util.Vector;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale;
import org.xml.sax.Locator; import org.xml.sax.Locator;
import org.xml.sax.InputSource; import org.xml.sax.InputSource;
import org.xml.sax.HandlerBase; import org.xml.sax.HandlerBase;
@@ -553,11 +554,12 @@ public class ProjectHelper {
IntrospectionHelper.getHelper(parentClass); IntrospectionHelper.getHelper(parentClass);


try { try {
String elementName = propType.toLowerCase(Locale.US);
if (parent instanceof UnknownElement) { if (parent instanceof UnknownElement) {
child = new UnknownElement(propType.toLowerCase());
child = new UnknownElement(elementName);
((UnknownElement) parent).addChild((UnknownElement) child); ((UnknownElement) parent).addChild((UnknownElement) child);
} else { } else {
child = ih.createElement(project, parent, propType.toLowerCase());
child = ih.createElement(project, parent, elementName);
} }


configureId(child, attrs); configureId(child, attrs);
@@ -568,7 +570,7 @@ public class ProjectHelper {
parentWrapper.addChild(childWrapper); parentWrapper.addChild(childWrapper);
} else { } else {
configure(child, attrs, project); configure(child, attrs, project);
ih.storeElement(project, parent, child, propType.toLowerCase());
ih.storeElement(project, parent, child, elementName);
} }
} catch (BuildException exc) { } catch (BuildException exc) {
throw new SAXParseException(exc.getMessage(), locator, exc); throw new SAXParseException(exc.getMessage(), locator, exc);
@@ -665,7 +667,7 @@ public class ProjectHelper {
project.getProperties() ); project.getProperties() );
try { try {
ih.setAttribute(project, target, ih.setAttribute(project, target,
attrs.getName(i).toLowerCase(), value);
attrs.getName(i).toLowerCase(Locale.US), value);


} catch (BuildException be) { } catch (BuildException be) {
// id attribute must be set externally // id attribute must be set externally


+ 2
- 1
src/main/org/apache/tools/ant/RuntimeConfigurable.java View File

@@ -55,6 +55,7 @@
package org.apache.tools.ant; package org.apache.tools.ant;


import java.util.Enumeration; import java.util.Enumeration;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;
import org.xml.sax.AttributeList; import org.xml.sax.AttributeList;
import org.xml.sax.helpers.AttributeListImpl; import org.xml.sax.helpers.AttributeListImpl;
@@ -152,7 +153,7 @@ public class RuntimeConfigurable {
while (enum.hasMoreElements()) { while (enum.hasMoreElements()) {
RuntimeConfigurable child = (RuntimeConfigurable) enum.nextElement(); RuntimeConfigurable child = (RuntimeConfigurable) enum.nextElement();
child.maybeConfigure(p); 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) { if (id != null) {


+ 2
- 2
src/main/org/apache/tools/ant/taskdefs/DependSet.java View File

@@ -61,6 +61,7 @@ import java.util.Date;
import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; 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.FileSet;
import org.apache.tools.ant.types.FileList; import org.apache.tools.ant.types.FileList;


@@ -170,8 +171,7 @@ public class DependSet extends MatchingTask {
be able to check file modification times. be able to check file modification times.
(Windows has a max resolution of two secs for 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; now += 2000;
} }




+ 20
- 29
src/main/org/apache/tools/ant/taskdefs/Execute.java View File

@@ -58,6 +58,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;
import org.apache.tools.ant.taskdefs.condition.Os;


import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@@ -68,6 +69,7 @@ import java.io.StringReader;
import java.io.ByteArrayOutputStream; import java.io.ByteArrayOutputStream;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;


/** /**
@@ -109,17 +111,17 @@ public class Execute {
// Ignore and keep try // Ignore and keep try
} }


String osname = System.getProperty("os.name").toLowerCase();
if ( osname.indexOf("mac os") >= 0 ) {
if ( (new Os("mac")).eval() ) {
// Mac // Mac
shellLauncher = new MacCommandLauncher(new CommandLauncher()); 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 // OS/2 - use same mechanism as Windows 2000
shellLauncher = new WinNTCommandLauncher(new CommandLauncher()); 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 // Windows. Need to determine which JDK we're running in

CommandLauncher baseLauncher; CommandLauncher baseLauncher;
if ( System.getProperty("java.version").startsWith("1.1") ) { if ( System.getProperty("java.version").startsWith("1.1") ) {
// JDK 1.1 // JDK 1.1
@@ -131,6 +133,9 @@ public class Execute {
} }


// Determine if we're running under 2000/NT or 98/95 // 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 ) { if ( osname.indexOf("nt") >= 0 || osname.indexOf("2000") >= 0 ) {
// Windows 2000/NT // Windows 2000/NT
shellLauncher = new WinNTCommandLauncher(baseLauncher); shellLauncher = new WinNTCommandLauncher(baseLauncher);
@@ -198,35 +203,15 @@ public class Execute {
} }


private static String[] getProcEnvCommand() { 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 // OS/2 - use same mechanism as Windows 2000
// Not sure // Not sure
String[] cmd = {"cmd", "/c", "set" }; String[] cmd = {"cmd", "/c", "set" };
return cmd; 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 // Determine if we're running under 2000/NT or 98/95
if ( osname.indexOf("nt") >= 0 || osname.indexOf("2000") >= 0 ) { if ( osname.indexOf("nt") >= 0 || osname.indexOf("2000") >= 0 ) {
// Windows 2000/NT // Windows 2000/NT
@@ -239,12 +224,18 @@ public class Execute {
return cmd; return cmd;
} }
} }
else {
else if ( (new Os("unix")).eval() ) {
// Generic UNIX // Generic UNIX
// Alternatively one could use: /bin/sh -c env // Alternatively one could use: /bin/sh -c env
String[] cmd = {"/usr/bin/env"}; String[] cmd = {"/usr/bin/env"};
return cmd; 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;
}
} }


/** /**


+ 2
- 7
src/main/org/apache/tools/ant/taskdefs/Javadoc.java View File

@@ -67,6 +67,7 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.ProjectHelper; import org.apache.tools.ant.ProjectHelper;
import org.apache.tools.ant.Task; 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.Path;
import org.apache.tools.ant.types.Reference; import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.EnumeratedAttribute; 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, // This is the most common extension case - exe for windows and OS/2,
// nothing for *nix. // 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 // Look for javadoc in the java.home/../bin directory. Unfortunately
// on Windows java.home doesn't always refer to the correct location, // on Windows java.home doesn't always refer to the correct location,


+ 2
- 6
src/main/org/apache/tools/ant/taskdefs/optional/Cab.java View File

@@ -59,6 +59,7 @@ import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.taskdefs.MatchingTask; import org.apache.tools.ant.taskdefs.MatchingTask;
import org.apache.tools.ant.taskdefs.ExecTask; 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.FileSet;
import org.apache.tools.ant.types.Commandline; import org.apache.tools.ant.types.Commandline;


@@ -91,13 +92,8 @@ public class Cab extends MatchingTask {
protected String archiveType = "cab"; protected String archiveType = "cab";


private static String myos; 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 * This is the name/location of where to
* create the .cab file. * create the .cab file.


+ 10
- 8
src/main/org/apache/tools/ant/taskdefs/optional/net/FTP.java View File

@@ -74,6 +74,7 @@ import java.io.FileWriter;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.util.Locale;
import java.util.Vector; import java.util.Vector;


/** /**
@@ -346,26 +347,27 @@ public class FTP
*/ */
public void setAction(String action) throws BuildException 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; 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; 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; this.action = DEL_FILES;
} }
else if (action.toLowerCase().equals("list"))
else if (actionL.equals("list"))
{ {
this.action = LIST_FILES; this.action = LIST_FILES;
} }
else if (action.toLowerCase().equals("mkdir"))
else if (actionL.equals("mkdir"))
{ {
this.action = MK_DIR; this.action = MK_DIR;
} }


+ 2
- 4
src/main/org/apache/tools/ant/types/CommandlineJava.java View File

@@ -59,6 +59,7 @@ import java.util.Enumeration;
import java.util.Vector; import java.util.Vector;
import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.BuildException; 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 * A representation of a Java command line that is nothing more
@@ -346,10 +347,7 @@ public class CommandlineJava implements Cloneable {
private String getJavaExecutableName() { private String getJavaExecutableName() {
// This is the most common extension case - exe for windows and OS/2, // This is the most common extension case - exe for windows and OS/2,
// nothing for *nix. // 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 // Look for java in the java.home/../bin directory. Unfortunately
// on Windows java.home doesn't always refer to the correct location, // on Windows java.home doesn't always refer to the correct location,


+ 2
- 2
src/main/org/apache/tools/ant/util/SourceFileScanner.java View File

@@ -56,6 +56,7 @@ package org.apache.tools.ant.util;


import org.apache.tools.ant.Project; import org.apache.tools.ant.Project;
import org.apache.tools.ant.Task; import org.apache.tools.ant.Task;
import org.apache.tools.ant.taskdefs.condition.Os;


import java.io.File; import java.io.File;
import java.util.Vector; import java.util.Vector;
@@ -106,8 +107,7 @@ public class SourceFileScanner {
be able to check file modification times. be able to check file modification times.
(Windows has a max resolution of two secs for 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; now += 2000;
} }




+ 3
- 3
src/testcases/org/apache/tools/ant/IntrospectionHelperTest.java View File

@@ -424,10 +424,10 @@ public class IntrospectionHelperTest extends TestCase {
public void setTen(File f) { public void setTen(File f) {
if (isUnixStyle) { if (isUnixStyle) {
assertEquals("/tmp/2", f.getAbsolutePath()); 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 { } else {
assertEquals(":\\tmp\\2", f.getAbsolutePath().toLowerCase().substring(1));
assertEquals(":\\tmp\\2", f.getAbsolutePath().toLowerCase(Locale.US).substring(1));
} }
} }




+ 6
- 5
src/testcases/org/apache/tools/ant/types/PathTest.java View File

@@ -61,6 +61,7 @@ import junit.framework.TestCase;
import junit.framework.AssertionFailedError; import junit.framework.AssertionFailedError;


import java.io.File; import java.io.File;
import java.util.Locale;


/** /**
* JUnit 3 testcases for org.apache.tools.ant.types.Path * JUnit 3 testcases for org.apache.tools.ant.types.Path
@@ -71,7 +72,7 @@ import java.io.File;
public class PathTest extends TestCase { public class PathTest extends TestCase {


public static boolean isUnixStyle = File.pathSeparatorChar == ':'; 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; private Project project;


@@ -140,10 +141,10 @@ public class PathTest extends TestCase {
assertEquals("/test", l[1]); assertEquals("/test", l[1]);
} else if (isNetWare) { } else if (isNetWare) {
assertEquals("volumes on NetWare", 1, l.length); assertEquals("volumes on NetWare", 1, l.length);
assertEquals("c:\\test", l[0].toLowerCase());
assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
} else { } else {
assertEquals("drives on DOS", 1, l.length); 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"); p = new Path(project, "c:/test");
@@ -155,10 +156,10 @@ public class PathTest extends TestCase {
assertEquals("/test", l[1]); assertEquals("/test", l[1]);
} else if (isNetWare) { } else if (isNetWare) {
assertEquals("volumes on NetWare", 1, l.length); assertEquals("volumes on NetWare", 1, l.length);
assertEquals("c:\\test", l[0].toLowerCase());
assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
} else { } else {
assertEquals("drives on DOS", 1, l.length); assertEquals("drives on DOS", 1, l.length);
assertEquals("c:\\test", l[0].toLowerCase());
assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
} }
} }




Loading…
Cancel
Save