net.sourceforge.cruisecontrol.publishers
Class EmailPublisher

java.lang.Object
  extended bynet.sourceforge.cruisecontrol.publishers.EmailPublisher
All Implemented Interfaces:
Publisher, java.io.Serializable
Direct Known Subclasses:
HTMLEmailPublisher, LinkEmailPublisher

public abstract class EmailPublisher
extends java.lang.Object
implements Publisher

Abstract implementation of the Publisher interface, specifically tailored for sending email. The only abstract method is createMessage, which allows different implementations to send different messages as the body of the email. As it currently stands, there is one concrete implementation-- LinkEmailPublisher, but the ability to create EmailPublishers that handle sending a text summary or an html summary is there.

Author:
alden almagro, ThoughtWorks, Inc. 2002
See Also:
Serialized Form

Nested Class Summary
static class EmailPublisher.Address
           
static class EmailPublisher.Alert
           
static class EmailPublisher.Always
           
static class EmailPublisher.Failure
           
static class EmailPublisher.Ignore
           
static class EmailPublisher.Success
           
 
Constructor Summary
EmailPublisher()
           
 
Method Summary
 void add(EmailMapper mapper)
           
 void add(EmailMapping mapping)
           
protected  void addContentToMessage(java.lang.String content, javax.mail.Message msg)
          Subclasses can override this method to control how the content is added to the Message.
 EmailPublisher.Alert createAlert()
           
protected  java.lang.String createAlertUserList(XMLLogHelper logHelper)
          Creates the list of email addresses to receive an alert email message.
protected  java.util.Set createAlertUserSet(XMLLogHelper logHelper)
          Creates a Set of email addresses to receive an alert email message based on the logHelper.
 EmailPublisher.Always createAlways()
           
protected  java.lang.String createEmailString(java.util.Set emails)
          Creates a comma delimited String from a Set of Strings.
 EmailPublisher.Failure createFailure()
           
 EmailPublisher.Ignore createIgnore()
           
protected abstract  java.lang.String createMessage(XMLLogHelper logHelper)
          Implementations of this method will create the email message body.
protected  java.lang.String createSubject(XMLLogHelper logHelper)
          Creates the subject line for the email message.
 EmailPublisher.Success createSuccess()
           
protected  java.lang.String createUserList(XMLLogHelper logHelper)
          Creates the list of email addresses to receive the email message.
protected  java.util.Set createUserSet(XMLLogHelper logHelper)
          Creates the Set of email addresses to receive the email message.
 java.lang.String getBuildResultsURL()
           
 java.lang.String getDefaultSuffix()
           
 EmailMapper[] getEmailMapper()
           
protected  javax.mail.internet.InternetAddress getFromAddress()
           
 java.lang.String getMailHost()
           
 java.lang.String getMailPort()
           
protected  java.util.Properties getMailProperties()
          builds the properties object for the mail session
 java.lang.String getPassword()
           
 java.lang.String getReturnAddress()
           
 java.lang.String getReturnName()
           
 java.lang.String getSubjectPrefix()
           
 java.lang.String getUsername()
           
protected  boolean matchRegExpr(java.lang.String input, org.apache.oro.io.GlobFilenameFilter pattern)
          Compare the input String against a regular expression pattern.
 void publish(org.jdom.Element cruisecontrolLog)
          Implementing the Publisher interface.
protected  boolean sendMail(java.lang.String toList, java.lang.String subject, java.lang.String message, boolean important)
          Sends an email message.
 void setBuildResultsURL(java.lang.String url)
           
 void setDefaultSuffix(java.lang.String defaultEmailSuffix)
           
 void setFailAsImportant(boolean important)
           
 void setMailHost(java.lang.String hostname)
           
 void setMailPort(java.lang.String port)
           
 void setPassword(java.lang.String passwd)
           
 void setReportSuccess(java.lang.String report)
           
 void setReturnAddress(java.lang.String emailAddress)
           
 void setReturnName(java.lang.String emailReturnName)
           
 void setSkipUsers(boolean skip)
           
 void setSpamWhileBroken(boolean spam)
           
 void setSubjectPrefix(java.lang.String prefix)
           
 void setUsername(java.lang.String name)
           
 void setUseSSL(boolean useSSL)
           
protected  boolean shouldSend(XMLLogHelper logHelper)
          Determines if the conditions are right for the email to be sent.
 void validate()
          Called after the configuration is read to make sure that all the mandatory parameters were specified..
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

EmailPublisher

public EmailPublisher()
Method Detail

createMessage

protected abstract java.lang.String createMessage(XMLLogHelper logHelper)
Implementations of this method will create the email message body.

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
String containing the message

validate

public void validate()
              throws CruiseControlException
Description copied from interface: Publisher
Called after the configuration is read to make sure that all the mandatory parameters were specified..

Specified by:
validate in interface Publisher
Throws:
CruiseControlException - if there was a configuration error.

createSubject

protected java.lang.String createSubject(XMLLogHelper logHelper)
                                  throws CruiseControlException
Creates the subject line for the email message.

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
String containing the subject line.
Throws:
CruiseControlException

shouldSend

protected boolean shouldSend(XMLLogHelper logHelper)
                      throws CruiseControlException
Determines if the conditions are right for the email to be sent.

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
whether or not the mail message should be sent.
Throws:
CruiseControlException

createUserList

protected java.lang.String createUserList(XMLLogHelper logHelper)
                                   throws CruiseControlException
Creates the list of email addresses to receive the email message. Uses configured emailmappers to map user names to email addresses. After all mappings are done, mapped users are checked for existence of the domain part (i.e

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
comma delimited String of email addresses to receive the email message.
Throws:
CruiseControlException

createUserSet

protected java.util.Set createUserSet(XMLLogHelper logHelper)
                               throws CruiseControlException
Creates the Set of email addresses to receive the email message.

Uses configured emailmappers to map user names to email addresses. After all mappings are done, mapped users are checked for existence of the domain part (i.e

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
A Set of email addresses to receive the email message.
Throws:
CruiseControlException

publish

public void publish(org.jdom.Element cruisecontrolLog)
             throws CruiseControlException
Implementing the Publisher interface. Sends modification alert and regular build emails. If a user is supposed to receive a modification alert and a regular build email, they will only receive the modification alert. This prevents duplicate emails (currently only the subject is different).

Specified by:
publish in interface Publisher
Parameters:
cruisecontrolLog - JDOM Element representation of the main cruisecontrol build log
Throws:
CruiseControlException

getMailProperties

protected java.util.Properties getMailProperties()
builds the properties object for the mail session

Returns:
a properties object containing configured properties.

sendMail

protected boolean sendMail(java.lang.String toList,
                           java.lang.String subject,
                           java.lang.String message,
                           boolean important)
                    throws CruiseControlException
Sends an email message.

Parameters:
toList - comma delimited String of email addresses
subject - subject line for the message
message - body of the message
Returns:
Boolean value indicating if an email was sent.
Throws:
CruiseControlException

addContentToMessage

protected void addContentToMessage(java.lang.String content,
                                   javax.mail.Message msg)
                            throws javax.mail.MessagingException
Subclasses can override this method to control how the content is added to the Message.

Parameters:
content - content returned by createMessage
msg - mail Message with headers and addresses added elsewhere
Throws:
javax.mail.MessagingException

getFromAddress

protected javax.mail.internet.InternetAddress getFromAddress()
                                                      throws javax.mail.internet.AddressException
Throws:
javax.mail.internet.AddressException

setMailHost

public void setMailHost(java.lang.String hostname)

getMailHost

public java.lang.String getMailHost()

setUsername

public void setUsername(java.lang.String name)

getUsername

public java.lang.String getUsername()

setPassword

public void setPassword(java.lang.String passwd)

getPassword

public java.lang.String getPassword()

setMailPort

public void setMailPort(java.lang.String port)

getMailPort

public java.lang.String getMailPort()

setUseSSL

public void setUseSSL(boolean useSSL)

setSubjectPrefix

public void setSubjectPrefix(java.lang.String prefix)

getSubjectPrefix

public java.lang.String getSubjectPrefix()

getBuildResultsURL

public java.lang.String getBuildResultsURL()

setBuildResultsURL

public void setBuildResultsURL(java.lang.String url)

getEmailMapper

public EmailMapper[] getEmailMapper()

getReturnAddress

public java.lang.String getReturnAddress()

setReturnAddress

public void setReturnAddress(java.lang.String emailAddress)

getReturnName

public java.lang.String getReturnName()

setReturnName

public void setReturnName(java.lang.String emailReturnName)

getDefaultSuffix

public java.lang.String getDefaultSuffix()

setDefaultSuffix

public void setDefaultSuffix(java.lang.String defaultEmailSuffix)

setReportSuccess

public void setReportSuccess(java.lang.String report)

setSkipUsers

public void setSkipUsers(boolean skip)

setSpamWhileBroken

public void setSpamWhileBroken(boolean spam)

setFailAsImportant

public void setFailAsImportant(boolean important)

createIgnore

public EmailPublisher.Ignore createIgnore()

createAlways

public EmailPublisher.Always createAlways()

createFailure

public EmailPublisher.Failure createFailure()

createSuccess

public EmailPublisher.Success createSuccess()

createAlert

public EmailPublisher.Alert createAlert()

add

public void add(EmailMapping mapping)

add

public void add(EmailMapper mapper)

createAlertUserList

protected java.lang.String createAlertUserList(XMLLogHelper logHelper)
                                        throws CruiseControlException
Creates the list of email addresses to receive an alert email message.

The full path of each modified file is compared against the regular expressions specified in the configuration. If a modified file's path matches a regular expression, the user's email address is included in the returned String.

Uses configured emailmappers to map user names to email addresses. After all mappings are done, mapped users are checked for existence of the domain part (i.e

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
comma delimited String of email addresses to receive the email message.
Throws:
CruiseControlException

createAlertUserSet

protected java.util.Set createAlertUserSet(XMLLogHelper logHelper)
                                    throws CruiseControlException
Creates a Set of email addresses to receive an alert email message based on the logHelper.

Parameters:
logHelper - XMLLogHelper wrapper for the build log.
Returns:
A Set of email addresses to receive the email message.
Throws:
CruiseControlException

createEmailString

protected java.lang.String createEmailString(java.util.Set emails)
Creates a comma delimited String from a Set of Strings.

Parameters:
emails - A Set containing Strings of emails addresses
Returns:
A comma delimited String of email addresses

matchRegExpr

protected boolean matchRegExpr(java.lang.String input,
                               org.apache.oro.io.GlobFilenameFilter pattern)
Compare the input String against a regular expression pattern.

Parameters:
input - A String to compare against the regExpr pattern
pattern - A GlobFilenameFilter pattern
Returns:
True if the file matches the regular expression pattern. Otherwise false.