continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r332026 - in /maven/continuum/trunk: continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/ continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/ continuum-notifiers/continuum-...
Date Wed, 09 Nov 2005 12:30:58 GMT
Author: evenisse
Date: Wed Nov  9 04:30:31 2005
New Revision: 332026

URL: http://svn.apache.org/viewcvs?rev=332026&view=rev
Log:
o define build state in message to project state if build result doens't exist
o put shouldNotify method in AbstractContinuumNotifier

Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-jabber/src/main/java/org/apache/maven/continuum/notification/jabber/JabberContinuumNotifier.java
    maven/continuum/trunk/continuum-notifiers/continuum-notifier-msn/src/main/java/org/apache/maven/continuum/notification/msn/MsnContinuumNotifier.java

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java?rev=332026&r1=332025&r2=332026&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
Wed Nov  9 04:30:31 2005
@@ -317,7 +317,7 @@
 
     private String generateSubject( Project project, BuildResult build )
     {
-        int state = -1;
+        int state = project.getState();
 
         if ( build != null )
         {
@@ -427,39 +427,6 @@
         }
 
         return address;
-    }
-
-    private boolean shouldNotify( BuildResult build, BuildResult previousBuild )
-    {
-        if ( build == null )
-        {
-            return true;
-        }
-
-        // Always send if the project failed
-        if ( build.getState() == ContinuumProjectState.FAILED || build.getState() == ContinuumProjectState.ERROR
)
-        {
-            return true;
-        }
-
-        // Send if this is the first build
-        if ( previousBuild == null )
-        {
-            return true;
-        }
-
-        // Send if the state has changed
-        getLogger().info(
-            "Current build state: " + build.getState() + ", previous build state: " + previousBuild.getState()
);
-
-        if ( build.getState() != previousBuild.getState() )
-        {
-            return true;
-        }
-
-        getLogger().info( "Same state, not sending mail." );
-
-        return false;
     }
 
     private BuildResult getPreviousBuild( Project project, BuildResult currentBuild )

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java?rev=332026&r1=332025&r2=332026&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-api/src/main/java/org/apache/maven/continuum/notification/AbstractContinuumNotifier.java
Wed Nov  9 04:30:31 2005
@@ -21,6 +21,7 @@
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.codehaus.plexus.notification.notifier.AbstractNotifier;
 
 public abstract class AbstractContinuumNotifier
@@ -59,5 +60,38 @@
         {
             throw new ContinuumException( "Can't obtain the base url from configuration.",
e );
         }
+    }
+
+    public boolean shouldNotify( BuildResult build, BuildResult previousBuild )
+    {
+        if ( build == null )
+        {
+            return true;
+        }
+
+        // Always send if the project failed
+        if ( build.getState() == ContinuumProjectState.FAILED || build.getState() == ContinuumProjectState.ERROR
)
+        {
+            return true;
+        }
+
+        // Send if this is the first build
+        if ( previousBuild == null )
+        {
+            return true;
+        }
+
+        // Send if the state has changed
+        getLogger().info(
+            "Current build state: " + build.getState() + ", previous build state: " + previousBuild.getState()
);
+
+        if ( build.getState() != previousBuild.getState() )
+        {
+            return true;
+        }
+
+        getLogger().info( "Same state, not sending message." );
+
+        return false;
     }
 }

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java?rev=332026&r1=332025&r2=332026&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-irc/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
Wed Nov  9 04:30:31 2005
@@ -185,7 +185,7 @@
     private String generateMessage( Project project, BuildResult build )
         throws ContinuumException
     {
-        int state = -1;
+        int state = project.getState();
 
         if ( build != null )
         {
@@ -214,39 +214,6 @@
         }
 
         return message + " " + getReportUrl( project, build, configurationService );
-    }
-
-    private boolean shouldNotify( BuildResult build, BuildResult previousBuild )
-    {
-        if ( build == null )
-        {
-            return true;
-        }
-
-        // Always send if the project failed
-        if ( build.getState() == ContinuumProjectState.FAILED || build.getState() == ContinuumProjectState.ERROR
)
-        {
-            return true;
-        }
-
-        // Send if this is the first build
-        if ( previousBuild == null )
-        {
-            return true;
-        }
-
-        // Send if the state has changed
-        getLogger().info(
-            "Current build state: " + build.getState() + ", previous build state: " + previousBuild.getState()
);
-
-        if ( build.getState() != previousBuild.getState() )
-        {
-            return true;
-        }
-
-        getLogger().info( "Same state, not sending message." );
-
-        return false;
     }
 
     private BuildResult getPreviousBuild( Project project, BuildResult currentBuild )

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-jabber/src/main/java/org/apache/maven/continuum/notification/jabber/JabberContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-notifier-jabber/src/main/java/org/apache/maven/continuum/notification/jabber/JabberContinuumNotifier.java?rev=332026&r1=332025&r2=332026&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-jabber/src/main/java/org/apache/maven/continuum/notification/jabber/JabberContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-jabber/src/main/java/org/apache/maven/continuum/notification/jabber/JabberContinuumNotifier.java
Wed Nov  9 04:30:31 2005
@@ -23,11 +23,14 @@
 import org.apache.maven.continuum.notification.AbstractContinuumNotifier;
 import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.jabber.JabberClient;
 import org.codehaus.plexus.jabber.JabberClientException;
 import org.codehaus.plexus.notification.NotificationException;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -53,6 +56,11 @@
      */
     private ConfigurationService configurationService;
 
+    /**
+     * @plexus.configuration
+     */
+    private ContinuumStore store;
+
     // ----------------------------------------------------------------------
     // Configuration
     // ----------------------------------------------------------------------
@@ -126,7 +134,7 @@
     private String generateMessage( Project project, BuildResult build )
         throws ContinuumException
     {
-        int state = -1;
+        int state = project.getState();
 
         if ( build != null )
         {
@@ -162,6 +170,17 @@
     {
         String message;
 
+        // ----------------------------------------------------------------------
+        // Check if the mail should be sent at all
+        // ----------------------------------------------------------------------
+
+        BuildResult previousBuild = getPreviousBuild( project, build );
+
+        if ( !shouldNotify( build, previousBuild ) )
+        {
+            return;
+        }
+
         try
         {
             message = generateMessage( project, build );
@@ -218,6 +237,39 @@
 
             }
         }
+    }
+
+    private BuildResult getPreviousBuild( Project project, BuildResult currentBuild )
+        throws NotificationException
+    {
+        try
+        {
+            // TODO: prefer to remove this and get them up front
+            if ( project.getId() > 0 )
+            {
+                project = store.getProjectWithBuilds( project.getId() );
+            }
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new NotificationException( "Unable to obtain project builds", e );
+        }
+        List builds = project.getBuildResults();
+
+        if ( builds.size() < 2 )
+        {
+            return null;
+        }
+
+        BuildResult build = (BuildResult) builds.get( builds.size() - 1 );
+
+        if ( currentBuild != null && build.getId() != currentBuild.getId() )
+        {
+            throw new NotificationException( "INTERNAL ERROR: The current build wasn't the
first in the build list. " +
+                "Current build: '" + currentBuild.getId() + "', " + "first build: '" + build.getId()
+ "'." );
+        }
+
+        return (BuildResult) builds.get( builds.size() - 2 );
     }
 
     public void sendNotification( String arg0, Set arg1, Properties arg2 )

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-msn/src/main/java/org/apache/maven/continuum/notification/msn/MsnContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-notifier-msn/src/main/java/org/apache/maven/continuum/notification/msn/MsnContinuumNotifier.java?rev=332026&r1=332025&r2=332026&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-msn/src/main/java/org/apache/maven/continuum/notification/msn/MsnContinuumNotifier.java
(original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-msn/src/main/java/org/apache/maven/continuum/notification/msn/MsnContinuumNotifier.java
Wed Nov  9 04:30:31 2005
@@ -23,11 +23,14 @@
 import org.apache.maven.continuum.notification.AbstractContinuumNotifier;
 import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.msn.MsnClient;
 import org.codehaus.plexus.msn.MsnException;
 import org.codehaus.plexus.notification.NotificationException;
 
 import java.util.Iterator;
+import java.util.List;
 import java.util.Map;
 import java.util.Properties;
 import java.util.Set;
@@ -53,6 +56,11 @@
      */
     private ConfigurationService configurationService;
 
+    /**
+     * @plexus.configuration
+     */
+    private ContinuumStore store;
+
     // ----------------------------------------------------------------------
     // Configuration
     // ----------------------------------------------------------------------
@@ -110,7 +118,12 @@
     private String generateMessage( Project project, BuildResult build )
         throws ContinuumException
     {
-        int state = build.getState();
+        int state = project.getState();
+
+        if ( build != null )
+        {
+            state = build.getState();
+        }
 
         String message;
 
@@ -141,6 +154,17 @@
     {
         String message;
 
+        // ----------------------------------------------------------------------
+        // Check if the message should be sent at all
+        // ----------------------------------------------------------------------
+
+        BuildResult previousBuild = getPreviousBuild( project, build );
+
+        if ( !shouldNotify( build, previousBuild ) )
+        {
+            return;
+        }
+
         try
         {
             message = generateMessage( project, build );
@@ -180,6 +204,39 @@
 
             }
         }
+    }
+
+    private BuildResult getPreviousBuild( Project project, BuildResult currentBuild )
+        throws NotificationException
+    {
+        try
+        {
+            // TODO: prefer to remove this and get them up front
+            if ( project.getId() > 0 )
+            {
+                project = store.getProjectWithBuilds( project.getId() );
+            }
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new NotificationException( "Unable to obtain project builds", e );
+        }
+        List builds = project.getBuildResults();
+
+        if ( builds.size() < 2 )
+        {
+            return null;
+        }
+
+        BuildResult build = (BuildResult) builds.get( builds.size() - 1 );
+
+        if ( currentBuild != null && build.getId() != currentBuild.getId() )
+        {
+            throw new NotificationException( "INTERNAL ERROR: The current build wasn't the
first in the build list. " +
+                "Current build: '" + currentBuild.getId() + "', " + "first build: '" + build.getId()
+ "'." );
+        }
+
+        return (BuildResult) builds.get( builds.size() - 2 );
     }
 
     /**



Mime
View raw message