continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r636916 - in /continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum: DefaultContinuum.java utils/PlexusContainerManager.java
Date Thu, 13 Mar 2008 23:11:04 GMT
Author: olamy
Date: Thu Mar 13 16:10:52 2008
New Revision: 636916

URL: http://svn.apache.org/viewvc?rev=636916&view=rev
Log:
[CONTINUUM-1676] deleting a project or group should cancel any current or scheduled builds,
and prevent any from being queued

add cancel the current build task if the project is the same as the one remove


Modified:
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/utils/PlexusContainerManager.java

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=636916&r1=636915&r2=636916&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
Thu Mar 13 16:10:52 2008
@@ -64,6 +64,7 @@
 import org.codehaus.plexus.action.Action;
 import org.codehaus.plexus.action.ActionManager;
 import org.codehaus.plexus.action.ActionNotFoundException;
+import org.codehaus.plexus.component.repository.exception.ComponentLookupException;
 import org.codehaus.plexus.context.Context;
 import org.codehaus.plexus.context.ContextException;
 import org.codehaus.plexus.formica.FormicaException;
@@ -75,8 +76,10 @@
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.Startable;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StartingException;
 import org.codehaus.plexus.personality.plexus.lifecycle.phase.StoppingException;
+import org.codehaus.plexus.taskqueue.Task;
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.TaskQueueException;
+import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
 import org.codehaus.plexus.util.FileUtils;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.dag.CycleDetectedException;
@@ -178,6 +181,8 @@
      * @plexus.requirement
      */
     private BuildExecutorManager executorManager;
+    
+    private PlexusContainer container;
 
 
     /**
@@ -544,7 +549,34 @@
             throw new ContinuumException( "Error while getting the checkout queue.", e );
         }
     }
+    
+    public TaskQueueExecutor getBuildTaskQueueExecutor()
+        throws ContinuumException
+    {
+        try
+        {
+            return (TaskQueueExecutor) container.lookup( TaskQueueExecutor.class, "build-project"
);
+        }
+        catch ( ComponentLookupException e )
+        {
+            throw new ContinuumException( e.getMessage(), e );
+        }
+    }
 
+    public int getCurrentProjectIdBuilding()
+        throws ContinuumException
+    {
+        Task task = getBuildTaskQueueExecutor().getCurrentTask();
+        if ( task != null )
+        {
+            if ( task instanceof BuildProjectTask )
+            {
+                return ( (BuildProjectTask) task ).getProjectId();
+            }
+        }
+        return -1;
+    }    
+    
     public boolean removeFromBuildingQueue( int projectId, int buildDefinitionId, int trigger,
String projectName )
         throws ContinuumException
     {
@@ -712,6 +744,23 @@
             {
                 removeProjectFromBuildingQueue( projectId );
             }
+            
+            // cancel it if currently building
+            
+            if ( getCurrentProjectIdBuilding() == projectId )
+            {
+                Task currentTask = getBuildTaskQueueExecutor().getCurrentTask();
+                {
+                    if ( currentTask instanceof BuildProjectTask )
+                    {
+                        if ( ( (BuildProjectTask) currentTask ).getProjectId() == projectId
)
+                        {
+                            getLogger().info( "Cancelling task for project " + projectId
);
+                            getBuildTaskQueueExecutor().cancelTask( currentTask );
+                        }
+                    }
+                }
+            }
 
             for ( Object o : project.getBuildResults() )
             {
@@ -2712,11 +2761,14 @@
                 project.getExecutorId() );
         }
     }
-
+    
+    // --------------------------------
+    //  Plexus Lifecycle
+    // --------------------------------
     public void contextualize( Context context )
         throws ContextException
     {
-        PlexusContainer container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY
);
+        container = (PlexusContainer) context.get( PlexusConstants.PLEXUS_KEY );
 
         PlexusContainerManager.getInstance().setContainer( container );
     }
@@ -2754,6 +2806,12 @@
             getLogger().error( "Error activating schedules.", e );
         }
     }
+    
+    public void stop()
+    throws StoppingException
+{
+    stopContinuum();
+}    
 
     private void closeStore()
     {
@@ -2763,11 +2821,7 @@
         }
     }
 
-    public void stop()
-        throws StoppingException
-    {
-        stopContinuum();
-    }
+
 
     public void stopContinuum()
         throws StoppingException

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/utils/PlexusContainerManager.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/utils/PlexusContainerManager.java?rev=636916&r1=636915&r2=636916&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/utils/PlexusContainerManager.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/utils/PlexusContainerManager.java
Thu Mar 13 16:10:52 2008
@@ -22,6 +22,7 @@
 import org.codehaus.plexus.PlexusContainer;
 
 /**
+ * TODO this class can be removed ?
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
  */



Mime
View raw message