ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r349638 - in /ant/core/trunk: docs/manual/CoreTasks/mail.html src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
Date Tue, 29 Nov 2005 04:44:10 GMT
Author: bodewig
Date: Mon Nov 28 20:44:04 2005
New Revision: 349638

URL: http://svn.apache.org/viewcvs?rev=349638&view=rev
Log:
support for filesystem based resource collections in <mail>

Modified:
    ant/core/trunk/docs/manual/CoreTasks/mail.html
    ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java

Modified: ant/core/trunk/docs/manual/CoreTasks/mail.html
URL: http://svn.apache.org/viewcvs/ant/core/trunk/docs/manual/CoreTasks/mail.html?rev=349638&r1=349637&r2=349638&view=diff
==============================================================================
--- ant/core/trunk/docs/manual/CoreTasks/mail.html (original)
+++ ant/core/trunk/docs/manual/CoreTasks/mail.html Mon Nov 28 20:44:04 2005
@@ -22,7 +22,14 @@
   </p>
   <p>
     Attachments may be sent using nested
-    <a href="../CoreTypes/fileset.html">fileset</a> elements.
+    <code>&lt;attachments&gt;</code> elements, which are <a
+    href="../using.html#path">path-like structures</a>.  This means
+    any filesystem based <a
+    href="../CoreTypes/resources.html">resource</a> or resource
+    collection can be used to point to attachments.  Prior to Ant 1.7
+    only <code>&lt;fileset&gt;</code> has been supported as a nested
+    element, you can still use this directly without an
+    <code>&lt;attachments&gt;</code> container.
   </p>
   <p>
     <strong>Note:</strong> This task may depend on external libraries
@@ -266,9 +273,11 @@
   &lt;replyto address=&quot;me@myisp.com&quot;/&gt;
   &lt;to address=&quot;all@xyz.com&quot;/&gt;
   &lt;message&gt;The ${buildname} nightly build has completed&lt;/message&gt;
-  &lt;fileset dir=&quot;dist&quot;&gt;
-    &lt;include name=&quot;**/*.zip&quot;/&gt;
-  &lt;/fileset&gt;
+  &lt;attachments&gt;
+    &lt;fileset dir=&quot;dist&quot;&gt;
+      &lt;include name=&quot;**/*.zip&quot;/&gt;
+    &lt;/fileset&gt;
+  &lt;/attachments&gt;
 &lt;/mail&gt;
 </pre></blockquote>
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java?rev=349638&r1=349637&r2=349638&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java Mon Nov 28
20:44:04 2005
@@ -17,9 +17,9 @@
 package org.apache.tools.ant.taskdefs.email;
 
 import java.io.File;
-import java.util.Vector;
-import java.util.Enumeration;
+import java.util.Iterator;
 import java.util.StringTokenizer;
+import java.util.Vector;
 
 import org.apache.tools.ant.BuildException;
 import org.apache.tools.ant.DirectoryScanner;
@@ -27,6 +27,8 @@
 import org.apache.tools.ant.Task;
 import org.apache.tools.ant.types.EnumeratedAttribute;
 import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.Path;
+import org.apache.tools.ant.types.resources.FileResource;
 import org.apache.tools.ant.util.ClasspathUtils;
 
 /**
@@ -88,8 +90,7 @@
     private Vector headers = new Vector();
 
     /** file list  */
-    private Vector files = new Vector();
-    private Vector filesets = new Vector();
+    private Path attachments = null;
     /** Character set for MimeMailer*/
     private String charset = null;
     /** User for SMTP auth */
@@ -342,7 +343,8 @@
         StringTokenizer t = new StringTokenizer(filenames, ", ");
 
         while (t.hasMoreTokens()) {
-            files.addElement(getProject().resolveFile(t.nextToken()));
+            createAttachments()
+                .add(new FileResource(getProject().resolveFile(t.nextToken())));
         }
     }
 
@@ -352,7 +354,20 @@
      * @param fs The fileset.
      */
     public void addFileset(FileSet fs) {
-        filesets.addElement(fs);
+        createAttachments().add(fs);
+    }
+
+    /**
+     * Creates a Path as container for attachments.  Supports any
+     * filesystem resource-collections that way.
+     *
+     * @since Ant 1.7
+     */
+    public Path createAttachments() {
+        if (attachments == null) {
+            attachments = new Path(getProject());
+        }
+        return attachments.createPath();
     }
 
     /**
@@ -389,7 +404,6 @@
      */
     public void execute() {
         Message savedMessage = message;
-        Vector savedFiles = (Vector) files.clone();
 
         try {
             Mailer mailer = null;
@@ -480,18 +494,15 @@
                 }
                 message.setCharset(charset);
             }
-            // identify which files should be attached
-            Enumeration e = filesets.elements();
 
-            while (e.hasMoreElements()) {
-                FileSet fs = (FileSet) e.nextElement();
-
-                DirectoryScanner ds = fs.getDirectoryScanner(getProject());
-                String[] includedFiles = ds.getIncludedFiles();
-                File baseDir = ds.getBasedir();
-
-                for (int j = 0; j < includedFiles.length; ++j) {
-                    files.addElement(new File(baseDir, includedFiles[j]));
+            // identify which files should be attached
+            Vector files = new Vector();
+            if (attachments != null) {
+                Iterator iter = attachments.iterator();
+
+                while (iter.hasNext()) {
+                    FileResource fr = (FileResource) iter.next();
+                    files.addElement(fr.getFile());
                 }
             }
             // let the user know what's going to happen
@@ -541,7 +552,6 @@
           }
         } finally {
             message = savedMessage;
-            files = savedFiles;
         }
     }
 
@@ -552,7 +562,7 @@
      * @since Ant 1.6
      */
     public void setCharset(String charset) {
-      this.charset = charset;
+        this.charset = charset;
     }
 
     /**
@@ -562,7 +572,7 @@
      * @since Ant 1.6
      */
     public String getCharset() {
-      return charset;
+        return charset;
     }
 
 }



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


Mime
View raw message