You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@continuum.apache.org by oc...@apache.org on 2009/01/09 11:31:53 UTC
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...
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<Task> 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<Task> 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<Project> projects, List<BuildDefinition> bds )
throws ContinuumException
{
- prepareBuildProjects( projects, bds, true, ContinuumProjectState.TRIGGER_FORCED );
+ Collection<Project> filteredProjectsList = getProjectsNotInReleaseStage( projects );
+
+ prepareBuildProjects( filteredProjectsList, bds, true, ContinuumProjectState.TRIGGER_FORCED );
}
public void buildProjectsWithBuildDefinition( List<Project> projects, int buildDefinitionId )
throws ContinuumException
{
- prepareBuildProjects( projects, buildDefinitionId, ContinuumProjectState.TRIGGER_FORCED );
+ Collection<Project> filteredProjectsList = getProjectsNotInReleaseStage( projects );
+
+ prepareBuildProjects( filteredProjectsList, buildDefinitionId, ContinuumProjectState.TRIGGER_FORCED );
}
/**
@@ -791,8 +796,10 @@
projectsList = getProjects();
}
-
- prepareBuildProjects( projectsList, null, true, trigger );
+
+ Collection<Project> filteredProjectsList = getProjectsNotInReleaseStage( projectsList );
+
+ prepareBuildProjects( filteredProjectsList, null, true, trigger );
}
/**
@@ -818,7 +825,9 @@
projectsList = getProjects();
}
- prepareBuildProjects( projectsList, buildDefinitionId, trigger );
+ Collection<Project> filteredProjectsList = getProjectsNotInReleaseStage( projectsList );
+
+ prepareBuildProjects( filteredProjectsList, buildDefinitionId, trigger );
}
/**
@@ -831,10 +840,13 @@
throws ContinuumException
{
List<BuildDefinition> 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<BuildDefinition> bds = new ArrayList<BuildDefinition>();
- BuildDefinition bd = getBuildDefinition( buildDefinitionId );
- if ( bd != null )
+ if( !isAnyProjectInGroupInReleaseStage( projectGroupId ) )
{
- bds.add( bd );
+ List<BuildDefinition> bds = new ArrayList<BuildDefinition>();
+ 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<Project> 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<Project> 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<Project> 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<Project> 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<Project> getProjectsNotInReleaseStage( Collection<Project> projectsList )
+ throws ContinuumException
+ {
+ // filter the projects to be built
+ // projects that are in the release stage will not be built
+ Collection<Project> filteredProjectsList = new ArrayList<Project>();
+ 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<Project> projects = new ArrayList<Project>();
+
+ 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
{