continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r579940 - in /maven/continuum/trunk: continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/ continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/ continuum-webapp/src/main/resources/META-INF/plexus/
Date Thu, 27 Sep 2007 08:24:59 GMT
Author: evenisse
Date: Thu Sep 27 01:24:57 2007
New Revision: 579940

URL: http://svn.apache.org/viewvc?rev=579940&view=rev
Log:
[CONTINUUM-1484] Allow customization of email subject
Submitted by: Tomislav Stojcevich

Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
    maven/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java?rev=579940&r1=579939&r2=579940&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
Thu Sep 27 01:24:57 2007
@@ -128,6 +128,18 @@
      */
     private boolean includeBuildSummary = true;
 
+    /**
+     * Customizable mail subject.  Use any combination of literal text, project or build
attributes.
+     * Examples: 
+     *   "[continuum] BUILD ${state}: ${project.groupId} ${project.name}" results in "[continuum]
BUILD SUCCESSFUL: foo.bar Hello World"
+     *   "[continuum] BUILD ${state}: ${project.name} ${project.scmTag}" results in "[continuum]
BUILD SUCCESSFUL: Hello World Branch001"
+     *   "[continuum] BUILD ${state}: ${project.name} ${build.durationTime}" results in "[continuum]
BUILD SUCCESSFUL: Hello World 2 sec"
+     *   "[continuum] BUILD ${state}: ${project.name}, Build Def - ${build.buildDefinition.description}"
results in "[continuum] BUILD SUCCESSFUL: Hello World, Build Def - Nightly Test Build"
+     * 
+     * @plexus.configuration
+     */
+    private String subjectFormat = "[continuum] BUILD ${state}: ${project.groupId} ${project.name}";
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------
@@ -343,7 +355,12 @@
         // Send the mail
         // ----------------------------------------------------------------------
 
-        String subject = generateSubject( project, build );
+        String subject;
+        try {
+            subject = generateSubject( project, build );
+        } catch ( Exception e ) {
+            throw new NotificationException( "Error while generating mail subject.", e );
+        }
 
         sendMessage( project, recipients, subject, content, configuration );
     }
@@ -414,33 +431,51 @@
             .getVarValue(), executorConfigurator, profile );
     }
 
-    private String generateSubject( Project project, BuildResult build )
+    private String generateSubject( Project project, BuildResult build ) throws Exception
+    {
+        String state = getState( project, build );
+        
+        VelocityContext context = new VelocityContext();
+        context.put( "project", project );
+        context.put( "build", build );
+        context.put( "state", state );
+        
+        StringWriter writer = new StringWriter();
+
+        boolean velocityResults = velocity.getEngine().evaluate( context, writer, "subjectPattern",
subjectFormat );
+            
+        String subject = writer.toString();
+
+        return subject;
+    }
+
+    private String getState( Project project, BuildResult build )
     {
         int state = project.getState();
 
-        if ( build != null )
-        {
+        if ( build != null ) {
             state = build.getState();
         }
 
+
         if ( state == ContinuumProjectState.OK )
         {
-            return "[continuum] BUILD SUCCESSFUL: " + project.getName();
+            return "SUCCESSFUL";
         }
         else if ( state == ContinuumProjectState.FAILED )
         {
-            return "[continuum] BUILD FAILURE: " + project.getName();
+            return "FAILURE";
         }
         else if ( state == ContinuumProjectState.ERROR )
         {
-            return "[continuum] BUILD ERROR: " + project.getName();
+            return "ERROR";
         }
         else
         {
             getLogger().warn( "Unknown build state " + state + " for project " + project.getId()
);
 
-            return "[continuum] ERROR: Unknown build state " + state + " for " + project.getName()
+ " project";
-        }
+            return "ERROR: Unknown build state " + state;
+       }
     }
 
     private void sendMessage( Project project, Set recipients, String subject, String content,
Map configuration )
@@ -478,6 +513,8 @@
         try
         {
             message.setSubject( subject );
+
+            getLogger().info( "Message Subject: '" + subject + "'." );
 
             message.setContent( content );
 

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java?rev=579940&r1=579939&r2=579940&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
(original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
Thu Sep 27 01:24:57 2007
@@ -47,11 +47,14 @@
         throws Exception
     {
         Project project = makeStubProject( "Test Project" );
+        project.setGroupId( "foo.bar" );
 
         BuildResult build = makeBuild( ContinuumProjectState.OK );
 
         MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots out
build output" );
 
+        assertEquals( "[continuum] BUILD SUCCESSFUL: foo.bar Test Project", mailMessage.getSubject()
);
+        
         dumpContent( mailMessage );
     }
 
@@ -59,11 +62,14 @@
         throws Exception
     {
         Project project = makeStubProject( "Test Project" );
+        project.setGroupId( "foo.bar" );
 
         BuildResult build = makeBuild( ContinuumProjectState.FAILED );
 
         MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "output"
);
 
+        assertEquals( "[continuum] BUILD FAILURE: foo.bar Test Project", mailMessage.getSubject()
);
+
         dumpContent( mailMessage );
     }
 
@@ -71,12 +77,15 @@
         throws Exception
     {
         Project project = makeStubProject( "Test Project" );
+        project.setGroupId( "foo.bar" );
 
         BuildResult build = makeBuild( ContinuumProjectState.ERROR );
 
         build.setError( "Big long error message" );
 
         MailMessage mailMessage = sendNotificationAndGetMessage( project, build, "lots of
stack traces" );
+
+        assertEquals( "[continuum] BUILD ERROR: foo.bar Test Project", mailMessage.getSubject()
);
 
         dumpContent( mailMessage );
     }

Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml?rev=579940&r1=579939&r2=579940&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
(original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/META-INF/plexus/application.xml
Thu Sep 27 01:24:57 2007
@@ -119,6 +119,24 @@
         <from-mailbox></from-mailbox>
         <from-name></from-name>
         <timestamp-format>EEE d MMM yyyy HH:mm:ss Z</timestamp-format>
+        <!-- Customizable mail subject.  Use any combination of literal text, or state,
project, or build attributes.
+          Examples: 
+            "[continuum] BUILD ${state}: ${project.groupId} ${project.name}"
+              results in "[continuum] BUILD SUCCESSFUL: foo.bar Hello World"
+            
+            "[continuum] BUILD ${state}: ${project.name} ${project.scmTag}" 
+              results in "[continuum] BUILD SUCCESSFULL: Hello World Branch001"
+            
+            "[continuum] BUILD ${state}: ${project.name} ${project.version}" 
+              results in "[continuum] BUILD SUCCESSFUL: Hello World 2.1-SNAPSHOT"
+            
+            "[continuum] BUILD ${state}: ${project.name} ${build.durationTime}" 
+              results in "[continuum] BUILD SUCCESSFUL: Hello World 2 sec"
+            
+            "[continuum] BUILD ${state}: ${project.name}, Build Def - ${build.buildDefinition.description}"

+              results in "[continuum] BUILD SUCCESSFUL: Hello World, Build Def - Nightly
Test Build"
+         -->
+        <subject-format>[continuum] BUILD ${state}: ${project.projectGroup.name} -
${project.name} - Build Def: ${build.buildDefinition.description}</subject-format>
         <includeBuildResult>true</includeBuildResult>
         <includeBuildSummary>true</includeBuildSummary>
         <alwaysSend>false</alwaysSend>



Mime
View raw message