git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267781 13f79535-47bb-0310-9956-ffa450edef68master
@@ -107,11 +107,26 @@ public class Path { | |||||
*/ | */ | ||||
public void setLocation(String location) { | public void setLocation(String location) { | ||||
if (location != null && location.length() > 0) { | if (location != null && location.length() > 0) { | ||||
definition.addElement(translateFile(location)); | |||||
String element = translateFile(location); | |||||
if (definition.indexOf(element) == -1) { | |||||
definition.addElement(element); | |||||
} | |||||
} | } | ||||
} | } | ||||
/** | |||||
* Append the contents of the other Path instance to this. | |||||
*/ | |||||
public void append(Path other) { | |||||
String[] l = other.list(); | |||||
for (int i=0; i<l.length; i++) { | |||||
if (definition.indexOf(l[i]) == -1) { | |||||
definition.addElement(l[i]); | |||||
} | |||||
} | |||||
} | |||||
/** | /** | ||||
* Parses a path definition and creates single PathElements. | * Parses a path definition and creates single PathElements. | ||||
* @param path the path definition. | * @param path the path definition. | ||||
@@ -119,7 +134,10 @@ public class Path { | |||||
public void setPath(String path) { | public void setPath(String path) { | ||||
final Vector elements = translatePath(path); | final Vector elements = translatePath(path); | ||||
for (int i=0; i < elements.size(); i++) { | for (int i=0; i < elements.size(); i++) { | ||||
definition.addElement(elements.elementAt(i)); | |||||
String element = (String) elements.elementAt(i); | |||||
if (definition.indexOf(element) == -1) { | |||||
definition.addElement(element); | |||||
} | |||||
} | } | ||||
} | } | ||||
@@ -130,7 +130,7 @@ public class Java extends Exec { | |||||
if (this.classpath == null) { | if (this.classpath == null) { | ||||
this.classpath = s; | this.classpath = s; | ||||
} else { | } else { | ||||
this.classpath.setPath(s.toString()); | |||||
this.classpath.append(s); | |||||
} | } | ||||
} | } | ||||
@@ -167,6 +167,39 @@ public class PathTest extends TestCase { | |||||
p.setPath("\\d;\\e"); | p.setPath("\\d;\\e"); | ||||
l = p.list(); | l = p.list(); | ||||
assertEquals("5 after setPath", 5, l.length); | assertEquals("5 after setPath", 5, l.length); | ||||
p.append(new Path("\\f")); | |||||
l = p.list(); | |||||
assertEquals("6 after append", 6, l.length); | |||||
} | |||||
public void testEmpyPath() { | |||||
Path p = new Path(""); | |||||
String[] l = p.list(); | |||||
assertEquals("0 after construction", 0, l.length); | |||||
p.setLocation(""); | |||||
l = p.list(); | |||||
assertEquals("0 after setLocation", 0, l.length); | |||||
p.setPath(""); | |||||
l = p.list(); | |||||
assertEquals("0 after setPath", 0, l.length); | |||||
p.append(new Path()); | |||||
l = p.list(); | |||||
assertEquals("0 after append", 0, l.length); | |||||
} | |||||
public void testUnique() { | |||||
Path p = new Path("/a:/a"); | |||||
String[] l = p.list(); | |||||
assertEquals("1 after construction", 1, l.length); | |||||
p.setLocation("\\a"); | |||||
l = p.list(); | |||||
assertEquals("1 after setLocation", 1, l.length); | |||||
p.setPath("\\a;/a"); | |||||
l = p.list(); | |||||
assertEquals("1 after setPath", 1, l.length); | |||||
p.append(new Path("/a;\\a:\\a")); | |||||
l = p.list(); | |||||
assertEquals("1 after append", 1, l.length); | |||||
} | } | ||||
} | } |