ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Will Stranathan <w...@thestranathans.com>
Subject [PATCH] Commandline.java
Date Mon, 01 Jan 2001 18:20:21 GMT
In the setExecutable() method of the Commandline class, the path 
separator isn't being corrected to file.separator.  This patch will 
perform that work.

I think it MAY be a problem, however, that it changes all /'s to 
file.separator if file.separator is not '/'.  This MAY be an issue if a 
/ is a valid character in a filename or pathname, but is not a path 
delimeter.  (I know on Windows, / is not an allowable character in the 
filename, but I'm not sure on others.)  If this is the case, it is 
CONCEIVABLE that /'s could get changed to the file separator un-necessarily.

Please comment on that observation.

Thanks,
Will Stranathan

Index: Commandline.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/types/Commandline.java,v
retrieving revision 1.13
diff -u -r1.13 Commandline.java
--- Commandline.java	2000/11/23 11:32:49	1.13
+++ Commandline.java	2001/01/01 18:10:21
@@ -206,7 +206,25 @@
       */
      public void setExecutable(String executable) {
          if (executable == null || executable.length() == 0) return;
-        this.executable = executable;
+
+        // Change the file separator path as necessary
+        StringBuffer execBuffer = new StringBuffer(executable);
+        if (System.getProperty("file.separator") != "/") {
+            for (int bufferCounter = 0;
+                bufferCounter < execBuffer.length(); bufferCounter++) {
+                if (execBuffer.charAt(bufferCounter) == '/') {
+                    execBuffer.replace(bufferCounter, bufferCounter + 1,
+                        System.getProperty("file.separator"));
+                    // Skip past the last character in the
+                    // file.separator in case for some reason we have a
+                    // file separator that ends in /, but is longer
+                    // than 1 char.
+                    bufferCounter += System
+                        .getProperty("file.separator").length() - 1;
+                }
+            }
+        }
+        this.executable = execBuffer.toString();
      }





Mime
View raw message