You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@commons.apache.org by im...@apache.org on 2005/01/29 16:29:07 UTC

svn commit: r149047 - /jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java /jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml

Author: imario
Date: Sat Jan 29 07:29:06 2005
New Revision: 149047

URL: http://svn.apache.org/viewcvs?view=rev&rev=149047
Log:
PR: 32356
Submitted by: Anthony Goubard

srcdirisbase optional Ant copy task attribute
Modified:
   jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
   jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml

Modified: jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java?view=diff&rev=149047&p1=jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java&r1=149046&p2=jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java&r2=149047
==============================================================================
--- jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java	(original)
+++ jakarta/commons/sandbox/vfs/trunk/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java	Sat Jan 29 07:29:06 2005
@@ -40,7 +40,7 @@
  * <li>Up-to-date destination file.
  *
  * @author <a href="mailto:adammurdoch@apache.org">Adam Murdoch</a>
- * @version $Revision: 1.13 $ $Date: 2004/12/03 20:33:51 $
+ * @version $Revision: 1.13 $ $Date$
  * @todo Deal with case where dest file maps to a child of one of the source files
  * @todo Deal with case where dest file already exists and is incorrect type (not file, not a folder)
  * @todo Use visitors
@@ -56,6 +56,7 @@
     private String destFileUrl;
     private String destDirUrl;
     private String srcDirUrl;
+    private boolean srcDirIsBase;
     private String filesList;
 
     /**
@@ -93,6 +94,14 @@
     }
 
     /**
+     * Sets whether the source directory should be consider as the base directory.
+     */
+    public void setSrcDirIsBase(final boolean srcDirIsBase)
+    {
+        this.srcDirIsBase = srcDirIsBase;
+    }
+
+    /**
      * Sets the files to includes
      */
     public void setIncludes(final String filesList)
@@ -197,6 +206,11 @@
         destFolder.createFolder();
 
         // Locate the source files, and make sure they exist
+        FileName srcDirName = null;
+        if (srcDirUrl !=null )
+        {
+            srcDirName = resolveFile(srcDirUrl).getName();
+        }
         final ArrayList srcs = new ArrayList();
         for (int i = 0; i < srcFiles.size(); i++)
         {
@@ -225,7 +239,16 @@
             if (rootFile.getType() == FileType.FILE)
             {
                 // Build the destination file name
-                final FileObject destFile = destFolder.resolveFile(rootName.getBaseName(), NameScope.DESCENDENT);
+                String relName = null;
+                if (srcDirName == null || !srcDirIsBase)
+                {
+                    relName = rootName.getBaseName();
+                }
+                else
+                {
+                    relName = srcDirName.getRelativeName(rootName);
+                }
+                final FileObject destFile = destFolder.resolveFile(relName, NameScope.DESCENDENT);
 
                 // Do the copy
                 handleFile(destFiles, rootFile, destFile);
@@ -233,13 +256,23 @@
             else
             {
                 // Find matching files
-                final FileObject[] files = rootFile.findFiles(Selectors.SELECT_FILES);
+                // If srcDirIsBase is true, select also the sub-directories
+                final FileObject[] files = rootFile.findFiles(srcDirIsBase ? Selectors.SELECT_ALL : Selectors.SELECT_FILES);
+
                 for (int j = 0; j < files.length; j++)
                 {
                     final FileObject srcFile = files[j];
 
                     // Build the destination file name
-                    String relName = rootName.getRelativeName(srcFile.getName());
+                    String relName = null;
+                    if (srcDirName == null || !srcDirIsBase)
+                    {
+                        relName = rootName.getRelativeName(srcFile.getName());
+                    }
+                    else
+                    {
+                        relName = srcDirName.getRelativeName(srcFile.getName());
+                    }
 
                     final FileObject destFile =
                         destFolder.resolveFile(relName, NameScope.DESCENDENT);

Modified: jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml
Url: http://svn.apache.org/viewcvs/jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml?view=diff&rev=149047&p1=jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml&r1=149046&p2=jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml&r2=149047
==============================================================================
--- jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml	(original)
+++ jakarta/commons/sandbox/vfs/trunk/xdocs/anttasks.xml	Sat Jan 29 07:29:06 2005
@@ -132,6 +132,14 @@
                     </td>
                 </tr>
                 <tr>
+                    <td>srcdirisbase</td>
+                    <td>Set whether the source directory should be used as base directory.
+                    If set to true, the subdirectories of the specified directories will be copied as well.</td>
+                    <td>No, default is
+                        <code>false</code>.
+                    </td>
+                </tr>
+                <tr>
                     <td>src</td>
                     <td>A source file or folder to copy.  Copies all descendents
                     of a folder.</td>

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org