Return-Path: Delivered-To: apmail-maven-continuum-commits-archive@www.apache.org Received: (qmail 7074 invoked from network); 4 Sep 2007 08:07:59 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Sep 2007 08:07:59 -0000 Received: (qmail 54304 invoked by uid 500); 4 Sep 2007 08:07:54 -0000 Delivered-To: apmail-maven-continuum-commits-archive@maven.apache.org Received: (qmail 54278 invoked by uid 500); 4 Sep 2007 08:07:54 -0000 Mailing-List: contact continuum-commits-help@maven.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: continuum-dev@maven.apache.org Delivered-To: mailing list continuum-commits@maven.apache.org Received: (qmail 54261 invoked by uid 99); 4 Sep 2007 08:07:54 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Sep 2007 01:07:54 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 04 Sep 2007 08:07:58 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id E27651A9832; Tue, 4 Sep 2007 01:07:37 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: 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... Date: Tue, 04 Sep 2007 08:07:34 -0000 To: continuum-commits@maven.apache.org From: evenisse@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20070904080737.E27651A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 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 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 Emmanuel Venisse * @version $Id$ @@ -41,6 +44,10 @@ private int projectId; + private int projectGroupId; + + private List 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 getSelectedProjects() + { + return selectedProjects; + } + + public void setSelectedProjects( List 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 @@ buildResults + + + + projectGroupSummary + ${projectGroupId} + +