You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by ev...@apache.org on 2007/09/04 10:07:34 UTC
svn commit: r572568 - in /maven/continuum/trunk:
continuum-api/src/main/java/org/apache/maven/continuum/
continuum-core/src/main/java/org/apache/maven/continuum/
continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/
continuum-webapp/src...
Author: evenisse
Date: Tue Sep 4 01:07:27 2007
New Revision: 572568
URL: http://svn.apache.org/viewvc?rev=572568&view=rev
Log:
[CONTINUUM-1424] Ability to Cancel Build for a subset of a project group
Submitted by: Olivier Lamy
Modified:
maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/CancelBuildAction.java
maven/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml
maven/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp
Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java (original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java Tue Sep 4 01:07:27 2007
@@ -138,10 +138,22 @@
boolean isInBuildingQueue( int projectId, int buildDefinitionId )
throws ContinuumException;
+ boolean removeProjectsFromBuildingQueue( int[] projectsId )
+ throws ContinuumException;
+
+ List getBuildProjectTasksInQueue()
+ throws ContinuumException;
+
boolean isInCheckoutQueue( int projectId )
throws ContinuumException;
boolean removeProjectFromCheckoutQueue( int projectId )
+ throws ContinuumException;
+
+ List getCheckOutTasksInQueue()
+ throws ContinuumException;
+
+ boolean removeProjectsFromCheckoutQueue( int[] projectId )
throws ContinuumException;
// ----------------------------------------------------------------------
Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java Tue Sep 4 01:07:27 2007
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.commons.lang.ArrayUtils;
import org.apache.maven.continuum.build.settings.SchedulesActivationException;
import org.apache.maven.continuum.build.settings.SchedulesActivator;
import org.apache.maven.continuum.buildqueue.BuildProjectTask;
@@ -32,7 +33,6 @@
import org.apache.maven.continuum.execution.manager.BuildExecutorManager;
import org.apache.maven.continuum.initialization.ContinuumInitializationException;
import org.apache.maven.continuum.initialization.ContinuumInitializer;
-import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
import org.apache.maven.continuum.installation.InstallationService;
import org.apache.maven.continuum.model.project.BuildDefinition;
import org.apache.maven.continuum.model.project.BuildResult;
@@ -302,7 +302,8 @@
{
ProjectGroup new_pg = store.addProjectGroup( projectGroup );
- addBuildDefinitionToProjectGroup( new_pg.getId(), configurationService.getDefaultMavenTwoBuildDefinition() );
+ addBuildDefinitionToProjectGroup( new_pg.getId(),
+ configurationService.getDefaultMavenTwoBuildDefinition() );
Map context = new HashMap();
context.put( AbstractContinuumAction.KEY_PROJECT_GROUP_ID, new Integer( new_pg.getId() ) );
@@ -519,6 +520,120 @@
}
}
+ return false;
+ }
+
+ public List getBuildProjectTasksInQueue()
+ throws ContinuumException
+ {
+ try
+ {
+ return buildQueue.getQueueSnapshot();
+ }
+ catch ( TaskQueueException e )
+ {
+ throw new ContinuumException( "Error while getting the building queue.", e );
+ }
+ }
+
+ public List getCheckOutTasksInQueue()
+ throws ContinuumException
+ {
+ try
+ {
+ return checkoutQueue.getQueueSnapshot();
+ }
+ catch ( TaskQueueException e )
+ {
+ throw new ContinuumException( "Error while getting the checkout queue.", e );
+ }
+ }
+
+ public boolean removeProjectsFromBuildingQueue( int[] projectsId )
+ throws ContinuumException
+ {
+ if ( projectsId == null )
+ {
+ return false;
+ }
+ if ( projectsId.length < 1 )
+ {
+ return false;
+ }
+ List queue;
+
+ try
+ {
+ queue = this.buildQueue.getQueueSnapshot();
+ }
+ catch ( TaskQueueException e )
+ {
+ throw new ContinuumException( "Error while getting the building queue.", e );
+ }
+ List<BuildProjectTask> tasks = new ArrayList<BuildProjectTask>();
+
+ for ( Iterator it = queue.iterator(); it.hasNext(); )
+ {
+ BuildProjectTask task = (BuildProjectTask) it.next();
+
+ if ( task != null )
+ {
+ if ( ArrayUtils.contains( projectsId, task.getProjectId() ) )
+ {
+ tasks.add( task );
+ }
+ }
+ }
+ if ( !tasks.isEmpty() )
+ {
+ return buildQueue.removeAll( tasks );
+ }
+ for ( BuildProjectTask buildProjectTask : tasks )
+ {
+ getLogger().info( "cancel build for project " + buildProjectTask.getProjectId() );
+ }
+ return false;
+ }
+
+ public boolean removeProjectsFromCheckoutQueue( int[] projectsId )
+ throws ContinuumException
+ {
+ if ( projectsId == null )
+ {
+ return false;
+ }
+ if ( projectsId.length < 1 )
+ {
+ return false;
+ }
+ List queue;
+
+ try
+ {
+ queue = this.checkoutQueue.getQueueSnapshot();
+ }
+ catch ( TaskQueueException e )
+ {
+ throw new ContinuumException( "Error while getting the checkout queue.", e );
+ }
+ List tasks = new ArrayList();
+
+ for ( Iterator it = queue.iterator(); it.hasNext(); )
+ {
+ BuildProjectTask task = (BuildProjectTask) it.next();
+
+ if ( task != null )
+ {
+ if ( ArrayUtils.contains( projectsId, task.getProjectId() ) )
+ {
+ tasks.add( task );
+ }
+ }
+ }
+ if ( !tasks.isEmpty() )
+ {
+ return checkoutQueue.removeAll( tasks );
+ }
return false;
}
Modified: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/CancelBuildAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/CancelBuildAction.java?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/CancelBuildAction.java (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/CancelBuildAction.java Tue Sep 4 01:07:27 2007
@@ -19,6 +19,7 @@
* under the License.
*/
+import org.apache.commons.lang.ArrayUtils;
import org.apache.maven.continuum.ContinuumException;
import org.apache.maven.continuum.buildqueue.BuildProjectTask;
import org.apache.maven.continuum.web.exception.AuthorizationRequiredException;
@@ -26,6 +27,8 @@
import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
import org.codehaus.plexus.util.StringUtils;
+import java.util.List;
+
/**
* @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
* @version $Id$
@@ -41,6 +44,10 @@
private int projectId;
+ private int projectGroupId;
+
+ private List<String> selectedProjects;
+
private String projectGroupName = "";
public String execute()
@@ -55,8 +62,39 @@
return REQUIRES_AUTHORIZATION;
}
- Task task = taskQueueExecutor.getCurrentTask();
+ cancelBuild( projectId );
+
+ return SUCCESS;
+ }
+ public String cancelBuilds()
+ throws ContinuumException
+ {
+ // first we remove from the build queue
+ if ( getSelectedProjects().isEmpty() )
+ {
+ return SUCCESS;
+ }
+ int[] projectsId = new int[getSelectedProjects().size()];
+ for ( String selectedProjectId : getSelectedProjects() )
+ {
+ int projectId = Integer.parseInt( selectedProjectId );
+ projectsId = ArrayUtils.add( projectsId, projectId );
+ }
+ getContinuum().removeProjectsFromBuildingQueue( projectsId );
+ // now we must check if the current build is one of this
+ int index = ArrayUtils.indexOf( projectsId, getCurrentProjectIdBuilding() );
+ if ( index > 0 )
+ {
+ cancelBuild( projectsId[index] );
+ }
+ return SUCCESS;
+ }
+
+ private boolean cancelBuild( int projectId )
+ throws ContinuumException
+ {
+ Task task = taskQueueExecutor.getCurrentTask();
getLogger().info( "TaskQueueExecutor: " + taskQueueExecutor );
if ( task != null )
@@ -66,7 +104,7 @@
if ( ( (BuildProjectTask) task ).getProjectId() == projectId )
{
getLogger().info( "Cancelling task for project " + projectId );
- taskQueueExecutor.cancelTask( task );
+ return taskQueueExecutor.cancelTask( task );
}
else
{
@@ -83,8 +121,25 @@
{
getLogger().warn( "No task running - not cancelling" );
}
+ return false;
+ }
- return SUCCESS;
+ /**
+ * @return -1 if not project currently building
+ * @throws ContinuumException
+ */
+ private int getCurrentProjectIdBuilding()
+ throws ContinuumException
+ {
+ Task task = taskQueueExecutor.getCurrentTask();
+ if ( task != null )
+ {
+ if ( task instanceof BuildProjectTask )
+ {
+ return ( (BuildProjectTask) task ).getProjectId();
+ }
+ }
+ return -1;
}
public void setProjectId( int projectId )
@@ -101,5 +156,25 @@
}
return projectGroupName;
+ }
+
+ public List<String> getSelectedProjects()
+ {
+ return selectedProjects;
+ }
+
+ public void setSelectedProjects( List<String> selectedProjects )
+ {
+ this.selectedProjects = selectedProjects;
+ }
+
+ public int getProjectGroupId()
+ {
+ return projectGroupId;
+ }
+
+ public void setProjectGroupId( int projectGroupId )
+ {
+ this.projectGroupId = projectGroupId;
}
}
Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties Tue Sep 4 01:07:27 2007
@@ -149,6 +149,7 @@
projectGroup.buildGroup = Build all projects
projectGroup.deleteProjects = Delete Project(s)
projectGroup.buildProjects = Build Project(s)
+projectGroup.cancelBuilds = Cancel Build(s)
projectGroup.buildsStatut.title = Project Group Last Build Result Overview
projectGroup.buildsStatut.errors = Errors
projectGroup.buildsStatut.failures = Failed
@@ -639,6 +640,7 @@
installation.envvar.type.label = Environment Variable
installation.ant.type.label = ANT
installation.automaticProfile.label=Create a Profile with the installation name
+
Modified: maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/resources/xwork.xml Tue Sep 4 01:07:27 2007
@@ -390,6 +390,13 @@
<action name="cancelBuild" class="cancelBuild">
<result name="success" type="chain">buildResults</result>
</action>
+
+ <action name="cancelBuilds" class="cancelBuild" method="cancelBuilds">
+ <result name="success" type="redirect-action">
+ <param name="actionName">projectGroupSummary</param>
+ <param name="projectGroupId">${projectGroupId}</param>
+ </result>
+ </action>
<!--
- continuum release
Modified: maven/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp?rev=572568&r1=572567&r2=572568&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp (original)
+++ maven/continuum/trunk/continuum-webapp/src/main/webapp/WEB-INF/jsp/components/projectSummaryComponent.jsp Tue Sep 4 01:07:27 2007
@@ -233,6 +233,7 @@
<input type="hidden" name="projectGroupId" value="${project.projectGroupId}" />
<input type="button" name="delete-projects" value="<ww:text name="projectGroup.deleteProjects"/>" onclick="document.forms.projectsForm.methodToCall.value='remove';document.forms.projectsForm.submit();" />
<input type="button" name="build-projects" value="<ww:text name="projectGroup.buildProjects"/>" onclick="document.forms.projectsForm.methodToCall.value='build';document.forms.projectsForm.submit();" />
+ <input type="button" name="cancel-builds" value="<ww:text name="projectGroup.cancelBuilds"/>" onclick="document.forms.projectsForm.action='cancelBuilds.action';document.forms.projectsForm.submit();" />
</redback:ifAuthorized>
</td>
</tr>