continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From eveni...@apache.org
Subject svn commit: r191242 - /maven/continuum/trunk/continuum-notifiers /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification /maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc /maven/continuum/trunk/continuum-plexus-application /maven/continuum/trunk/continuum-plexus-application/src/conf
Date Sat, 18 Jun 2005 01:05:57 GMT
Author: evenisse
Date: Fri Jun 17 18:05:56 2005
New Revision: 191242

URL: http://svn.apache.org/viewcvs?rev=191242&view=rev
Log:
Add a basic IRC notifier

Added:
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/   (with props)
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/pom.xml
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/
    maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
Modified:
    maven/continuum/trunk/continuum-notifiers/pom.xml
    maven/continuum/trunk/continuum-plexus-application/pom.xml
    maven/continuum/trunk/continuum-plexus-application/src/conf/application.xml

Propchange: maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Fri Jun 17 18:05:56 2005
@@ -0,0 +1,3 @@
+.project
+target
+.classpath

Added: maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/pom.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/pom.xml?rev=191242&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/pom.xml (added)
+++ maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/pom.xml Fri Jun 17 18:05:56
2005
@@ -0,0 +1,18 @@
+<project>
+  <modelVersion>4.0.0</modelVersion>
+  <parent>
+    <groupId>org.apache.maven.continuum</groupId>
+    <artifactId>continuum-parent-notifiers</artifactId>
+    <version>1.0-alpha-3-SNAPSHOT</version>
+  </parent>
+  <artifactId>continuum-irc-notifier</artifactId>
+  <name>Continuum IRC Notifier</name>
+  <version>1.0-alpha-3-SNAPSHOT</version>
+  <dependencies>
+    <dependency>
+      <groupId>plexus</groupId>
+      <artifactId>plexus-ircbot</artifactId>
+      <version>1.1-alpha-4-SNAPSHOT</version>
+    </dependency>
+  </dependencies>
+</project>

Added: maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java?rev=191242&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
(added)
+++ maven/continuum/trunk/continuum-notifiers/continuum-irc-notifier/src/main/java/org/apache/maven/continuum/notification/irc/IrcContinuumNotifier.java
Fri Jun 17 18:05:56 2005
@@ -0,0 +1,230 @@
+package org.apache.maven.continuum.notification.irc;
+
+/*
+ * Copyright 2004-2005 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.
+ */
+
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
+import org.apache.maven.continuum.project.ContinuumBuild;
+import org.apache.maven.continuum.project.ContinuumProject;
+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.ircbot.IrcBot;
+import org.codehaus.plexus.notification.NotificationException;
+import org.codehaus.plexus.notification.notifier.AbstractNotifier;
+
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+
+/**
+ * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
+ * @version $Id: $
+ */
+public class IrcContinuumNotifier
+    extends AbstractNotifier
+{
+    // ----------------------------------------------------------------------
+    // Requirements
+    // ----------------------------------------------------------------------
+
+    /** @plexus.configuration */
+    private ContinuumStore store;
+
+    /** @plexus.configuration */
+    private IrcBot ircClient;
+
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private Map configuration;
+
+    // ----------------------------------------------------------------------
+    // Notifier Implementation
+    // ----------------------------------------------------------------------
+
+    public void sendNotification( String source, Set recipients, Map configuration, Map context
)
+        throws NotificationException
+    {
+        this.configuration = configuration;
+
+        ContinuumProject project = (ContinuumProject) context.get( ContinuumNotificationDispatcher.CONTEXT_PROJECT
);
+
+        ContinuumBuild build = (ContinuumBuild) context.get( ContinuumNotificationDispatcher.CONTEXT_BUILD
);
+
+        // ----------------------------------------------------------------------
+        // If there wasn't any building done, don't notify
+        // ----------------------------------------------------------------------
+
+        if ( build == null )
+        {
+            return;
+        }
+
+        // ----------------------------------------------------------------------
+        // Generate and send message
+        // ----------------------------------------------------------------------
+
+        try
+        {
+            if ( source.equals( ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_COMPLETE
) )
+            {
+                buildComplete( project, build, source, recipients );
+            }
+        }
+        catch ( ContinuumException e )
+        {
+            throw new NotificationException( "Error while notifiying.", e );
+        }
+    }
+
+    private void buildComplete( ContinuumProject project, ContinuumBuild build, String source,
Set recipients )
+        throws ContinuumException
+    {
+        // ----------------------------------------------------------------------
+        // Check if the message should be sent at all
+        // ----------------------------------------------------------------------
+
+        ContinuumBuild previousBuild = getPreviousBuild( project, build );
+
+        if ( !shouldNotify( build, previousBuild ) )
+        {
+            return;
+        }
+
+        // ----------------------------------------------------------------------
+        // Send the message
+        // ----------------------------------------------------------------------
+
+        ircClient.connect( (String) configuration.get( "host" ), ( (Integer) configuration.get(
"host" ) ).intValue() );
+
+        ircClient.logon();
+
+        ircClient.sendNotice( (String) configuration.get( "channel" ), generateMessage( project
) );
+
+        ircClient.logoff();
+
+        ircClient.disconnect();
+    }
+
+    private String generateMessage( ContinuumProject project )
+    {
+        int state = project.getState();
+
+        if ( state == ContinuumProjectState.OK )
+        {
+            return "BUILD SUCCESSFUL: " + project.getName();
+        }
+        else if ( state == ContinuumProjectState.FAILED )
+        {
+            return "BUILD FAILURE: " + project.getName();
+        }
+        else if ( state == ContinuumProjectState.ERROR )
+        {
+            return "BUILD ERROR: " + project.getName();
+        }
+        else
+        {
+            getLogger().warn( "Unknown build state " + project.getState() );
+
+            return "ERROR: Unknown build state " + project.getState();
+        }
+    }
+
+    private boolean shouldNotify( ContinuumBuild build, ContinuumBuild 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 ContinuumBuild getPreviousBuild( ContinuumProject project, ContinuumBuild currentBuild
)
+        throws ContinuumException
+    {
+        Collection builds;
+
+        try
+        {
+            builds = store.getBuildsForProject( project.getId(), 0, 0 );
+        }
+        catch ( ContinuumStoreException ex )
+        {
+            throw new ContinuumException( "Error while finding the last project build.",
ex );
+        }
+
+        if ( builds.size() == 0 )
+        {
+            return null;
+        }
+
+        Iterator itr = builds.iterator();
+        ContinuumBuild build = (ContinuumBuild) itr.next();
+
+        if ( currentBuild != null && !build.getId().equals( currentBuild.getId()
) )
+        {
+            throw new ContinuumException( "INTERNAL ERROR: The current build wasn't the first
in the build list. "
+                                          + "Current build: '" + currentBuild.getId() + "',
" + "first build: '"
+                                          + build.getId() + "'." );
+        }
+
+        if ( !itr.hasNext() )
+        {
+            return null;
+        }
+
+        return (ContinuumBuild) itr.next();
+    }
+
+    /**
+     * @see org.codehaus.plexus.notification.notifier.Notifier#sendNotification(java.lang.String,
java.util.Set, java.util.Properties)
+     */
+    public void sendNotification( String arg0, Set arg1, Properties arg2 )
+        throws NotificationException
+    {
+        throw new NotificationException( "Not implemented." );
+    }
+}

Modified: maven/continuum/trunk/continuum-notifiers/pom.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-notifiers/pom.xml?rev=191242&r1=191241&r2=191242&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/pom.xml (original)
+++ maven/continuum/trunk/continuum-notifiers/pom.xml Fri Jun 17 18:05:56 2005
@@ -22,6 +22,7 @@
     </dependency>
   </dependencies>
   <modules>
+    <module>continuum-irc-notifier</module>
     <module>continuum-jabber-notifier</module>
     <module>continuum-msn-notifier</module>
   </modules>

Modified: maven/continuum/trunk/continuum-plexus-application/pom.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-plexus-application/pom.xml?rev=191242&r1=191241&r2=191242&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-plexus-application/pom.xml (original)
+++ maven/continuum/trunk/continuum-plexus-application/pom.xml Fri Jun 17 18:05:56 2005
@@ -38,6 +38,11 @@
      |-->
     <dependency>
       <groupId>org.apache.maven.continuum</groupId>
+      <artifactId>continuum-irc-notifier</artifactId>
+      <version>1.0-alpha-3-SNAPSHOT</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.continuum</groupId>
       <artifactId>continuum-jabber-notifier</artifactId>
       <version>1.0-alpha-3-SNAPSHOT</version>
     </dependency>

Modified: maven/continuum/trunk/continuum-plexus-application/src/conf/application.xml
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-plexus-application/src/conf/application.xml?rev=191242&r1=191241&r2=191242&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-plexus-application/src/conf/application.xml (original)
+++ maven/continuum/trunk/continuum-plexus-application/src/conf/application.xml Fri Jun 17
18:05:56 2005
@@ -112,6 +112,21 @@
     </component>
 
     <!--
+    | The irc notifier
+    |-->
+    <component>
+      <role>org.codehaus.plexus.notification.notifier.Notifier</role>
+      <role-hint>irc</role-hint>
+      <implementation>org.apache.maven.continuum.notification.irc.IrcContinuumNotifier</implementation>
+      <requirements>
+        <requirement>
+          <role>org.codehaus.plexus.ircbot.IrcBot</role>
+          <role-hint>client</role-hint>
+        </requirement>
+      </requirements>
+    </component>
+
+    <!--
     | The jabber notifier
     |-->
     <component>
@@ -122,6 +137,7 @@
         <requirement>
           <role>org.codehaus.plexus.jabber.JabberClient</role>
         </requirement>
+      </requirements>
       <!-- configuration>
         <from-address/>
         <from-password/>
@@ -141,6 +157,7 @@
         <requirement>
           <role>org.codehaus.plexus.msn.MsnClient</role>
         </requirement>
+      </requirements>
       <!-- configuration>
         <from-address/>
         <from-password/>



Mime
View raw message