Author: snicoll
Date: Sun Sep 16 06:02:42 2007
New Revision: 576098

URL: http://svn.apache.org/viewvc?rev=576098&view=rev
Log:
MCHANGES-87: Ability to specify the mail sender explicitely.

Added:
    
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/MailSender.java
    
maven/plugins/trunk/maven-changes-plugin/src/site/apt/examples/specifying-mail-sender.apt
Modified:
    maven/plugins/trunk/maven-changes-plugin/pom.xml
    
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
    maven/plugins/trunk/maven-changes-plugin/src/site/apt/index.apt

Modified: maven/plugins/trunk/maven-changes-plugin/pom.xml
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/pom.xml?rev=576098&r1=576097&r2=576098&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/pom.xml (original)
+++ maven/plugins/trunk/maven-changes-plugin/pom.xml Sun Sep 16 06:02:42 2007
@@ -115,13 +115,13 @@
     <dependency>
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-velocity</artifactId>
-      <version>1.1.4</version>
+      <version>1.1.7</version>
     </dependency>
     <dependency>
       <!-- Required by plexus-velocity -->
       <groupId>org.codehaus.plexus</groupId>
       <artifactId>plexus-container-default</artifactId>
-      <version>1.0-alpha-15</version>
+      <version>1.0-alpha-20</version>
     </dependency>
     <dependency>
       <groupId>plexus</groupId>
@@ -152,6 +152,11 @@
       <version>2.1</version>
     </dependency>
     <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.0</version>
+    </dependency>
+    <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
       <version>1.1</version>
@@ -228,8 +233,8 @@
     </plugins>
   </reporting>
   <properties>
-    <doxiaVersion>1.0-alpha-9-SNAPSHOT</doxiaVersion>
-    <doxiaSiteVersion>1.0-SNAPSHOT</doxiaSiteVersion>
+    <doxiaVersion>1.0-alpha-9</doxiaVersion>
+    <doxiaSiteVersion>1.0-alpha-9</doxiaSiteVersion>
   </properties>
 </project>
 

Modified: 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java?rev=576098&r1=576097&r2=576098&view=diff
==============================================================================
--- 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
 (original)
+++ 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/AnnouncementMailMojo.java
 Sun Sep 16 06:02:42 2007
@@ -19,13 +19,6 @@
  * under the License.
  */
 
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileReader;
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.List;
-
 import org.apache.maven.model.Developer;
 import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
@@ -35,13 +28,20 @@
 import org.codehaus.plexus.mailsender.MailSenderException;
 import org.codehaus.plexus.util.IOUtil;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
+import java.io.IOException;
+import java.util.Iterator;
+import java.util.List;
+
 /**
  * Goal which sends an announcement through email.
  *
- * @goal announcement-mail
- * @execute goal="announcement-generate"
  * @author [EMAIL PROTECTED]
  * @version $Id$
+ * @goal announcement-mail
+ * @execute goal="announcement-generate"
  */
 public class AnnouncementMailMojo
     extends AbstractMojo
@@ -102,18 +102,28 @@
     private String subject;
 
     /**
-     * The id of the developer sending the announcement mail. This should match
-     * the id of one of the developers in the pom. If a matching developer is
-     * not found, then the first developer in the pom will be used.
+     * The id of the developer sending the announcement mail. Only used if the 
<tt>mailSender</tt>
+     * attribute is not set. In this case, this should match the id of one of 
the developers in
+     * the pom. If a matching developer is not found, then the first developer 
in the pom will be
+     * used.
      *
      * @parameter expression="${changes.fromDeveloperId}"
      */
     private String fromDeveloperId;
 
     /**
+     * Defines the sender of the announcement if the list of developer is 
empty or
+     * if the sender is not a member of the development team.
+     *
+     * @parameter
+     */
+    private MailSender mailSender;
+
+
+    /**
      * Recipient email address.
      *
-     * @parameter 
+     * @parameter
      * @required
      */
     private List toAddresses;
@@ -207,50 +217,30 @@
     /**
      * Send the email.
      *
-     * @throws MojoExecutionException
+     * @throws MojoExecutionException if the mail could not be sent
      */
     protected void sendMessage()
         throws MojoExecutionException
     {
         String email = "";
-
+        final MailSender ms = getActualMailSender();
+        final String fromName = ms.getName();
+        final String fromAddress = ms.getEmail();
+        if ( fromAddress == null || fromAddress.equals( "" ) )
+        {
+            throw new MojoExecutionException( "Invalid mail sender: name and 
email is mandatory (" + ms + ")." );
+        }
+        getLog().info( "Using this sender for email announcement: " + 
fromAddress + " < " + fromName + " > " );
         try
         {
-            int i = 0;
-
-            Developer sendingDeveloper;
-            if ( getFromDeveloperId() != null )
+            final Iterator it = getToAddresses().iterator();
+            while ( it.hasNext() )
             {
-                sendingDeveloper = getDeveloperById( getFromDeveloperId(), 
getFrom() );
-            }
-            else
-            {
-                sendingDeveloper = getFirstDeveloper( getFrom() );
-            }
-
-            String fromName = sendingDeveloper.getName();
-            String fromAddress = sendingDeveloper.getEmail();
-
-            getLog().info( "Using this sender for email announcement: " + 
fromAddress + " < " + fromName + " > " );
-
-            if ( fromAddress == null || fromAddress.equals( "" ) )
-            {
-                throw new MojoExecutionException( "Email address in 
<developers> section is required." );
-            }
-
-
-            while ( i < getToAddresses().size() )
-            {
-                email = getToAddresses().get( i ).toString();
-
-                getLog().info( "Sending mail... " + email );
-
-                mailer.send( getSubject(), IOUtil.toString( readAnnouncement( 
template ) ),
-                             email, "", fromAddress, fromName );
-
+                email = it.next().toString();
+                getLog().info( "Sending mail to " + email + "..." );
+                mailer.send( getSubject(), IOUtil.toString( readAnnouncement( 
template ) ), email, "", fromAddress,
+                             fromName );
                 getLog().info( "Sent..." );
-
-                i++;
             }
         }
         catch ( IOException ioe )
@@ -278,19 +268,18 @@
 
     /**
      * Read the announcement generated file.
-     * 
-     * @param  fileName         Accepts filename to be read.
-     * @return  fileReader      Return the FileReader.
+     *
+     * @param fileName the filename to be read
+     * @return fileReader Return the FileReader
+     * @throws MojoExecutionException if the file could not be found
      */
-    public FileReader readAnnouncement( String fileName )
+    protected FileReader readAnnouncement( String fileName )
         throws MojoExecutionException
     {
-        FileReader fileReader = null;
-
+        FileReader fileReader;
         try
         {
             File file = new File( fileName );
-
             fileReader = new FileReader( file );
         }
         catch ( FileNotFoundException fnfe )
@@ -301,47 +290,50 @@
     }
 
     /**
-     * Retrieve the first name and email address found in the developers list.
+     * Returns the identify of the mail sender according to the plugin's 
configuration:
+     * <ul>
+     * <li>if the <tt>mailSender</tt> parameter is set, it is returned</li>
+     * <li>if no <tt>fromDeveloperId</tt> is set, the first developer in the 
list is returned</li>
+     * <li>if a <tt>fromDeveloperId</tt> is set, the developer with that id is 
returned</li>
+     * <li>if the developers list is empty or if the specified id does not 
exist, an exception is thrown</li>
+     * </ul>
      *
-     * @param developers A List of developers
-     * @return The first developer in the list
+     * @return the mail sender to use
+     * @throws MojoExecutionException if the mail sender could not be retrieved
      */
-    protected Developer getFirstDeveloper( List developers )
+    protected MailSender getActualMailSender()
         throws MojoExecutionException
     {
-        if ( developers.size() > 0 )
+        if ( mailSender != null )
         {
-            return (Developer) developers.get( 0 );
+            return mailSender;
         }
-        else
+        else if ( from == null || from.isEmpty() )
         {
-            throw new MojoExecutionException( "Email address is required in 
the <developers> section in your pom." );
+            throw new MojoExecutionException(
+                "<developers> section in your pom could not be empty: add a 
<developer> entry or set the " +
+                    "mailSender parameter." );
         }
-    }
-
-    /**
-     * Retrieve the developer with the given id.
-     *
-     * @param developers A List of developers
-     * @return The developer in the list with the specified id
-     */
-    protected Developer getDeveloperById( String id, List developers )
-        throws MojoExecutionException
-    {
-        Iterator it = developers.iterator();
-        while ( it.hasNext() )
+        else if ( fromDeveloperId == null )
         {
-            Developer developer = (Developer) it.next();
-
-            if ( id.equals( developer.getId() ) )
+            final Developer dev = (Developer) from.get( 0 );
+            return new MailSender( dev.getName(), dev.getEmail() );
+        }
+        else
+        {
+            final Iterator it = from.iterator();
+            while ( it.hasNext() )
             {
-                return developer;
-            }
+                Developer developer = (Developer) it.next();
 
+                if ( fromDeveloperId.equals( developer.getId() ) )
+                {
+                    return new MailSender( developer.getName(), 
developer.getEmail() );
+                }
+            }
+            throw new MojoExecutionException(
+                "Missing developer with id '" + fromDeveloperId + "' in the 
<developers> section in your pom." );
         }
-
-        throw new MojoExecutionException( "Missing developer with id '"  + id
-            + "' in the <developers> section in your pom." );
     }
 
     //================================
@@ -416,5 +408,66 @@
     public void setFromDeveloperId( String fromDeveloperId )
     {
         this.fromDeveloperId = fromDeveloperId;
+    }
+
+
+    public String getUsername()
+    {
+        return username;
+    }
+
+    public void setUsername( String username )
+    {
+        this.username = username;
+    }
+
+    public String getPassword()
+    {
+        return password;
+    }
+
+    public void setPassword( String password )
+    {
+        this.password = password;
+    }
+
+    public boolean isSslMode()
+    {
+        return sslMode;
+    }
+
+    public void setSslMode( boolean sslMode )
+    {
+        this.sslMode = sslMode;
+    }
+
+    public MailSender getMailSender()
+    {
+        return mailSender;
+    }
+
+    public void setMailSender( MailSender mailSender )
+    {
+        this.mailSender = mailSender;
+    }
+
+    public String getTemplateOutputDirectory()
+    {
+        return templateOutputDirectory;
+    }
+
+    public void setTemplateOutputDirectory( String templateOutputDirectory )
+    {
+        this.templateOutputDirectory = templateOutputDirectory;
+    }
+
+    public String getTemplate()
+    {
+        return template;
+    }
+
+    public void setTemplate( String template )
+    {
+        this.template = template;
     }
 }

Added: 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/MailSender.java
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/MailSender.java?rev=576098&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/MailSender.java
 (added)
+++ 
maven/plugins/trunk/maven-changes-plugin/src/main/java/org/apache/maven/plugin/announcement/MailSender.java
 Sun Sep 16 06:02:42 2007
@@ -0,0 +1,72 @@
+package org.apache.maven.plugin.announcement;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+
+/**
+ * Defines the sender of the announcement if the list of developer is empty or
+ * if the sender is not a member of the development team.
+ *
+ * @author Stephane Nicoll
+ */
+public class MailSender
+{
+
+    private String name;
+
+    private String email;
+
+
+    public MailSender()
+    {
+        super();
+    }
+
+
+    public MailSender( String name, String email )
+    {
+        this.name = name;
+        this.email = email;
+    }
+
+    public String getName()
+    {
+        return name;
+    }
+
+    public void setName( String name )
+    {
+        this.name = name;
+    }
+
+    public String getEmail()
+    {
+        return email;
+    }
+
+    public void setEmail( String email )
+    {
+        this.email = email;
+    }
+
+    public String toString()
+    {
+        return getName() + " (" + getEmail() + ")";
+    }
+}

Added: 
maven/plugins/trunk/maven-changes-plugin/src/site/apt/examples/specifying-mail-sender.apt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/site/apt/examples/specifying-mail-sender.apt?rev=576098&view=auto
==============================================================================
--- 
maven/plugins/trunk/maven-changes-plugin/src/site/apt/examples/specifying-mail-sender.apt
 (added)
+++ 
maven/plugins/trunk/maven-changes-plugin/src/site/apt/examples/specifying-mail-sender.apt
 Sun Sep 16 06:02:42 2007
@@ -0,0 +1,93 @@
+ ------
+ Specifying the mail sender
+ ------
+ Stephane Nicoll
+ ------
+ 16 September 2007
+ ------
+
+ ~~ Licensed to the Apache Software Foundation (ASF) under one
+ ~~ or more contributor license agreements.  See the NOTICE file
+ ~~ distributed with this work for additional information
+ ~~ regarding copyright ownership.  The ASF licenses this file
+ ~~ to you 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.
+
+ ~~ NOTE: For help with the syntax of this file, see:
+ ~~ http://maven.apache.org/guides/mini/guide-apt-format.html
+
+
+Specifying the mail sender
+
+ The identify used to send announcement mail can be customized. It can be 
either a
+ member of the <<<developers>>> section of the pom or it can be specified 
explicitely
+ with the <<<mailSender>>> configuration of the plugin
+
+* Specifying the developer to use
+
+ To specify the developer to use to send the announcement, simply specify the 
<<<id>>> of
+ the developer as in the example below:
+
++-----------------+
+<project>
+  <developers>
+    ...
+    <developer>
+      <id>jsmith</id>
+      <name>John Smith</name>
+      <email>[EMAIL PROTECTED]</email>
+  </developer>
+  ...
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <configuration>
+          <fromDeveloperId>jsmith</fromDeveloperId>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+  ...
+</project>
++-----------------+
+
+  If no developer id is specified, the first developer in the list will be 
used.
+
+* Specifying the sender explicitely
+
+ If you want to specify the sender explicitely and not rely on the 
<<<developers>>> section of your pom,
+ define the <<<mailSender>>> attribute of the plugin.
+
++-----------------+
+<project>
+  ...
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <configuration>
+          <mailSender>
+            <name>Release Notification</name>
+            <email>[EMAIL PROTECTED]</email>
+          </mailSender>
+        </configuration>
+      </plugin>
+    </plugins>
+  </reporting>
+  ...
+</project>
++-----------------+
+

Modified: maven/plugins/trunk/maven-changes-plugin/src/site/apt/index.apt
URL: 
http://svn.apache.org/viewvc/maven/plugins/trunk/maven-changes-plugin/src/site/apt/index.apt?rev=576098&r1=576097&r2=576098&view=diff
==============================================================================
--- maven/plugins/trunk/maven-changes-plugin/src/site/apt/index.apt (original)
+++ maven/plugins/trunk/maven-changes-plugin/src/site/apt/index.apt Sun Sep 16 
06:02:42 2007
@@ -62,3 +62,5 @@
   * {{{examples/smtp-authentication.html}SMTP authentication}}
 
   * {{{examples/using-a-custom-announcement-template.html}Using a Custom 
Announcement Template}}
+
+  * {{{examples/specifying-mail-sender.html}Specifying the mail sender}}


Reply via email to