continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r699511 - in /continuum/trunk: ./ continuum-core/ continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/ continuum-core/src/main/resources/META-INF/ continuum-core/src/test/java/org/apache/continuum/notification/ continu...
Date Fri, 26 Sep 2008 21:36:40 GMT
Author: olamy
Date: Fri Sep 26 14:36:39 2008
New Revision: 699511

URL: http://svn.apache.org/viewvc?rev=699511&view=rev
Log:
 merge -r699508:699509 from 1.2.x branch
fix [CONTINUUM-1842]


Added:
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/notification/
      - copied from r699509, continuum/branches/continuum-1.2.x/continuum-core/src/test/java/org/apache/continuum/notification/
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/notification/mail/
      - copied from r699509, continuum/branches/continuum-1.2.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/
    continuum/trunk/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java
      - copied unchanged from r699509, continuum/branches/continuum-1.2.x/continuum-core/src/test/java/org/apache/continuum/notification/mail/MockJavaMailSender.java
Modified:
    continuum/trunk/continuum-core/pom.xml
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
    continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
    continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.xml
    continuum/trunk/continuum-webapp/pom.xml
    continuum/trunk/continuum-webapp/src/   (props changed)
    continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
    continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml
    continuum/trunk/pom.xml

Modified: continuum/trunk/continuum-core/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/pom.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-core/pom.xml (original)
+++ continuum/trunk/continuum-core/pom.xml Fri Sep 26 14:36:39 2008
@@ -167,6 +167,16 @@
       <artifactId>archiva-repository-layer</artifactId>
       <version>${archiva.version}</version>
     </dependency>
+    <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+    </dependency>    
+    <dependency>
+      <groupId>javax.mail</groupId>
+      <artifactId>mail</artifactId>
+      <version>1.4</version>
+      <scope>provided</scope>
+    </dependency>    
     <!-- === Testing Dependencies === -->
     <dependency>
       <groupId>hsqldb</groupId>

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
Fri Sep 26 14:36:39 2008
@@ -19,6 +19,23 @@
  * under the License.
  */
 
+import java.io.StringWriter;
+import java.io.UnsupportedEncodingException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.Address;
+import javax.mail.Message;
+import javax.mail.MessagingException;
+import javax.mail.internet.AddressException;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+
 import org.apache.maven.continuum.Continuum;
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.execution.ExecutorConfigurator;
@@ -45,23 +62,12 @@
 import org.apache.maven.continuum.reports.surefire.ReportTestSuiteGenerator;
 import org.apache.velocity.VelocityContext;
 import org.apache.velocity.exception.ResourceNotFoundException;
-import org.codehaus.plexus.mailsender.MailMessage;
-import org.codehaus.plexus.mailsender.MailSender;
-import org.codehaus.plexus.mailsender.MailSenderException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.velocity.VelocityComponent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-
-import java.io.StringWriter;
-import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import org.springframework.mail.javamail.JavaMailSender;
 
 /**
  * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
@@ -93,9 +99,9 @@
     private Continuum continuum;
 
     /**
-     * @plexus.configuration
+     * @plexus.requirement
      */
-    private MailSender mailSender;
+    private JavaMailSender javaMailSender;
 
     /**
      * @plexus.requirement
@@ -538,23 +544,26 @@
             return;
         }
 
-        MailMessage message = new MailMessage();
-
-        message.addHeader( "X-Continuum-Build-Host", buildHost );
 
-        message.addHeader( "X-Continuum-Project-Id", Integer.toString( project.getId() )
);
-
-        message.addHeader( "X-Continuum-Project-Name", project.getName() );
 
         try
         {
+            
+            MimeMessage message = javaMailSender.createMimeMessage();
+            
+            message.addHeader( "X-Continuum-Build-Host", buildHost );
+
+            message.addHeader( "X-Continuum-Project-Id", Integer.toString( project.getId()
) );
+
+            message.addHeader( "X-Continuum-Project-Name", project.getName() );         
  
+            
             message.setSubject( subject );
 
             log.info( "Message Subject: '" + subject + "'." );
 
-            message.setContent( content );
+            message.setText( content );
 
-            MailMessage.Address from = new MailMessage.Address( fromMailbox, fromName );
+            InternetAddress from = new InternetAddress( fromMailbox, fromName );
 
             message.setFrom( from );
 
@@ -572,18 +581,19 @@
                         if ( StringUtils.isNotEmpty( addressField ) )
                         {
                             String[] addresses = StringUtils.split( addressField, "," );
-
+                            List<Address> recipients = new ArrayList<Address>();
                             for ( String address : addresses )
                             {
                                 // TODO: set a proper name
-                                MailMessage.Address to = new MailMessage.Address( address.trim()
);
+                            	InternetAddress to = new InternetAddress( address.trim() );
 
                                 log.info( "Recipient: To '" + to + "'." );
 
-                                message.addTo( to );
+                                recipients.add( to );
                             }
+                            message.setRecipients(Message.RecipientType.TO, recipients.toArray(new
Address[recipients.size()]));
                         }
-
+                        
                         String committerField = (String) notifier.getConfiguration().get(
COMMITTER_FIELD );
                         if ( StringUtils.isNotEmpty( committerField ) && context.getBuildResult()
!= null )
                         {
@@ -620,11 +630,10 @@
                                             else
                                             {
                                                 // TODO: set a proper name
-                                                MailMessage.Address to = new MailMessage.Address(
email.trim() );
-
+                                                InternetAddress to = new InternetAddress(
email.trim() );
                                                 log.info( "Recipient: To '" + to + "'." );
 
-                                                message.addTo( to );
+                                                message.addRecipient( Message.RecipientType.TO,
to );
                                             }
                                         }
                                     }
@@ -638,19 +647,27 @@
             {
                 // TODO: use configuration file instead of to load it fron component configuration
                 // TODO: set a proper name
-                MailMessage.Address to = new MailMessage.Address( toOverride.trim() );
-
+                InternetAddress to = new InternetAddress( toOverride.trim() );
                 log.info( "Recipient: To '" + to + "'." );
 
-                message.addTo( to );
+                message.addRecipient( Message.RecipientType.TO, to );
             }
 
-            mailSender.send( message );
+            javaMailSender.send( message );
+            //mailSender.send( message );
+        }
+        catch ( AddressException ex )
+        {
+            throw new NotificationException( "Exception while sending message.", ex );
         }
-        catch ( MailSenderException ex )
+        catch ( MessagingException ex )
         {
             throw new NotificationException( "Exception while sending message.", ex );
         }
+        catch ( UnsupportedEncodingException ex )
+        {
+            throw new NotificationException( "Exception while sending message.", ex );
+        }         
     }
 
     private Map<String, String> mapDevelopersToRecipients( List<ProjectDeveloper>
developers )

Modified: continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml (original)
+++ continuum/trunk/continuum-core/src/main/resources/META-INF/spring-context.xml Fri Sep
26 14:36:39 2008
@@ -32,4 +32,5 @@
       <bean class="org.apache.maven.continuum.notification.manager.spring.NotifierFactoryBean"/>
     </property>
   </bean>
+  
 </beans>

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
Fri Sep 26 14:36:39 2008
@@ -19,6 +19,17 @@
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.mail.Address;
+import javax.mail.internet.InternetAddress;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.MimeMessage.RecipientType;
+
+import org.apache.continuum.notification.mail.MockJavaMailSender;
 import org.apache.maven.continuum.AbstractContinuumTest;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
@@ -27,15 +38,9 @@
 import org.apache.maven.continuum.notification.MessageContext;
 import org.apache.maven.continuum.notification.Notifier;
 import org.apache.maven.continuum.project.ContinuumProjectState;
-import org.codehaus.plexus.mailsender.MailMessage;
-import org.codehaus.plexus.mailsender.MailSender;
-import org.codehaus.plexus.mailsender.test.MockMailSender;
-import org.codehaus.plexus.util.CollectionUtils;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.mail.javamail.JavaMailSender;
 
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
@@ -44,18 +49,22 @@
 public class MailContinuumNotifierTest
     extends AbstractContinuumTest
 {
+    
+    protected Logger logger = LoggerFactory.getLogger( getClass() );
+    
     public void testSuccessfulBuild()
         throws Exception
     {
         MailContinuumNotifier notifier = (MailContinuumNotifier) lookup( Notifier.class.getName(),
"mail" );
-        notifier.setToOverride( "recipient@host.com" );
+        String toOverride = "recipient@host.com";
+        notifier.setToOverride( toOverride );
 
         Project project = makeStubProject( "Test Project" );
         project.setGroupId( "foo.bar" );
 
         BuildResult build = makeBuild( ContinuumProjectState.OK );
 
-        MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots out
build output" );
+        MimeMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots out
build output", toOverride );
 
         assertEquals( "[continuum] BUILD SUCCESSFUL: foo.bar Test Project", mailMessage.getSubject()
);
 
@@ -70,7 +79,7 @@
 
         BuildResult build = makeBuild( ContinuumProjectState.FAILED );
 
-        MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "output"
);
+        MimeMessage mailMessage = sendNotificationAndGetMessage( project, build, "output",
null );
 
         assertEquals( "[continuum] BUILD FAILURE: foo.bar Test Project", mailMessage.getSubject()
);
 
@@ -87,38 +96,39 @@
 
         build.setError( "Big long error message" );
 
-        MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots of
stack traces" );
+        MimeMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots of
stack traces", null );
 
         assertEquals( "[continuum] BUILD ERROR: foo.bar Test Project", mailMessage.getSubject()
);
 
         dumpContent( mailMessage );
     }
 
-    private void dumpContent( MailMessage mailMessage )
+    private void dumpContent( MimeMessage mailMessage )
         throws Exception
     {
         dumpContent( mailMessage, null );
     }
 
-    private void dumpContent( MailMessage mailMessage, String toOverride )
+    private void dumpContent( MimeMessage mailMessage, String toOverride )
         throws Exception
     {
+        Address[] tos  = mailMessage.getRecipients( RecipientType.TO );
         if ( toOverride != null )
         {
-            assertEquals( toOverride, ( (MailMessage.Address) mailMessage.getToAddresses().get(
0 ) ).getMailbox() );
+            assertEquals( toOverride, ( (InternetAddress) tos[ 0 ] ).getAddress() );
         }
         else
         {
-            assertEquals( "foo@bar", ( (MailMessage.Address) mailMessage.getToAddresses().get(
0 ) ).getMailbox() );
+            assertEquals( "foo@bar", ( (InternetAddress) tos[ 0 ] ).getAddress() );
         }
         assertTrue( "The template isn't loaded correctly.",
-                    mailMessage.getContent().indexOf( "#shellBuildResult()" ) < 0 );
+                    ((String)mailMessage.getContent()).indexOf( "#shellBuildResult()" ) <
0 );
         assertTrue( "The template isn't loaded correctly.",
-                    mailMessage.getContent().indexOf( "Build statistics" ) > 0 );
+                    ((String)mailMessage.getContent()).indexOf( "Build statistics" ) >
0 );
 
         if ( true )
         {
-            System.err.println( mailMessage.getContent() );
+            logger.info( ((String)mailMessage.getContent()) );
         }
     }
 
@@ -126,7 +136,7 @@
     //
     // ----------------------------------------------------------------------
 
-    private MailMessage sendNotificationAndGetMessage( Project project, BuildResult build,
String buildOutput )
+    private MimeMessage sendNotificationAndGetMessage( Project project, BuildResult build,
String buildOutput, String toOverride )
         throws Exception
     {
         MessageContext context = new MessageContext();
@@ -162,29 +172,27 @@
         //
         // ----------------------------------------------------------------------
 
-        MockMailSender mailSender = (MockMailSender) lookup( MailSender.ROLE );
+        MockJavaMailSender mailSender = (MockJavaMailSender) lookup( JavaMailSender.class,
"continuum" );
 
-        assertEquals( 1, mailSender.getReceivedEmailSize() );
+        assertEquals( 1, mailSender.getReceivedEmails().size() );
 
-        List mails = CollectionUtils.iteratorToList( mailSender.getReceivedEmail() );
+        List<MimeMessage> mails = mailSender.getReceivedEmails();
 
-        MailMessage mailMessage = (MailMessage) mails.get( 0 );
+        MimeMessage mailMessage = (MimeMessage) mails.get( 0 );
 
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------
 
-        assertEquals( "continuum@localhost", mailMessage.getFrom().getMailbox() );
-
-        assertEquals( "Continuum", mailMessage.getFrom().getName() );
+        assertEquals( "continuum@localhost", ((InternetAddress) mailMessage.getFrom()[0]).getAddress()
);
 
-        List to = mailMessage.getToAddresses();
+        assertEquals( "Continuum", ((InternetAddress) mailMessage.getFrom()[0]).getPersonal()
);
 
-        assertEquals( 1, to.size() );
+        Address[] tos  = mailMessage.getRecipients( RecipientType.TO );
 
-        //assertEquals( "foo@bar", ( (MailMessage.Address) to.get( 0 ) ).getMailbox() );
+        assertEquals( 1, tos.length );
 
-        assertNull( ( (MailMessage.Address) to.get( 0 ) ).getName() );
+        assertEquals(toOverride == null ? "foo@bar" : toOverride, ( (InternetAddress) tos[0]
).getAddress() );
 
         return mailMessage;
     }

Modified: continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.xml
(original)
+++ continuum/trunk/continuum-core/src/test/resources/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.xml
Fri Sep 26 14:36:39 2008
@@ -21,8 +21,9 @@
   <components>
 
     <component>
-      <role>org.codehaus.plexus.mailsender.MailSender</role>
-      <implementation>org.codehaus.plexus.mailsender.test.MockMailSender</implementation>
+      <role>org.springframework.mail.javamail.JavaMailSender</role>
+      <implementation>org.apache.continuum.notification.mail.MockJavaMailSender</implementation>
+      <role-hint>continuum</role-hint>
     </component>
 
     <component>
@@ -40,7 +41,9 @@
           <role>org.apache.continuum.dao.BuildResultDao</role>
         </requirement>
         <requirement>
-          <role>org.codehaus.plexus.mailsender.MailSender</role>
+          <field-name>javaMailSender</field-name>
+          <role>javaMailSender</role>
+          <role-hint>continuum</role-hint>
         </requirement>
         <requirement>
           <role>org.apache.maven.continuum.Continuum</role>

Modified: continuum/trunk/continuum-webapp/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/pom.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/pom.xml (original)
+++ continuum/trunk/continuum-webapp/pom.xml Fri Sep 26 14:36:39 2008
@@ -516,6 +516,10 @@
       <artifactId>spring-web</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.springframework</groupId>
+      <artifactId>spring-context-support</artifactId>
+    </dependency>    
+    <dependency>
       <groupId>jmock</groupId>
       <artifactId>jmock</artifactId>
       <scope>test</scope>
@@ -600,6 +604,26 @@
           </plugin>
         </plugins>
       </build>
+    </profile>
+    <profile>
+      <!-- local dev settings use a file which is ignore in svn -->
+      <id>local-jetty-env</id>
+      <activation>
+        <file>
+          <exists>src/local-jettyenv.xml</exists>
+        </file>
+      </activation>
+      <build>
+        <plugins>
+          <plugin>
+            <groupId>org.mortbay.jetty</groupId>
+            <artifactId>maven-jetty-plugin</artifactId>
+            <configuration>
+              <jettyEnvXml>src/local-jettyenv.xml</jettyEnvXml>
+            </configuration>
+          </plugin>
+        </plugins>
+      </build>      
     </profile>  
   </profiles>
 </project>

Propchange: continuum/trunk/continuum-webapp/src/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Sep 26 14:36:39 2008
@@ -0,0 +1 @@
+local-jettyenv.xml

Modified: continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml (original)
+++ continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml Fri
Sep 26 14:36:39 2008
@@ -57,7 +57,8 @@
           <role>org.apache.continuum.dao.BuildResultDao</role>
         </requirement>
         <requirement>
-          <role>org.codehaus.plexus.mailsender.MailSender</role>
+          <role>mailSender</role>
+          <role-hint>continuum</role-hint>
         </requirement>
         <requirement>
           <role>org.apache.maven.continuum.configuration.ConfigurationService</role>
@@ -113,7 +114,8 @@
         <to-override></to-override>
       </configuration>
     </component>
-
+  
+    <!-- TODO remove when redback will not use anymore plexus-mail -->
     <component>
       <role>org.codehaus.plexus.mailsender.MailSender</role>
       <implementation>org.codehaus.plexus.mailsender.javamail.JndiJavamailMailSender</implementation>

Modified: continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml (original)
+++ continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/applicationContext.xml Fri Sep
26 14:36:39 2008
@@ -59,4 +59,14 @@
       <bean class="org.apache.continuum.scm.manager.spring.ScmProviderFactoryBean"/>
     </property>
   </bean>
+  
+  <bean id="mailSession" class="org.springframework.jndi.JndiObjectFactoryBean">
+    <property name="jndiName" value="java:comp/env/mail/Session">
+    </property>
+  </bean>  
+  
+  <bean name="mailSender#continuum" class="org.springframework.mail.javamail.JavaMailSenderImpl">
+    <property name="session" ref="mailSession"/>
+  </bean>   
+  
 </beans>

Modified: continuum/trunk/pom.xml
URL: http://svn.apache.org/viewvc/continuum/trunk/pom.xml?rev=699511&r1=699510&r2=699511&view=diff
==============================================================================
--- continuum/trunk/pom.xml (original)
+++ continuum/trunk/pom.xml Fri Sep 26 14:36:39 2008
@@ -928,6 +928,11 @@
       </dependency>
       <dependency>
         <groupId>org.springframework</groupId>
+        <artifactId>spring-context-support</artifactId>
+        <version>${spring.version}</version>
+      </dependency>      
+      <dependency>
+        <groupId>org.springframework</groupId>
         <artifactId>spring-core</artifactId>
         <version>${spring.version}</version>
       </dependency>



Mime
View raw message