This patch obsoletes the previous patch with the same subject
On Fri, 9 Nov 2001, Jose Alberto Fernandez wrote:
> From: "Holger Engels" <[EMAIL PROTECTED]>
>
> > On Fri, 9 Nov 2001, Jose Alberto Fernandez wrote:
> >
> > > I think it is best not making the task extend from MatchingTask but
> > > still support <fileset> elements or as I call it <antfileset> :-)
> > >
> > > <ant target="xx">
> > > <fileset dir="sub">
> > > <include name="sub1/**/build.xml" />
> > > </fileset>
> > > </ant>
> > >
> > > here the different meanings of dir are kept appart. And in this
> > > particular case
> > > you will be using the "basedir" defined in the sub-buildfiles. If you use
> > > <ant dir="xyz"> then it should mean use this value for "basedir", as it
> > > does today.
> > >
> >
> > Ok, I agree. I'm going to remove the matching task stuff and only support
> > nested antfilesets. This makes it better understandable.
> >
> > If I got you right, the 'dir' attribute of ant should override the dir of
> > any particular fileset.
>
> No, not the dir of the fileset (which is used to find the files in the
> fileset) but
> the value used inside the task to compute the basedir property of the
> subbuild. Which is quite different.
>
the ant task's dir attribute ..
.. is the project's basedir for all antfiles of all filesets, if specified
.. does not override the antfileset's basedir meaning for finding files
if no dir argument is specified ..
.. dir defaults to the current project's dir for the single antfile
argument
.. the basedir arguments of the antfilesets are used as the project's
basedir
>
> I would also make the attribute "antfile" and <antfileset> mutially exclusive.
> That would probably keep strange combinations to become a "bad feature" ;-)
>
ok .. did that
Holger
Index: src/main/org/apache/tools/ant/taskdefs/Ant.java
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Ant.java,v
retrieving revision 1.32
diff -u -r1.32 Ant.java
--- src/main/org/apache/tools/ant/taskdefs/Ant.java 2001/11/02 12:07:34
1.32
+++ src/main/org/apache/tools/ant/taskdefs/Ant.java 2001/11/09 12:56:36
@@ -60,12 +60,17 @@
import org.apache.tools.ant.DefaultLogger;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.ProjectHelper;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.types.*;
import org.apache.tools.ant.util.FileUtils;
import java.io.File;
import java.io.PrintStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Vector;
+import java.util.Iterator;
+import java.util.List;
+import java.util.LinkedList;
import java.util.Hashtable;
import java.util.Enumeration;
@@ -112,6 +117,18 @@
private Project newProject;
/**
+ * Vector to hold source file sets.
+ */
+ private Vector filesets = new Vector();
+
+ /**
+ * Adds a set of files (nested fileset attribute).
+ */
+ public void addAntfileset(FileSet set) {
+ filesets.addElement(set);
+ }
+
+ /**
* If true, inherit all properties from parent Project
* If false, inherit only userProperties and those defined
* inside the ant call itself
@@ -233,65 +250,98 @@
super.handleErrorOutput(line);
}
}
-
+
/**
* Do the execution.
*/
public void execute() throws BuildException {
try {
- if (newProject == null) {
- reinit();
- }
-
- if ( (dir == null) && (inheritAll == true) ) {
- dir = project.getBaseDir();
- }
-
- initializeProject();
+ if (antFile != null && filesets.size() > 0) {
+ throw new BuildException("Only one of antfile or nested
filesets is allowed.",
+ location);
+ }
- if (dir != null) {
- newProject.setBaseDir(dir);
- newProject.setUserProperty("basedir" , dir.getAbsolutePath());
- } else {
- dir = project.getBaseDir();
- }
-
- // Override with local-defined properties
- Enumeration e = properties.elements();
- while (e.hasMoreElements()) {
- Property p=(Property) e.nextElement();
- p.setProject(newProject);
- p.execute();
- }
-
- if (antFile == null) {
- antFile = "build.xml";
- }
-
- File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
- antFile = file.getAbsolutePath();
-
- newProject.setUserProperty( "ant.file" , antFile );
- ProjectHelper.configureProject(newProject, new File(antFile));
-
if (target == null) {
target = newProject.getDefaultTarget();
}
- // Are we trying to call the target in which we are defined?
- if (newProject.getBaseDir().equals(project.getBaseDir()) &&
-
newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
- getOwningTarget() != null &&
- target.equals(this.getOwningTarget().getName())) {
-
- throw new BuildException("ant task calling its own parent
target");
- }
+ if (filesets.size() == 0) {
+ if (antFile == null) {
+ antFile = "build.xml";
+ }
+ log("single antfile: " + antFile, Project.MSG_VERBOSE);
+
+ if ((dir == null) && (inheritAll == true)) {
+ dir = project.getBaseDir();
+ }
+
+ File file = FileUtils.newFileUtils().resolveFile(dir, antFile);
+ antFile = file.getAbsolutePath();
+ call(dir, antFile);
+ }
+
+ Iterator scanners = getDirectoryScanners().iterator();
+ while (scanners.hasNext()) {
+ DirectoryScanner scanner = (DirectoryScanner)scanners.next();
+ log("antfileset - dir: " + scanner.getBasedir(),
Project.MSG_VERBOSE);
+ String[] srcFiles = scanner.getIncludedFiles();
+ for (int j = 0; j < srcFiles.length; j++) {
+ File file =
FileUtils.newFileUtils().resolveFile(scanner.getBasedir(), srcFiles[j]);
+ log("file: " + file, Project.MSG_VERBOSE);
+
+ File basedir = dir;
+ if (basedir == null)
+ basedir = scanner.getBasedir();
+ call(basedir, file.getAbsolutePath());
+ }
+ }
+ }
+ finally {
+ // help the gc
+ newProject = null;
+ filesets.clear();
+ }
+ }
- newProject.executeTarget(target);
- } finally {
- // help the gc
- newProject = null;
- }
+ protected void call(File dir, String antFile) {
+ reinit();
+ initializeProject();
+
+ newProject.setBaseDir(dir);
+ newProject.setUserProperty("basedir" , dir.getAbsolutePath());
+
+ // Override with local-defined properties
+ Enumeration e = properties.elements();
+ while (e.hasMoreElements()) {
+ Property p=(Property) e.nextElement();
+ p.setProject(newProject);
+ p.execute();
+ }
+
+ log("calling " + target + " in " + antFile, Project.MSG_VERBOSE);
+
+ newProject.setUserProperty("ant.file" , antFile);
+ ProjectHelper.configureProject(newProject, new File(antFile));
+
+ // Are we trying to call the target in which we are defined?
+ if (newProject.getBaseDir().equals(project.getBaseDir()) &&
+
newProject.getProperty("ant.file").equals(project.getProperty("ant.file")) &&
+ getOwningTarget() != null &&
+ target.equals(this.getOwningTarget().getName())) {
+
+ throw new BuildException("ant task calling its own parent target");
+ }
+ newProject.executeTarget(target);
+ }
+
+ public List getDirectoryScanners() {
+ List list = new LinkedList();
+ for (int i = 0; i < filesets.size(); i++) {
+ FileSet fs = (FileSet) filesets.elementAt(i);
+ DirectoryScanner ds = fs.getDirectoryScanner(project);
+ list.add(ds);
+ }
+ return list;
}
/**
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>