continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r822971 - in /continuum/branches/continuum-1.3.x/continuum-webapp/src: main/java/org/apache/maven/continuum/web/action/ test/java/org/apache/maven/continuum/web/action/ test/java/org/apache/maven/continuum/web/action/stub/
Date Thu, 08 Oct 2009 00:34:21 GMT
Author: ctan
Date: Thu Oct  8 00:34:21 2009
New Revision: 822971

URL: http://svn.apache.org/viewvc?rev=822971&view=rev
Log:
[CONTINUUM-2367] view build result from distributed build agent only if the user is trying
to view the current build because it is not yet stored in the master's database

Added:
    continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/BuildResultActionTest.java
    continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/BuildResultActionStub.java
Modified:
    continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildAction.java
    continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildResultAction.java

Modified: continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildAction.java?rev=822971&r1=822970&r2=822971&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildAction.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildAction.java
Thu Oct  8 00:34:21 2009
@@ -22,6 +22,7 @@
 import java.util.Set;
 
 import org.apache.continuum.buildmanager.BuildManagerException;
+import org.apache.continuum.buildmanager.BuildsManager;
 import org.apache.continuum.taskqueue.BuildProjectTask;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.project.ContinuumProjectState;
@@ -41,7 +42,9 @@
     protected boolean canRemoveBuildResult( BuildResult buildResult )
         throws BuildManagerException
     {
-        Map<String, BuildProjectTask> currentBuilds = getContinuum().getBuildsManager().getCurrentBuilds();
+        BuildsManager buildsManager = getContinuum().getBuildsManager();
+
+        Map<String, BuildProjectTask> currentBuilds = buildsManager.getCurrentBuilds();
         Set<String> keySet = currentBuilds.keySet();
         for ( String key : keySet )
         {

Modified: continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildResultAction.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildResultAction.java?rev=822971&r1=822970&r2=822971&view=diff
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildResultAction.java
(original)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildResultAction.java
Thu Oct  8 00:34:21 2009
@@ -34,6 +34,7 @@
 import org.apache.continuum.web.util.AuditLogConstants;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.configuration.ConfigurationException;
+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.model.scm.ChangeSet;
@@ -92,9 +93,16 @@
         // check if there are surefire results to display
         project = getContinuum().getProject( getProjectId() );
 
-        if ( getContinuum().getConfiguration().isDistributedBuildEnabled() &&
-            project.getState() == ContinuumProjectState.BUILDING )
+        buildResult = getContinuum().getBuildResult( getBuildId() );
+
+        ConfigurationService configuration = getContinuum().getConfiguration();
+
+        // view build result of the current build from the distributed build agent
+        if ( configuration.isDistributedBuildEnabled() &&
+            project.getState() == ContinuumProjectState.BUILDING && buildResult ==
null )
         {
+            // if the project is currently building in distributed build agent, the build
result will be stored in the database after the build is finished. 
+            // it's safe to assume that the build result will be null at this point
             Map<String, Object> map = distributedBuildManager.getBuildResult( project.getId()
);
 
             if ( map == null )
@@ -110,8 +118,11 @@
 
                 buildOutput = ContinuumBuildConstant.getBuildOutput( map );
 
-                state =
-                    StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath()
);
+                if ( ServletActionContext.getRequest() != null )
+                {
+                    state =
+                        StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath()
);
+                }
             }
             changeSet = null;
 
@@ -121,19 +132,20 @@
         }
         else
         {
-            buildResult = getContinuum().getBuildResult( getBuildId() );
-
             // directory contains files ?
             File surefireReportsDirectory =
-                getContinuum().getConfiguration().getTestReportsDirectory( buildId, getProjectId()
);
+                configuration.getTestReportsDirectory( buildId, getProjectId() );
             File[] files = surefireReportsDirectory.listFiles();
             hasSurefireResults = files != null && files.length > 0;
             changeSet = getContinuum().getChangesSinceLastSuccess( getProjectId(), getBuildId()
);
 
             buildOutput = getBuildOutputText();
 
-            state =
-                StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath()
);
+            if ( ServletActionContext.getRequest() != null )
+            {
+                state =
+                    StateGenerator.generate( buildResult.getState(), ServletActionContext.getRequest().getContextPath()
);
+            }
 
             this.setCanDelete( this.canRemoveBuildResult( buildResult ) );
         }
@@ -204,7 +216,8 @@
     private String getBuildOutputText()
         throws ConfigurationException, IOException
     {
-        File buildOutputFile = getContinuum().getConfiguration().getBuildOutputFile( getBuildId(),
getProjectId() );
+        ConfigurationService configuration = getContinuum().getConfiguration();
+        File buildOutputFile = configuration.getBuildOutputFile( getBuildId(), getProjectId()
);
 
         if ( buildOutputFile.exists() )
         {
@@ -274,4 +287,10 @@
     {
         return projectGroupId;
     }
+
+    // for testing
+    public void setDistributedBuildManager( DistributedBuildManager distributedBuildManager
)
+    {
+        this.distributedBuildManager = distributedBuildManager;
+    }
 }

Added: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/BuildResultActionTest.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/BuildResultActionTest.java?rev=822971&view=auto
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/BuildResultActionTest.java
(added)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/BuildResultActionTest.java
Thu Oct  8 00:34:21 2009
@@ -0,0 +1,96 @@
+package org.apache.maven.continuum.web.action;
+
+import java.io.File;
+import java.util.HashMap;
+
+import org.apache.continuum.builder.distributed.manager.DistributedBuildManager;
+import org.apache.continuum.buildmanager.BuildsManager;
+import org.apache.continuum.taskqueue.BuildProjectTask;
+import org.apache.maven.continuum.Continuum;
+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.web.action.stub.BuildResultActionStub;
+import org.apache.maven.continuum.xmlrpc.project.ContinuumProjectState;
+import org.jmock.Mock;
+import org.jmock.MockObjectTestCase;
+
+public class BuildResultActionTest
+    extends MockObjectTestCase
+{
+    private BuildResultActionStub action;
+
+    private Mock continuum;
+
+    private Mock configurationService;
+
+    private Mock distributedBuildManager;
+
+    private Mock buildsManager;
+
+    protected void setUp()
+    {
+        action = new BuildResultActionStub();
+        continuum = mock( Continuum.class );
+        configurationService = mock( ConfigurationService.class );
+        distributedBuildManager = mock( DistributedBuildManager.class );
+        buildsManager = mock( BuildsManager.class );
+
+        action.setContinuum( (Continuum) continuum.proxy() );
+        action.setDistributedBuildManager( (DistributedBuildManager) distributedBuildManager.proxy()
);
+    }
+
+    public void testViewPreviousBuild()
+        throws Exception
+    {
+        Project project = createProject( "stub-project" );
+        BuildResult buildResult = createBuildResult( project );
+
+        continuum.expects( once() ).method( "getProject" ).will( returnValue( project ) );
+        continuum.expects( once() ).method( "getBuildResult" ).will( returnValue( buildResult
) );
+        continuum.expects( atLeastOnce() ).method( "getConfiguration" ).will( returnValue(
(ConfigurationService) configurationService.proxy()  ) );
+        configurationService.expects( once() ).method( "isDistributedBuildEnabled" ).will(
returnValue( false ) );
+        configurationService.expects( once() ).method( "getTestReportsDirectory" ).will(
returnValue( new File( "testReportsDir" ) ) );
+        continuum.expects( once() ).method( "getChangesSinceLastSuccess" ).will( returnValue(
null ) );
+        configurationService.expects( once() ).method( "getBuildOutputFile" ).will( returnValue(
new File( "buildOutputFile" ) ) );
+        continuum.expects( once() ).method( "getBuildsManager" ).will( returnValue( buildsManager.proxy()
) );
+        buildsManager.expects( once() ).method( "getCurrentBuilds" ).will( returnValue( new
HashMap<String, BuildProjectTask>() ) );
+
+        action.execute();
+    }
+
+    public void testViewCurrentBuildInDistributedBuildAgent()
+        throws Exception
+    {
+        Project project = createProject( "stub-project" );
+
+        continuum.expects( once() ).method( "getProject" ).will( returnValue( project ) );
+        continuum.expects( once() ).method( "getBuildResult" ).will( returnValue( null )
);
+        continuum.expects( once() ).method( "getConfiguration" ).will( returnValue( (ConfigurationService)
configurationService.proxy()  ) );
+        configurationService.expects( once() ).method( "isDistributedBuildEnabled" ).will(
returnValue( true ) );
+        distributedBuildManager.expects( once() ).method( "getBuildResult" ).will( returnValue(
new HashMap<String, Object>() ) );
+
+        action.execute();
+    }
+
+    private Project createProject( String name )
+    {
+        Project project = new Project();
+        project.setId( 1 );
+        project.setName( name );
+        project.setArtifactId( "foo:bar" );
+        project.setVersion( "1.0" );
+        project.setState( ContinuumProjectState.BUILDING );
+
+        return project;
+    }
+
+    private BuildResult createBuildResult( Project project )
+    {
+        BuildResult buildResult = new BuildResult();
+        buildResult.setId( 1 );
+        buildResult.setProject( project );
+
+        return buildResult;
+    }
+}

Added: continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/BuildResultActionStub.java
URL: http://svn.apache.org/viewvc/continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/BuildResultActionStub.java?rev=822971&view=auto
==============================================================================
--- continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/BuildResultActionStub.java
(added)
+++ continuum/branches/continuum-1.3.x/continuum-webapp/src/test/java/org/apache/maven/continuum/web/action/stub/BuildResultActionStub.java
Thu Oct  8 00:34:21 2009
@@ -0,0 +1,17 @@
+package org.apache.maven.continuum.web.action.stub;
+
+import org.apache.maven.continuum.web.action.BuildResultAction;
+
+public class BuildResultActionStub
+    extends BuildResultAction
+{
+    public String getProjectGroupName()
+    {
+        return "test-group";
+    }
+    
+    protected void checkViewProjectGroupAuthorization( String resource )
+    {
+        // skip authorization check
+    }
+}



Mime
View raw message