continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tryg...@apache.org
Subject svn commit: r209095 - in /maven/continuum/trunk/continuum-core/src: main/java/org/apache/maven/continuum/buildcontroller/ main/java/org/apache/maven/continuum/notification/mail/ main/resources/org/apache/maven/continuum/notification/mail/templates/ tes...
Date Mon, 04 Jul 2005 15:50:26 GMT
Author: trygvis
Date: Mon Jul  4 08:50:25 2005
New Revision: 209095

URL: http://svn.apache.org/viewcvs?rev=209095&view=rev
Log:
Fixing CONTINUUM-174.

Modified:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifier.java
    maven/continuum/trunk/continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java?rev=209095&r1=209094&r2=209095&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
(original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/buildcontroller/DefaultBuildController.java
Mon Jul  4 08:50:25 2005
@@ -127,9 +127,9 @@
                     // Check to see if there was a error while checking out the project
                     // ----------------------------------------------------------------------
 
-                    // TODO: remove once CONTINUUM-193 is resolved
                     if ( StringUtils.isEmpty( checkoutErrorMessage ) && StringUtils.isEmpty(
checkoutErrorException ) )
                     {
+                        // TODO: remove once CONTINUUM-193 is resolved
                         UpdateScmResult updateScmResult = new UpdateScmResult();
 
                         updateScmResult.setCommandOutput( checkOutScmResult.getCommandOutput()
);
@@ -190,58 +190,6 @@
                 buildId = storeBuild( project, build );
             }
 
-/////////////////////// This section should delegate to UpdateWorkingDirectoryFromScmContinuumAction
-/*
-/////////////////////// START SECTION
-            // ----------------------------------------------------------------------
-            // Update the project
-            //
-            // If this fails, create a build, store the scm result and set the
-            // build status to error.
-            // ----------------------------------------------------------------------
-
-
-            if ( !update( context ) )
-            {
-                return;
-            }
-/////////////////////// END SECTION
-*/
-/*
-/////////////////////// This section should delegate to UpdateProjectFromWorkingDirectoryContinuumAction
-/////////////////////// START SECTION
-            if ( !updateProjectMetadata( context ) )
-            {
-                return;
-            }
-/////////////////////// END SECTION
-*/
-/*
-/////////////////////// This section should delegate to ExecuteBuilderContinuumAction
-/////////////////////// START SECTION
-
-            // ----------------------------------------------------------------------
-            // Figure out if the project needs to be built
-            // ----------------------------------------------------------------------
-
-            if ( context.scmResult.getUpdatedFiles().size() == 0 &&
-                 !forced &&
-                 !isNew( context.project ) )
-            {
-                getLogger().info( "No files updated, not building. Project id '" + context.project.getId()
+ "'." );
-
-//                Nothing to do, the project doesn't contain any state anymore
-//                store.setBuildNotExecuted( projectId );
-
-                return;
-            }
-
-            makeBuild( context );
-
-            buildProject( context );
-
-/////////////////////// END SECTION
-*/
         }
         catch ( Exception ex )
         {
@@ -270,104 +218,6 @@
         }
     }
 
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-/*
-    private boolean update( BuildContext context )
-        throws ContinuumStoreException
-    {
-        try
-        {
-// No state in the project
-//            store.setIsUpdating( context.project.getId() );
-
-            notifier.checkoutStarted( context.project );
-
-            context.scmResult = scm.updateProject( context.project );
-
-// No state in the project
-//            store.setUpdateDone( context.project.getId() );
-
-            return true;
-        }
-        catch ( ContinuumScmException e )
-        {
-            getLogger().fatalError( "Error while updating from SCM. Project id '" + context.project.getId()
+ "'." );
-
-            makeAndStoreErrorBuildResult( context, e );
-
-            return false;
-        }
-        finally
-        {
-            notifier.checkoutComplete( context.project, context.scmResult );
-        }
-    }
-*/
-/*
-    private boolean updateProjectMetadata( BuildContext context )
-        throws ContinuumStoreException
-    {
-        // TODO: Update the metadata files and then update the project descriptor
-        // before updating the project itself. This will make it possible to migrate
-        // a project from one SCM to another.
-
-        ContinuumProject project = context.project;
-
-        try
-        {
-            continuum.updateProjectFromScm( project.getId() );
-        }
-        catch ( ContinuumException e )
-        {
-            getLogger().fatalError( "Error while updating project metadata from check out.",
e );
-
-            makeAndStoreErrorBuildResult( context, e );
-
-            return false;
-        }
-
-        return true;
-    }
-*/
-/*
-    private void buildProject( BuildContext context )
-        throws ContinuumStoreException
-    {
-        try
-        {
-            notifier.runningGoals( context.project, context.build );
-
-            context.result = context.builder.build( context.project );
-
-            if ( context.result.isSuccess() )
-            {
-                context.state = ContinuumProjectState.OK;
-            }
-            else
-            {
-                context.state = ContinuumProjectState.FAILED;
-            }
-
-            setBuildResult( context.build.getId(),
-                            context.state,
-                            context.result,
-                            context.scmResult,
-                            null );
-        }
-        catch ( Throwable ex )
-        {
-            getLogger().fatalError( "Error building the project, project id: '" + context.project.getId()
+ "'.", ex );
-
-            makeAndStoreErrorBuildResult( context, ex );
-        }
-        finally
-        {
-            notifier.goalsCompleted( context.project, context.build );
-        }
-    }
-*/
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

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=209095&r1=209094&r2=209095&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
Mon Jul  4 08:50:25 2005
@@ -83,7 +83,7 @@
     //
     // ----------------------------------------------------------------------
 
-    private String localHostName;
+    private String buildHost;
 
     private FormatterTool formatterTool;
 
@@ -101,6 +101,17 @@
 
     public void initialize()
     {
+        try
+        {
+            InetAddress address = InetAddress.getLocalHost();
+
+            buildHost = StringUtils.clean( address.getCanonicalHostName() );
+        }
+        catch ( UnknownHostException ex )
+        {
+            fromName = "Continuum";
+        }
+
         // ----------------------------------------------------------------------
         // From mailbox
         // ----------------------------------------------------------------------
@@ -118,22 +129,13 @@
 
         if ( StringUtils.isEmpty( fromName ) )
         {
-            try
-            {
-                InetAddress address = InetAddress.getLocalHost();
-
-                localHostName = address.getCanonicalHostName();
-
-                fromName = "Continuum@" + localHostName;
-            }
-            catch ( UnknownHostException ex )
-            {
-                fromName = "Continuum";
-            }
+            fromName = "Continuum@" + buildHost;
         }
 
         getLogger().info( "From name: " + fromName );
 
+        getLogger().info( "Build host name: " + buildHost );
+
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------
@@ -221,8 +223,6 @@
 
             context.put( "build", build );
 
-            context.put( "build", build );
-
             context.put( "previousBuild", previousBuild );
 
             // ----------------------------------------------------------------------
@@ -233,7 +233,7 @@
 
             // TODO: Make the build host a part of the build
 
-            context.put( "buildHost", localHostName );
+            context.put( "buildHost", buildHost );
 
             // ----------------------------------------------------------------------
             //
@@ -305,7 +305,7 @@
 
         MailMessage message = new MailMessage();
 
-        message.addHeader( "X-Continuum-Host", localHostName );
+        message.addHeader( "X-Continuum-Build-Host", buildHost );
 
         message.addHeader( "X-Continuum-Project-Id", project.getId() );
 

Modified: maven/continuum/trunk/continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm?rev=209095&r1=209094&r2=209095&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm
(original)
+++ maven/continuum/trunk/continuum-core/src/main/resources/org/apache/maven/continuum/notification/mail/templates/common.vm
Mon Jul  4 08:50:25 2005
@@ -14,37 +14,55 @@
  * limitations under the License.
  *#
 #macro( shellBuildResult )
-****************************************************************************
 Build statistics:
   State: $formatter.formatProjectState( $build.state )
 #if ( $previousBuild )
   Previous State: $formatter.formatProjectState( $previousBuild.state )
 #else
-  Previous build: No previous build.
+  Previous Build: No previous build.
 #end
   Started at: $formatter.formatTimestamp( $build.startTime )
   Finished at: $formatter.formatTimestamp( $build.endTime )
   Total time: $formatter.formatInterval( $build.startTime, $build.endTime )
+  Forced: $build.forced
+  Exit code: $build.exitCode
   Building machine hostname: $buildHost
-****************************************************************************
 
-#if ( $buildResult.standardOutput && $buildResult.standardOutput != "" )
+#if ( $build.updateScmResult )
+Changes
+#if ( $build.updateScmResult.updatedFiles.size() == 0 )
+ No files changed
+#else
+ #foreach ( $file in $build.updateScmResult.updatedFiles )
+ * $file.path
+ #end
+#end
+#end
+
+#if ( $build.state == 4 )
 ****************************************************************************
-Standard output:
+Build Error:
 ****************************************************************************
-$buildResult.standardOutput
+$build.error
+#else
+****************************************************************************
+Standard Output:
 ****************************************************************************
+#if ( $build.standardOutput && $build.standardOutput != "" )
+$build.standardOutput
 #else
 There was no content on standard output.
 #end
-
-#if( $buildResult.standardError && $buildResult.standardError != "" )
 ****************************************************************************
-Standard error:
+
 ****************************************************************************
-$buildResult.standardError
+Standard Error:
 ****************************************************************************
+#if( $build.standardError && $build.standardError != "" )
+$build.standardError
 #else
 There was no content on standard error.
 #end
+****************************************************************************
 #end
+#end ## #macro( shellBuildResult )

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java
URL: http://svn.apache.org/viewcvs/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/notification/mail/MailContinuumNotifierTest.java?rev=209095&r1=209094&r2=209095&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
Mon Jul  4 08:50:25 2005
@@ -28,6 +28,8 @@
 import org.apache.maven.continuum.project.ContinuumProject;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.continuum.project.MavenTwoProject;
+import org.apache.maven.continuum.scm.UpdateScmResult;
+import org.apache.maven.continuum.scm.ScmFile;
 
 import org.codehaus.plexus.PlexusTestCase;
 import org.codehaus.plexus.mailsender.MailMessage;
@@ -42,71 +44,103 @@
 public class MailContinuumNotifierTest
     extends PlexusTestCase
 {
-    public void testMailNotification()
+    public void testSuccessfulBuild()
         throws Exception
     {
-        Notifier notifier = (Notifier) lookup( Notifier.ROLE, "mail" );
+        ContinuumProject project = makeProject();
 
-        MockMailSender mailSender = (MockMailSender) lookup( MockMailSender.ROLE );
+        ContinuumBuild build = makeBuild( ContinuumProjectState.OK );
 
-        // ----------------------------------------------------------------------
-        //
-        // ----------------------------------------------------------------------
+        build.setStandardOutput( "stdout" );
 
-        String source = ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_COMPLETE;
+        build.setStandardError( "stderr" );
 
-        Set recipients = new HashSet();
+        MailMessage mailMessage = sendNotificationAndGetMessage( project, build );
 
-        recipients.add( "foo@bar" );
+        dumpContent( mailMessage );
+    }
 
-        Map context =  new HashMap();
+    public void testFailedBuild()
+        throws Exception
+    {
+        ContinuumProject project = makeProject();
 
-        // ----------------------------------------------------------------------
-        // ContinuumProject
-        // ----------------------------------------------------------------------
+        ContinuumBuild build = makeBuild( ContinuumProjectState.FAILED );
 
-        ContinuumProject project = new MavenTwoProject();
+        MailMessage mailMessage = sendNotificationAndGetMessage( project, build );
 
-        project.setName( "Test Project" );
+        build.setStandardOutput( "stdout" );
 
-        project.setExecutorId( MavenTwoBuildExecutor.ID );
+        dumpContent( mailMessage );
+    }
 
-        context.put( ContinuumNotificationDispatcher.CONTEXT_PROJECT, project );
+    public void testErrorenousBuild()
+        throws Exception
+    {
+        ContinuumProject project = makeProject();
 
-        // ----------------------------------------------------------------------
-        // ContinuumBuild
-        // ----------------------------------------------------------------------
+        ContinuumBuild build = makeBuild( ContinuumProjectState.ERROR );
 
-        ContinuumBuild build = new ContinuumBuild();
+        build.setStandardError( "stderr" );
 
-        build.setId( "17" );
+        build.setError( "Big long error message" );
 
-        build.setStartTime( System.currentTimeMillis() );
+        MailMessage mailMessage = sendNotificationAndGetMessage( project, build );
 
-        build.setEndTime( System.currentTimeMillis() + 1234567 );
+        dumpContent( mailMessage );
+    }
 
-        build.setError( null );
+    private void dumpContent( MailMessage mailMessage )
+    {
+//        System.err.println( mailMessage.getContent() );
+    }
 
-        build.setState( ContinuumProjectState.OK );
+    // ----------------------------------------------------------------------
+    //
+    // ----------------------------------------------------------------------
+
+    private MailMessage sendNotificationAndGetMessage( ContinuumProject project,
+                                                       ContinuumBuild build )
+        throws Exception
+    {
+        Set recipients = new HashSet();
+
+        recipients.add( "foo@bar" );
+
+        Map context = new HashMap();
+
+        context.put( ContinuumNotificationDispatcher.CONTEXT_PROJECT, project );
 
         context.put( ContinuumNotificationDispatcher.CONTEXT_BUILD, build );
 
+        context.put( "buildHost", "foo.bar.com" );
+
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------
 
-        notifier.sendNotification( source, recipients, context );
+        Notifier notifier = (Notifier) lookup( Notifier.ROLE, "mail" );
+
+        notifier.sendNotification( ContinuumNotificationDispatcher.MESSAGE_ID_BUILD_COMPLETE,
+                                   recipients,
+                                   context );
 
         // ----------------------------------------------------------------------
         //
         // ----------------------------------------------------------------------
 
+        MockMailSender mailSender = (MockMailSender) lookup( MockMailSender.ROLE );
+
         assertEquals( 1, mailSender.getReceivedEmailSize() );
 
         List mails = CollectionUtils.iteratorToList( mailSender.getReceivedEmail() );
 
         MailMessage mailMessage = (MailMessage) mails.get( 0 );
 
+        // ----------------------------------------------------------------------
+        //
+        // ----------------------------------------------------------------------
+
         assertEquals( "continuum@localhost", mailMessage.getFrom().getMailbox() );
 
         assertEquals( "Continuum", mailMessage.getFrom().getName() );
@@ -118,5 +152,48 @@
         assertEquals( "foo@bar", ( (MailMessage.Address) to.get( 0 ) ).getMailbox() );
 
         assertNull( ( (MailMessage.Address) to.get( 0 ) ).getName() );
+
+        return mailMessage;
+    }
+
+    private ContinuumProject makeProject()
+    {
+        ContinuumProject project = new MavenTwoProject();
+
+        project.setName( "Test Project" );
+
+        project.setExecutorId( MavenTwoBuildExecutor.ID );
+        return project;
+    }
+
+    private ContinuumBuild makeBuild( int state )
+    {
+        ContinuumBuild build = new ContinuumBuild();
+
+        build.setId( "17" );
+
+        build.setStartTime( System.currentTimeMillis() );
+
+        build.setEndTime( System.currentTimeMillis() + 1234567 );
+
+        build.setState( state );
+
+        build.setSuccess( state == ContinuumProjectState.OK );
+
+        build.setForced( true );
+
+        build.setExitCode( 10 );
+
+        UpdateScmResult updateScmResult = new UpdateScmResult();
+
+        ScmFile file = new ScmFile();
+
+        file.setPath( "/hey/yo/lets/go");
+
+        updateScmResult.getUpdatedFiles().add( file );
+
+        build.setUpdateScmResult( updateScmResult );
+
+        return build;
     }
 }



Mime
View raw message