Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Refactoring.

  • Loading branch information...
commit 7038397e248684a1df546bcaf778d3229b614f16 1 parent e070f8e
@mmichaelis authored
View
5 pom.xml
@@ -71,6 +71,11 @@
</exclusions>
</dependency>
<dependency>
+ <groupId>org.apache.maven.reporting</groupId>
+ <artifactId>maven-reporting-impl</artifactId>
+ <version>2.1</version>
+ </dependency>
+ <dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${maven.version}</version>
View
209 src/main/java/de/mmichaelis/maven/mojo/AbstractMailMojo.java
@@ -16,29 +16,15 @@
package de.mmichaelis.maven.mojo;
-import de.mmichaelis.maven.mojo.mail.MailBulk;
-import de.mmichaelis.maven.mojo.mail.MailExpiration;
-import de.mmichaelis.maven.mojo.mail.MailPriority;
+import de.mmichaelis.maven.mojo.mail.MailBase;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
-import javax.mail.Message.RecipientType;
-import javax.mail.MessagingException;
-import javax.mail.Session;
-import javax.mail.Transport;
-import javax.mail.internet.AddressException;
import javax.mail.internet.InternetAddress;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.MimeUtility;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
import java.nio.charset.Charset;
-import java.util.Date;
-import java.util.Properties;
import static javax.mail.internet.MimeUtility.mimeCharset;
-import static org.codehaus.plexus.util.StringUtils.isEmpty;
/**
* Abstract Mojo for derived mail mojos.
@@ -46,13 +32,6 @@
* @since 5/27/11 11:01 PM
*/
public abstract class AbstractMailMojo extends AbstractMojo {
- protected static final String LF = "\r\n";
- private static final String HOSTNAME;
- private static final String HOSTIP;
- private static final String DEFAULT_FROM;
- private static final String USERNAME = System.getProperty("user.name");
- private static final String SIGNATURE_SEPARATOR = "-- ";
-
/**
* Can be used to disable sending mails.
*
@@ -110,11 +89,6 @@
private String charset;
/**
- * Will contain the mime encoded charset.
- */
- private String mimeCharSet;
-
- /**
* Priority for the notification email.
*
* @parameter default="low" expression="${mail.priority}"
@@ -162,49 +136,6 @@
@SuppressWarnings({"UnusedDeclaration"})
private boolean dryRun;
- static {
- String hostname;
- String hostip;
- try {
- final InetAddress addr = InetAddress.getLocalHost();
- hostip = addr.getHostAddress();
- hostname = addr.getHostName();
- } catch (UnknownHostException e) {
- hostname = "localhost";
- hostip = "127.0.0.1";
- }
- HOSTNAME = hostname;
- HOSTIP = hostip;
-
- DEFAULT_FROM = USERNAME + "@" + HOSTNAME;
- }
-
- /**
- * Create the mail session.
- *
- * @return session to send mails with
- */
- protected Session getSession() {
- final Properties properties = new Properties();
- properties.setProperty("mail.smtp.host", smtphost);
- properties.setProperty("mail.smtp.port", smtpport.toString());
- // Influences the Message-ID
- properties.setProperty("mail.from", from == null ? DEFAULT_FROM : from);
- final Session session = Session.getDefaultInstance(properties);
- session.setDebug(getLog().isDebugEnabled());
- return session;
- }
-
- private String getSignature() {
- return LF + LF + SIGNATURE_SEPARATOR + LF + MimeUtility.fold(0, "Sent via maven-mail-plugin from " + USERNAME + " on " + HOSTNAME + " (" + HOSTIP + ")");
- }
-
- private void addHeaderInformation(final MimeMessage message) {
- MailBulk.getInstance().addHeader(message, getLog());
- MailExpiration.parse(expires, getLog()).addHeader(message, getLog());
- MailPriority.parse(priority, getLog()).addHeader(message, getLog());
- }
-
/**
* Execute the Mojo.
*
@@ -215,134 +146,30 @@ private void addHeaderInformation(final MimeMessage message) {
*/
@Override
public final void execute() throws MojoExecutionException, MojoFailureException {
- try {
- final InternetAddress[] addresses = getRecipients();
-
- if (addresses.length == 0) {
- getLog().debug("No recipients. Skipping to send mail.");
- return;
- }
-
- final InternetAddress sender = getSender();
- final String text = MimeUtility.fold(0, getPlainText());
- final String signedText = text + getSignature();
- final String subject = getSubject();
- final String topic = getTopic();
- final String completeSubject = topic == null ? subject : "[" + topic + "] " + subject;
-
- final Session session = getSession();
- final MimeMessage message = new MimeMessage(session);
- addHeaderInformation(message);
- try {
- message.setSentDate(new Date());
- message.addRecipients(RecipientType.TO, getRecipients());
- message.setSender(sender);
- message.setSubject(completeSubject, getMimeCharSet());
- message.setText(signedText, getMimeCharSet(), "plain");
- } catch (MessagingException e) {
- throw new MojoExecutionException("Failed to compose email message.", e);
- }
- if (dryRun) {
- getLog().info("maven-mail-plugin dryRun for " + this.getClass().getName() + ". Mail:\n" + message);
- } else {
- try {
- getLog().info("Sending mail to recipients: " + InternetAddress.toString(addresses));
- Transport.send(message);
- } catch (MessagingException e) {
- throw new MojoExecutionException("Failed to send mail.", e);
- }
- }
- } catch (MojoExecutionException e) {
- if (failOnError) {
- throw e;
- }
- getLog().error("failOnError deactivated. Ignoring exception.", e);
- } catch (MojoFailureException e) {
- if (failOnError) {
- throw e;
- }
- getLog().error("failOnError deactivated. Ignoring exception.", e);
- }
- }
-
- /**
- * Get the sender for the given email. Multiple configured senders are ignored.
- * If no sender is configured or parsing the sender-string fails a default sender
- * will be chosen.
- *
- * @return an address to use as sender
- * @throws MojoExecutionException if parsing the sender fails
- */
- private InternetAddress getSender() throws MojoExecutionException {
- InternetAddress[] senders;
- if (isEmpty(from)) {
- senders = getDefaultSenders();
- } else {
- try {
- senders = InternetAddress.parse(from);
- } catch (AddressException e) {
- getLog().warn("Could not parse sender: '" + from + "'. Using default address.", e);
- senders = getDefaultSenders();
- }
- }
- if (senders.length > 1) {
- getLog().warn("Multiple senders specified. Choosing only the first one. Was: " + from);
- }
- return senders[0];
- }
-
- /**
- * Get the default sender if no sender is configured or parsing the configured sender fails.
- *
- * @return the list of default senders (should be actually only one)
- * @throws MojoExecutionException if parsing the default mail address fails
- */
- private static InternetAddress[] getDefaultSenders() throws MojoExecutionException {
- final InternetAddress[] senders;
- try {
- senders = InternetAddress.parse(DEFAULT_FROM);
- } catch (AddressException e) {
- throw new MojoExecutionException("Could not parse default sender mail address " + DEFAULT_FROM + ".", e);
- }
- return senders;
+ final MailBase base = new MailBase(getLog());
+ base.setCharset(charset);
+ base.setDryRun(dryRun);
+ base.setExpires(expires);
+ base.setFailOnError(failOnError);
+ base.setFrom(from);
+ base.setPlainText(getPlainText());
+ base.setPriority(priority);
+ base.setRecipients(getRecipients());
+ base.setSkip(skip);
+ base.setSmtphost(smtphost);
+ base.setSmtpport(smtpport);
+ base.setSubject(subject);
+ base.setTopic(topic);
+ base.execute();
}
/**
* Return the charset in MIME-format.
+ *
* @return charset
*/
protected final String getMimeCharSet() {
- if (mimeCharSet == null && charset != null) {
- mimeCharSet = mimeCharset(charset);
- }
- return mimeCharSet;
- }
-
- /**
- * Topic to add to the mail subject.
- *
- * @return topic to add or <code>null</code> for no topic prefix
- * @throws MojoExecutionException if an unexpected problem occurs.
- * Throwing this exception causes a "BUILD ERROR" message to be displayed.
- * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
- * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
- */
- protected String getTopic() throws MojoExecutionException, MojoFailureException {
- return topic;
- }
-
- /**
- * Return the subject for the email. Derived Mojos may override the default which just returns
- * the subject as configured in the Mojo.
- *
- * @return the subject of the email
- * @throws MojoExecutionException if an unexpected problem occurs.
- * Throwing this exception causes a "BUILD ERROR" message to be displayed.
- * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
- * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
- */
- protected String getSubject() throws MojoExecutionException, MojoFailureException {
- return subject;
+ return mimeCharset(charset);
}
/**
View
23 src/main/java/de/mmichaelis/maven/mojo/MailDevelopersMojo.java
@@ -18,8 +18,11 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
import java.io.File;
+import java.io.IOException;
/**
* Goal which touches a timestamp file.
@@ -47,24 +50,6 @@
*/
@Override
protected String getPlainText() throws MojoExecutionException, MojoFailureException {
- if (message == null) {
- throw new MojoExecutionException("No message set.");
- }
- final String text = message.getText();
- final File textFile = message.getTextFile();
- if (text == null && textFile == null) {
- throw new MojoExecutionException("You should either specify <text> or <textFile> as message.");
- }
- if (text != null && textFile != null) {
- getLog().warn("Specified both <text> and <textFile> as message. <textFile> will be taken.");
- }
- if (textFile != null) {
- return getPlainTextFromFile();
- }
- return text;
- }
-
- private String getPlainTextFromFile() throws MojoExecutionException, MojoFailureException {
- return null;
+ return message.getText(getLog());
}
}
View
87 src/main/java/de/mmichaelis/maven/mojo/MailMojo.java
@@ -0,0 +1,87 @@
+/******************************************************************************
+ * Copyright 2011 Mark Michaelis *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the "License"); *
+ * you may not use this file except in compliance with the License. *
+ * You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ ******************************************************************************/
+
+package de.mmichaelis.maven.mojo;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @since 6/7/11 9:53 PM
+ * @goal mail
+ */
+public final class MailMojo extends AbstractMailMojo {
+ /**
+ * The message to send.
+ * @parameter
+ * @required
+ */
+ private Message message;
+
+ /**
+ * To whom to send the emails to.
+ * @parameter
+ * @required
+ */
+ private List<String> to;
+
+ /**
+ * Get the recipients for this email. If the length of the array is <code>null</code> no mail will be sent.
+ *
+ * @return the list of recipients
+ * @throws MojoExecutionException
+ * if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException
+ * if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ @Override
+ protected InternetAddress[] getRecipients() throws MojoExecutionException, MojoFailureException {
+ final List<InternetAddress> result = new ArrayList<InternetAddress>(to.size());
+ for (final String s : to) {
+ try {
+ result.addAll(Arrays.asList(InternetAddress.parse(s)));
+ } catch (AddressException e) {
+ throw new MojoExecutionException("E-Mail address " + s + " is invalid.", e);
+ }
+ }
+ return result.toArray(new InternetAddress[result.size()]);
+ }
+
+ /**
+ * Get the text body for this email.
+ *
+ * @return the text of the email
+ * @throws MojoExecutionException
+ * if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException
+ * if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ @Override
+ protected String getPlainText() throws MojoExecutionException, MojoFailureException {
+ return message.getText(getLog());
+ }
+}
View
28 src/main/java/de/mmichaelis/maven/mojo/Message.java
@@ -16,13 +16,19 @@
package de.mmichaelis.maven.mojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+import org.codehaus.plexus.util.FileUtils;
+
import java.io.File;
+import java.io.IOException;
/**
* Represents the message to be sent. If both, text and textFile is set textFile will be taken.
* @since 6/4/11 11:26 PM
*/
-public class Message {
+public final class Message {
/**
* The message to send.
*/
@@ -35,11 +41,25 @@
public Message() {
}
- public String getText() {
+ public String getText(final Log log) throws MojoExecutionException, MojoFailureException {
+ if (text == null && textFile == null) {
+ throw new MojoExecutionException("You should either specify <text> or <textFile> as message.");
+ }
+ if (text != null && textFile != null) {
+ log.warn("Specified both <text> and <textFile> as message. <textFile> will be taken.");
+ }
+ if (textFile != null) {
+ return getPlainTextFromFile(textFile);
+ }
return text;
}
- public File getTextFile() {
- return textFile;
+ private String getPlainTextFromFile(final File textFile) throws MojoExecutionException, MojoFailureException {
+ try {
+ return FileUtils.fileRead(textFile);
+ } catch (IOException e) {
+ throw new MojoExecutionException("Failed to read file " + textFile.getAbsolutePath(), e);
+ }
}
+
}
View
378 src/main/java/de/mmichaelis/maven/mojo/mail/MailBase.java
@@ -0,0 +1,378 @@
+/******************************************************************************
+ * Copyright 2011 Mark Michaelis *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the "License"); *
+ * you may not use this file except in compliance with the License. *
+ * You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ ******************************************************************************/
+
+package de.mmichaelis.maven.mojo.mail;
+
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.plugin.logging.Log;
+
+import javax.mail.Message.RecipientType;
+import javax.mail.MessagingException;
+import javax.mail.Session;
+import javax.mail.Transport;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import java.util.Date;
+import java.util.Properties;
+
+import static javax.mail.internet.MimeUtility.fold;
+import static javax.mail.internet.MimeUtility.mimeCharset;
+import static org.codehaus.plexus.util.StringUtils.isEmpty;
+
+/**
+ * This helper class can be used to combine standard and reporting mojos to use the same base.
+ * To use a new instance is created, configured and then provides helper methods.
+ *
+ * @since 6/7/11 10:33 PM
+ */
+public final class MailBase {
+ private final Log log;
+
+ private InternetAddress[] recipients;
+ private String plainText;
+
+ /**
+ * Can be used to disable sending mails.
+ */
+ private boolean skip;
+
+ /**
+ * <p>
+ * The address to send the email from. Examples:
+ * <pre>
+ * john.doe@example.com
+ * John Doe &lt;john.doe@example.com>
+ * </pre>
+ * or any valid email address.
+ * </p>
+ */
+ private String from;
+
+ /**
+ * The host to send the mail from.
+ */
+ private String smtphost;
+
+ /**
+ * The host to send the mail from.
+ */
+ private Integer smtpport;
+
+ /**
+ * When automatic mails should expire in days.
+ */
+ private String expires;
+
+ /**
+ * Charset for the emails.
+ *
+ * @see java.nio.charset.Charset
+ */
+ private String charset;
+
+ /**
+ * Will contain the mime encoded charset.
+ */
+ private String mimeCharSet;
+
+ /**
+ * Priority for the notification email.
+ */
+ private String priority;
+
+ /**
+ * If to fail the build if an error occurs while composing or sending the mail.
+ */
+ private boolean failOnError;
+
+ /**
+ * Topic to add to the mail subject. Might ease filtering mails. Set it to
+ * empty string to omit a prepended topic. Topic will be added like this:
+ * <pre>
+ * [&lt;Topic>] &lt;Subject>
+ * </pre>
+ */
+ private String topic;
+
+ /**
+ * Subject to add to the email. For possibly supported tokens see the appropriate
+ * goal description.
+ * <pre>
+ * [&lt;Topic>] &lt;Subject>
+ * </pre>
+ */
+ private String subject;
+
+ /**
+ * If true the mail won't be send but just logged at INFO level.
+ */
+ private boolean dryRun;
+
+ public MailBase(final Log log) {
+ this.log = log;
+ }
+
+ /**
+ * Create the mail session.
+ *
+ * @return session to send mails with
+ */
+ private Session getSession() {
+ final Properties properties = new Properties();
+ properties.setProperty("mail.smtp.host", smtphost);
+ properties.setProperty("mail.smtp.port", smtpport.toString());
+ // Influences the Message-ID
+ properties.setProperty("mail.from", from == null ? MailConstants.DEFAULT_FROM : from);
+ final Session session = Session.getDefaultInstance(properties);
+ session.setDebug(log.isDebugEnabled());
+ return session;
+ }
+
+ private String getSignature() {
+ return MailConstants.LF + MailConstants.LF + MailConstants.SIGNATURE_SEPARATOR + MailConstants.LF + fold(0, "Sent via maven-mail-plugin from " + MailConstants.USERNAME + " on " + MailConstants.HOSTNAME + " (" + MailConstants.HOSTIP + ")");
+ }
+
+ private void addHeaderInformation(final MimeMessage message) {
+ MailBulk.getInstance().addHeader(message, log);
+ MailExpiration.parse(expires, log).addHeader(message, log);
+ MailPriority.parse(priority, log).addHeader(message, log);
+ }
+
+ /**
+ * Execute the Mojo.
+ *
+ * @throws MojoExecutionException
+ * if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException
+ * if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ public final void execute() throws MojoExecutionException, MojoFailureException {
+ if (skip) {
+ return;
+ }
+ try {
+ final InternetAddress[] addresses = getRecipients();
+
+ if (addresses.length == 0) {
+ log.debug("No recipients. Skipping to send mail.");
+ return;
+ }
+
+ final InternetAddress sender = getSender();
+ final String text = fold(0, getPlainText());
+ final String signedText = text + getSignature();
+ final String subject = getSubject();
+ final String topic = getTopic();
+ final String completeSubject = topic == null ? subject : "[" + topic + "] " + subject;
+
+ final Session session = getSession();
+ final MimeMessage message = new MimeMessage(session);
+ addHeaderInformation(message);
+ try {
+ message.setSentDate(new Date());
+ message.addRecipients(RecipientType.TO, getRecipients());
+ message.setSender(sender);
+ message.setSubject(completeSubject, getMimeCharSet());
+ message.setText(signedText, getMimeCharSet(), "plain");
+ } catch (MessagingException e) {
+ throw new MojoExecutionException("Failed to compose email message.", e);
+ }
+ if (dryRun) {
+ log.info("maven-mail-plugin dryRun for " + this.getClass().getName() + ". Mail:\n" + message);
+ } else {
+ try {
+ log.info("Sending mail to recipients: " + InternetAddress.toString(addresses));
+ Transport.send(message);
+ } catch (MessagingException e) {
+ throw new MojoExecutionException("Failed to send mail.", e);
+ }
+ }
+ } catch (MojoExecutionException e) {
+ if (failOnError) {
+ throw e;
+ }
+ log.error("failOnError deactivated. Ignoring exception.", e);
+ } catch (MojoFailureException e) {
+ if (failOnError) {
+ throw e;
+ }
+ log.error("failOnError deactivated. Ignoring exception.", e);
+ }
+ }
+
+ /**
+ * Get the sender for the given email. Multiple configured senders are ignored.
+ * If no sender is configured or parsing the sender-string fails a default sender
+ * will be chosen.
+ *
+ * @return an address to use as sender
+ * @throws MojoExecutionException if parsing the sender fails
+ */
+ private InternetAddress getSender() throws MojoExecutionException {
+ InternetAddress[] senders;
+ if (isEmpty(from)) {
+ senders = getDefaultSenders();
+ } else {
+ try {
+ senders = InternetAddress.parse(from);
+ } catch (AddressException e) {
+ log.warn("Could not parse sender: '" + from + "'. Using default address.", e);
+ senders = getDefaultSenders();
+ }
+ }
+ if (senders.length > 1) {
+ log.warn("Multiple senders specified. Choosing only the first one. Was: " + from);
+ }
+ return senders[0];
+ }
+
+ /**
+ * Get the default sender if no sender is configured or parsing the configured sender fails.
+ *
+ * @return the list of default senders (should be actually only one)
+ * @throws MojoExecutionException if parsing the default mail address fails
+ */
+ private static InternetAddress[] getDefaultSenders() throws MojoExecutionException {
+ final InternetAddress[] senders;
+ try {
+ senders = InternetAddress.parse(MailConstants.DEFAULT_FROM);
+ } catch (AddressException e) {
+ throw new MojoExecutionException("Could not parse default sender mail address " + MailConstants.DEFAULT_FROM + ".", e);
+ }
+ return senders;
+ }
+
+ /**
+ * Return the charset in MIME-format.
+ *
+ * @return charset
+ */
+ private String getMimeCharSet() {
+ if (mimeCharSet == null && charset != null) {
+ mimeCharSet = mimeCharset(charset);
+ }
+ return mimeCharSet;
+ }
+
+ /**
+ * Topic to add to the mail subject.
+ *
+ * @return topic to add or <code>null</code> for no topic prefix
+ * @throws MojoExecutionException if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ private String getTopic() throws MojoExecutionException, MojoFailureException {
+ return topic;
+ }
+
+ /**
+ * Return the subject for the email. Derived Mojos may override the default which just returns
+ * the subject as configured in the Mojo.
+ *
+ * @return the subject of the email
+ * @throws MojoExecutionException if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ private String getSubject() throws MojoExecutionException, MojoFailureException {
+ return subject;
+ }
+
+ /**
+ * Get the recipients for this email. If the length of the array is <code>null</code> no mail will be sent.
+ *
+ * @return the list of recipients
+ * @throws MojoExecutionException if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ private InternetAddress[] getRecipients() throws MojoExecutionException, MojoFailureException {
+ return recipients;
+ }
+
+ /**
+ * Get the text body for this email.
+ *
+ * @return the text of the email
+ * @throws MojoExecutionException if an unexpected problem occurs.
+ * Throwing this exception causes a "BUILD ERROR" message to be displayed.
+ * @throws MojoFailureException if an expected problem (such as a compilation failure) occurs.
+ * Throwing this exception causes a "BUILD FAILURE" message to be displayed.
+ */
+ private String getPlainText() throws MojoExecutionException, MojoFailureException {
+ return plainText;
+ }
+
+ public void setRecipients(final InternetAddress[] recipients) {
+ this.recipients = recipients;
+ }
+
+ public void setPlainText(final String plainText) {
+ this.plainText = plainText;
+ }
+
+ public void setSkip(final boolean skip) {
+ this.skip = skip;
+ }
+
+ public void setFrom(final String from) {
+ this.from = from;
+ }
+
+ public void setSmtphost(final String smtphost) {
+ this.smtphost = smtphost;
+ }
+
+ public void setSmtpport(final Integer smtpport) {
+ this.smtpport = smtpport;
+ }
+
+ public void setExpires(final String expires) {
+ this.expires = expires;
+ }
+
+ public void setCharset(final String charset) {
+ this.charset = charset;
+ }
+
+ public void setPriority(final String priority) {
+ this.priority = priority;
+ }
+
+ public void setFailOnError(final boolean failOnError) {
+ this.failOnError = failOnError;
+ }
+
+ public void setTopic(final String topic) {
+ this.topic = topic;
+ }
+
+ public void setSubject(final String subject) {
+ this.subject = subject;
+ }
+
+ public void setDryRun(final boolean dryRun) {
+ this.dryRun = dryRun;
+ }
+}
View
50 src/main/java/de/mmichaelis/maven/mojo/mail/MailConstants.java
@@ -0,0 +1,50 @@
+/******************************************************************************
+ * Copyright 2011 Mark Michaelis *
+ * *
+ * Licensed under the Apache License, Version 2.0 (the "License"); *
+ * you may not use this file except in compliance with the License. *
+ * You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, software *
+ * distributed under the License is distributed on an "AS IS" BASIS, *
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
+ * See the License for the specific language governing permissions and *
+ * limitations under the License. *
+ ******************************************************************************/
+
+package de.mmichaelis.maven.mojo.mail;
+
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
+/**
+ * @since 6/7/11 10:21 PM
+ */
+public class MailConstants {
+ public static final String LF = "\r\n";
+ public static final String HOSTNAME;
+ public static final String HOSTIP;
+ public static final String DEFAULT_FROM;
+ public static final String USERNAME = System.getProperty("user.name");
+ public static final String SIGNATURE_SEPARATOR = "-- ";
+
+ static {
+ String hostname;
+ String hostip;
+ try {
+ final InetAddress addr = InetAddress.getLocalHost();
+ hostip = addr.getHostAddress();
+ hostname = addr.getHostName();
+ } catch (UnknownHostException e) {
+ hostname = "localhost";
+ hostip = "127.0.0.1";
+ }
+ HOSTNAME = hostname;
+ HOSTIP = hostip;
+
+ DEFAULT_FROM = USERNAME + "@" + HOSTNAME;
+ }
+
+}
Please sign in to comment.
Something went wrong with that request. Please try again.