You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by vm...@apache.org on 2004/08/07 17:49:37 UTC

cvs commit: maven-plugins/announcement/xdocs changes.xml goals.xml properties.xml

vmassol     2004/08/07 08:49:37

  Modified:    announcement project.xml plugin.jelly plugin.properties
               announcement/xdocs changes.xml goals.xml properties.xml
  Added:       announcement/src/main/org/apache/maven/announcement
                        MailUtils.java
  Log:
  Added new <code>announcement:mail</code> goal to automatically send the generated announcement by email.
  
  Revision  Changes    Path
  1.26      +10 -0     maven-plugins/announcement/project.xml
  
  Index: project.xml
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/project.xml,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- project.xml	15 Jul 2004 19:19:48 -0000	1.25
  +++ project.xml	7 Aug 2004 15:49:37 -0000	1.26
  @@ -87,5 +87,15 @@
         <version>20030211.142705</version>
         <url>http://jakarta.apache.org/commons/jelly/libs/xml/</url>
       </dependency>
  +    <dependency>
  +      <id>commons-lang</id>
  +      <version>2.0</version>
  +      <url>http://jakarta.apache.org/commons/lang/</url>
  +    </dependency>
  +    <dependency>
  +      <id>commons-net</id>
  +      <version>1.2.1</version>
  +      <url>http://jakarta.apache.org/commons/net/</url>
  +    </dependency>
     </dependencies>
   </project>
  
  
  
  1.12      +50 -0     maven-plugins/announcement/plugin.jelly
  
  Index: plugin.jelly
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/plugin.jelly,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- plugin.jelly	22 Jul 2004 11:26:28 -0000	1.11
  +++ plugin.jelly	7 Aug 2004 15:49:37 -0000	1.12
  @@ -40,6 +40,17 @@
       <maven:property var="announcementFile" name="maven.announcement.file" 
           defaultValue="${maven.gen.docs}/announcements/announcement-${versionVariable}.txt"/>
   
  +    <!-- If from email address is empty, find the first non empty email 
  +         address from the POM. -->
  +    <j:if test="${context.getVariable('maven.announcement.mail.from') == null}">
  +       <j:forEach var="developer" items="${pom.developers}">
  +          <j:if test="${not empty(developer.email)}">
  +             <j:set var="maven.announcement.mail.from" value="${developer.email}"/>
  +             <j:break/>
  +          </j:if>
  +       </j:forEach>
  +    </j:if>
  +
       <!-- Ensure the directory where the announcement will be created exists -->
       <ant:dirname property="announcementDir" file="${announcementFile}"/>
       <ant:mkdir dir="${announcementDir}"/>
  @@ -49,6 +60,8 @@
       <maven:property var="distributionUrl" name="maven.announcement.distributionUrl" 
           defaultValue="${maven.repo.remote}/${pom.groupId}/plugins"/>
   
  +    <j:useBean var="stringUtils" class="org.apache.commons.lang.StringUtils"/>
  +
     </goal>
   
     <goal name="announcement:check-version" prereqs="announcement:init">
  @@ -97,6 +110,13 @@
       
     </goal>
   
  +  <goal name="announcement:mail" prereqs="announcement:generate"
  +    description="Send an email containing the release announcement">
  +
  +    <announcement:mail file="${announcementFile}"/>
  +
  +  </goal>
  +
     <!-- Define common jelly script used by different goals as a jelly tag -->
     <define:taglib uri="announcement">
       <define:tag name="generate">
  @@ -118,6 +138,36 @@
         </j:file>
   
       </define:tag>
  +
  +    <define:tag name="mail">
  +      <!-- @file: Announcement file location -->
  +
  +      <maven:param-check value="${maven.announcement.mail.server}" fail="true">The SMTP server name must be specified using the maven.announcement.mail.server property</maven:param-check> 
  +      <maven:param-check value="${maven.announcement.mail.from}" fail="true">The From address must be specified using the maven.announcement.mail.from property or by ensuring that at least one developer in the POM has an email address specified</maven:param-check> 
  +      <maven:param-check value="${maven.announcement.mail.to}" fail="true">The To address must be specified using the maven.announcement.mail.to property</maven:param-check> 
  +      
  +      <!-- Resolve dynamic %% templates from maven.announcement.mail.subject -->
  +      <j:set var="maven.announcement.mail.subject"
  +          value="${stringUtils.replace(context.getVariable('maven.announcement.mail.subject'), '%VERSION%', versionVariable)}"/>
  +      
  +      <echo>Sending mail using SMTP server "${maven.announcement.mail.server}", client ${maven.announcement.mail.client} and subject "${maven.announcement.mail.subject}"...</echo>
  +      <echo>Sending from "${maven.announcement.mail.from}" to "${maven.announcement.mail.to}"...</echo>
  +
  +      <util:loadText uri="file:${file}" var="announcementContent"/>
  +      <j:invokeStatic className="org.apache.maven.announcement.MailUtils" method="sendMail" var="result">
  +          <j:arg type="java.lang.String" value="${maven.announcement.mail.server}"/>
  +          <j:arg type="java.lang.String" value="${maven.announcement.mail.client}"/>
  +          <j:arg type="java.lang.String" value="${maven.announcement.mail.from}"/>
  +          <j:arg type="java.lang.String" value="${maven.announcement.mail.to}"/>
  +          <j:arg type="java.lang.String" value="${maven.announcement.mail.subject}"/>
  +          <j:arg type="java.lang.String" value="${announcementContent}"/>
  +      </j:invokeStatic>
  +      <j:if test="${result != 'ok'}">
  +         <fail>Could not send message. Reason: ${result}</fail>
  +      </j:if>
  +
  +    </define:tag>
  +
     </define:taglib>
   
   </project>
  
  
  
  1.12      +16 -0     maven-plugins/announcement/plugin.properties
  
  Index: plugin.properties
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/plugin.properties,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- plugin.properties	22 Jul 2004 11:26:28 -0000	1.11
  +++ plugin.properties	7 Aug 2004 15:49:37 -0000	1.12
  @@ -33,3 +33,19 @@
   
   # Stylesheet to use to generate the text announcement
   maven.announcement.stylesheet.path = ${plugin.resources}/announcement.jsl
  +
  +# IP address or name of the SMTP server used to send an announcement email
  +# maven.announcement.mail.server = 
  +
  +# IP address or name of the host used to log on the SMTP server
  +maven.announcement.mail.client = localhost
  +
  +# From address to use when sending an announcement email. If not defined, 
  +# the first email address found in the POM will be used.
  +# maven.announcement.mail.from =
  +
  +# Comma-separated list of addresses to use when sending an announcement email.
  +# maven.announcement.mail.to =
  +
  +# Mail subject to use when sending an announcement email.
  +maven.announcement.mail.subject = [ANN] ${pom.name} %VERSION% released
  
  
  
  1.1                  maven-plugins/announcement/src/main/org/apache/maven/announcement/MailUtils.java
  
  Index: MailUtils.java
  ===================================================================
  package org.apache.maven.announcement;
  
  import java.io.PrintWriter;
  import java.io.Writer;
  import java.util.StringTokenizer;
  
  import org.apache.commons.net.smtp.SMTPClient;
  import org.apache.commons.net.smtp.SMTPReply;
  import org.apache.commons.net.smtp.SimpleSMTPHeader;
  
  /* ====================================================================
   *   Copyright 2004 The Apache Software Foundation.
   *
   *   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.
   * ====================================================================
   */
  
  /**
   * Send an email message using Jakarta Commons Net
   * 
   * @author Felipe Leme
   * 
   * @version $Id: MailUtils.java,v 1.1 2004/08/07 15:49:37 vmassol Exp $
   */
  public class MailUtils
  {
      private static final String ADDRESS_SEPARATOR = ",";
  
      public static String sendMail(String server, String client,
          String from, String to, String subject, String msg)
      {
          // Check arguments
          if (server == null)
          {
              return "no smtp server configured";
          }
          if (client == null)
          {
              return "no smtp client configured";
          }
          if (to == null)
          {
              return "no to address specified";
          }
          if (from == null)
          {
              return "no from address specified";
          }
          if (msg == null)
          {
              return "no message specified";
          }
          if (subject == null)
          {
              return "no subject specified";
          }
  
          // create a SMTP connection
          SMTPClient smtpClient = new SMTPClient();
          System.out.println("Connecting to SMTP Server [" + server + "]");
          try
          {
              smtpClient.connect(server);
              // checks the server reply
              int reply = smtpClient.getReplyCode();
              if (!SMTPReply.isPositiveCompletion(reply))
              {
                  smtpClient.disconnect();
                  return "SMTP server [" + server + "] refused connection.";
              }
              // Login
              smtpClient.login(client);
              // Set the sender and recipient(s)
              smtpClient.setSender(from);
              // parse out the to addresses
              StringTokenizer st = new StringTokenizer(to.toString(),
                      ADDRESS_SEPARATOR);
              while (st.hasMoreTokens())
              {
                  smtpClient.addRecipient(st.nextToken().trim());
              }
  
              System.out.println("Sending message from [" + from + "] to [" 
                  + to + "]");
  
              // Use the SimpleSMTPHeader class to build the header
              Writer clientWriter = smtpClient.sendMessageData();
              if (clientWriter == null)
              {
                  return "Could not send data to the SMTP server";
              }
              PrintWriter writer = new PrintWriter(clientWriter);
              SimpleSMTPHeader header = new SimpleSMTPHeader(from, to, subject);
  
              //NOTE: if would be nice to add some Maven info here
              //            header.addHeaderField("Organization", "xxx");
  
              // Write the header to the SMTP Server
              writer.write(header.toString());
  
              // Write the body of the message
              writer.write(msg);
  
              // Close the writer
              writer.close();
              if (!smtpClient.completePendingCommand())
              {
                  return "Could not send the SMTP message";
              }
  
              // Logout from the e-mail server (QUIT)
              smtpClient.logout();
  
              // Close the connection
              smtpClient.disconnect();
  
              // everything is fine
              return "ok";
          } 
          catch (Exception e)
          {
              e.printStackTrace();
              return e.getMessage();
          }
      }
  
  }
  
  
  1.22      +4 -0      maven-plugins/announcement/xdocs/changes.xml
  
  Index: changes.xml
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/xdocs/changes.xml,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- changes.xml	22 Jul 2004 11:26:28 -0000	1.21
  +++ changes.xml	7 Aug 2004 15:49:37 -0000	1.22
  @@ -25,6 +25,10 @@
     </properties>
     <body>
       <release version="1.3-SNAPSHOT" date="in CVS">
  +      <action dev="vmassol" type="add" issue="MPANNOUNCEMENT-9" due-to="Felipe Leme">
  +        Added new <code>announcement:mail</code> goal to automatically
  +        send the generated announcement by email.
  +      </action>
         <action dev="vmassol" type="add" issue="MPANNOUNCEMENT-11" due-to="Felipe Leme">
           Added new optional <code>maven.announcement.stylesheet.path</code>property 
           that defines what stylesheet to use to generate the text announcement.
  
  
  
  1.5       +6 -0      maven-plugins/announcement/xdocs/goals.xml
  
  Index: goals.xml
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/xdocs/goals.xml,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- goals.xml	2 Jul 2004 20:57:16 -0000	1.4
  +++ goals.xml	7 Aug 2004 15:49:37 -0000	1.5
  @@ -48,6 +48,12 @@
               found in <code>changes.xml</code>
             </td>
           </tr>
  +        <tr>
  +          <td>announcement:mail</td>
  +          <td>
  +            Send the generated announcement message by email.
  +          </td>
  +        </tr>
         </table>
       </section>
    </body>
  
  
  
  1.10      +48 -0     maven-plugins/announcement/xdocs/properties.xml
  
  Index: properties.xml
  ===================================================================
  RCS file: /home/cvs/maven-plugins/announcement/xdocs/properties.xml,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -r1.9 -r1.10
  --- properties.xml	22 Jul 2004 11:26:28 -0000	1.9
  +++ properties.xml	7 Aug 2004 15:49:37 -0000	1.10
  @@ -1,4 +1,5 @@
   <?xml version="1.0" encoding="ISO-8859-1"?>
  +
   <!-- 
   /*
    * Copyright 2001-2004 The Apache Software Foundation.
  @@ -69,6 +70,53 @@
             </td>
             <td>
               <code>${plugin.resources}/announcement.jsl</code>
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>maven.announcement.mail.server</td>
  +          <td>Required for announcement:mail goal</td>
  +          <td>
  +            Address of the SMTP server used to send the email message.
  +          </td>
  +          <td>none
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>maven.announcement.mail.client</td>
  +          <td>Yes</td>
  +          <td>
  +            Name of the host/domain used to log on the SMTP server.
  +          </td>
  +          <td>localhost
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>maven.announcement.mail.subject</td>
  +          <td>Yes</td>
  +          <td>
  +            Subject of the announcement email message.
  +          </td>
  +          <td>
  +            <code>[ANN] ${pom.name} %VERSION% released</code>
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>maven.announcement.mail.from</td>
  +          <td>Yes</td>
  +          <td>
  +            Sender (email address) of the announcement message.
  +          </td>
  +          <td>
  +            First developer email found in the POM
  +          </td>
  +        </tr>
  +        <tr>
  +          <td>maven.announcement.mail.to</td>
  +          <td>Required for announcement:mail goal</td>
  +          <td>
  +            Comma-separated list of To: address used as recipients of the announcement message.
  +          </td>
  +          <td>none
             </td>
           </tr>
         </table>
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org