From a8d4fe6d9b8c7a4adb1704b12de610dc6e18fe94 Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Wed, 2 Aug 2000 09:24:24 +0000 Subject: [PATCH] Add nested fileset and filesetref attributes to Path. This means you can now add somedir/*.jar to the CLASSPATH by and probably adjust the pattern if you don't want to recurse the tree. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@267864 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/tools/ant/taskdefs/Javac.java | 6 +- .../org/apache/tools/ant/taskdefs/Rmic.java | 2 +- .../taskdefs/optional/junit/JUnitTask.java | 2 +- .../taskdefs/optional/metamata/MParse.java | 6 +- src/main/org/apache/tools/ant/types/Path.java | 164 +++++++++++++----- .../tools/ant/types/CommandlineJavaTest.java | 9 +- .../org/apache/tools/ant/types/PathTest.java | 20 +-- 7 files changed, 139 insertions(+), 70 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Javac.java b/src/main/org/apache/tools/ant/taskdefs/Javac.java index a59762122..aa2e3d100 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Javac.java +++ b/src/main/org/apache/tools/ant/taskdefs/Javac.java @@ -357,7 +357,7 @@ public class Javac extends MatchingTask { // add dest dir to classpath so that previously compiled and // untouched classes are on classpath - classpath.setLocation(destDir.getAbsolutePath()); + classpath.setLocation(destDir); // add our classpath to the mix @@ -415,7 +415,7 @@ public class Javac extends MatchingTask { File f = project.resolveFile(list[i]); if (f.exists()) { - target.setLocation(f.getAbsolutePath()); + target.setLocation(f); } else { log("Dropping from classpath: "+ f.getAbsolutePath(), Project.MSG_VERBOSE); @@ -782,7 +782,7 @@ public class Javac extends MatchingTask { for (int i=0 ; i < files.length ; i++) { File f = new File(dir,files[i]); if (f.exists() && f.isFile()) { - classpath.setLocation(f.getAbsolutePath()); + classpath.setLocation(f); } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/Rmic.java b/src/main/org/apache/tools/ant/taskdefs/Rmic.java index 08cf076ce..fbba2787a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Rmic.java +++ b/src/main/org/apache/tools/ant/taskdefs/Rmic.java @@ -410,7 +410,7 @@ public class Rmic extends MatchingTask { File f = project.resolveFile(list[i]); if (f.exists()) { - target.setLocation(f.getAbsolutePath()); + target.setLocation(f); } else { log("Dropping from classpath: "+ f.getAbsolutePath(), Project.MSG_VERBOSE); diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java index 9091c8fc2..ef7748595 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/junit/JUnitTask.java @@ -103,7 +103,7 @@ public class JUnitTask extends Task { * Set the path to junit classes. * @param junit path to junit classes. */ - public void setJunit(String junit) { + public void setJunit(File junit) { commandline.createClasspath(project).createPathElement().setLocation(junit); } diff --git a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java index 4d1149858..8b974a88d 100644 --- a/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java +++ b/src/main/org/apache/tools/ant/taskdefs/optional/metamata/MParse.java @@ -134,9 +134,9 @@ public class MParse extends Task { } final Path classpath = cmdl.createClasspath(project); - classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/metamatadebug.jar"); - classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/metamata.jar"); - classpath.createPathElement().setLocation(metahome.getAbsolutePath() + "/lib/JavaCC.zip"); + classpath.createPathElement().setLocation(new File(metahome.getAbsolutePath() + "/lib/metamatadebug.jar")); + classpath.createPathElement().setLocation(new File(metahome.getAbsolutePath() + "/lib/metamata.jar")); + classpath.createPathElement().setLocation(new File(metahome.getAbsolutePath() + "/lib/JavaCC.zip")); final Commandline.Argument arg = cmdl.createVmArgument(); arg.setValue("-mx140M"); diff --git a/src/main/org/apache/tools/ant/types/Path.java b/src/main/org/apache/tools/ant/types/Path.java index f7b5496f2..61d9ed876 100644 --- a/src/main/org/apache/tools/ant/types/Path.java +++ b/src/main/org/apache/tools/ant/types/Path.java @@ -54,6 +54,8 @@ package org.apache.tools.ant.types; +import org.apache.tools.ant.BuildException; +import org.apache.tools.ant.DirectoryScanner; import org.apache.tools.ant.Project; import org.apache.tools.ant.PathTokenizer; @@ -93,20 +95,44 @@ import java.text.StringCharacterIterator; public class Path { - private Vector definition; + private Vector elements; private Project project; public static Path systemClasspath = new Path(null, System.getProperty("java.class.path")); + + /** + * Helper class, holds the nested values. + */ + public class PathElement { + private String[] parts; + + public void setLocation(File loc) { + parts = new String[] {translateFile(loc.getAbsolutePath())}; + } + + public void setPath(String path) { + parts = Path.translatePath(project, path); + } + + public String[] getParts() { + return parts; + } + } + + /** + * Invoked by IntrospectionHelper for setXXX(Path p) + * attribute setters. + */ public Path(Project p, String path) { this(p); - setPath(path); + createPathElement().setPath(path); } public Path(Project p) { this.project = project; - definition = new Vector(); + elements = new Vector(); } /** @@ -114,56 +140,98 @@ public class Path { * @param location the location of the element to add (must not be * null nor empty. */ - public void setLocation(String location) { - if (location != null && location.length() > 0) { - String element = translateFile(resolveFile(project, location)); - if (definition.indexOf(element) == -1) { - definition.addElement(element); - } - } + public void setLocation(File location) { + createPathElement().setLocation(location); } /** - * Append the contents of the other Path instance to this. + * Parses a path definition and creates single PathElements. + * @param path the path definition. */ - public void append(Path other) { - String[] l = other.list(); - for (int i=0; i element. */ - public void setPath(String path) { - final Vector elements = translatePath(project, path); - for (int i=0; i < elements.size(); i++) { - String element = (String) elements.elementAt(i); - if (definition.indexOf(element) == -1) { - definition.addElement(element); - } - } + public PathElement createPathElement() { + PathElement pe = new PathElement(); + elements.addElement(pe); + return pe; } + /** + * Adds a nested element. + */ + public void addFileset(FileSet fs) { + elements.addElement(fs); + } - public Path createPathElement() { - return this; + /** + * Adds a nested element. + */ + public void addFilesetRef(Reference r) { + elements.addElement(r); } + /** + * Append the contents of the other Path instance to this. + */ + public void append(Path other) { + String[] l = other.list(); + for (int i=0; i"); + } + for (int j=0; j= 0); + assert("ant.jar contained", s[3].endsWith("ant.jar")); assertEquals("with classpath", "junit.textui.TestRunner", s[4]); assertEquals("with classpath", "org.apache.tools.ant.CommandlineJavaTest", s[5]); diff --git a/src/testcases/org/apache/tools/ant/types/PathTest.java b/src/testcases/org/apache/tools/ant/types/PathTest.java index 76b71a854..b036f86b2 100644 --- a/src/testcases/org/apache/tools/ant/types/PathTest.java +++ b/src/testcases/org/apache/tools/ant/types/PathTest.java @@ -145,7 +145,7 @@ public class PathTest extends TestCase { public void testSetLocation() { Path p = new Path(project); - p.setLocation("/a"); + p.setLocation(new File(File.separatorChar+"a")); String[] l = p.list(); if (isUnixStyle) { assertEquals(1, l.length); @@ -154,24 +154,13 @@ public class PathTest extends TestCase { assertEquals(1, l.length); assertEquals("\\a", l[0]); } - - p = new Path(project); - p.setLocation("\\a"); - l = p.list(); - if (isUnixStyle) { - assertEquals(1, l.length); - assertEquals("/a", l[0]); - } else { - assertEquals(1, l.length); - assertEquals("\\a", l[0]); - } } public void testAppending() { Path p = new Path(project, "/a:/b"); String[] l = p.list(); assertEquals("2 after construction", 2, l.length); - p.setLocation("/c"); + p.setLocation(new File("/c")); l = p.list(); assertEquals("3 after setLocation", 3, l.length); p.setPath("\\d;\\e"); @@ -186,9 +175,6 @@ public class PathTest extends TestCase { Path p = new Path(project, ""); 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); @@ -201,7 +187,7 @@ public class PathTest extends TestCase { Path p = new Path(project, "/a:/a"); String[] l = p.list(); assertEquals("1 after construction", 1, l.length); - p.setLocation("\\a"); + p.setLocation(new File(File.separatorChar+"a")); l = p.list(); assertEquals("1 after setLocation", 1, l.length); p.setPath("\\a;/a");