You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by Bill Kelly <bi...@softwired-inc.com> on 2000/06/23 11:24:37 UTC

[PATCH] Add new/undocumented attributes to task doc

Adds documentation for missing attributes, puts FixCRLF into alphabetic
order (diff makes it look like a major delete/insert).  New jvm
attribute for java included here, code change is in an upcoming patch.

Index: index.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
retrieving revision 1.24
diff -u -r1.24 index.html
--- index.html 2000/06/17 16:14:03 1.24
+++ index.html 2000/06/23 09:17:08
@@ -524,6 +524,12 @@
     <td valign="top">the target of the new Ant project that should be
executed.</td>
     <td valign="top" align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">output</td>
+    <td valign="top">Filename to write the ant output to.
+    </td>
+    <td align="center" valign="top">No</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <blockquote>
@@ -992,111 +998,6 @@
 the <i>dest.dir</i> directory replacing all the occurencies of the
string <i>@year@</i>
 with <i>2000.</i></p>
 <hr>
-<h2><a name="get">Get</a></h2>
-<h3>Description</h3>
-<p>Gets a file from an URL. When the verbose option is &quot;on&quot;,
this task
-displays a '.' for every 100 Kb retrieved.</p>
-<p>This task should be preferred above the <a href="#cvs">CVS task</a>
when
-doing automated builds. CVS is significant slower than loading a
compressed
-archive with http/ftp.</p>
-<h3>Parameters</h3>
-<table border="1" cellpadding="2" cellspacing="0">
-  <tr>
-    <td valign="top"><b>Attribute</b></td>
-    <td valign="top"><b>Description</b></td>
-    <td align="center" valign="top"><b>Required</b></td>
-  </tr>
-  <tr>
-    <td valign="top">src</td>
-    <td valign="top">the URL from which to retrieve a file.</td>
-    <td align="center" valign="top">Yes</td>
-  </tr>
-  <tr>
-    <td valign="top">dest</td>
-    <td valign="top">the file where to store the retrieved file.</td>
-    <td align="center" valign="top">Yes</td>
-  </tr>
-  <tr>
-    <td valign="top">verbose</td>
-    <td valign="top">show verbose information
(&quot;on&quot;/&quot;off&quot;).</td>
-    <td align="center" valign="top">No</td>
-  </tr>
-</table>
-<h3>Examples</h3>
-<pre>  &lt;get src=&quot;http://jakarta.apache.org/&quot;
dest=&quot;help/index.html&quot; /&gt;</pre>
-<p>gets the index page of http://jakarta.apache.org/, and stores it in
the file <code>help/index.html</code>.</p>
-<hr>
-<h2><a name="gunzip">GUnzip</a></h2>
-<h3>Description</h3>
-<p>Expands a GZip file.</p>
-
-<p>If <i>dest</i> is a directory the name of the destination file is
-the same as <i>src</i> (with the &quot;.gz&quot; extension removed if
-present). If <i>dest</i> is ommited, the parent dir of <i>src</i> is
-taken. The file is only expanded if the source file is newer than the
-destination file, or when the destination file does not exist.</p>
-
-<h3>Parameters</h3>
-<table border="1" cellpadding="2" cellspacing="0">
-  <tr>
-    <td valign="top"><b>Attribute</b></td>
-    <td valign="top"><b>Description</b></td>
-    <td align="center" valign="top"><b>Required</b></td>
-  </tr>
-  <tr>
-    <td valign="top">src</td>
-    <td valign="top">the file to expand.</td>
-    <td align="center" valign="top">Yes</td>
-  </tr>
-  <tr>
-    <td valign="top">dest</td>
-    <td valign="top">the destination file or directory.</td>
-    <td align="center" valign="top">No</td>
-  </tr>
-</table>
-<h3>Examples</h3>
-<blockquote>
-  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;/&gt;</code></p>
-</blockquote>
-<p>expands <i>test.tar.gz</i> to <i>test.tar</i></p>
-<blockquote>
-  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;
dest=&quot;test2.tar&quot;/&gt;</code></p>
-</blockquote>
-<p>expands <i>test.tar.gz</i> to <i>test2.tar</i></p>
-<blockquote>
-  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;
dest=&quot;subdir&quot;/&gt;</code></p>
-</blockquote>
-<p>expands <i>test.tar.gz</i> to <i>subdir/test.tar</i> (assuming
-subdir is a directory).</p>
-
-<hr>
-<h2><a name="gzip">GZip</a></h2>
-<h3>Description</h3>
-<p>GZips a file.</p>
-<h3>Parameters</h3>
-<table border="1" cellpadding="2" cellspacing="0">
-  <tr>
-    <td valign="top"><b>Attribute</b></td>
-    <td valign="top"><b>Description</b></td>
-    <td align="center" valign="top"><b>Required</b></td>
-  </tr>
-  <tr>
-    <td valign="top">src</td>
-    <td valign="top">the file to gzip.</td>
-    <td align="center" valign="top">Yes</td>
-  </tr>
-  <tr>
-    <td valign="top">zipfile</td>
-    <td valign="top">the destination file.</td>
-    <td align="center" valign="top">Yes</td>
-  </tr>
-</table>
-<h3>Examples</h3>
-<blockquote>
-  <p><code>&lt;gzip src=&quot;test.tar&quot;
zipfile=&quot;test.tar.gz&quot;
-  /&gt;</code></p>
-</blockquote>
-<hr>
 <h2><a name="fixcrlf">FixCRLF</a></h2>
 <h3>Description</h3>
 <p>Adjusts a text file to local.</p>
@@ -1132,6 +1033,12 @@
     <td valign="top" align="center">No</td>
   </tr>
   <tr>
+    <td valign="top">defaultexcludes</td>
+    <td valign="top">indicates whether default excludes should be used
or not
+      (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when
omitted.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
     <td valign="top">cr</td>
     <td valign="top">Specifies how carriage return (CR) characters are
to
       be handled.  Valid values for this property are:
@@ -1213,6 +1120,116 @@
 DOS systems, and are removed if run on Unix systems.
 You never know what editor a user will use to browse README's.</p>
 <hr>
+<h2><a name="get">Get</a></h2>
+<h3>Description</h3>
+<p>Gets a file from an URL. When the verbose option is &quot;on&quot;,
this task
+displays a '.' for every 100 Kb retrieved.</p>
+<p>This task should be preferred above the <a href="#cvs">CVS task</a>
when
+doing automated builds. CVS is significant slower than loading a
compressed
+archive with http/ftp.</p>
+<h3>Parameters</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">src</td>
+    <td valign="top">the URL from which to retrieve a file.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">dest</td>
+    <td valign="top">the file where to store the retrieved file.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">verbose</td>
+    <td valign="top">show verbose information
(&quot;on&quot;/&quot;off&quot;).</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
+    <td valign="top">ignoreerrors</td>
+    <td valign="top">Log errors but don't treat as fatal.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+</table>
+<h3>Examples</h3>
+<pre>  &lt;get src=&quot;http://jakarta.apache.org/&quot;
dest=&quot;help/index.html&quot; /&gt;</pre>
+<p>gets the index page of http://jakarta.apache.org/, and stores it in
the file <code>help/index.html</code>.</p>
+<hr>
+<h2><a name="gunzip">GUnzip</a></h2>
+<h3>Description</h3>
+<p>Expands a GZip file.</p>
+
+<p>If <i>dest</i> is a directory the name of the destination file is
+the same as <i>src</i> (with the &quot;.gz&quot; extension removed if
+present). If <i>dest</i> is ommited, the parent dir of <i>src</i> is
+taken. The file is only expanded if the source file is newer than the
+destination file, or when the destination file does not exist.</p>
+
+<h3>Parameters</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">src</td>
+    <td valign="top">the file to expand.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">dest</td>
+    <td valign="top">the destination file or directory.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+</table>
+<h3>Examples</h3>
+<blockquote>
+  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;/&gt;</code></p>
+</blockquote>
+<p>expands <i>test.tar.gz</i> to <i>test.tar</i></p>
+<blockquote>
+  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;
dest=&quot;test2.tar&quot;/&gt;</code></p>
+</blockquote>
+<p>expands <i>test.tar.gz</i> to <i>test2.tar</i></p>
+<blockquote>
+  <p><code>&lt;gunzip src=&quot;test.tar.gz&quot;
dest=&quot;subdir&quot;/&gt;</code></p>
+</blockquote>
+<p>expands <i>test.tar.gz</i> to <i>subdir/test.tar</i> (assuming
+subdir is a directory).</p>
+
+<hr>
+<h2><a name="gzip">GZip</a></h2>
+<h3>Description</h3>
+<p>GZips a file.</p>
+<h3>Parameters</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">src</td>
+    <td valign="top">the file to gzip.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">zipfile</td>
+    <td valign="top">the destination file.</td>
+    <td align="center" valign="top">Yes</td>
+  </tr>
+</table>
+<h3>Examples</h3>
+<blockquote>
+  <p><code>&lt;gzip src=&quot;test.tar&quot;
zipfile=&quot;test.tar.gz&quot;
+  /&gt;</code></p>
+</blockquote>
+<hr>
 <h2><a name="jar">Jar</a></h2>
 <h3>Description</h3>
 <p>Jars a set of files.</p>
@@ -1353,12 +1370,25 @@
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">classpath</td>
+    <td valign="top">the classpath to use.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
     <td valign="top">fork</td>
     <td valign="top">if enabled triggers the class execution in another
VM
       (disabled by default)</td>
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
+    <td valign="top">jvm</td>
+    <td valign="top">the command used to invoke the Java Virtual
Machine,
+      default is 'java'.  The command is resolved by
java.lang.Runtime.exec().
+      Ignored if fork is disabled.
+    </td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
     <td valign="top">jvmargs</td>
     <td valign="top">the arguments to pass to the forked VM (ignored if
fork is
       disabled)</td>
@@ -1478,6 +1508,11 @@
     <td valign="top">indicates whether token filtering should take
place</td>
     <td valign="top" align="center">No</td>
   </tr>
+  <tr>
+    <td valign="top">target</td>
+    <td valign="top">Generate class files for specific VM version, e.g.
"1.1" or "1.2".</td>
+    <td align="center" valign="top">No</td>
+  </tr>
 </table>
 <h3>Examples</h3>
 <pre>  &lt;javac srcdir=&quot;${src}&quot;
@@ -1740,13 +1775,13 @@
   </tr>
   <tr>
     <td valign="top">serialwarn</td>
-    <td valign="top">Generate warning about @serial tag</td>
+    <td valign="top">FUTURE: Generate warning about @serial tag</td>
     <td align="center" valign="top">1.2</td>
     <td align="center" valign="top">No</td>
   </tr>
   <tr>
     <td valign="top">helpfile</td>
-    <td valign="top">Specifies the HTML help file to use</td>
+    <td valign="top">FUTURE: Specifies the HTML help file to use</td>
     <td align="center" valign="top">1.2</td>
     <td align="center" valign="top">No</td>
   </tr>
@@ -1758,7 +1793,7 @@
   </tr>
   <tr>
     <td valign="top">charset</td>
-    <td valign="top">Charset for cross-platform viewing of generated
+    <td valign="top">FUTURE: Charset for cross-platform viewing of
generated
       documentation</td>
     <td align="center" valign="top">1.2</td>
     <td align="center" valign="top">No</td>
@@ -1769,6 +1804,16 @@
     <td align="center" valign="top">1.1</td>
     <td align="center" valign="top">No</td>
   </tr>
+  <tr>
+    <td valign="top">doclet</td>
+    <td valign="top">Specifies the class file that starts the doclet
used in generating the documentation.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
+    <td valign="top">docletpath</td>
+    <td valign="top">Specifies the path to the doclet class file that
is specified with the -doclet option.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
 </table>
 <h3>Example</h3>
 <pre>  &lt;javadoc packagenames=&quot;com.dummy.test.*&quot;
@@ -1994,6 +2039,23 @@
     <td valign="top">filtering</td>
     <td valign="top">indicates whether token filtering should take
place</td>
     <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">sourcebase</td>
+    <td valign="top">Pass the "-keepgenerated" flag to rmic and
+ move the generated source file to the base directory.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
+    <td valign="top">stubversion</td>
+    <td valign="top">Specify the JDK version for the generated stub
code.
+ Specify "1.1" to pass the "-v1.1" option to rmic.</td>
+    <td align="center" valign="top">No</td>
+  </tr>
+  <tr>
+    <td valign="top">classpath</td>
+    <td valign="top">The classpath to use during compilation</td>
+    <td align="center" valign="top">No</td>
   </tr>
 </table>
 <h3>Examples</h3>



Re: [PATCH] Email taskdef with ability to attach files

Posted by Jason Hunter <jh...@collab.net>.
> Please note that I did not mean to conflict with James Duncan Davidson or
> Jason Hunter here.  I had already implemented this task before the
> discussion of adding the com.oreilly.servlet.MailMessage took place, and I
> decided to err on the side of openness and not hold on to my code.  In
> other words, this is my first patch submission, and I definitely don't want
> to step on anyone's toes. ( Especially the guy who wrote the book I learned
> servlets from. :-| )

My poor toes.  :-)  

I think with the contribution of MailMessage we can make this a core
task (assuming people agree a sending mail task merits being core).  On
the topic of attachments, I'm not sure why a build completion email
needs an attachment, but assuming it does, then someone can have a
little fun and add attachments to MailMessage.  The javadocs point to
the RFC you need to follow.  I think an addAttachment() method would be
a good hook, taking a file or url, and optionally taking an overriding
name and content type.

-jh-

Re: [PATCH] Email taskdef with ability to attach files

Posted by Jason Hunter <jh...@collab.net>.
James Duncan Davidson wrote:
> 
> on 6/23/00 8:11 PM, Tim O'Brien at tmobrien@mindspring.com wrote:
> 
> > Please note that I did not mean to conflict with James Duncan Davidson or
> > Jason Hunter here.
> 
> No prob here... I'm cool with this code in as an optional (since it relies
> upon external jars). I'd be even better with it in core (yes, I think it's
> valuable in the offline build case) as long as it's done with Jason's
> lightweight mailer class checked in so that there aren't any external
> dependancies. Even in that case, I'd still be fine with this as optional
> since it has functionality that's not part of Jason's class (attachments).

Not part of the class *yet*.  I think it'd be kind of a fun thing to
add.  Maybe next time I'm on a plane and don't feel like doing real
work.  That's how ant was started afterall.  :-)

-jh-

Re: [PATCH] Email taskdef with ability to attach files

Posted by James Duncan Davidson <ja...@eng.sun.com>.
on 6/23/00 8:11 PM, Tim O'Brien at tmobrien@mindspring.com wrote:

> Please note that I did not mean to conflict with James Duncan Davidson or
> Jason Hunter here.

No prob here... I'm cool with this code in as an optional (since it relies
upon external jars). I'd be even better with it in core (yes, I think it's
valuable in the offline build case) as long as it's done with Jason's
lightweight mailer class checked in so that there aren't any external
dependancies. Even in that case, I'd still be fine with this as optional
since it has functionality that's not part of Jason's class (attachments).

.duncan



RE: [PATCH] Email taskdef with ability to attach files

Posted by Tim O'Brien <tm...@mindspring.com>.
Correction to PATCH for build.xml, sorry..  I listed javax.mail.MimeMessage
instead of javax.mail.internet.MimeMessage.

Tim O'Brien.

Patch below.

Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/build.xml,v
retrieving revision 1.23
diff -u -r1.23 build.xml
--- build.xml   2000/06/24 02:46:17     1.23
+++ build.xml   2000/06/26 18:10:58
@@ -41,6 +41,8 @@
                classname="com.kvisco.xsl.XSLProcessor" />
     <available property="xalan.present"
                classname="org.apache.xalan.xslt.XSLTProcessorFactory" />
+    <available property="javamail.present"
+               classname="javax.mail.internet.MimeMessage"/>
   </target>

   <!--
=================================================================== -->
@@ -66,6 +68,7 @@
       <exclude name="**/NetRexxC.java" unless="netrexx.present" />
       <exclude name="**/XslpLiaison.java" unless="xslp.present" />
       <exclude name="**/XalanLiaison.java" unless="xalan.present" />
+      <exclude name="**/Email.java" unless="javamail.present" />
     </javac>

     <copydir src="${src.dir}" dest="${build.classes}">



-----Original Message-----
From: Tim O'Brien [mailto:tmobrien@mindspring.com]
Sent: Friday, June 23, 2000 11:12 PM
To: ant-dev@jakarta.apache.org
Subject: [PATCH] Email taskdef with ability to attach files


Adds optional functionality of sending an email message with multiple file
attachments from Ant.  Uses javax.mail and javax.activation and is an
optional taskdef because of this.

Changes below include:

	Modified build.xml to test for the existence of javax.mail.MimeMessage
	Modified index.html
	Modified defaults.properties
	Email.java source to be added to optional taskdefs directory.

This functionality could be used to notify users about the status of a
nightly build process to anything device that has an email address.  It
could also be used to "forward" build output to mail filter on multiple
machines that would then operate on the MIME attachments, etc.

Please note that I did not mean to conflict with James Duncan Davidson or
Jason Hunter here.  I had already implemented this task before the
discussion of adding the com.oreilly.servlet.MailMessage took place, and I
decided to err on the side of openness and not hold on to my code.  In
other words, this is my first patch submission, and I definitely don't want
to step on anyone's toes. ( Especially the guy who wrote the book I learned
servlets from. :-| )

PS: One thing that might help this is if the Available task could check for
the existence of more than one class at a time.  Only checking for
javax.mail.MimeMessage is dangerous, because I'm using the JAF to deal with
the mime attachments.

Tim O'Brien
tobrien@ieee.org


Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/build.xml,v
retrieving revision 1.22
diff -u -r1.22 build.xml
--- build.xml   2000/06/23 16:46:38     1.22
+++ build.xml   2000/06/24 02:58:52
@@ -41,6 +41,8 @@
                 classname="com.kvisco.xsl.XSLProcessor" />
      <available property="xalan.present"
                 classname="org.apache.xalan.xslt.XSLTProcessorFactory" />
+    <available property="javamail.present"
+               classname="javax.mail.MimeMessage"/>
    </target>

    <!--
=================================================================== -->
@@ -66,6 +68,7 @@
        <exclude name="**/NetRexxC.java" unless="netrexx.present" />
        <exclude name="**/XslpLiaison.java" unless="xslp.present" />
        <exclude name="**/XalanLiaison.java" unless="xalan.present" />
+      <exclude name="**/Email.java" unless="javamail.present" />
      </javac>

      <copydir src="${src.dir}" dest="${build.classes}">



Index: index.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
retrieving revision 1.28
diff -u -r1.28 index.html
--- index.html  2000/06/23 16:46:45     1.28
+++ index.html  2000/06/24 03:00:10
@@ -19,6 +19,7 @@
    <li>Arnout J. Kuiper (<a
href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>)</li>
    <li>Stefano Mazzocchi (<a
href="mailto:stefano@apache.org">stefano@apache.org</a>)</li>
    <li>Sam Ruby (<a
href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
+  <li>Tim O'Brien (<a
href="mailto:tobrien@ieee.org">tobrien@ieee.org</a>)</li>
  </ul>

  <p>Version 1.0.8.1 - 2000/06/13</p>
@@ -2571,10 +2572,71 @@

  <h2><a name="optionaltasks">Optional tasks</a></h2>
  <ul>
+  <li><a href="#email">Email</a></li>
    <li><a href="#netrexxc">NetRexxC</a></li>
    <li><a href="#renameexts">RenameExtensions</a></li>
    <li><a href="#script">Script</a></li>
  </ul>
+<hr>
+<h2><a name="email">Email</a></h2>
+<h3><b>Description:</b></h3>
+<p>Emails a message originating from a supplied string or file, and can
also send multiple files as Mime attachments.
+</p>
+<h3>Parameters:</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">mailto</td>
+    <td valign="top">comma separated list of email addresses to send
message to.</Td>
+    <td valign="top" align="center">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">mailfrom</td>
+    <td valign="top">email address that message is from.</td>
+    <td valign="top" align="center">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">subject</td>
+    <td valign="top">subject of message to send. (default is "Ant
Notification")</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">message</td>
+    <td valign="top">message to include in email body. ( message OR
messageFile must be present. )</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">messagefile</td>
+    <td valign="top">comma separated list of files to include in the
message body.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">attachfile</td>
+    <td valign="top">comma separated list of files to attach to email
message.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">smtphost</td>
+    <td valign="top">SMTP host to send message with. (default is
"localhost")</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+</table>
+<h3>Examples</h3>
+<blockquote>
+  <p><code>&lt;email mailto=&quot;foo@somedomain.com&quot;
+              mailfrom=&quot;bar@somedomain.com&quot;
+              subject=&quot;Build Status&quot;
+              message=&quot;Build Success!&quot;
+             messagefile=&quot;status.log,error.log&quot;
+             attachfile=&quot;build.xml,distribution.tar.gz&quot;
+             smtphost=&quot;mail.somedomain.com&quot;/&gt;
+</code>
+  </p>
+</blockquote>
  <hr>
  <h2><a name="netrexxc">NetRexxC</a></h2>
  <h3><b>Description:</b></h3>



Index: defaults.properties
===================================================================
RCS file:
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults.
properties,v
retrieving revision 1.15
diff -r1.15 defaults.properties
39a40
 > email=org.apache.tools.ant.taskdefs.optional.Email





************************
And add the following file to the optional taskdefs src directory:
Email.java
BEGIN FILE:
************************


/*
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 1999 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution, if
  *    any, must include the following acknowlegement:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowlegement may appear in the software itself,
  *    if and wherever such third-party acknowlegements normally appear.
  *
  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  *    Foundation" must not be used to endorse or promote products derived
  *    from this software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache"
  *    nor may "Apache" appear in their names without prior written
  *    permission of the Apache Group.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */

package org.apache.tools.ant.taskdefs.optional;

import org.apache.tools.ant.*;
import java.io.*;
import java.net.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;

import javax.activation.*;

/**
  * Task to send email messages from Ant.  This task can take the following
  * arguments:
  * <ul>
  * <li><B>mailto</B> - A comma separated list of email addresses</li>
  * <li><B>mailfrom</B> - An email address from which mail is sent</li>
  * <li><B>subject</B> - The subject of the email message</li>
  * <li><B>message</B> - The message body</li>
  * <li><B>messagefile</B> - A comma separated list of files to include in
the message body</li>
  * <li><B>attachfile</B> - A comma separated list of files to attach as
MIME attachments</li>
  * <li><B>smtphost</B> - SMTP host to send mail</LI>
  * </ul>
  * Of these arguments, <b>mailto</b> and <b>mailfrom</b> must be
specified, and one of the following
  * arguments must be present <B>message</B> and <B>messagefile</B>.
  *
  * @author Tim O'Brien <a
href="mailto:tobrien@ieee.org">tobrien@ieee.org</a>
  */
public class Email extends Task {

     private static final String delimiter = ",";

     private File messageFile;
     private File[] attachFiles;
     private InternetAddress[] toAddresses;
     private InternetAddress fromAddress;
     private String subject = "Ant notification";
     private String message;
     private String smtpHost = "localhost";

     public void setMessagefile(String msgfile) {

         try {

             messageFile = project.resolveFile(msgfile);

         } catch( Exception e ) {

             throw new BuildException( "Email: messagefile " + msgfile + "
not found." );

         }

     }

     public void setAttachfile(String attachfile) {

         StringTokenizer sToke = new StringTokenizer( attachfile,
delimiter );

         ArrayList tokens = new ArrayList();

         while( sToke.hasMoreElements() ) {

             tokens.add( sToke.nextElement() );

         }

         attachFiles = new File[ tokens.size() ];

         for( int i = 0; i < tokens.size(); i++ ) {

             try {

                 File fileToAttach = project.resolveFile( (String)
tokens.get(i) );
                 attachFiles[i] = fileToAttach;

             } catch( Exception e ) {

                 throw new BuildException( "Email: attachfile " +
tokens.get(i) + " not found." );

             }


         }

     }

     public void setMailto( String to_addr ) {

         StringTokenizer sToke = new StringTokenizer( to_addr, delimiter );

         ArrayList tokens = new ArrayList();

         while( sToke.hasMoreElements() ) {

             tokens.add( sToke.nextElement() );

         }

         toAddresses = new InternetAddress[ tokens.size() ];

         for( int i = 0; i < tokens.size(); i++ ) {

             try {

                 toAddresses[i] = new InternetAddress( (String)
tokens.get(i) );

             } catch( AddressException e ) {

                 throw new BuildException( "Email: Invalid email address
supplied in mailto " + to_addr );

             }

         }

     }

     public void setMailfrom( String from_addr ) {

         try {

             fromAddress = new InternetAddress( from_addr );

         } catch( Exception e ) {

             throw new BuildException( "Email: Invalid email address
supplied in mailfrom " + from_addr );

         }

     }

     public void setSubject( String subj ) {
         subject = subj;
     }

     public void setMessage( String msg ) {
         message = msg;
     }

     public void setSmtphost( String host ) {
         smtpHost = host;
     }

     /**
      * Does the work.
      *
      * @exception BuildException if someting goes wrong with the build
      */
     public void execute() throws BuildException {

         if( toAddresses == null ) {

             throw new BuildException("Email: mailto is not specified");

         }

         if( fromAddress == null ) {

             throw new BuildException("Email: mailfrom is not specified" );

         }

         if( message == null && messageFile == null ) {

             throw new BuildException("Email: message and messagefile
missing, one must be present.");

         }

         // Create properties to hold smtpHost for Session.
         Properties props = new Properties();
         props.put("mail.smtp.host", smtpHost);

         Session session = Session.getDefaultInstance(props, null);

         try {

             // Create a MimeMessage
             MimeMessage msg = new MimeMessage(session);

             // Set the from and to addresses
             // Set the subject and date.
             msg.setFrom( fromAddress );
             msg.setRecipients(Message.RecipientType.TO, toAddresses);
             msg.setSubject(subject);
             msg.setSentDate(new Date());

             // create the Multipart and its parts to it
             Multipart mp = new MimeMultipart();

             MimeBodyPart mbp1 = new MimeBodyPart();

             StringBuffer messageBody = new StringBuffer();

             if( message != null ) {

                 messageBody.append( message );

             }

             if( messageFile != null ) {

                 FileReader mFileReader = null;

                 try {

                     mFileReader = new FileReader( messageFile );

                 } catch( FileNotFoundException e ) {

                 }

                 LineNumberReader lnReader = new
eNumberReader( 
mFileReader );

                 String currentLine = new String();

                 try {

                     messageBody.append( "\n\n********* Included File: " + 
messageFile.getName() + "\n\n");


                     while( ( currentLine = lnReader.readLine() ) != null )
{

                         messageBody.append( currentLine + "\n");

                     }

                 } catch( IOException e ) {

                 }

             }

             mbp1.setText( messageBody.toString() );

             mp.addBodyPart(mbp1);

             if( attachFiles != null ) {

                 for( int i = 0; i < attachFiles.length; i++ ) {

                     // create and fill the second message part
                     MimeBodyPart mbp = new MimeBodyPart();

                     FileDataSource fds= new FileDataSource(attachFiles[i]);
                     mbp.setDataHandler(new DataHandler(fds));
                     mbp.setFileName(fds.getName());

                     // Add this file as a MIME attachment
                     mp.addBodyPart(mbp);

                 }

             }

             // add the Multipart to the message
             msg.setContent(mp);

             // Send the email
             Transport.send(msg);

         } catch (MessagingException mex) {

             throw new BuildException( mex );

         }
     }

}



[PATCH] Email taskdef with ability to attach files

Posted by Tim O'Brien <tm...@mindspring.com>.
Adds optional functionality of sending an email message with multiple file 
attachments from Ant.  Uses javax.mail and javax.activation and is an 
optional taskdef because of this.

Changes below include:

	Modified build.xml to test for the existence of javax.mail.MimeMessage
	Modified index.html
	Modified defaults.properties
	Email.java source to be added to optional taskdefs directory.

This functionality could be used to notify users about the status of a 
nightly build process to anything device that has an email address.  It 
could also be used to "forward" build output to mail filter on multiple 
machines that would then operate on the MIME attachments, etc.

Please note that I did not mean to conflict with James Duncan Davidson or 
Jason Hunter here.  I had already implemented this task before the 
discussion of adding the com.oreilly.servlet.MailMessage took place, and I 
decided to err on the side of openness and not hold on to my code.  In 
other words, this is my first patch submission, and I definitely don't want 
to step on anyone's toes. ( Especially the guy who wrote the book I learned 
servlets from. :-| )

PS: One thing that might help this is if the Available task could check for 
the existence of more than one class at a time.  Only checking for 
javax.mail.MimeMessage is dangerous, because I'm using the JAF to deal with 
the mime attachments.

Tim O'Brien
tobrien@ieee.org


Index: build.xml
===================================================================
RCS file: /home/cvspublic/jakarta-ant/build.xml,v
retrieving revision 1.22
diff -u -r1.22 build.xml
--- build.xml   2000/06/23 16:46:38     1.22
+++ build.xml   2000/06/24 02:58:52
@@ -41,6 +41,8 @@
                 classname="com.kvisco.xsl.XSLProcessor" />
      <available property="xalan.present"
                 classname="org.apache.xalan.xslt.XSLTProcessorFactory" />
+    <available property="javamail.present"
+               classname="javax.mail.MimeMessage"/>
    </target>

    <!-- 
=================================================================== -->
@@ -66,6 +68,7 @@
        <exclude name="**/NetRexxC.java" unless="netrexx.present" />
        <exclude name="**/XslpLiaison.java" unless="xslp.present" />
        <exclude name="**/XalanLiaison.java" unless="xalan.present" />
+      <exclude name="**/Email.java" unless="javamail.present" />
      </javac>

      <copydir src="${src.dir}" dest="${build.classes}">



Index: index.html
===================================================================
RCS file: /home/cvspublic/jakarta-ant/docs/index.html,v
retrieving revision 1.28
diff -u -r1.28 index.html
--- index.html  2000/06/23 16:46:45     1.28
+++ index.html  2000/06/24 03:00:10
@@ -19,6 +19,7 @@
    <li>Arnout J. Kuiper (<a 
href="mailto:ajkuiper@wxs.nl">ajkuiper@wxs.nl</a>)</li>
    <li>Stefano Mazzocchi (<a 
href="mailto:stefano@apache.org">stefano@apache.org</a>)</li>
    <li>Sam Ruby (<a href="mailto:rubys@us.ibm.com">rubys@us.ibm.com</a>)</li>
+  <li>Tim O'Brien (<a 
href="mailto:tobrien@ieee.org">tobrien@ieee.org</a>)</li>
  </ul>

  <p>Version 1.0.8.1 - 2000/06/13</p>
@@ -2571,10 +2572,71 @@

  <h2><a name="optionaltasks">Optional tasks</a></h2>
  <ul>
+  <li><a href="#email">Email</a></li>
    <li><a href="#netrexxc">NetRexxC</a></li>
    <li><a href="#renameexts">RenameExtensions</a></li>
    <li><a href="#script">Script</a></li>
  </ul>
+<hr>
+<h2><a name="email">Email</a></h2>
+<h3><b>Description:</b></h3>
+<p>Emails a message originating from a supplied string or file, and can 
also send multiple files as Mime attachments.
+</p>
+<h3>Parameters:</h3>
+<table border="1" cellpadding="2" cellspacing="0">
+  <tr>
+    <td valign="top"><b>Attribute</b></td>
+    <td valign="top"><b>Description</b></td>
+    <td align="center" valign="top"><b>Required</b></td>
+  </tr>
+  <tr>
+    <td valign="top">mailto</td>
+    <td valign="top">comma separated list of email addresses to send 
message to.</Td>
+    <td valign="top" align="center">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">mailfrom</td>
+    <td valign="top">email address that message is from.</td>
+    <td valign="top" align="center">Yes</td>
+  </tr>
+  <tr>
+    <td valign="top">subject</td>
+    <td valign="top">subject of message to send. (default is "Ant 
Notification")</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">message</td>
+    <td valign="top">message to include in email body. ( message OR 
messageFile must be present. )</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">messagefile</td>
+    <td valign="top">comma separated list of files to include in the 
message body.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">attachfile</td>
+    <td valign="top">comma separated list of files to attach to email 
message.</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+  <tr>
+    <td valign="top">smtphost</td>
+    <td valign="top">SMTP host to send message with. (default is 
"localhost")</td>
+    <td valign="top" align="center">No</td>
+  </tr>
+</table>
+<h3>Examples</h3>
+<blockquote>
+  <p><code>&lt;email mailto=&quot;foo@somedomain.com&quot;
+              mailfrom=&quot;bar@somedomain.com&quot;
+              subject=&quot;Build Status&quot;
+              message=&quot;Build Success!&quot;
+             messagefile=&quot;status.log,error.log&quot;
+             attachfile=&quot;build.xml,distribution.tar.gz&quot;
+             smtphost=&quot;mail.somedomain.com&quot;/&gt;
+</code>
+  </p>
+</blockquote>
  <hr>
  <h2><a name="netrexxc">NetRexxC</a></h2>
  <h3><b>Description:</b></h3>



Index: defaults.properties
===================================================================
RCS file: 
/home/cvspublic/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/defaults. 
properties,v
retrieving revision 1.15
diff -r1.15 defaults.properties
39a40
 > email=org.apache.tools.ant.taskdefs.optional.Email





************************
And add the following file to the optional taskdefs src directory:  Email.java
BEGIN FILE:
************************


/*
  * The Apache Software License, Version 1.1
  *
  * Copyright (c) 1999 The Apache Software Foundation.  All rights
  * reserved.
  *
  * Redistribution and use in source and binary forms, with or without
  * modification, are permitted provided that the following conditions
  * are met:
  *
  * 1. Redistributions of source code must retain the above copyright
  *    notice, this list of conditions and the following disclaimer.
  *
  * 2. Redistributions in binary form must reproduce the above copyright
  *    notice, this list of conditions and the following disclaimer in
  *    the documentation and/or other materials provided with the
  *    distribution.
  *
  * 3. The end-user documentation included with the redistribution, if
  *    any, must include the following acknowlegement:
  *       "This product includes software developed by the
  *        Apache Software Foundation (http://www.apache.org/)."
  *    Alternately, this acknowlegement may appear in the software itself,
  *    if and wherever such third-party acknowlegements normally appear.
  *
  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
  *    Foundation" must not be used to endorse or promote products derived
  *    from this software without prior written permission. For written
  *    permission, please contact apache@apache.org.
  *
  * 5. Products derived from this software may not be called "Apache"
  *    nor may "Apache" appear in their names without prior written
  *    permission of the Apache Group.
  *
  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  * SUCH DAMAGE.
  * ====================================================================
  *
  * This software consists of voluntary contributions made by many
  * individuals on behalf of the Apache Software Foundation.  For more
  * information on the Apache Software Foundation, please see
  * <http://www.apache.org/>.
  */

package org.apache.tools.ant.taskdefs.optional;

import org.apache.tools.ant.*;
import java.io.*;
import java.net.*;
import java.util.*;

import javax.mail.*;
import javax.mail.internet.*;

import javax.activation.*;

/**
  * Task to send email messages from Ant.  This task can take the following
  * arguments:
  * <ul>
  * <li><B>mailto</B> - A comma separated list of email addresses</li>
  * <li><B>mailfrom</B> - An email address from which mail is sent</li>
  * <li><B>subject</B> - The subject of the email message</li>
  * <li><B>message</B> - The message body</li>
  * <li><B>messagefile</B> - A comma separated list of files to include in 
the message body</li>
  * <li><B>attachfile</B> - A comma separated list of files to attach as 
MIME attachments</li>
  * <li><B>smtphost</B> - SMTP host to send mail</LI>
  * </ul>
  * Of these arguments, <b>mailto</b> and <b>mailfrom</b> must be 
specified, and one of the following
  * arguments must be present <B>message</B> and <B>messagefile</B>.
  *
  * @author Tim O'Brien <a href="mailto:tobrien@ieee.org">tobrien@ieee.org</a>
  */
public class Email extends Task {

     private static final String delimiter = ",";

     private File messageFile;
     private File[] attachFiles;
     private InternetAddress[] toAddresses;
     private InternetAddress fromAddress;
     private String subject = "Ant notification";
     private String message;
     private String smtpHost = "localhost";

     public void setMessagefile(String msgfile) {

         try {

             messageFile = project.resolveFile(msgfile);

         } catch( Exception e ) {

             throw new BuildException( "Email: messagefile " + msgfile + " 
not found." );

         }

     }

     public void setAttachfile(String attachfile) {

         StringTokenizer sToke = new StringTokenizer( attachfile, delimiter );

         ArrayList tokens = new ArrayList();

         while( sToke.hasMoreElements() ) {

             tokens.add( sToke.nextElement() );

         }

         attachFiles = new File[ tokens.size() ];

         for( int i = 0; i < tokens.size(); i++ ) {

             try {

                 File fileToAttach = project.resolveFile( (String) 
tokens.get(i) );
                 attachFiles[i] = fileToAttach;

             } catch( Exception e ) {

                 throw new BuildException( "Email: attachfile " + 
tokens.get(i) + " not found." );

             }


         }

     }

     public void setMailto( String to_addr ) {

         StringTokenizer sToke = new StringTokenizer( to_addr, delimiter );

         ArrayList tokens = new ArrayList();

         while( sToke.hasMoreElements() ) {

             tokens.add( sToke.nextElement() );

         }

         toAddresses = new InternetAddress[ tokens.size() ];

         for( int i = 0; i < tokens.size(); i++ ) {

             try {

                 toAddresses[i] = new InternetAddress( (String) 
tokens.get(i) );

             } catch( AddressException e ) {

                 throw new BuildException( "Email: Invalid email address 
supplied in mailto " + to_addr );

             }

         }

     }

     public void setMailfrom( String from_addr ) {

         try {

             fromAddress = new InternetAddress( from_addr );

         } catch( Exception e ) {

             throw new BuildException( "Email: Invalid email address 
supplied in mailfrom " + from_addr );

         }

     }

     public void setSubject( String subj ) {
         subject = subj;
     }

     public void setMessage( String msg ) {
         message = msg;
     }

     public void setSmtphost( String host ) {
         smtpHost = host;
     }

     /**
      * Does the work.
      *
      * @exception BuildException if someting goes wrong with the build
      */
     public void execute() throws BuildException {

         if( toAddresses == null ) {

             throw new BuildException("Email: mailto is not specified");

         }

         if( fromAddress == null ) {

             throw new BuildException("Email: mailfrom is not specified" );

         }

         if( message == null && messageFile == null ) {

             throw new BuildException("Email: message and messagefile 
missing, one must be present.");

         }

         // Create properties to hold smtpHost for Session.
         Properties props = new Properties();
         props.put("mail.smtp.host", smtpHost);

         Session session = Session.getDefaultInstance(props, null);

         try {

             // Create a MimeMessage
             MimeMessage msg = new MimeMessage(session);

             // Set the from and to addresses
             // Set the subject and date.
             msg.setFrom( fromAddress );
             msg.setRecipients(Message.RecipientType.TO, toAddresses);
             msg.setSubject(subject);
             msg.setSentDate(new Date());

             // create the Multipart and its parts to it
             Multipart mp = new MimeMultipart();

             MimeBodyPart mbp1 = new MimeBodyPart();

             StringBuffer messageBody = new StringBuffer();

             if( message != null ) {

                 messageBody.append( message );

             }

             if( messageFile != null ) {

                 FileReader mFileReader = null;

                 try {

                     mFileReader = new FileReader( messageFile );

                 } catch( FileNotFoundException e ) {

                 }

                 LineNumberReader lnReader = new LineNumberReader( 
mFileReader );

                 String currentLine = new String();

                 try {

                     messageBody.append( "\n\n********* Included File: " + 
messageFile.getName() + "\n\n");

                     while( ( currentLine = lnReader.readLine() ) != null ) {

                         messageBody.append( currentLine + "\n");

                     }

                 } catch( IOException e ) {

                 }

             }

             mbp1.setText( messageBody.toString() );

             mp.addBodyPart(mbp1);

             if( attachFiles != null ) {

                 for( int i = 0; i < attachFiles.length; i++ ) {

                     // create and fill the second message part
                     MimeBodyPart mbp = new MimeBodyPart();

                     FileDataSource fds= new FileDataSource(attachFiles[i]);
                     mbp.setDataHandler(new DataHandler(fds));
                     mbp.setFileName(fds.getName());

                     // Add this file as a MIME attachment
                     mp.addBodyPart(mbp);

                 }

             }

             // add the Multipart to the message
             msg.setContent(mp);

             // Send the email
             Transport.send(msg);

         } catch (MessagingException mex) {

             throw new BuildException( mex );

         }
     }

}