continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From c...@apache.org
Subject svn commit: r743956 - in /continuum/trunk: continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/ continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ continuum-buildagent/continuum-builda...
Date Fri, 13 Feb 2009 02:18:12 GMT
Author: ctan
Date: Fri Feb 13 02:18:11 2009
New Revision: 743956

URL: http://svn.apache.org/viewvc?rev=743956&view=rev
Log:
[CONTINUUM-2070] logged scm changes and added check if should build


Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/AbstractBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ContinuumAgentBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ant/AntBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m1/MavenOneBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m2/MavenTwoBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/shell/ShellBuildExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/BuildAgentManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/BuildAgentTaskQueueManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultBuildAgentTaskQueueManager.java
    continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
    continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
    continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
    continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-api/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportService.java
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
    continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportServer.java
    continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java (original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/continuum/builder/distributed/manager/DistributedBuildManager.java Fri Feb 13 02:18:11 2009
@@ -66,4 +66,6 @@
 
     void updateProject( Map context )
         throws ContinuumException;
+
+    boolean shouldBuild( Map context );
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/ContinuumBuildAgentServiceImpl.java Fri Feb 13 02:18:11 2009
@@ -256,7 +256,7 @@
             context.setTrigger( ContinuumBuildAgentUtil.getTrigger( map ) );
             context.setLocalRepository( ContinuumBuildAgentUtil.getLocalRepository( map ) );
             context.setBuildNumber( ContinuumBuildAgentUtil.getBuildNumber( map ) );
-            context.setOldScmResult( getOldScmResult( map ) );
+            context.setOldScmResult( getScmResult( ContinuumBuildAgentUtil.getOldScmChanges( map ) ) );
 
             buildContext.add( context );
         }
@@ -286,15 +286,13 @@
         return null;
     }
 
-    private ScmResult getOldScmResult( Map context )
+    private ScmResult getScmResult( List<Map> scmChanges )
     {
-        ScmResult oldScmResult = null;
-
-        List<Map> scmChanges = ContinuumBuildAgentUtil.getOldScmChanges( context );
+        ScmResult scmResult = null;
 
         if ( scmChanges != null && scmChanges.size() > 0 )
         {
-            oldScmResult = new ScmResult();
+            scmResult = new ScmResult();
             
             for ( Map map : scmChanges )
             {
@@ -303,11 +301,11 @@
                 changeSet.setComment( ContinuumBuildAgentUtil.getChangeSetComment( map ) );
                 changeSet.setDate( ContinuumBuildAgentUtil.getChangeSetDate( map ) );
                 setChangeFiles( changeSet, map );
-                oldScmResult.addChange( changeSet );
+                scmResult.addChange( changeSet );
             }
         }
 
-        return oldScmResult;
+        return scmResult;
     }
 
     private void setChangeFiles( ChangeSet changeSet, Map context )

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/AbstractBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/AbstractBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/AbstractBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/AbstractBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -40,6 +40,7 @@
 import org.apache.maven.continuum.model.project.ProjectDeveloper;
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.commandline.ExecutableResolver;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Initializable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.InitializationException;
@@ -307,7 +308,7 @@
         return properties;
     }
 
-    protected String getBuildFileForProject( Project project, BuildDefinition buildDefinition )
+    protected String getBuildFileForProject( BuildDefinition buildDefinition )
     {
         String buildFile = StringUtils.clean( buildDefinition.getBuildFile() );
         
@@ -486,6 +487,12 @@
         return Collections.EMPTY_LIST;
     }
 
+    public MavenProject getMavenProject( File workingDirectory, BuildDefinition buildDefinition )
+        throws ContinuumAgentBuildExecutorException
+    {
+        return null;
+    }
+
     public File getWorkingDirectory( int projectId )
     {
         return getBuildAgentConfigurationService().getWorkingDirectory( projectId );

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ContinuumAgentBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ContinuumAgentBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ContinuumAgentBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ContinuumAgentBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -26,6 +26,7 @@
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.project.MavenProject;
 
 public interface ContinuumAgentBuildExecutor
 {
@@ -45,4 +46,7 @@
 
     void updateProjectFromWorkingDirectory( File workingDirectory, Project project, BuildDefinition buildDefinition )
         throws ContinuumAgentBuildExecutorException;
+
+    MavenProject getMavenProject( File workingDirectory, BuildDefinition buildDefinition )
+        throws ContinuumAgentBuildExecutorException;
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ant/AntBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ant/AntBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ant/AntBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/ant/AntBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -60,7 +60,7 @@
 
         StringBuffer arguments = new StringBuffer();
     
-        String buildFile = getBuildFileForProject( project, buildDefinition );
+        String buildFile = getBuildFileForProject( buildDefinition );
     
         if ( !StringUtils.isEmpty( buildFile ) )
         {

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m1/MavenOneBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m1/MavenOneBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m1/MavenOneBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m1/MavenOneBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -64,7 +64,7 @@
     
         StringBuffer arguments = new StringBuffer();
     
-        String buildFile = getBuildFileForProject( project, buildDefinition );
+        String buildFile = getBuildFileForProject( buildDefinition );
     
         if ( !StringUtils.isEmpty( buildFile ) && !"project.xml".equals( buildFile ) )
         {

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m2/MavenTwoBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m2/MavenTwoBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m2/MavenTwoBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/maven/m2/MavenTwoBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -96,7 +96,7 @@
 
         StringBuffer arguments = new StringBuffer();
     
-        String buildFile = getBuildFileForProject( project, buildDefinition );
+        String buildFile = getBuildFileForProject( buildDefinition );
     
         if ( !StringUtils.isEmpty( buildFile ) && !"pom.xml".equals( buildFile ) )
         {
@@ -141,7 +141,7 @@
                                         BuildDefinition buildDefinition )
         throws ContinuumAgentBuildExecutorException
     {
-        MavenProject project = getMavenProject( continuumProject, workingDirectory, buildDefinition );
+        MavenProject project = getMavenProject( workingDirectory, buildDefinition );
 
         // Maven could help us out a lot more here by knowing how to get the deployment artifacts from a project.
         // TODO: this is currently quite lame
@@ -234,7 +234,7 @@
     public void updateProjectFromWorkingDirectory( File workingDirectory, Project project, BuildDefinition buildDefinition )
         throws ContinuumAgentBuildExecutorException
     {
-        File f = getPomFile( getBuildFileForProject( project, buildDefinition ), workingDirectory );
+        File f = getPomFile( getBuildFileForProject( buildDefinition ), workingDirectory );
     
         if ( !f.exists() )
         {
@@ -255,13 +255,13 @@
         }
     }
 
-    private MavenProject getMavenProject( Project continuumProject, File workingDirectory,
-                                          BuildDefinition buildDefinition )
+    @Override
+    public MavenProject getMavenProject( File workingDirectory, BuildDefinition buildDefinition )
         throws ContinuumAgentBuildExecutorException
     {
         ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
 
-        File f = getPomFile( getBuildFileForProject( continuumProject, buildDefinition ), workingDirectory );
+        File f = getPomFile( getBuildFileForProject( buildDefinition ), workingDirectory );
 
         if ( !f.exists() )
         {

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/shell/ShellBuildExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/shell/ShellBuildExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/shell/ShellBuildExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/build/execution/shell/ShellBuildExecutor.java Fri Feb 13 02:18:11 2009
@@ -49,7 +49,7 @@
                                                      String localRepository )
         throws ContinuumAgentBuildExecutorException, ContinuumAgentBuildCancelledException
     {
-        String executable = getBuildFileForProject( project, buildDefinition );
+        String executable = getBuildFileForProject( buildDefinition );
 
         return executeShellCommand( project, executable, buildDefinition.getArguments(), buildOutput, environments );
     }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/BuildAgentManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/BuildAgentManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/BuildAgentManager.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/BuildAgentManager.java Fri Feb 13 02:18:11 2009
@@ -43,4 +43,7 @@
 
     void updateProject( Map project )
         throws ContinuumException;
+
+    boolean shouldBuild( Map context )
+        throws ContinuumException;
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentManager.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/manager/DefaultBuildAgentManager.java Fri Feb 13 02:18:11 2009
@@ -25,6 +25,7 @@
 import java.util.List;
 import java.util.Map;
 
+import org.apache.continuum.buildagent.build.execution.manager.BuildAgentBuildExecutorManager;
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
 import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
 import org.apache.continuum.buildagent.taskqueue.manager.BuildAgentTaskQueueManager;
@@ -70,6 +71,11 @@
      */
     private BuildAgentTaskQueueManager buildAgentTaskQueueManager;
 
+    /**
+     * @plexus.requirement
+     */
+    private BuildAgentBuildExecutorManager executorManager;
+
     public void prepareBuildProjects( List<BuildContext> buildContexts)
         throws ContinuumException
     {
@@ -111,7 +117,7 @@
                         if ( !buildDef.isBuildFresh() )
                         {
                             mergeScmResults( buildContext );
-                        }    
+                        }
                     }
                     finally
                     {
@@ -220,6 +226,27 @@
         }
     }
 
+    public boolean shouldBuild( Map context )
+        throws ContinuumException
+    {
+        try
+        {
+            MasterBuildAgentTransportClient client = new MasterBuildAgentTransportClient(
+                new URL( buildAgentConfigurationService.getContinuumServerUrl() ) );
+            return client.shouldBuild( context );
+        }
+        catch ( MalformedURLException e )
+        {
+            log.error( "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
+            throw new ContinuumException( "Invalid continuum server URL '" + buildAgentConfigurationService.getContinuumServerUrl() + "'" );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed to determine if project should build", e );
+            throw new ContinuumException( "Failed to determine if project should build", e );
+        }
+    }
+
     private void startPrepareBuild( BuildContext buildContext )
         throws ContinuumException
     {
@@ -461,25 +488,29 @@
     {
         for ( BuildContext buildContext : buildContexts )
         {
-            // only build if it's forced build or project state is not OK
-            if ( buildContext.getTrigger() == ContinuumProjectState.TRIGGER_FORCED || 
-                 buildContext.getProjectState() != ContinuumProjectState.OK )
-            {
-                BuildProjectTask buildProjectTask = new BuildProjectTask( buildContext.getProjectId(),
-                                                                          buildContext.getBuildDefinitionId(),
-                                                                          buildContext.getTrigger(),
-                                                                          buildContext.getProjectName(),
-                                                                          "", 
-                                                                          buildContext.getScmResult() );
-                try
+            BuildProjectTask buildProjectTask = new BuildProjectTask( buildContext.getProjectId(),
+                                                                      buildContext.getBuildDefinitionId(),
+                                                                      buildContext.getTrigger(),
+                                                                      buildContext.getProjectName(),
+                                                                      "", 
+                                                                      buildContext.getScmResult() );
+
+            try
+            {
+                if ( !buildAgentTaskQueueManager.isProjectInBuildQueue( buildProjectTask.getProjectId() ) )
                 {
                     buildAgentTaskQueueManager.getBuildQueue().put( buildProjectTask );
                 }
-                catch ( TaskQueueException e )
-                {
-                    log.error( "Error while enqueing build task for project " + buildContext.getProjectId(), e );
-                    throw new ContinuumException( "Error while enqueuing build task for project " + buildContext.getProjectId(), e );
-                }
+            }
+            catch ( TaskQueueException e )
+            {
+                log.error( "Error while enqueing build task for project " + buildContext.getProjectId(), e );
+                throw new ContinuumException( "Error while enqueuing build task for project " + buildContext.getProjectId(), e );
+            }
+            catch ( TaskQueueManagerException e )
+            {
+                log.error( "Error while checking if project " + buildContext.getProjectId() + " is in build queue", e );
+                throw new ContinuumException( "Error while checking if project " + buildContext.getProjectId() + " is in build queue", e );
             }
         }
 

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/execution/BuildProjectTaskExecutor.java Fri Feb 13 02:18:11 2009
@@ -27,6 +27,9 @@
 import java.util.Map;
 
 import org.apache.commons.lang.StringEscapeUtils;
+import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutor;
+import org.apache.continuum.buildagent.build.execution.ContinuumAgentBuildExecutorException;
+import org.apache.continuum.buildagent.build.execution.manager.BuildAgentBuildExecutorManager;
 import org.apache.continuum.buildagent.buildcontext.BuildContext;
 import org.apache.continuum.buildagent.buildcontext.manager.BuildContextManager;
 import org.apache.continuum.buildagent.configuration.BuildAgentConfigurationService;
@@ -38,6 +41,7 @@
 import org.apache.continuum.taskqueue.BuildProjectTask;
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
+import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
@@ -45,6 +49,7 @@
 import org.apache.maven.continuum.model.scm.ChangeSet;
 import org.apache.maven.continuum.model.scm.ScmResult;
 import org.apache.maven.continuum.project.ContinuumProjectState;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.scm.ScmException;
 import org.apache.maven.scm.repository.ScmRepositoryException;
 import org.codehaus.plexus.action.ActionManager;
@@ -86,6 +91,11 @@
      */
     private BuildAgentManager buildAgentManager;
 
+    /**
+     * @plexus.requirement
+     */
+    private BuildAgentBuildExecutorManager buildAgentBuildExecutorManager;
+
     public void executeTask( Task task )
         throws TaskExecutionException
     {
@@ -102,7 +112,13 @@
             log.info( "Error updating from SCM, not building" );
             return;
         }
-        
+
+        log.info( "Checking if project '" + context.getProjectName() + "' should build" );
+        if ( !shouldBuild( context ) )
+        {
+            return;
+        }
+
         log.info( "Starting build of " + context.getProjectName() );
         startBuild( context );
 
@@ -147,6 +163,7 @@
         
         actionContext.put( ContinuumBuildAgentUtil.KEY_PROJECT, project );
         actionContext.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION, BuildContextToBuildDefinition.getBuildDefinition( buildContext ) );
+        actionContext.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION_ID, buildContext.getBuildDefinitionId() );
         actionContext.put( ContinuumBuildAgentUtil.KEY_TRIGGER, buildContext.getTrigger() );
         actionContext.put( ContinuumBuildAgentUtil.KEY_ENVIRONMENTS, getEnvironments( buildContext.getBuildDefinitionId(), 
                                                                                       getInstallationType( buildContext ) ) );
@@ -372,4 +389,138 @@
 
         return null;
     }
+
+    private boolean shouldBuild( BuildContext context )
+        throws TaskExecutionException
+    {
+        Map map = new HashMap();
+        map.put( ContinuumBuildAgentUtil.KEY_PROJECT_ID, new Integer( context.getProjectId() ) );
+        map.put( ContinuumBuildAgentUtil.KEY_BUILD_DEFINITION_ID, new Integer( context.getBuildDefinitionId() ) );
+        map.put( ContinuumBuildAgentUtil.KEY_TRIGGER, new Integer( context.getTrigger() ) );
+        map.put( ContinuumBuildAgentUtil.KEY_SCM_CHANGES, getScmChanges( context.getScmResult() ) );
+        map.put( ContinuumBuildAgentUtil.KEY_MAVEN_PROJECT, getMavenProject( context ) );
+
+        try
+        {
+            return buildAgentManager.shouldBuild( map );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Failed to determine if project should build", e );
+            throw new TaskExecutionException( "Failed to determine if project should build", e );
+        }
+    }
+
+    private List getScmChanges( ScmResult scmResult )
+    {
+        List scmChanges = new ArrayList();
+
+        if ( scmResult != null && scmResult.getChanges() != null )
+        {
+            for ( Object obj : scmResult.getChanges() )
+            {
+                ChangeSet changeSet = (ChangeSet) obj; 
+
+                Map map = new HashMap();
+                if ( StringUtils.isNotEmpty( changeSet.getAuthor() ) )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_AUTHOR, changeSet.getAuthor() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_AUTHOR, "" );
+                }
+                if ( StringUtils.isNotEmpty( changeSet.getComment() ) )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_COMMENT, changeSet.getComment() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_COMMENT, "" );
+                }
+                if ( changeSet.getDateAsDate() != null )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_DATE, changeSet.getDateAsDate() );
+                }
+                map.put( ContinuumBuildAgentUtil.KEY_CHANGESET_FILES, getScmChangeFiles( changeSet.getFiles() ) );
+                scmChanges.add( map );
+            }
+        }
+
+        return scmChanges;
+    }
+
+    private List<Map> getScmChangeFiles( List<ChangeFile> files )
+    {
+        List<Map> scmChangeFiles = new ArrayList<Map>();
+
+        if ( files != null )
+        {
+            for ( ChangeFile changeFile : files )
+            {
+                Map map = new HashMap();
+
+                if ( StringUtils.isNotEmpty( changeFile.getName() ) )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_NAME, changeFile.getName() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_NAME, "" );
+                }
+                if ( StringUtils.isNotEmpty( changeFile.getRevision() ) )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_REVISION, changeFile.getRevision() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_REVISION, "" );
+                }
+                if ( StringUtils.isNotEmpty( changeFile.getStatus() ) )
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_STATUS, changeFile.getStatus() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildAgentUtil.KEY_CHANGEFILE_STATUS, "" );   
+                }
+                scmChangeFiles.add( map );
+            }
+        }
+        return scmChangeFiles;
+    }
+
+    private Map getMavenProject( BuildContext context )
+        throws TaskExecutionException
+    {
+        Map mavenProject = new HashMap();
+
+        try
+        {
+            ContinuumAgentBuildExecutor buildExecutor = buildAgentBuildExecutorManager.getBuildExecutor( context.getExecutorId() );
+
+            BuildDefinition buildDefinition = BuildContextToBuildDefinition.getBuildDefinition( context );
+
+            File workingDirectory = buildAgentConfigurationService.getWorkingDirectory( context.getProjectId() );
+
+            MavenProject project = buildExecutor.getMavenProject( workingDirectory, buildDefinition );
+
+            mavenProject.put( ContinuumBuildAgentUtil.KEY_PROJECT_VERSION, project.getVersion() );
+
+            if ( project.getModules() != null )
+            {
+                mavenProject.put( ContinuumBuildAgentUtil.KEY_PROJECT_MODULES, project.getModules() );
+            }
+        }
+        catch ( ContinuumAgentBuildExecutorException e )
+        {
+            log.error( "Error getting maven project", e );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Error getting build executor", e );   
+        }
+
+        return mavenProject;
+    }
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/BuildAgentTaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/BuildAgentTaskQueueManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/BuildAgentTaskQueueManager.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/BuildAgentTaskQueueManager.java Fri Feb 13 02:18:11 2009
@@ -36,4 +36,7 @@
 
     boolean hasBuildTaskInQueue()
         throws TaskQueueManagerException;
+
+    boolean isProjectInBuildQueue( int projectId )
+        throws TaskQueueManagerException;
 }

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultBuildAgentTaskQueueManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultBuildAgentTaskQueueManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultBuildAgentTaskQueueManager.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/taskqueue/manager/DefaultBuildAgentTaskQueueManager.java Fri Feb 13 02:18:11 2009
@@ -156,6 +156,37 @@
         return false;
     }
 
+    public boolean isProjectInBuildQueue( int projectId )
+        throws TaskQueueManagerException
+    {
+        try
+        {
+            List<BuildProjectTask> queues = buildAgentBuildQueue.getQueueSnapshot();
+        
+            if ( queues != null )
+            {
+                for ( BuildProjectTask task : queues )
+                {
+                    if ( task.getProjectId() == projectId )
+                    {
+                        log.info( "project already in build queue" );
+                        return true;
+                    }
+                }
+            }
+            else
+            {
+                log.info( "no build task in queue" );
+            }
+        }
+        catch ( TaskQueueException e )
+        {
+            throw new TaskQueueManagerException( e.getMessage(), e );
+        }
+
+        return false;
+    }
+
     public void contextualize( Context context )
         throws ContextException
     {

Modified: continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java (original)
+++ continuum/trunk/continuum-buildagent/continuum-buildagent-core/src/main/java/org/apache/continuum/buildagent/utils/ContinuumBuildAgentUtil.java Fri Feb 13 02:18:11 2009
@@ -196,6 +196,10 @@
 
     public static final String KEY_PROJECT_DEVELOPER_SCMID = "developer-scmid";
 
+    public static final String KEY_PROJECT_MODULES = "project-modules";
+
+    public static final String KEY_MAVEN_PROJECT = "maven-project";
+
     public static Integer getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
@@ -385,6 +389,11 @@
         return (ScmResult) getObject( context, KEY_OLD_SCM_RESULT, defaultValue );
     }
 
+    public static List getScmChanges( Map context )
+    {
+        return getList( context, KEY_SCM_CHANGES );
+    }
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java (original)
+++ continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/distributed/executor/DistributedBuildProjectTaskExecutor.java Fri Feb 13 02:18:11 2009
@@ -44,7 +44,6 @@
 import org.apache.maven.continuum.model.scm.ChangeFile;
 import org.apache.maven.continuum.model.scm.ChangeSet;
 import org.apache.maven.continuum.model.scm.ScmResult;
-import org.apache.maven.continuum.notification.ContinuumNotificationDispatcher;
 import org.apache.maven.continuum.project.ContinuumProjectState;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.taskqueue.Task;
@@ -282,41 +281,53 @@
         if ( oldBuildResult != null )
         {
             ScmResult scmResult = getOldScmResults( projectId, oldBuildResult.getBuildNumber(), oldBuildResult.getEndTime() );
-        
-            if ( scmResult != null && scmResult.getChanges() != null )
+
+            scmChanges = getScmChanges( scmResult );
+        }
+
+        return scmChanges;
+    }
+
+    private List getScmChanges( ScmResult scmResult )
+    {
+        List scmChanges = new ArrayList();
+
+        if ( scmResult != null && scmResult.getChanges() != null )
+        {
+            for ( Object obj : scmResult.getChanges() )
             {
-                for ( Object obj : scmResult.getChanges() )
-                {
-                    ChangeSet changeSet = (ChangeSet) obj; 
+                ChangeSet changeSet = (ChangeSet) obj; 
 
-                    Map map = new HashMap();
-                    if ( StringUtils.isNotEmpty( changeSet.getAuthor() ) )
-                    {
-                        map.put( ContinuumBuildConstant.KEY_CHANGESET_AUTHOR, changeSet.getAuthor() );
-                    }
-                    else
-                    {
-                        map.put( ContinuumBuildConstant.KEY_CHANGESET_AUTHOR, "" );
-                    }
-                    if ( StringUtils.isNotEmpty( changeSet.getComment() ) )
-                    {
-                        map.put( ContinuumBuildConstant.KEY_CHANGESET_COMMENT, changeSet.getComment() );
-                    }
-                    else
-                    {
-                        map.put( ContinuumBuildConstant.KEY_CHANGESET_COMMENT, "" );
-                    }
+                Map map = new HashMap();
+                if ( StringUtils.isNotEmpty( changeSet.getAuthor() ) )
+                {
+                    map.put( ContinuumBuildConstant.KEY_CHANGESET_AUTHOR, changeSet.getAuthor() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildConstant.KEY_CHANGESET_AUTHOR, "" );
+                }
+                if ( StringUtils.isNotEmpty( changeSet.getComment() ) )
+                {
+                    map.put( ContinuumBuildConstant.KEY_CHANGESET_COMMENT, changeSet.getComment() );
+                }
+                else
+                {
+                    map.put( ContinuumBuildConstant.KEY_CHANGESET_COMMENT, "" );
+                }
+                if ( changeSet.getDateAsDate() != null )
+                {
                     map.put( ContinuumBuildConstant.KEY_CHANGESET_DATE, changeSet.getDateAsDate() );
-                    map.put( ContinuumBuildConstant.KEY_CHANGESET_FILES, getOldScmChangeFiles( changeSet.getFiles() ) );
-                    scmChanges.add( map );
                 }
+                map.put( ContinuumBuildConstant.KEY_CHANGESET_FILES, getScmChangeFiles( changeSet.getFiles() ) );
+                scmChanges.add( map );
             }
         }
 
         return scmChanges;
     }
 
-    private List<Map> getOldScmChangeFiles( List<ChangeFile> files )
+    private List<Map> getScmChangeFiles( List<ChangeFile> files )
     {
         List<Map> scmChangeFiles = new ArrayList<Map>();
 

Modified: continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java (original)
+++ continuum/trunk/continuum-builder/src/main/java/org/apache/continuum/builder/utils/ContinuumBuildConstant.java Fri Feb 13 02:18:11 2009
@@ -168,6 +168,10 @@
 
     public static final String KEY_PROJECT_DEVELOPER_SCMID = "developer-scmid";
 
+    public static final String KEY_MAVEN_PROJECT = "maven-project";
+
+    public static final String KEY_PROJECT_MODULES = "project-modules";
+
     public static int getProjectId( Map context )
     {
         return getInteger( context, KEY_PROJECT_ID );
@@ -458,6 +462,16 @@
         return getMap( context, KEY_SCM_RESULT );
     }
 
+    public static Map getMavenProject( Map context )
+    {
+        return getMap( context, KEY_MAVEN_PROJECT );
+    }
+
+    public static List getProjectModules( Map context )
+    {
+        return getList( context, KEY_PROJECT_MODULES );
+    }
+
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java (original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/continuum/builder/distributed/manager/DefaultDistributedBuildManager.java Fri Feb 13 02:18:11 2009
@@ -46,6 +46,7 @@
 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.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.BuildResult;
@@ -492,75 +493,7 @@
             throw new ContinuumException( "Unable to get available installations of build agent", e );
         }
     }
-
-    private List<ProjectDependency> getModifiedDependencies( BuildResult oldBuildResult, Map context )
-        throws ContinuumException
-    {
-        if ( oldBuildResult == null )
-        {
-            return null;
-        }
-
-        try
-        {
-            Project project = projectDao.getProjectWithAllDetails( ContinuumBuildConstant.getProjectId( context ) );
-            List<ProjectDependency> dependencies = project.getDependencies();
-
-            if ( dependencies == null )
-            {
-                dependencies = new ArrayList<ProjectDependency>();
-            }
-
-            if ( project.getParent() != null )
-            {
-                dependencies.add( project.getParent() );
-            }
-
-            if ( dependencies.isEmpty() )
-            {
-                return null;
-            }
-
-            List<ProjectDependency> modifiedDependencies = new ArrayList<ProjectDependency>();
-
-            for ( ProjectDependency dep : dependencies )
-            {
-                Project dependencyProject =
-                    projectDao.getProject( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() );
-
-                if ( dependencyProject != null )
-                {
-                    List buildResults = buildResultDao.getBuildResultsInSuccessForProject( dependencyProject.getId(),
-                                                                                           oldBuildResult.getEndTime() );
-                    if ( buildResults != null && !buildResults.isEmpty() )
-                    {
-                        log.debug( "Dependency changed: " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" +
-                            dep.getVersion() );
-                        modifiedDependencies.add( dep );
-                    }
-                    else
-                    {
-                        log.debug( "Dependency not changed: " + dep.getGroupId() + ":" + dep.getArtifactId() +
-                            ":" + dep.getVersion() );
-                    }
-                }
-                else
-                {
-                    log.debug( "Skip non Continuum project: " + dep.getGroupId() + ":" + dep.getArtifactId() +
-                        ":" + dep.getVersion() );
-                }
-            }
-
-            return modifiedDependencies;
-        }
-        catch ( ContinuumStoreException e )
-        {
-            log.warn( "Can't get the project dependencies", e );
-        }
-
-        return null;
-    }
-
+    
     public void startProjectBuild( int projectId )
         throws ContinuumException
     {
@@ -735,6 +668,299 @@
         }
     }
 
+    public boolean shouldBuild( Map context )
+    {
+        try
+        {
+            int projectId = ContinuumBuildConstant.getProjectId( context );
+
+            int buildDefinitionId = ContinuumBuildConstant.getBuildDefinitionId( context );
+
+            int trigger = ContinuumBuildConstant.getTrigger( context );
+
+            Project project = projectDao.getProjectWithAllDetails( projectId );
+
+            BuildDefinition buildDefinition = buildDefinitionDao.getBuildDefinition( buildDefinitionId );
+
+            BuildResult oldBuildResult = buildResultDao.getLatestBuildResultForBuildDefinition( projectId, buildDefinitionId );
+
+            List<ProjectDependency> modifiedDependencies = getModifiedDependencies( oldBuildResult, context );
+
+            List<ChangeSet> changes = getScmChanges( context );
+
+            if ( buildDefinition.isBuildFresh() )
+            {
+                log.info( "FreshBuild configured, building" );
+                return true;
+            }
+            if ( buildDefinition.isAlwaysBuild() )
+            {
+                log.info( "AlwaysBuild configured, building" );
+                return true;
+            }
+            if ( oldBuildResult == null )
+            {
+                log.info( "The project was never be built with the current build definition, building" );
+                return true;
+            }
+
+            //CONTINUUM-1428
+            if ( project.getOldState() == ContinuumProjectState.ERROR ||
+                oldBuildResult.getState() == ContinuumProjectState.ERROR )
+            {
+                log.info( "Latest state was 'ERROR', building" );
+                return true;
+            }
+
+            if ( trigger == ContinuumProjectState.TRIGGER_FORCED )
+            {
+                log.info( "The project build is forced, building" );
+                return true;
+            }
+
+            boolean shouldBuild = false;
+
+            boolean allChangesUnknown = true;
+
+            if ( project.getOldState() != ContinuumProjectState.NEW &&
+                project.getOldState() != ContinuumProjectState.CHECKEDOUT &&
+                trigger != ContinuumProjectState.TRIGGER_FORCED &&
+                project.getState() != ContinuumProjectState.NEW && project.getState() != ContinuumProjectState.CHECKEDOUT )
+            {
+                // Check SCM changes
+                allChangesUnknown = checkAllChangesUnknown( changes );
+
+                if ( allChangesUnknown )
+                {
+                    if ( !changes.isEmpty() )
+                    {
+                        log.info(
+                            "The project was not built because all changes are unknown (maybe local modifications or ignored files not defined in your SCM tool." );
+                    }
+                    else
+                    {
+                        log.info(
+                            "The project was not built because no changes were detected in sources since the last build." );
+                    }
+                }
+
+                // Check dependencies changes
+                if ( modifiedDependencies != null && !modifiedDependencies.isEmpty() )
+                {
+                    log.info( "Found dependencies changes, building" );
+                    shouldBuild = true;
+                }
+            }
+
+            // Check changes
+            if ( !shouldBuild && ( ( !allChangesUnknown && !changes.isEmpty() ) ||
+                project.getExecutorId().equals( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR ) ) )
+            {
+                shouldBuild = shouldBuild( changes, buildDefinition, project, getMavenProjectVersion( context ), getMavenProjectModules( context ) );
+            }
+
+            if ( shouldBuild )
+            {
+                log.info( "Changes found in the current project, building" );
+            }
+            else
+            {
+                log.info( "No changes in the current project, not building" );
+            }
+
+            return shouldBuild;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            log.error( "Failed to determine if project should build", e );
+        }
+        catch ( ContinuumException e )
+        {
+            log.error( "Failed to determine if project should build", e );
+        }
+
+        return false;
+    }
+
+    private boolean shouldBuild( List<ChangeSet> changes, BuildDefinition buildDefinition, Project project, 
+                                 String mavenProjectVersion, List<String> mavenProjectModules )
+    {
+        //Check if it's a recursive build
+        boolean isRecursive = false;
+        if (StringUtils.isNotEmpty( buildDefinition.getArguments() ) )
+        {
+            isRecursive = buildDefinition.getArguments().indexOf( "-N" ) < 0 &&
+                buildDefinition.getArguments().indexOf( "--non-recursive" ) < 0 ;
+        }
+
+        if ( isRecursive && changes != null && !changes.isEmpty() )
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "recursive build and changes found --> building" );
+            }
+            return true;
+        }
+
+        if ( !project.getVersion().equals( mavenProjectVersion ) )
+        {
+            log.info( "Found changes in project's version ( maybe project was recently released ), building" );
+            return true;
+        }
+
+        if ( changes.isEmpty() )
+        {
+            if ( log.isInfoEnabled() )
+            {
+                log.info( "Found no changes, not building" );
+            }
+            return false;
+        }
+
+        //check if changes are only in sub-modules or not
+        List<ChangeFile> files = new ArrayList<ChangeFile>();
+        for ( ChangeSet changeSet : changes )
+        {
+            files.addAll( changeSet.getFiles() );
+        }
+
+        int i = 0;
+        while ( i <= files.size() - 1 )
+        {
+            ChangeFile file = files.get( i );
+            if ( log.isDebugEnabled() )
+            {
+                log.debug( "changeFile.name " + file.getName() );
+                log.debug( "check in modules " + mavenProjectModules );
+            }
+            boolean found = false;
+            if ( mavenProjectModules != null )
+            {
+                for ( String module : mavenProjectModules )
+                {
+                    if ( file.getName().indexOf( module ) >= 0 )
+                    {
+                        if ( log.isDebugEnabled() )
+                        {
+                            log.debug( "changeFile.name " + file.getName() + " removed because in a module" );
+                        }                    
+                        files.remove( file );
+                        found = true;
+                        break;
+                    }
+                    if (log.isDebugEnabled())
+                    {
+                        log.debug( "not removing file " + file.getName() + " not in module " + module );
+                    }
+                }
+            }
+            if ( !found )
+            {
+                i++;
+            }
+        }
+
+        boolean shouldBuild = !files.isEmpty();
+
+        if ( !shouldBuild )
+        {
+            log.info( "Changes are only in sub-modules." );
+        }
+
+        if ( log.isDebugEnabled() )
+        {
+            log.debug( "shoulbuild = " + shouldBuild );
+        }
+
+        return shouldBuild;
+    }
+
+    private boolean checkAllChangesUnknown( List<ChangeSet> changes )
+    {
+        for ( ChangeSet changeSet : changes )
+        {
+            List<ChangeFile> changeFiles = changeSet.getFiles();
+
+            for ( ChangeFile changeFile : changeFiles )
+            {
+                if ( !"unknown".equalsIgnoreCase( changeFile.getStatus() ) )
+                {
+                    return false;
+                }
+            }
+        }
+
+        return true;
+    }
+
+    private List<ProjectDependency> getModifiedDependencies( BuildResult oldBuildResult, Map context )
+        throws ContinuumException
+    {
+        if ( oldBuildResult == null )
+        {
+            return null;
+        }
+    
+        try
+        {
+            Project project = projectDao.getProjectWithAllDetails( ContinuumBuildConstant.getProjectId( context ) );
+            List<ProjectDependency> dependencies = project.getDependencies();
+    
+            if ( dependencies == null )
+            {
+                dependencies = new ArrayList<ProjectDependency>();
+            }
+    
+            if ( project.getParent() != null )
+            {
+                dependencies.add( project.getParent() );
+            }
+    
+            if ( dependencies.isEmpty() )
+            {
+                return null;
+            }
+    
+            List<ProjectDependency> modifiedDependencies = new ArrayList<ProjectDependency>();
+    
+            for ( ProjectDependency dep : dependencies )
+            {
+                Project dependencyProject =
+                    projectDao.getProject( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() );
+    
+                if ( dependencyProject != null )
+                {
+                    List buildResults = buildResultDao.getBuildResultsInSuccessForProject( dependencyProject.getId(),
+                                                                                           oldBuildResult.getEndTime() );
+                    if ( buildResults != null && !buildResults.isEmpty() )
+                    {
+                        log.debug( "Dependency changed: " + dep.getGroupId() + ":" + dep.getArtifactId() + ":" +
+                            dep.getVersion() );
+                        modifiedDependencies.add( dep );
+                    }
+                    else
+                    {
+                        log.debug( "Dependency not changed: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                            ":" + dep.getVersion() );
+                    }
+                }
+                else
+                {
+                    log.debug( "Skip non Continuum project: " + dep.getGroupId() + ":" + dep.getArtifactId() +
+                        ":" + dep.getVersion() );
+                }
+            }
+    
+            return modifiedDependencies;
+        }
+        catch ( ContinuumStoreException e )
+        {
+            log.warn( "Can't get the project dependencies", e );
+        }
+    
+        return null;
+    }
+
     private String getBuildAgent( int projectId )
         throws ContinuumException
     {
@@ -950,4 +1176,28 @@
 
         return null;
     }
+
+    private String getMavenProjectVersion( Map context )
+    {
+        Map map = ContinuumBuildConstant.getMavenProject( context );
+
+        if ( !map.isEmpty() )
+        {
+            return ContinuumBuildConstant.getVersion( map );
+        }
+
+        return null;
+    }
+
+    private List<String> getMavenProjectModules( Map context )
+    {
+        Map map = ContinuumBuildConstant.getMavenProject( context );
+
+        if ( !map.isEmpty() )
+        {
+            return ContinuumBuildConstant.getProjectModules( map );
+        }
+
+        return null;
+    }
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-api/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-api/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportService.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-api/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportService.java (original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-api/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportService.java Fri Feb 13 02:18:11 2009
@@ -42,4 +42,6 @@
     public Boolean updateProject( Map project ) throws Exception;
 
     public Boolean ping() throws Exception;
+
+    public Boolean shouldBuild( Map context ) throws Exception;
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java (original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-client/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportClient.java Fri Feb 13 02:18:11 2009
@@ -194,4 +194,23 @@
 
         return result;
     }
+
+    public Boolean shouldBuild( Map context )
+        throws Exception
+    {
+        Boolean result = null;
+
+        try
+        {
+            result = master.shouldBuild( context );
+            log.info( "Checking if project should build" );
+        }
+        catch ( Exception e )
+        {
+            log.error( "Failed to determine if project should build", e );
+            throw new Exception( "Failed to determine if project should build", e );
+        }
+
+        return result;
+    }
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportServer.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportServer.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportServer.java (original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-master/continuum-distributed-master-server/src/main/java/org/apache/continuum/distributed/transport/master/MasterBuildAgentTransportServer.java Fri Feb 13 02:18:11 2009
@@ -95,4 +95,11 @@
         distributedBuildManager.updateProject( project );
         return Boolean.TRUE;
     }
+
+    public Boolean shouldBuild( Map context )
+        throws Exception
+    {
+        log.info( "Checking if project should build" );
+        return distributedBuildManager.shouldBuild( context );
+    }
 }

Modified: continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java?rev=743956&r1=743955&r2=743956&view=diff
==============================================================================
--- continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java (original)
+++ continuum/trunk/continuum-distributed/continuum-distributed-slave/continuum-distributed-slave-server/src/main/java/org/apache/continuum/distributed/transport/slave/SlaveBuildAgentTransportServer.java Fri Feb 13 02:18:11 2009
@@ -58,6 +58,7 @@
         catch ( ContinuumBuildAgentException e )
         {
             log.error( "Failed to build projects.", e );
+            throw e;
         }
         
         return result;
@@ -76,6 +77,7 @@
         catch ( ContinuumBuildAgentException e )
         {
             log.error( "Failed to get available installations.", e );
+            throw e;
         }
 
         return installations;
@@ -94,6 +96,7 @@
         catch ( ContinuumBuildAgentException e )
         {
             log.error( "Failed to get build result for project " + projectId, e );
+            throw e;
         }
         
         return buildResult;



Mime
View raw message