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 2004/06/18 18:54:21 UTC

cvs commit: jakarta-commons-sandbox/vfs/xdocs anttasks.xml

imario      2004/06/18 09:54:21

  Modified:    vfs/src/java/org/apache/commons/vfs/tasks
                        AbstractSyncTask.java DeleteTask.java
               vfs/xdocs anttasks.xml
  Log:
  Allow srcdir and includes (list of files) in v-copy and v-delete tasks.
  
  PR: 29605
  Submitted By: Anthony Goubard (adagoubard -at- chello.nl)
  
  Revision  Changes    Path
  1.12      +38 -1     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java
  
  Index: AbstractSyncTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/AbstractSyncTask.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- AbstractSyncTask.java	10 May 2004 20:09:45 -0000	1.11
  +++ AbstractSyncTask.java	18 Jun 2004 16:54:20 -0000	1.12
  @@ -27,6 +27,7 @@
   import java.util.ArrayList;
   import java.util.HashSet;
   import java.util.Set;
  +import java.util.StringTokenizer;
   
   /**
    * An abstract file synchronization task.  Scans a set of source files and
  @@ -54,6 +55,8 @@
       private final ArrayList srcFiles = new ArrayList();
       private String destFileUrl;
       private String destDirUrl;
  +    private String srcDirUrl;
  +    private String filesList;
   
       /**
        * Sets the destination file.
  @@ -82,6 +85,22 @@
       }
   
       /**
  +     * Sets the source directory
  +     */
  +    public void setSrcDir(final String srcDir)
  +    {
  +        this.srcDirUrl = srcDir;
  +    }
  +
  +    /**
  +     * Sets the files to includes
  +     */
  +    public void setIncludes(final String filesList)
  +    {
  +        this.filesList = filesList;
  +    }
  +
  +    /**
        * Adds a nested <src> element.
        */
       public void addConfiguredSrc(final SourceInfo srcInfo)
  @@ -107,11 +126,29 @@
                   Messages.getString("vfs.tasks/sync.no-destination.error");
               throw new BuildException(message);
           }
  +
           if (destFileUrl != null && destDirUrl != null)
           {
               final String message =
                   Messages.getString("vfs.tasks/sync.too-many-destinations.error");
               throw new BuildException(message);
  +        }
  +
  +        // Add the files of the includes attribute to the list
  +        if (srcDirUrl != null && !srcDirUrl.equals(destDirUrl) && filesList != null && filesList.length() > 0)
  +        {
  +            if (!srcDirUrl.endsWith("/"))
  +            {
  +                srcDirUrl += "/";
  +            }
  +            StringTokenizer tok = new StringTokenizer(filesList, ", \t\n\r\f", false);
  +            while (tok.hasMoreTokens())
  +            {
  +                String nextFile = tok.nextToken();
  +                final SourceInfo src = new SourceInfo();
  +                src.setFile(srcDirUrl + nextFile);
  +                addConfiguredSrc(src);
  +            }
           }
   
           if (srcFiles.size() == 0)
  
  
  
  1.9       +43 -5     jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/DeleteTask.java
  
  Index: DeleteTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/src/java/org/apache/commons/vfs/tasks/DeleteTask.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DeleteTask.java	10 May 2004 20:09:45 -0000	1.8
  +++ DeleteTask.java	18 Jun 2004 16:54:20 -0000	1.9
  @@ -20,6 +20,8 @@
   import org.apache.commons.vfs.util.Messages;
   import org.apache.tools.ant.BuildException;
   
  +import java.util.StringTokenizer;
  +
   /**
    * An Ant task that deletes matching files.
    *
  @@ -31,6 +33,8 @@
       extends VfsTask
   {
       private String file;
  +    private String srcDirUrl;
  +    private String filesList;
   
       /**
        * Sets the file/folder to delete.
  @@ -43,11 +47,27 @@
       }
   
       /**
  +     * Sets the source directory
  +     */
  +    public void setSrcDir(final String srcDir)
  +    {
  +        this.srcDirUrl = srcDir;
  +    }
  +
  +    /**
  +     * Sets the files to includes
  +     */
  +    public void setIncludes(final String filesList)
  +    {
  +        this.filesList = filesList;
  +    }
  +
  +    /**
        * Executes this task.
        */
       public void execute() throws BuildException
       {
  -        if (file == null)
  +        if ((file == null && srcDirUrl == null) || (filesList != null && filesList.length() > 0))
           {
               final String message = Messages.getString("vfs.tasks/delete.no-source-files.error");
               throw new BuildException(message);
  @@ -55,9 +75,27 @@
   
           try
           {
  -            final FileObject srcFile = resolveFile(file);
  -            log("Deleting " + srcFile);
  -            srcFile.delete(Selectors.SELECT_ALL);
  +            if (srcDirUrl != null && filesList != null)
  +            {
  +                log("Deleting " + filesList + " in the directory " + srcDirUrl);
  +                if (!srcDirUrl.endsWith("/"))
  +                {
  +                    srcDirUrl += "/";
  +                }
  +                StringTokenizer tok = new StringTokenizer(filesList, ", \t\n\r\f", false);
  +                while (tok.hasMoreTokens())
  +                {
  +                    String nextFile = tok.nextToken();
  +                    final FileObject srcFile = resolveFile(srcDirUrl + nextFile);
  +                    srcFile.delete(Selectors.SELECT_ALL);
  +                }
  +            }
  +            else
  +            {
  +                final FileObject srcFile = resolveFile(file);
  +                log("Deleting " + srcFile);
  +                srcFile.delete(Selectors.SELECT_ALL);
  +            }
           }
           catch (final Exception e)
           {
  
  
  
  1.5       +23 -1     jakarta-commons-sandbox/vfs/xdocs/anttasks.xml
  
  Index: anttasks.xml
  ===================================================================
  RCS file: /home/cvs/jakarta-commons-sandbox/vfs/xdocs/anttasks.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- anttasks.xml	8 May 2004 20:39:55 -0000	1.4
  +++ anttasks.xml	18 Jun 2004 16:54:21 -0000	1.5
  @@ -102,6 +102,17 @@
                           single source file.</td>
                   </tr>
                   <tr>
  +                    <td>srcdir</td>
  +                    <td>The source folder. If used the includes and desdir 
  +                        attributes should be specified.</td>
  +                </tr>
  +                <tr>
  +                    <td>includes</td>
  +                    <td>A comma or space separated list of files. The files
  +                        are resolved in combination with the specified 
  +                        srcdir attribute.</td>
  +                </tr>
  +                <tr>
                       <td>overwrite</td>
                       <td>Always copy files, ignoring the last-modified time of
                       the destination file.</td>
  @@ -190,7 +201,18 @@
                       <td>file</td>
                       <td>The file or folder to delete.  All descendents of
                           the folder are deleted.</td>
  -                    <td>Yes</td>
  +                    <td rowspan="2">One only</td>
  +                </tr>
  +                <tr>
  +                    <td>srcdir</td>
  +                    <td>The source folder. If used the includes attribute 
  +                        should be specified.</td>
  +                </tr>
  +                <tr>
  +                    <td>includes</td>
  +                    <td>A comma or space separated list of files. The files
  +                        are resolved in combination with the specified 
  +                        srcdir attribute.</td>
                   </tr>
               </table>
           </section>
  
  
  

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