From b5b99c769a21d3602ee35948cf004925f03464ba Mon Sep 17 00:00:00 2001 From: Stefan Bodewig Date: Fri, 12 Apr 2002 07:27:45 +0000 Subject: [PATCH] bug 7552 audit of - reset internal state. Cosmetics. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@272393 13f79535-47bb-0310-9956-ffa450edef68 --- .../apache/tools/ant/taskdefs/LoadFile.java | 6 +- .../tools/ant/taskdefs/LoadProperties.java | 1 + .../apache/tools/ant/taskdefs/SendEmail.java | 2 + .../ant/taskdefs/email/EmailAddress.java | 22 ++-- .../tools/ant/taskdefs/email/EmailTask.java | 123 ++++++++++++------ .../tools/ant/taskdefs/email/Mailer.java | 40 ++++-- .../tools/ant/taskdefs/email/Message.java | 31 +++-- .../tools/ant/taskdefs/email/MimeMailer.java | 27 ++-- .../tools/ant/taskdefs/email/PlainMailer.java | 14 +- .../tools/ant/taskdefs/email/UUMailer.java | 7 +- 10 files changed, 178 insertions(+), 95 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/LoadFile.java b/src/main/org/apache/tools/ant/taskdefs/LoadFile.java index f69d1dd08..e54b0f701 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LoadFile.java +++ b/src/main/org/apache/tools/ant/taskdefs/LoadFile.java @@ -72,6 +72,7 @@ import java.util.Vector; * * @author Steve Loughran * @author Magesh Umasankar + * @since Ant 1.5 * @ant.task category="utility" */ public final class LoadFile extends Task { @@ -103,7 +104,7 @@ public final class LoadFile extends Task { private final Vector filterChains = new Vector(); /** - * Encoding to use for filenames, defaults to the platform's default + * Encoding to use for input, defaults to the platform's default * encoding.

* * For a list of possible values see @@ -192,7 +193,8 @@ public final class LoadFile extends Task { if (text != null) { project.setNewProperty(property, text); - log("loaded " + text.length() + " characters",Project.MSG_VERBOSE); + log("loaded " + text.length() + " characters", + Project.MSG_VERBOSE); log(property+" := "+text,Project.MSG_DEBUG); } diff --git a/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java b/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java index 6195e736c..7d0fc932e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java +++ b/src/main/org/apache/tools/ant/taskdefs/LoadProperties.java @@ -73,6 +73,7 @@ import java.util.Vector; * Load a file's contents as Ant Properties. * * @author Magesh Umasankar + * @since Ant 1.5 * @ant.task category="utility" */ public final class LoadProperties extends Task { diff --git a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java index d071db630..f052316e9 100644 --- a/src/main/org/apache/tools/ant/taskdefs/SendEmail.java +++ b/src/main/org/apache/tools/ant/taskdefs/SendEmail.java @@ -106,6 +106,8 @@ import org.apache.tools.ant.taskdefs.email.EmailTask; * @author glenn_twiggs@bmc.com * @author Magesh Umasankar * + * @since Ant 1.2 + * * @ant.task name="mail" category="network" */ public class SendEmail extends EmailTask diff --git a/src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java b/src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java index ed22d7339..d4e4b22a2 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/EmailAddress.java @@ -57,7 +57,7 @@ package org.apache.tools.ant.taskdefs.email; * Holds an email address. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ public class EmailAddress { @@ -70,7 +70,8 @@ public class EmailAddress { } - /** Creates a new email address based on the given string + /** + * Creates a new email address based on the given string * @param address the email address */ public EmailAddress( String address ) @@ -78,7 +79,8 @@ public class EmailAddress this.address = address; } - /** sets the personal / display name of the address + /** + * Sets the personal / display name of the address * @param name the display name */ public void setName( String name ) @@ -86,7 +88,8 @@ public class EmailAddress this.name = name; } - /** sets the email address + /** + * Sets the email address * @param address the actual email address */ public void setAddress( String address ) @@ -94,7 +97,8 @@ public class EmailAddress this.address = address; } - /** Constructs a string "name <address>" or "address" + /** + * Constructs a string "name <address>" or "address" * @return a string representation of the address */ public String toString() @@ -109,7 +113,8 @@ public class EmailAddress } } - /** returns the address + /** + * Returns the address * @return the address part */ public String getAddress() @@ -117,11 +122,12 @@ public class EmailAddress return address; } - /** returns the display name + /** + * Returns the display name * @return the display name part */ public String getName() { return name; } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java b/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java index bd1732625..084907c69 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/EmailTask.java @@ -67,8 +67,8 @@ import org.apache.tools.ant.types.EnumeratedAttribute; import org.apache.tools.ant.types.FileSet; /** - * A task to send SMTP email. This is a refactoring of the SendMail and MimeMail - * tasks such that both are within a single task. + * A task to send SMTP email. This is a refactoring of the SendMail + * and MimeMail tasks such that both are within a single task. * * @author Magesh Umasankar * @author glenn_twiggs@bmc.com @@ -76,7 +76,7 @@ import org.apache.tools.ant.types.FileSet; * @author ehatcher@apache.org Erik Hatcher * @author paulo.gaspar@krankikom.de Paulo Gaspar * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 * * @ant.task name="mail" category="network" */ @@ -152,7 +152,8 @@ public class EmailTask private Vector files = new Vector(); private Vector filesets = new Vector(); - /** Allows the build writer to choose the preferred encoding method + /** + * Allows the build writer to choose the preferred encoding method * @param encoding The encoding (one of AUTO,MIME,UU,PLAIN) */ public void setEncoding( Encoding encoding ) @@ -160,7 +161,8 @@ public class EmailTask this.encoding = encoding.getValue(); } - /** Sets the mail server port + /** + * Sets the mail server port * @param port The port to use */ public void setMailport( int port ) @@ -168,7 +170,8 @@ public class EmailTask this.port = port; } - /** Sets the host + /** + * Sets the host * @param host The host to connect to */ public void setMailhost( String host ) @@ -176,7 +179,8 @@ public class EmailTask this.host = host; } - /** Sets the subject line of the email + /** + * Sets the subject line of the email * * @param subject Subject of this email. */ @@ -185,34 +189,39 @@ public class EmailTask this.subject = subject; } - /** Shorthand method to set the message + /** + * Shorthand method to set the message * @param message Message body of this email. */ public void setMessage( String message ) { if( this.message != null ) { - throw new BuildException( "Only one message can be sent in an email" ); + throw new BuildException( "Only one message can be sent in an " + + "email" ); } this.message = new Message( message ); } - /** Shorthand method to set the message from a file + /** + * Shorthand method to set the message from a file * @param file The file from which to take the message */ public void setMessageFile( File file ) { if( this.message != null ) { - throw new BuildException( "Only one message can be sent in an email" ); + throw new BuildException( "Only one message can be sent in an " + + "email" ); } this.message = new Message( file ); } - /** Shorthand method to set type of the text message, text/plain by default but text/html - * or text/xml is quite feasible. + /** + * Shorthand method to set type of the text message, text/plain by + * default but text/html or text/xml is quite feasible. * * @param type The new MessageMimeType value */ @@ -221,7 +230,8 @@ public class EmailTask this.messageMimeType = type; } - /** Add a message elemnt + /** + * Add a message elemnt * @param message The message object * @throws BuildException if a message has already been added */ @@ -230,13 +240,15 @@ public class EmailTask { if( this.message != null ) { - throw new BuildException( "Only one message can be sent in an email" ); + throw new BuildException( "Only one message can be sent in an " + + "email" ); } this.message = message; } - /** Adds a from address element + /** + * Adds a from address element * @param address The address to send from */ public void addFrom( EmailAddress address ) @@ -249,7 +261,8 @@ public class EmailTask this.from = address; } - /** Shorthand to set the from address element + /** + * Shorthand to set the from address element * * @param address The address to send mail from */ @@ -263,7 +276,8 @@ public class EmailTask this.from = new EmailAddress( address ); } - /** Adds a to address element + /** + * Adds a to address element * @param address An email address */ public void addTo( EmailAddress address ) @@ -271,8 +285,8 @@ public class EmailTask toList.addElement( address ); } - /** Adds "to" address elements - * + /** + * Adds "to" address elements * * @param list Comma separated list of addresses */ @@ -286,7 +300,8 @@ public class EmailTask } } - /** Adds "cc" address element + /** + * Adds "cc" address element * @param address The email address */ public void addCc( EmailAddress address ) @@ -294,8 +309,8 @@ public class EmailTask ccList.addElement( address ); } - /** Adds "cc" address elements - * + /** + * Adds "cc" address elements * * @param list Comma separated list of addresses */ @@ -309,7 +324,8 @@ public class EmailTask } } - /** Adds "bcc" address elements + /** + * Adds "bcc" address elements * @param address The email address */ public void addBcc( EmailAddress address ) @@ -317,8 +333,8 @@ public class EmailTask bccList.addElement( address ); } - /** Adds "bcc" address elements - * + /** + * Adds "bcc" address elements * * @param list comma separated list of addresses */ @@ -332,7 +348,8 @@ public class EmailTask } } - /** Indicates whether BuildExceptions should be passed back to the core + /** + * Indicates whether BuildExceptions should be passed back to the core * * @param failOnError The new FailOnError value */ @@ -341,7 +358,8 @@ public class EmailTask this.failOnError = failOnError; } - /** Adds a list of files to be attached + /** + * Adds a list of files to be attached * * @param filenames Comma separated list of files */ @@ -355,7 +373,8 @@ public class EmailTask } } - /** Adds a set of files (nested fileset attribute). + /** + * Adds a set of files (nested fileset attribute). * @param fs The fileset */ public void addFileset( FileSet fs ) @@ -363,16 +382,19 @@ public class EmailTask filesets.addElement( fs ); } - /** Sets Includefilenames attribute + /** + * Sets Includefilenames attribute * - * @param includeFileNames Whether to include filenames in the text of the message + * @param includeFileNames Whether to include filenames in the + * text of the message */ public void setIncludefilenames( boolean includeFileNames ) { this.includeFileNames = includeFileNames; } - /** Identifies whether file names should be included + /** + * Identifies whether file names should be included * @return Identifies whether file names should be included */ public boolean getIncludeFileNames() @@ -380,10 +402,13 @@ public class EmailTask return includeFileNames; } - /** Sends an email + /** + * Sends an email */ public void execute() { + Message savedMessage = message; + Vector savedFiles = (Vector) files.clone(); try { Mailer mailer = null; @@ -392,11 +417,14 @@ public class EmailTask boolean autoFound = false; // try MIME format - if( encoding.equals( MIME ) || ( encoding.equals( AUTO ) && !autoFound ) ) + if( encoding.equals( MIME ) + || ( encoding.equals( AUTO ) && !autoFound ) ) { try { - mailer = (Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.MimeMailer" ).newInstance(); + mailer = + (Mailer) Class.forName( "org.apache.tools.ant.taskdefs.email.MimeMailer" ) + .newInstance(); autoFound = true; log( "Using MIME mail", Project.MSG_VERBOSE ); } @@ -407,11 +435,14 @@ public class EmailTask } // try UU format - if( encoding.equals( UU ) || ( encoding.equals( AUTO ) && !autoFound ) ) + if( encoding.equals( UU ) + || ( encoding.equals( AUTO ) && !autoFound ) ) { try { - mailer = (Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.UUMailer" ).newInstance(); + mailer = + (Mailer)Class.forName( "org.apache.tools.ant.taskdefs.email.UUMailer" ) + .newInstance(); autoFound = true; log( "Using UU mail", Project.MSG_VERBOSE ); } @@ -422,7 +453,8 @@ public class EmailTask } // try plain format - if( encoding.equals( PLAIN ) || ( encoding.equals( AUTO ) && !autoFound ) ) + if( encoding.equals( PLAIN ) + || ( encoding.equals( AUTO ) && !autoFound ) ) { mailer = new PlainMailer(); autoFound = true; @@ -432,7 +464,8 @@ public class EmailTask // a valid mailer must be present by now if( mailer == null ) { - throw new BuildException( "Failed to initialise encoding: " + encoding ); + throw new BuildException( "Failed to initialise encoding: " + + encoding ); } // a valid message is required @@ -450,7 +483,8 @@ public class EmailTask // at least one address to send to/cc/bcc is required if( toList.isEmpty() && ccList.isEmpty() && bccList.isEmpty() ) { - throw new BuildException( "At least one of to,cc or bcc must be supplied" ); + throw new BuildException( "At least one of to,cc or bcc must " + + "be supplied" ); } // set the mimetype if not done already (and required) @@ -458,7 +492,8 @@ public class EmailTask { if( message.isMimeTypeSpecified() ) { - throw new BuildException( "The mime type can only be specified in one location" ); + throw new BuildException( "The mime type can only be " + + "specified in one location" ); } else { @@ -508,7 +543,8 @@ public class EmailTask // let the user know what happened int count = files.size(); - log( "Sent email with " + count + " attachment" + ( count == 1?"":"s" ), Project.MSG_INFO ); + log( "Sent email with " + count + " attachment" + + ( count == 1?"":"s" ), Project.MSG_INFO ); } catch( BuildException e ) { @@ -517,6 +553,9 @@ public class EmailTask { throw e; } + } finally { + message = savedMessage; + files = savedFiles; } } } diff --git a/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java b/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java index 0c1ead99b..8cef2371a 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/Mailer.java @@ -61,7 +61,7 @@ import org.apache.tools.ant.Task; * Base class for the various emailing implementations. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ abstract class Mailer { @@ -77,7 +77,8 @@ abstract class Mailer protected Task task; protected boolean includeFileNames = false; - /** sets the mail server + /** + * Sets the mail server * @param host */ public void setHost( String host ) @@ -85,7 +86,8 @@ abstract class Mailer this.host = host; } - /** sets the smtp port + /** + * Sets the smtp port * @param port */ public void setPort( int port ) @@ -93,7 +95,8 @@ abstract class Mailer this.port = port; } - /** sets the message + /** + * Sets the message * @param m */ public void setMessage( Message m ) @@ -101,7 +104,8 @@ abstract class Mailer this.message = m; } - /** sets the address to send from + /** + * Sets the address to send from * @param from */ public void setFrom( EmailAddress from ) @@ -109,7 +113,8 @@ abstract class Mailer this.from = from; } - /** set the to addresses + /** + * Set the to addresses * @param list */ public void setToList( Vector list ) @@ -117,7 +122,8 @@ abstract class Mailer this.toList = list; } - /** sets the cc addresses + /** + * Sets the cc addresses * @param list */ public void setCcList( Vector list ) @@ -125,7 +131,8 @@ abstract class Mailer this.ccList = list; } - /** sets the bcc addresses + /** + * Sets the bcc addresses * @param list */ public void setBccList( Vector list ) @@ -133,7 +140,8 @@ abstract class Mailer this.bccList = list; } - /** sets the files to attach + /** + * Sets the files to attach * @param files */ public void setFiles( Vector files ) @@ -141,7 +149,8 @@ abstract class Mailer this.files = files; } - /** sets the subject + /** + * Sets the subject * @param subject */ public void setSubject( String subject ) @@ -149,7 +158,8 @@ abstract class Mailer this.subject = subject; } - /** sets the owning task + /** + * Sets the owning task * @param task */ public void setTask( Task task ) @@ -157,7 +167,8 @@ abstract class Mailer this.task = task; } - /** indicates whether filenames should be listed in the body + /** + * Indicates whether filenames should be listed in the body * @param b */ public void setIncludeFileNames( boolean b ) @@ -165,9 +176,10 @@ abstract class Mailer this.includeFileNames = b; } - /** This method should send the email + /** + * This method should send the email * @throws BuildException */ public abstract void send() throws BuildException; -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/email/Message.java b/src/main/org/apache/tools/ant/taskdefs/email/Message.java index 88d96cd00..c89816a4e 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/Message.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/Message.java @@ -63,7 +63,7 @@ import java.io.PrintStream; * Class representing an email message. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ public class Message { @@ -72,13 +72,15 @@ public class Message private String mimeType = "text/plain"; private boolean specified = false; - /** creates a new empty message + /** + * Creates a new empty message */ public Message() { } - /** Creates a new message based on the given string + /** + * Creates a new message based on the given string * @param text the message */ public Message( String text ) @@ -86,7 +88,8 @@ public class Message addText( text ); } - /** Creates a new message using the contents of the given file. + /** + * Creates a new message using the contents of the given file. * @param file the source of the message */ public Message( File file ) @@ -94,7 +97,8 @@ public class Message messageSource = file; } - /** Adds a textual part of the message + /** + * Adds a textual part of the message * @param text some text to add */ public void addText( String text ) @@ -102,7 +106,8 @@ public class Message buffer.append( text ); } - /** Sets the source file of the message + /** + * Sets the source file of the message * @param src the source of the message */ public void setSrc( File src ) @@ -110,7 +115,8 @@ public class Message this.messageSource = src; } - /** Sets the content type for the message + /** + * Sets the content type for the message * @param mimeType a mime type e.g. "text/plain" */ public void setMimeType( String mimeType ) @@ -119,7 +125,8 @@ public class Message specified = true; } - /** Returns the content type + /** + * Returns the content type * @return the mime type */ public String getMimeType() @@ -127,7 +134,8 @@ public class Message return mimeType; } - /** prints the message onto an output stream + /** + * Prints the message onto an output stream * @param out The print stream to write to * @throws IOException if an error occurs */ @@ -158,11 +166,12 @@ public class Message } } - /** returns true iff the mimeType has been set. + /** + * Returns true iff the mimeType has been set. * @return false if the default value is in use */ public boolean isMimeTypeSpecified() { return specified; } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java b/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java index aca654adf..1ab652fcc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/MimeMailer.java @@ -78,7 +78,7 @@ import org.apache.tools.ant.BuildException; * Uses the JavaMail classes to send Mime format email. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ class MimeMailer extends Mailer @@ -93,8 +93,9 @@ class MimeMailer props.put( "mail.smtp.host", host ); props.put( "mail.smtp.port", String.valueOf( port ) ); - //Aside, the JDK is clearly unaware of the scottish 'session', which - //involves excessive quantities of alcohol :-) + // Aside, the JDK is clearly unaware of the scottish + // 'session', which //involves excessive quantities of + // alcohol :-) Session sesh = Session.getDefaultInstance( props, null ); //create the message @@ -108,12 +109,16 @@ class MimeMailer } else { - msg.setFrom( new InternetAddress( from.getAddress(), from.getName() ) ); + msg.setFrom( new InternetAddress( from.getAddress(), + from.getName() ) ); } - msg.setRecipients( Message.RecipientType.TO, internetAddresses( toList ) ); - msg.setRecipients( Message.RecipientType.CC, internetAddresses( ccList ) ); - msg.setRecipients( Message.RecipientType.BCC, internetAddresses( bccList ) ); + msg.setRecipients( Message.RecipientType.TO, + internetAddresses( toList ) ); + msg.setRecipients( Message.RecipientType.CC, + internetAddresses( ccList ) ); + msg.setRecipients( Message.RecipientType.BCC, + internetAddresses( bccList ) ); if( subject != null ) { @@ -139,7 +144,8 @@ class MimeMailer if( !file.exists() || !file.canRead() ) { throw new BuildException( "File \"" + file.getAbsolutePath() - + "\" does not exist or is not readable." ); + + "\" does not exist or is not " + + "readable." ); } FileDataSource fileData = new FileDataSource( file ); DataHandler fileDataHandler = new DataHandler( fileData ); @@ -175,10 +181,11 @@ class MimeMailer } else { - addrs[ i ] = new InternetAddress( addr.getAddress(), addr.getName() ); + addrs[ i ] = new InternetAddress( addr.getAddress(), + addr.getName() ); } } return addrs; } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java b/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java index 1eb715ec7..d8e3926dc 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/PlainMailer.java @@ -66,12 +66,14 @@ import org.apache.tools.mail.MailMessage; * Class responsible for sending email through raw protocol methods. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ class PlainMailer extends Mailer { - /** Sends the email using the apache {@link org.apache.tools.mail.MailMessage MailMessage} class. + /** + * Sends the email using the apache MailMessage class. + * @see org.apache.tools.mail.MailMessage */ public void send() { @@ -129,7 +131,8 @@ class PlainMailer } - /** Attaches a file to this email + /** + * Attaches a file to this email * @param file The file to attache * @param out The message stream to add to * @throws IOException if errors occur @@ -140,7 +143,8 @@ class PlainMailer if( !file.exists() || !file.canRead() ) { throw new BuildException( "File \"" + file.getName() - + "\" does not exist or is not readable." ); + + "\" does not exist or is not " + + "readable." ); } if( includeFileNames ) @@ -172,4 +176,4 @@ class PlainMailer finstr.close(); } } -} \ No newline at end of file +} diff --git a/src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java b/src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java index ce855b701..386682573 100644 --- a/src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java +++ b/src/main/org/apache/tools/ant/taskdefs/email/UUMailer.java @@ -65,7 +65,7 @@ import sun.misc.UUEncoder; * An emailer that uuencodes attachments. * * @author roxspring@yahoo.com Rob Oxspring - * @since 1.5 + * @since Ant 1.5 */ class UUMailer extends PlainMailer @@ -76,7 +76,8 @@ class UUMailer if( !file.exists() || !file.canRead() ) { throw new BuildException( "File \"" + file.getName() - + "\" does not exist or is not readable." ); + + "\" does not exist or is not " + + "readable." ); } FileInputStream finstr = new FileInputStream( file ); @@ -92,4 +93,4 @@ class UUMailer finstr.close(); } } -} \ No newline at end of file +}