Return-Path: Delivered-To: apmail-continuum-commits-archive@www.apache.org Received: (qmail 59747 invoked from network); 9 Jan 2009 10:32:19 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 9 Jan 2009 10:32:19 -0000 Received: (qmail 54974 invoked by uid 500); 9 Jan 2009 10:32:19 -0000 Delivered-To: apmail-continuum-commits-archive@continuum.apache.org Received: (qmail 54959 invoked by uid 500); 9 Jan 2009 10:32:18 -0000 Mailing-List: contact commits-help@continuum.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@continuum.apache.org Delivered-To: mailing list commits@continuum.apache.org Received: (qmail 54949 invoked by uid 99); 9 Jan 2009 10:32:18 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jan 2009 02:32:18 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 09 Jan 2009 10:32:15 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 412752388988; Fri, 9 Jan 2009 02:31:54 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r733001 - in /continuum/branches/continuum-parallel-builds: continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/ continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/ continuum-core/src/main/java/org/apache/mav... Date: Fri, 09 Jan 2009 10:31:53 -0000 To: commits@continuum.apache.org From: oching@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090109103154.412752388988@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: oching Date: Fri Jan 9 02:31:52 2009 New Revision: 733001 URL: http://svn.apache.org/viewvc?rev=733001&view=rev Log: - do not allow project to be built if project is in release stage Modified: continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/TaskQueueManager.java continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java Modified: continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/TaskQueueManager.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/TaskQueueManager.java?rev=733001&r1=733000&r2=733001&view=diff ============================================================================== --- continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/TaskQueueManager.java (original) +++ continuum/branches/continuum-parallel-builds/continuum-api/src/main/java/org/apache/continuum/taskqueue/manager/TaskQueueManager.java Fri Jan 9 02:31:52 2009 @@ -53,6 +53,16 @@ boolean isRepositoryInUse( int repositoryId ) throws TaskQueueManagerException; + /** + * Check whether a project is in the release stage based on the given releaseId. + * + * @param releaseId + * @return + * @throws TaskQueueManagerException + */ + boolean isProjectInReleaseStage( String releaseId ) + throws TaskQueueManagerException; + boolean releaseInProgress() throws TaskQueueManagerException; Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java?rev=733001&r1=733000&r2=733001&view=diff ============================================================================== --- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java (original) +++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/continuum/taskqueue/manager/DefaultTaskQueueManager.java Fri Jan 9 02:31:52 2009 @@ -31,6 +31,7 @@ import org.apache.maven.continuum.buildqueue.BuildProjectTask; import org.apache.maven.continuum.model.project.Project; import org.apache.maven.continuum.release.tasks.PerformReleaseProjectTask; +import org.apache.maven.continuum.release.tasks.PrepareReleaseProjectTask; import org.apache.maven.continuum.store.ContinuumStoreException; import org.codehaus.plexus.PlexusConstants; import org.codehaus.plexus.PlexusContainer; @@ -58,6 +59,16 @@ private TaskQueue purgeQueue; /** + * @plexus.requirement role-hint="prepare-release" + */ + private TaskQueue prepareReleaseQueue; + + /** + * @plexus.requirement role-hint="perform-release" + */ + private TaskQueue performReleaseQueue; + + /** * @plexus.requirement */ private ProjectDao projectDao; @@ -131,6 +142,68 @@ throw new TaskQueueManagerException( e.getMessage(), e ); } } + + public boolean isProjectInReleaseStage( String releaseId ) + throws TaskQueueManagerException + { + Task prepareTask = getCurrentTask( "prepare-release" ); + if( prepareTask != null && prepareTask instanceof PrepareReleaseProjectTask ) + { + if( ( ( PrepareReleaseProjectTask ) prepareTask ).getReleaseId().equals( releaseId ) ) + { + return true; + } + else + { + try + { + // check if in queue + List tasks = prepareReleaseQueue.getQueueSnapshot(); + for( Task prepareReleaseTask : tasks ) + { + if( ( ( PrepareReleaseProjectTask) prepareReleaseTask ).getReleaseId().equals( releaseId ) ) + { + return true; + } + } + } + catch ( TaskQueueException e ) + { + throw new TaskQueueManagerException( e ); + } + } + } + + Task performTask = getCurrentTask( "perform-release" ); + if( performTask != null && performTask instanceof PerformReleaseProjectTask ) + { + if( ( ( PerformReleaseProjectTask ) performTask ).getReleaseId().equals( releaseId ) ) + { + return true; + } + else + { + try + { + // check if in queue + List tasks = performReleaseQueue.getQueueSnapshot(); + for( Task performReleaseTask : tasks ) + { + if( ( ( PerformReleaseProjectTask) performReleaseTask ).getReleaseId().equals( releaseId ) ) + { + return true; + } + } + } + catch ( TaskQueueException e ) + { + throw new TaskQueueManagerException( e ); + } + } + } + + return false; + } public boolean releaseInProgress() throws TaskQueueManagerException @@ -239,5 +312,5 @@ { throw new TaskQueueManagerException( "Unable to lookup current task", e ); } - } + } } Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java?rev=733001&r1=733000&r2=733001&view=diff ============================================================================== --- continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java (original) +++ continuum/branches/continuum-parallel-builds/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java Fri Jan 9 02:31:52 2009 @@ -53,6 +53,7 @@ import org.apache.continuum.purge.PurgeConfigurationService; import org.apache.continuum.repository.RepositoryService; import org.apache.continuum.taskqueue.manager.TaskQueueManager; +import org.apache.continuum.taskqueue.manager.TaskQueueManagerException; import org.apache.maven.continuum.build.settings.SchedulesActivationException; import org.apache.maven.continuum.build.settings.SchedulesActivator; import org.apache.maven.continuum.builddefinition.BuildDefinitionService; @@ -761,13 +762,17 @@ public void buildProjectsWithBuildDefinition( List projects, List bds ) throws ContinuumException { - prepareBuildProjects( projects, bds, true, ContinuumProjectState.TRIGGER_FORCED ); + Collection filteredProjectsList = getProjectsNotInReleaseStage( projects ); + + prepareBuildProjects( filteredProjectsList, bds, true, ContinuumProjectState.TRIGGER_FORCED ); } public void buildProjectsWithBuildDefinition( List projects, int buildDefinitionId ) throws ContinuumException { - prepareBuildProjects( projects, buildDefinitionId, ContinuumProjectState.TRIGGER_FORCED ); + Collection filteredProjectsList = getProjectsNotInReleaseStage( projects ); + + prepareBuildProjects( filteredProjectsList, buildDefinitionId, ContinuumProjectState.TRIGGER_FORCED ); } /** @@ -791,8 +796,10 @@ projectsList = getProjects(); } - - prepareBuildProjects( projectsList, null, true, trigger ); + + Collection filteredProjectsList = getProjectsNotInReleaseStage( projectsList ); + + prepareBuildProjects( filteredProjectsList, null, true, trigger ); } /** @@ -818,7 +825,9 @@ projectsList = getProjects(); } - prepareBuildProjects( projectsList, buildDefinitionId, trigger ); + Collection filteredProjectsList = getProjectsNotInReleaseStage( projectsList ); + + prepareBuildProjects( filteredProjectsList, buildDefinitionId, trigger ); } /** @@ -831,10 +840,13 @@ throws ContinuumException { List groupDefaultBDs = null; + + if( !isAnyProjectInGroupInReleaseStage( projectGroupId ) ) + { + groupDefaultBDs = getDefaultBuildDefinitionsForProjectGroup( projectGroupId ); - groupDefaultBDs = getDefaultBuildDefinitionsForProjectGroup( projectGroupId ); - - buildProjectGroupWithBuildDefinition( projectGroupId, groupDefaultBDs, true ); + buildProjectGroupWithBuildDefinition( projectGroupId, groupDefaultBDs, true ); + } } /** @@ -847,13 +859,16 @@ public void buildProjectGroupWithBuildDefinition( int projectGroupId, int buildDefinitionId ) throws ContinuumException { - List bds = new ArrayList(); - BuildDefinition bd = getBuildDefinition( buildDefinitionId ); - if ( bd != null ) + if( !isAnyProjectInGroupInReleaseStage( projectGroupId ) ) { - bds.add( bd ); + List bds = new ArrayList(); + BuildDefinition bd = getBuildDefinition( buildDefinitionId ); + if ( bd != null ) + { + bds.add( bd ); + } + buildProjectGroupWithBuildDefinition( projectGroupId, bds, false ); } - buildProjectGroupWithBuildDefinition( projectGroupId, bds, false ); } /** @@ -866,20 +881,23 @@ boolean checkDefaultBuildDefinitionForProject ) throws ContinuumException { - Collection projectsList; - - try + if( !isAnyProjectInGroupInReleaseStage( projectGroupId ) ) { - projectsList = getProjectsInBuildOrder( projectDao.getProjectsWithDependenciesByGroupId( projectGroupId ) ); - } - catch ( CycleDetectedException e ) - { - getLogger().warn( "Cycle detected while sorting projects for building, falling back to unsorted build." ); - - projectsList = getProjects(); + Collection projectsList; + + try + { + projectsList = getProjectsInBuildOrder( projectDao.getProjectsWithDependenciesByGroupId( projectGroupId ) ); + } + catch ( CycleDetectedException e ) + { + getLogger().warn( "Cycle detected while sorting projects for building, falling back to unsorted build." ); + + projectsList = getProjects(); + } + + prepareBuildProjects( projectsList, bds, checkDefaultBuildDefinitionForProject, ContinuumProjectState.TRIGGER_FORCED ); } - - prepareBuildProjects( projectsList, bds, checkDefaultBuildDefinitionForProject, ContinuumProjectState.TRIGGER_FORCED ); } /** @@ -896,7 +914,7 @@ Collection projectsList; Map projectsMap = null; - + try { projectsMap = daoUtils.getAggregatedProjectIdsAndBuildDefinitionIdsBySchedule( schedule.getId() ); @@ -983,6 +1001,12 @@ public void buildProject( int projectId, int trigger ) throws ContinuumException { + Project project = getProject( projectId ); + if( isProjectInReleaseStage( project ) ) + { + throw new ContinuumException( "Project (id=" + projectId + ") is currently in release stage." ); + } + BuildDefinition buildDef = getDefaultBuildDefinition( projectId ); if ( buildDef == null ) @@ -1008,11 +1032,17 @@ projectsBuildDefinitionsMap.put( projectId, buildDef.getId() ); prepareBuildProjects( projectsBuildDefinitionsMap, trigger ); - } + } public void buildProject( int projectId, int buildDefinitionId, int trigger ) throws ContinuumException { + Project project = getProject( projectId ); + if( isProjectInReleaseStage( project ) ) + { + throw new ContinuumException( "Project (id=" + projectId + ") is currently in release stage." ); + } + try { if ( parallelBuildsManager.isInAnyBuildQueue( projectId, buildDefinitionId ) || @@ -3552,4 +3582,68 @@ throw new ContinuumException( "Error while creating project scm root with scm root address:" + url ); } } + + private boolean isProjectInReleaseStage( Project project ) throws ContinuumException + { + String releaseId = project.getGroupId() + ":" + project.getArtifactId(); + try + { + if( taskQueueManager.isProjectInReleaseStage( releaseId ) ) + { + return true; + } + return false; + } + catch ( TaskQueueManagerException e ) + { + throw new ContinuumException( "Error occurred while checking if project is currently being released.", e ); + } + } + + private boolean isAnyProjectInGroupInReleaseStage( int projectGroupId ) + throws ContinuumException + { + Collection projects = getProjectsInGroup( projectGroupId ); + for( Project project : projects ) + { + if( isProjectInReleaseStage( project ) ) + { + throw new ContinuumException( "Cannot build project group. Project (id=" + project.getId() + + ") in group is currently in release stage." ); + } + } + return false; + } + + private Collection getProjectsNotInReleaseStage( Collection projectsList ) + throws ContinuumException + { + // filter the projects to be built + // projects that are in the release stage will not be built + Collection filteredProjectsList = new ArrayList(); + for( Project project : projectsList ) + { + if( !isProjectInReleaseStage( project ) ) + { + filteredProjectsList.add( project ); + } + else + { + getLogger().warn( + "Project (id=" + project.getId() + + ") will not be built. It is currently in the release stage." ); + } + } + return filteredProjectsList; + } + + void setTaskQueueManager( TaskQueueManager taskQueueManager ) + { + this.taskQueueManager = taskQueueManager; + } + + void setProjectDao( ProjectDao projectDao ) + { + this.projectDao = projectDao; + } } Modified: continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java URL: http://svn.apache.org/viewvc/continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java?rev=733001&r1=733000&r2=733001&view=diff ============================================================================== --- continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java (original) +++ continuum/branches/continuum-parallel-builds/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java Fri Jan 9 02:31:52 2009 @@ -20,6 +20,7 @@ */ import java.io.File; +import java.util.ArrayList; import java.util.Collection; import java.util.HashMap; import java.util.Iterator; @@ -27,9 +28,11 @@ import java.util.Map; import org.apache.continuum.buildmanager.BuildsManager; +import org.apache.continuum.dao.ProjectDao; import org.apache.continuum.model.release.ContinuumReleaseResult; import org.apache.continuum.model.repository.LocalRepository; import org.apache.continuum.repository.RepositoryService; +import org.apache.continuum.taskqueue.manager.TaskQueueManager; import org.apache.maven.continuum.builddefinition.BuildDefinitionService; import org.apache.maven.continuum.configuration.ConfigurationService; import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants; @@ -39,6 +42,9 @@ import org.apache.maven.continuum.model.project.ProjectNotifier; import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult; import org.apache.maven.continuum.utils.ContinuumUrlValidator; +import org.jmock.Expectations; +import org.jmock.Mockery; +import org.jmock.integration.junit3.JUnit3Mockery; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -51,6 +57,25 @@ { protected Logger log = LoggerFactory.getLogger( getClass() ); + private Mockery context; + + private TaskQueueManager taskQueueManager; + + private ProjectDao projectDao; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + context = new JUnit3Mockery(); + + taskQueueManager = context.mock( TaskQueueManager.class ); + + projectDao = context.mock( ProjectDao.class ); + } + public void testContinuumConfiguration() throws Exception { @@ -476,7 +501,92 @@ assertFalse( logFile.exists() ); assertEquals( defaultProjectGroup, continuum.getProjectGroupByGroupId( Continuum.DEFAULT_PROJECT_GROUP_GROUP_ID ) ); } - + + public void testBuildProjectWhileProjectIsInReleaseStage() + throws Exception + { + DefaultContinuum continuum = ( DefaultContinuum ) getContinuum(); + + continuum.setTaskQueueManager( taskQueueManager ); + + continuum.setProjectDao( projectDao ); + + final Project project = new Project(); + project.setId( 1 ); + project.setName( "Continuum Core" ); + project.setGroupId( "org.apache.continuum" ); + project.setArtifactId( "continuum-core" ); + + context.checking( new Expectations() + { + { + one( projectDao ).getProject( 1 ); + will( returnValue( project ) ); + + one( taskQueueManager ).isProjectInReleaseStage( "org.apache.continuum:continuum-core" ); + will( returnValue( true ) ); + } + }); + + try + { + continuum.buildProject( 1 ); + fail( "An exception should have been thrown." ); + } + catch ( ContinuumException e ) + { + assertEquals( "Project (id=1) is currently in release stage.", e.getMessage() ); + } + } + + public void testBuildProjectGroupWhileAtLeastOneProjectIsInReleaseStage() + throws Exception + { + DefaultContinuum continuum = ( DefaultContinuum ) getContinuum(); + + continuum.setTaskQueueManager( taskQueueManager ); + + continuum.setProjectDao( projectDao ); + + final List projects = new ArrayList(); + + Project project = new Project(); + project.setId( 1 ); + project.setName( "Continuum Core" ); + project.setGroupId( "org.apache.continuum" ); + project.setArtifactId( "continuum-core" ); + projects.add( project ); + + project = new Project(); + project.setId( 2 ); + project.setName( "Continuum API" ); + project.setGroupId( "org.apache.continuum" ); + project.setArtifactId( "continuum-api" ); + projects.add( project ); + + context.checking( new Expectations() + { + { + one( projectDao ).getProjectsInGroup( 1 ); + will( returnValue( projects ) ); + + one( taskQueueManager ).isProjectInReleaseStage( "org.apache.continuum:continuum-core" ); + will( returnValue( true ) ); + } + }); + + try + { + continuum.buildProjectGroup( 1 ); + fail( "An exception should have been thrown." ); + } + catch ( ContinuumException e ) + { + assertEquals( "Cannot build project group. Project (id=1) in group is currently in release stage.", + e.getMessage() ); + } + } + private Continuum getContinuum() throws Exception {