Browse Source

\ is no special character for Commandline anymore.

Also made Project.resolveFile more consistent. /a would have been an
absolute filename on all platform while \a would be considered a
relative filename on Unix like systems.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267913 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 25 years ago
parent
commit
a252eb8543
4 changed files with 16 additions and 31 deletions
  1. +4
    -3
      src/main/org/apache/tools/ant/Project.java
  2. +1
    -16
      src/main/org/apache/tools/ant/types/Commandline.java
  3. +7
    -10
      src/testcases/org/apache/tools/ant/types/CommandlineTest.java
  4. +4
    -2
      src/testcases/org/apache/tools/ant/types/PathTest.java

+ 4
- 3
src/main/org/apache/tools/ant/Project.java View File

@@ -453,9 +453,10 @@ public class Project {
}

public File resolveFile(String fileName) {
fileName = fileName.replace('/', File.separatorChar).replace('\\', File.separatorChar);

// deal with absolute files
if (fileName.startsWith("/")) return new File( fileName );
if (fileName.startsWith(System.getProperty("file.separator")))
if (fileName.startsWith(File.separator))
return new File( fileName );

// Eliminate consecutive slashes after the drive spec
@@ -488,7 +489,7 @@ public class Project {
}

File file = new File(baseDir.getAbsolutePath());
StringTokenizer tok = new StringTokenizer(fileName, "/", false);
StringTokenizer tok = new StringTokenizer(fileName, File.separator, false);
while (tok.hasMoreTokens()) {
String part = tok.nextToken();
if (part.equals("..")) {


+ 1
- 16
src/main/org/apache/tools/ant/types/Commandline.java View File

@@ -265,7 +265,7 @@ public class Commandline implements Cloneable {
final int inQuote = 1;
final int inDoubleQuote = 2;
int state = normal;
StringTokenizer tok = new StringTokenizer(to_process, "\\\"\' ", true);
StringTokenizer tok = new StringTokenizer(to_process, "\"\' ", true);
Vector v = new Vector();
StringBuffer current = new StringBuffer();

@@ -296,21 +296,6 @@ public class Commandline implements Cloneable {
v.addElement(current.toString());
current.setLength(0);
}
} else if ("\\".equals(nextTok)) {
if (tok.hasMoreTokens()) {
String escapedToken = tok.nextToken();
char escapedChar = escapedToken.charAt(0);
if (escapedChar == '\\' || escapedChar == '\'' ||
escapedChar == '\"') {
current.append(escapedToken);
}
else {
current.append("\\" + escapedToken);
}
} else {
// just add the backslash
current.append("\\");
}
} else {
current.append(nextTok);
}


+ 7
- 10
src/testcases/org/apache/tools/ant/types/CommandlineTest.java View File

@@ -111,17 +111,14 @@ public class CommandlineTest extends TestCase {
assertEquals("Single quotes stripped, double quote included", "2\"3",
s[1]);

s = Commandline.translateCommandline("1 2\\\'3 4");
assertEquals("Case with quoted single quote", 3, s.length);
assertEquals("single quote included", "2\'3", s[1]);
s = Commandline.translateCommandline("1 2\\\"3 4");
assertEquals("Case with quoted double quote", 3, s.length);
assertEquals("double quote included", "2\"3", s[1]);
// \ doesn't have a special meaning anymore - this is different from
// what the Unix sh does but causes a lot of problems on DOS
// based platforms otherwise
s = Commandline.translateCommandline("1 2\\ 3 4");
assertEquals("case with quotes whitespace", 4, s.length);
assertEquals("Single quotes stripped, double quote included", "2\\",
s[1]);

s = Commandline.translateCommandline("1 2\\\\3 4");
assertEquals("Case with quoted backslash", 3, s.length);
assertEquals("backslash included", "2\\3", s[1]);

// now to the expected failures


+ 4
- 2
src/testcases/org/apache/tools/ant/types/PathTest.java View File

@@ -124,7 +124,8 @@ public class PathTest extends TestCase {
l = p.list();
if (isUnixStyle) {
assertEquals("no drives on Unix", 2, l.length);
assertEquals("c", l[0]);
assert("c resolved relative to project\'s basedir",
l[0].endsWith("/c"));
assertEquals("/test", l[1]);
} else {
assertEquals("drives on DOS", 1, l.length);
@@ -135,7 +136,8 @@ public class PathTest extends TestCase {
l = p.list();
if (isUnixStyle) {
assertEquals("no drives on Unix", 2, l.length);
assertEquals("c", l[0]);
assert("c resolved relative to project\'s basedir",
l[0].endsWith("/c"));
assertEquals("/test", l[1]);
} else {
assertEquals("drives on DOS", 1, l.length);


Loading…
Cancel
Save