You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2009/11/11 06:32:15 UTC

svn commit: r834772 - /ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java

Author: bodewig
Date: Wed Nov 11 05:32:15 2009
New Revision: 834772

URL: http://svn.apache.org/viewvc?rev=834772&view=rev
Log:
make import support resource collections.  PR 22269

Modified:
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java
URL: http://svn.apache.org/viewvc/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java?rev=834772&r1=834771&r2=834772&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/ImportTask.java Wed Nov 11 05:32:15 2009
@@ -23,10 +23,14 @@
 import org.apache.tools.ant.Project;
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.Resource;
+import org.apache.tools.ant.types.ResourceCollection;
+import org.apache.tools.ant.types.resources.FileProvider;
 import org.apache.tools.ant.types.resources.FileResource;
+import org.apache.tools.ant.types.resources.Union;
 import org.apache.tools.ant.util.FileUtils;
 
 import java.io.File;
+import java.util.Iterator;
 import java.util.Vector;
 
 /**
@@ -59,9 +63,13 @@
     private boolean optional;
     private String targetPrefix;
     private String prefixSeparator = ".";
-    private Resource resource = null;
+    private final Union resources = new Union();
     private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
 
+    public ImportTask() {
+        resources.setCache(true);
+    }
+
     /**
      * sets the optional attribute
      *
@@ -107,14 +115,14 @@
      *
      * @since Ant 1.8.0
      */
-    public void add(Resource r) {
-        resource = r;
+    public void add(ResourceCollection r) {
+        resources.add(r);
     }
 
     public void execute() {
-        if (file == null && resource == null) {
+        if (file == null && resources.size() == 0) {
             throw new BuildException("import requires file attribute or"
-                                     + " nested resource");
+                                     + " at least one nested resource");
         }
         if (getOwningTarget() == null
             || !"".equals(getOwningTarget().getName())) {
@@ -142,19 +150,27 @@
             throw new BuildException("Unable to get location of import task");
         }
 
-        Resource importedResource = resource;
-        File importedFile = null;
-        if (resource == null) {
+        Union resourcesToImport = new Union(getProject(), resources);
+        if (file != null) {
 
-        File buildFile = new File(getLocation().getFileName()).getAbsoluteFile();
+            File buildFile =
+                new File(getLocation().getFileName()).getAbsoluteFile();
 
-        // Paths are relative to the build file they're imported from,
-        // *not* the current directory (same as entity includes).
+            // Paths are relative to the build file they're imported from,
+            // *not* the current directory (same as entity includes).
 
-        File buildFileParent = new File(buildFile.getParent());
-            importedFile = FILE_UTILS.resolveFile(buildFileParent, file);
-            importedResource = new FileResource(importedFile);
+            File buildFileParent = new File(buildFile.getParent());
+            File importedFile = FILE_UTILS.resolveFile(buildFileParent, file);
+            resources.add(new FileResource(importedFile));
         }
+        for (Iterator i = resourcesToImport.iterator(); i.hasNext(); ) {
+            importResource(helper, (Resource) i.next());
+        }
+    }
+
+    private void importResource(ProjectHelper helper,
+                                Resource importedResource) {
+        Vector importStack = helper.getImportStack();
 
         getProject().log("Importing file " + importedResource + " from "
                          + getLocation().getFileName(), Project.MSG_VERBOSE);
@@ -171,6 +187,12 @@
             }
         }
 
+        File importedFile = null;
+        FileProvider fp = (FileProvider) importedResource.as(FileProvider.class);
+        if (fp != null) {
+            importedFile = fp.getFile();
+        }
+
         if (!isInIncludeMode() &&
             (importStack.contains(importedResource)
              || (importedFile != null && importStack.contains(importedFile))