continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jmcconn...@apache.org
Subject svn commit: r432460 [1/2] - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/ continuum-api/src/main/java/org/apache/maven/continuum/store/ continuum-core/src/main/java/org/apache/maven/continuum/ continuum-core/src/mai...
Date Fri, 18 Aug 2006 01:42:48 GMT
Author: jmcconnell
Date: Thu Aug 17 18:42:46 2006
New Revision: 432460

URL: http://svn.apache.org/viewvc?rev=432460&view=rev
Log:
my first pass through with project grouping which required a fair amount of changes to -api -core -store to support the concepts already in place in the -model.  the -webapp parts are basically working, the triggered builds are still building everything across the board but support for fixing that is in place to be wired in.  Whole slew of changes but brett and jason were both cool with my getting this big commit out of the way so I could continue on the same path without this looming.

Added:
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java   (with props)
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildDefinitionAction.java   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/ProjectGroupAction.java   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/component/
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/component/BuildDefinitionSummaryAction.java   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/exception/
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/exception/ContinuumActionException.java   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/components/buildDefinitionGroupSummaryComponent.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/components/buildDefinitionSummaryComponent.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/components/failureComponent.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/components/projectSummaryComponent.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/projectGroupBuildDefinition.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/projectGroupNotifier.jsp   (with props)
    maven/continuum/trunk/continuum-webapp/src/main/webapp/projectGroupView.jsp   (with props)
Removed:
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AddBuildDefinitionAction.java
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/BuildDefinitionEditAction.java
    maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/DeleteBuildDefinitionAction.java
Modified:
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/Continuum.java
    maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/DefaultContinuum.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractContinuumAction.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/StoreProjectGroupAction.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
    maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
    maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
    maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java
    maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
    maven/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
    maven/continuum/trunk/continuum-webapp/src/main/mdo/view-models.xml
    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/buildDefinitionEdit.jsp
    maven/continuum/trunk/continuum-webapp/src/main/webapp/deleteBuildDefinition.jsp
    maven/continuum/trunk/continuum-webapp/src/main/webapp/groupSummary.jsp
    maven/continuum/trunk/continuum-webapp/src/main/webapp/navigations/Menu.jsp
    maven/continuum/trunk/continuum-webapp/src/main/webapp/projectView.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=432460&r1=432459&r2=432460&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 Thu Aug 17 18:42:46 2006
@@ -22,6 +22,7 @@
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.model.project.Schedule;
+import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.model.system.ContinuumUser;
 import org.apache.maven.continuum.model.system.UserGroup;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
@@ -46,8 +47,14 @@
     // Project Groups
     // ----------------------------------------------------------------------
 
+    public ProjectGroup getProjectGroup( int projectGroupId )
+        throws ContinuumException;
+
     public Collection getAllProjectGroupsWithProjects();
 
+    public ProjectGroup getProjectGroupByProjectId( int projectId )
+        throws ContinuumException;
+
     public Collection getProjectsInGroup( int projectGroupId )
         throws ContinuumException;
     
@@ -202,29 +209,70 @@
     // Build Definition
     // ----------------------------------------------------------------------
 
+    /**
+     * @deprecated
+     */
     List getBuildDefinitions( int projectId )
         throws ContinuumException;
 
+    /**
+     * @deprecated
+     */
+    BuildDefinition getBuildDefinition( int projectId, int buildDefinitionId )
+        throws ContinuumException;
+
+    /**
+     * @deprecated
+     */
+    void removeBuildDefinition( int projectId, int buildDefinitionId )
+        throws ContinuumException;
+
+    /**
+     * returns the build definition from either the project or the project group it is a part of
+     *
+     * @param buildDefinitionId
+     * @return
+     */
+    BuildDefinition getBuildDefinition( int buildDefinitionId )
+        throws ContinuumException;
+
+    /**
+     * returns the default build definition for the project
+     *
+     * 1) if project has default build definition, return that
+     * 2) otherwise return default build definition for parent project group
+     *
+     * @param projectId
+     * @return
+     * @throws ContinuumException
+     */
     BuildDefinition getDefaultBuildDefinition( int projectId )
         throws ContinuumException;
 
-    BuildDefinition getBuildDefinition( int projectId, int buildDefinitionId )
+    void addBuildDefinitionToProject( int projectId, BuildDefinition buildDefinition )
         throws ContinuumException;
 
-    void updateBuildDefinition( BuildDefinition buildDefinition, int projectId )
+    void addBuildDefinitionToProjectGroup( int projectGroupId, BuildDefinition buildDefinition )
+        throws ContinuumException;    
+
+    List getBuildDefinitionsForProject( int projectId )
         throws ContinuumException;
 
-    void updateBuildDefinition( int projectId, int buildDefinitionId, Map configuration )
+    List getBuildDefinitionsForProjectGroup( int projectGroupId )
         throws ContinuumException;
 
-    void addBuildDefinition( int projectId, BuildDefinition buildDefinition )
+    void removeBuildDefinitionFromProject( int projectId, int buildDefinitionId )
         throws ContinuumException;
 
-    void addBuildDefinitionFromParams( int projectId, Map configuration )
+    void removeBuildDefinitionFromProjectGroup( int projectGroupId, int buildDefinitionId )
         throws ContinuumException;
 
-    void removeBuildDefinition( int projectId, int buildDefinitionId )
+    void updateBuildDefinitionForProject( int projectId, BuildDefinition buildDefinition )
         throws ContinuumException;
+
+    void updateBuildDefinitionForProjectGroup( int projectGroupId, BuildDefinition buildDefinition )
+        throws ContinuumException;
+
 
     // ----------------------------------------------------------------------
     // Schedule

Modified: maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java (original)
+++ maven/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/store/ContinuumStore.java Thu Aug 17 18:42:46 2006
@@ -53,7 +53,41 @@
 
     Map getDefaultBuildDefinitions();
 
-    BuildDefinition getDefaultBuildDefinition( int projectId );
+    /**
+     * returns the default build definition of the project, if the project doesn't have on declared the default
+     * of the project group will be returned
+     *
+     * this should be the most common usage of the default build definition accessing methods
+     *
+     * @param projectId
+     * @return
+     * @throws ContinuumStoreException
+     * @throws ContinuumObjectNotFoundException
+     */
+    BuildDefinition getDefaultBuildDefinition( int projectId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException;
+
+    /**
+     * returns the default build definition for the project without consulting the project group
+     *
+     * @param projectId
+     * @return
+     * @throws ContinuumStoreException
+     * @throws ContinuumObjectNotFoundException
+     */
+    BuildDefinition getDefaultBuildDefinitionForProject( int projectId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException;
+
+    /**
+     * returns the default build definition for the project group and there should always be one declared
+     * 
+     * @param projectGroupId
+     * @return
+     * @throws ContinuumStoreException
+     * @throws ContinuumObjectNotFoundException
+     */
+    BuildDefinition getDefaultBuildDefinitionForProjectGroup( int projectGroupId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException;
 
     BuildDefinition getBuildDefinition( int buildDefinitionId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException;
@@ -69,6 +103,9 @@
     ProjectGroup getProjectGroup( int projectGroupId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException;
 
+    public ProjectGroup getProjectGroupByProjectId( int projectId )
+        throws ContinuumObjectNotFoundException;
+
     void updateProjectGroup( ProjectGroup group )
         throws ContinuumStoreException;
 
@@ -78,6 +115,8 @@
 
     List getAllProjectsByNameWithDependencies();
 
+    public List getProjectsWithDependenciesByGroupId( int projectGroupId );
+
     List getAllProjectsByNameWithBuildDetails();
 
     List getAllSchedulesByName();
@@ -104,6 +143,9 @@
         throws ContinuumStoreException, ContinuumObjectNotFoundException;
 
     Map getProjectIdsAndBuildDefinitionsIdsBySchedule( int scheduleId )
+        throws ContinuumStoreException;
+
+    Map getProjectGroupIdsAndBuildDefinitionsIdsBySchedule( int scheduleId )
         throws ContinuumStoreException;
 
     void updateProject( Project project )

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=432460&r1=432459&r2=432460&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 Thu Aug 17 18:42:46 2006
@@ -181,6 +181,41 @@
     }
 
     // ----------------------------------------------------------------------
+    // Project Groups
+    // ----------------------------------------------------------------------
+    public ProjectGroup getProjectGroup( int projectGroupId )
+        throws ContinuumException
+    {
+        List projectGroups = store.getAllProjectGroupsWithBuildDetails();
+
+        for ( Iterator i = projectGroups.iterator(); i.hasNext(); )
+        {
+            ProjectGroup pg = (ProjectGroup) i.next();
+
+            if ( pg.getId() == projectGroupId )
+            {
+                return pg;
+            }
+        }
+
+        throw new ContinuumException( "invalid group id" );
+    }
+
+
+    public ProjectGroup getProjectGroupByProjectId( int projectId )
+        throws ContinuumException
+    {
+        try
+        {
+            return store.getProjectGroupByProjectId( projectId );
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            throw new ContinuumException( "could not find project group containing " + projectId );
+        }
+    }
+
+    // ----------------------------------------------------------------------
     // Projects
     // ----------------------------------------------------------------------
 
@@ -382,6 +417,13 @@
         buildProjects( ContinuumProjectState.TRIGGER_FORCED );
     }
 
+
+    /**
+     * fire of the builds of all projects across all project groups using their default build definitions
+     *
+     * @param trigger
+     * @throws ContinuumException
+     */
     public void buildProjects( int trigger )
         throws ContinuumException
     {
@@ -398,24 +440,89 @@
             projectsList = getProjects();
         }
 
-        Map buildDefinitionsIds = store.getDefaultBuildDefinitions();
+        //Map buildDefinitionsIds = store.getDefaultBuildDefinitions();
+
+        for ( Iterator i = projectsList.iterator(); i.hasNext(); )
+        {
+            Project project = (Project) i.next();
+
+            Integer buildDefId = null;
+
+            try
+            {
+                buildDefId = store.getDefaultBuildDefinition( project.getId() ).getId();
+            }
+            catch (ContinuumStoreException e)
+            {
+                throw new ContinuumException(
+                    "Project (id=" + project.getId() + " doens't have a default build definition, this should be impossible, parent should have default definition set." );
+            }
+            if ( buildDefId == null )
+            {
+                throw new ContinuumException(
+                    "Project (id=" + project.getId() + " doens't have a default build definition, this should be even more impossible since store should have throw exception" );
+            }
+
+            buildProject( project, buildDefId.intValue(), trigger );
+        }
+    }
+
+    /**
+     * fire off a build for all of the projects in a project group using their default builds
+     *
+     * @param projectGroupId
+     * @param trigger
+     * @throws ContinuumException
+     */
+    public void buildProjectGroup( int projectGroupId, int trigger )
+        throws ContinuumException
+    {
+        Collection projectsList;
+
+        try
+        {
+            projectsList = getProjectsInBuildOrder( store.getProjectsWithDependenciesByGroupId( projectGroupId ));
+        }
+        catch ( CycleDetectedException e )
+        {
+            getLogger().warn( "Cycle detected while sorting projects for building, falling back to unsorted build." );
+
+            projectsList = getProjects();
+        }
+
+        //Map buildDefinitionsIds = store.getDefaultBuildDefinitions();
 
         for ( Iterator i = projectsList.iterator(); i.hasNext(); )
         {
             Project project = (Project) i.next();
 
-            Integer buildDefId = (Integer) buildDefinitionsIds.get( new Integer( project.getId() ) );
+            Integer buildDefId = null;
 
+            try
+            {
+                buildDefId = store.getDefaultBuildDefinition( project.getId() ).getId();
+            }
+            catch (ContinuumStoreException e)
+            {
+                throw new ContinuumException(
+                    "Project (id=" + project.getId() + " doens't have a default build definition, this should be impossible, parent should have default definition set." );
+            }
             if ( buildDefId == null )
             {
-                throw new ContinuumException( "Project (id=" + project.getId()
-                    + " doens't have a default build definition." );
+                throw new ContinuumException(
+                    "Project (id=" + project.getId() + " doens't have a default build definition, this should be even more impossible since store should have throw exception" );
             }
 
             buildProject( project, buildDefId.intValue(), trigger );
         }
     }
 
+    /**
+     * takes a given schedule and determines which projects need to build
+     *
+     * @param schedule
+     * @throws ContinuumException
+     */
     public void buildProjects( Schedule schedule )
         throws ContinuumException
     {
@@ -423,57 +530,98 @@
 
         Map projectsMap = null;
 
+        Map projectGroupsMap = null;
+
         try
         {
+            // todo the store should get cleaned up some so this isn't as clunky, I think the store should be able to return all of these info
             projectsMap = store.getProjectIdsAndBuildDefinitionsIdsBySchedule( schedule.getId() );
 
-            if ( projectsMap == null )
+            projectGroupsMap = store.getProjectGroupIdsAndBuildDefinitionsIdsBySchedule( schedule.getId() );
+
+            if ( projectsMap == null && projectGroupsMap == null )
             {
                 // We don't have projects attached to this schedule
                 getLogger().info( "No projects to build for schedule " + schedule );
                 return;
             }
 
-            projectsList = getProjectsInBuildOrder();
+
         }
         catch ( ContinuumStoreException e )
         {
             throw new ContinuumException( "Can't get project list for schedule " + schedule.getName(), e );
         }
-        catch ( CycleDetectedException e )
+
+        Collection projectGroups = getAllProjectGroupsWithProjects();
+
+        for ( Iterator i = projectGroups.iterator(); i.hasNext(); )
         {
-            getLogger().warn( "Cycle detected while sorting projects for building, falling back to unsorted build." );
+            ProjectGroup projectGroup = (ProjectGroup) i.next();
 
-            projectsList = getProjects();
-        }
+            try
+            {
+                projectsList = getProjectsInBuildOrder( store.getProjectsWithDependenciesByGroupId( projectGroup.getId() ) );
+            }
+            catch ( CycleDetectedException e )
+            {
+                getLogger().warn(
+                    "Cycle detected while sorting projects for building, falling back to unsorted build." );
 
-        getLogger().info( "Building " + projectsList.size() + " projects" );
+                projectsList = getProjects();
+            }
 
-        for ( Iterator projectIterator = projectsList.iterator(); projectIterator.hasNext(); )
-        {
-            Project project = (Project) projectIterator.next();
+            getLogger().info( "Building " + projectsList.size() + " projects" );
 
-            // FIXME: if store.getProjectIdsAndBuildDefinitionsIdsBySchedule above throws a CycleDetectedException,
-            // then projectsMap is null.
-            List buildDefIds = (List) projectsMap.get( new Integer( project.getId() ) );
+            List groupBuildDefinitionIds = (List) projectGroupsMap.get( new Integer( projectGroup.getId() ) );
 
-            if ( buildDefIds != null && !buildDefIds.isEmpty() )
+            for ( Iterator j = projectsList.iterator(); j.hasNext(); )
             {
-                getLogger().info( "Processing " + buildDefIds.size() + " build definitions for project " + project );
-                for ( Iterator buildDefinitionIterator = buildDefIds.iterator(); buildDefinitionIterator.hasNext(); )
+                Project project = (Project) j.next();
+
+                // iterate through the project group build definitions and build
+                if ( groupBuildDefinitionIds != null && !groupBuildDefinitionIds.isEmpty() )
                 {
-                    Integer buildDefId = (Integer) buildDefinitionIterator.next();
+                    getLogger().info(
+                        "Processing " + groupBuildDefinitionIds.size() + " build definitions for project " + project );
+                    for ( Iterator buildDefinitionIterator = groupBuildDefinitionIds.iterator();
+                          buildDefinitionIterator.hasNext(); )
+                    {
+                        Integer buildDefId = (Integer) buildDefinitionIterator.next();
+
+                        if ( buildDefId != null && !isInBuildingQueue( project.getId(), buildDefId.intValue() ) &&
+                            !isInCheckoutQueue( project.getId() ) )
+                        {
+                            buildProject( project, buildDefId.intValue(), ContinuumProjectState.TRIGGER_SCHEDULED,
+                                          false );
+                        }
+                    }
+                }
+
+                // iterate through the project build definitions and build
+                List buildDefIds = (List) projectsMap.get( new Integer( project.getId() ) );
 
-                    if ( buildDefId != null && !isInBuildingQueue( project.getId(), buildDefId.intValue() )
-                        && !isInCheckoutQueue( project.getId() ) )
+                if ( buildDefIds != null && !buildDefIds.isEmpty() )
+                {
+                    getLogger().info(
+                        "Processing " + buildDefIds.size() + " build definitions for project " + project );
+                    for ( Iterator buildDefinitionIterator = buildDefIds.iterator();
+                          buildDefinitionIterator.hasNext(); )
                     {
-                        buildProject( project, buildDefId.intValue(), ContinuumProjectState.TRIGGER_SCHEDULED, false );
+                        Integer buildDefId = (Integer) buildDefinitionIterator.next();
+
+                        if ( buildDefId != null && !isInBuildingQueue( project.getId(), buildDefId.intValue() ) &&
+                            !isInCheckoutQueue( project.getId() ) )
+                        {
+                            buildProject( project, buildDefId.intValue(), ContinuumProjectState.TRIGGER_SCHEDULED,
+                                          false );
+                        }
                     }
                 }
-            }
-            else
-            {
-                getLogger().info( "No build definitions, not building for project " + project );
+                else
+                {
+                    getLogger().info( "No build definitions, not building for project " + project );
+                }
             }
         }
     }
@@ -550,10 +698,10 @@
 
         try
         {
-            if ( project.getState() != ContinuumProjectState.NEW
-                && project.getState() != ContinuumProjectState.CHECKEDOUT
-                && project.getState() != ContinuumProjectState.OK && project.getState() != ContinuumProjectState.FAILED
-                && project.getState() != ContinuumProjectState.ERROR )
+            if ( project.getState() != ContinuumProjectState.NEW &&
+                project.getState() != ContinuumProjectState.CHECKEDOUT &&
+                project.getState() != ContinuumProjectState.OK && project.getState() != ContinuumProjectState.FAILED &&
+                project.getState() != ContinuumProjectState.ERROR )
             {
                 ContinuumBuildExecutor executor = executorManager.getBuildExecutor( project.getExecutorId() );
 
@@ -574,7 +722,8 @@
                 }
             }
 
-            getLogger().info( "Enqueuing '" + project.getName() + "' (Build definition id=" + buildDefinitionId + ")." );
+            getLogger().info(
+                "Enqueuing '" + project.getName() + "' (Build definition id=" + buildDefinitionId + ")." );
 
             buildQueue.put( new BuildProjectTask( project.getId(), buildDefinitionId, trigger ) );
         }
@@ -805,10 +954,10 @@
 
     /**
      * Add a Maven 1 / Maven 2 project to Continuum
-     * 
-     * @param metadataUrl url of the pom
+     *
+     * @param metadataUrl      url of the pom
      * @param projectBuilderId {@link MavenTwoContinuumProjectBuilder#ID} for Maven 2 project
-     * or {@link MavenOneContinuumProjectBuilder#ID} for Maven 1 project.
+     *                         or {@link MavenOneContinuumProjectBuilder#ID} for Maven 1 project.
      * @return a holder with the projects, project groups and errors occurred during the project adding
      * @throws ContinuumException
      */
@@ -881,8 +1030,7 @@
                 projectGroup = store.getProjectGroupByGroupIdWithProjects( projectGroup.getGroupId() );
 
                 getLogger().info(
-                                  "Using existing project group with the group id: '" + projectGroup.getGroupId()
-                                      + "'." );
+                    "Using existing project group with the group id: '" + projectGroup.getGroupId() + "'." );
             }
             catch ( ContinuumObjectNotFoundException e )
             {
@@ -1025,8 +1173,8 @@
             if ( value instanceof String )
             {
                 String val = (String) value;
-                if ( !"sendOnSuccess".equals( val ) && !"sendOnFailure".equals( val ) && !"sendOnError".equals( val )
-                    && !"sendOnWarning".equals( val ) )
+                if ( !"sendOnSuccess".equals( val ) && !"sendOnFailure".equals( val ) && !"sendOnError".equals( val ) &&
+                    !"sendOnWarning".equals( val ) )
                 {
                     if ( !StringUtils.isEmpty( val ) )
                     {
@@ -1135,12 +1283,6 @@
         return project.getBuildDefinitions();
     }
 
-    public BuildDefinition getDefaultBuildDefinition( int projectId )
-        throws ContinuumException
-    {
-        return store.getDefaultBuildDefinition( projectId );
-    }
-
     public BuildDefinition getBuildDefinition( int projectId, int buildDefinitionId )
         throws ContinuumException
     {
@@ -1161,133 +1303,124 @@
         return buildDefinition;
     }
 
-    public void updateBuildDefinition( BuildDefinition buildDefinition, int projectId )
+    public BuildDefinition getDefaultBuildDefinition( int projectId )
         throws ContinuumException
     {
-        BuildDefinition bd = getBuildDefinition( projectId, buildDefinition.getId() );
-
-        bd.setBuildFile( buildDefinition.getBuildFile() );
-
-        bd.setGoals( buildDefinition.getGoals() );
-
-        bd.setArguments( buildDefinition.getArguments() );
-
-        Schedule schedule;
-
-        if ( buildDefinition.getSchedule() == null )
+        try
         {
-            try
-            {
-                schedule = store.getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
-            }
-            catch ( ContinuumStoreException e )
-            {
-                throw new ContinuumException( "Can't get default schedule.", e );
-            }
+            return store.getDefaultBuildDefinition( projectId );
         }
-        else
+        catch ( ContinuumObjectNotFoundException cne )
         {
-            schedule = getSchedule( buildDefinition.getSchedule().getId() );
+            throw new ContinuumException( "no default build definition for project", cne );
         }
-
-        bd.setSchedule( schedule );
-
-        if ( buildDefinition.isDefaultForProject() && !bd.isDefaultForProject() )
+        catch ( ContinuumStoreException cse )
         {
-            bd.setDefaultForProject( true );
-
-            BuildDefinition defaultBd = getDefaultBuildDefinition( projectId );
-
-            if ( defaultBd != null )
-            {
-                defaultBd.setDefaultForProject( false );
-
-                storeBuildDefinition( defaultBd );
-            }
+            throw new ContinuumException(
+                "error attempting to access default build definition for project + " + projectId, cse );
         }
 
-        storeBuildDefinition( bd );
     }
 
-    public void updateBuildDefinition( int projectId, int buildDefinitionId, Map configuration )
+    public BuildDefinition getBuildDefinition( int buildDefinitionId )
         throws ContinuumException
     {
-        BuildDefinition buildDefinition = getBuildDefinition( projectId, buildDefinitionId );
-
-        buildDefinition.setBuildFile( (String) configuration.get( "buildFile" ) );
+        try
+        {
+            return store.getBuildDefinition( buildDefinitionId );
+        }
+        catch ( ContinuumObjectNotFoundException cne )
+        {
+            throw new ContinuumException( "no build definition found", cne );
+        }
+        catch ( ContinuumStoreException cse )
+        {
+            throw new ContinuumException( "error attempting to access build definition", cse );
+        }
+    }
 
-        buildDefinition.setGoals( (String) configuration.get( "goals" ) );
 
-        buildDefinition.setArguments( (String) configuration.get( "arguments" ) );
+    public List getBuildDefinitionsForProject( int projectId )
+        throws ContinuumException
+    {
+        Project project = getProjectWithAllDetails( projectId );
 
-        Schedule schedule = getSchedule( Integer.parseInt( (String) configuration.get( "schedule" ) ) );
+        return project.getBuildDefinitions();
+    }
 
-        buildDefinition.setSchedule( schedule );
+    public List getBuildDefinitionsForProjectGroup( int projectGroupId )
+        throws ContinuumException
+    {
 
-        if ( convertBoolean( (String) configuration.get( "defaultForProject" ) ) )
-        {
-            buildDefinition.setDefaultForProject( true );
-        }
+        ProjectGroup projectGroup = getProjectGroupWithBuildDetails( projectGroupId );
 
-        updateBuildDefinition( buildDefinition, projectId );
+        return projectGroup.getBuildDefinitions();
     }
 
-    public BuildDefinition storeBuildDefinition( BuildDefinition buildDefinition )
+    public void addBuildDefinitionToProject( int projectId, BuildDefinition buildDefinition )
         throws ContinuumException
     {
-        try
-        {
-            return store.storeBuildDefinition( buildDefinition );
-        }
-        catch ( ContinuumStoreException ex )
-        {
-            throw logAndCreateException( "Error while storing buildDefinition.", ex );
-        }
+        HashMap context = new HashMap();
+
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        context.put( AbstractContinuumAction.KEY_PROJECT_ID, new Integer( projectId ) );
+
+        executeAction( "add-build-definition-to-project", context );
     }
 
-    public void addBuildDefinition( int projectId, BuildDefinition buildDefinition )
+    public void removeBuildDefinitionFromProject( int projectId, int buildDefinitionId )
         throws ContinuumException
     {
-        if ( buildDefinition.isDefaultForProject() )
-        {
-            BuildDefinition bd = getDefaultBuildDefinition( projectId );
+        HashMap context = new HashMap();
 
-            if ( bd != null )
-            {
-                bd.setDefaultForProject( false );
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, getBuildDefinition( buildDefinitionId ) );
+        context.put( AbstractContinuumAction.KEY_PROJECT_ID, new Integer( projectId ) );
 
-                storeBuildDefinition( bd );
-            }
-        }
+        executeAction( "remove-build-definition-from-project", context );
+    }
 
-        Project project = getProjectWithAllDetails( projectId );
+    public void updateBuildDefinitionForProject( int projectId, BuildDefinition buildDefinition )
+        throws ContinuumException
+    {
+        HashMap context = new HashMap();
 
-        project.addBuildDefinition( buildDefinition );
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        context.put( AbstractContinuumAction.KEY_PROJECT_ID, new Integer( projectId ) );
 
-        updateProject( project );
+        executeAction( "update-build-definition-for-project", context );
     }
 
-    public void addBuildDefinitionFromParams( int projectId, Map configuration )
+    public void addBuildDefinitionToProjectGroup( int projectGroupId, BuildDefinition buildDefinition )
         throws ContinuumException
     {
-        BuildDefinition buildDefinition = new BuildDefinition();
+        HashMap context = new HashMap();
 
-        buildDefinition.setBuildFile( (String) configuration.get( "buildFile" ) );
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        context.put( AbstractContinuumAction.KEY_PROJECT_GROUP_ID, new Integer( projectGroupId ) );
 
-        buildDefinition.setGoals( (String) configuration.get( "goals" ) );
+        executeAction( "add-build-definition-to-project-group", context );
+    }
 
-        buildDefinition.setArguments( (String) configuration.get( "arguments" ) );
+    public void removeBuildDefinitionFromProjectGroup( int projectGroupId, int buildDefinitionId )
+        throws ContinuumException
+    {
+        HashMap context = new HashMap();
 
-        Schedule schedule = getSchedule( Integer.parseInt( (String) configuration.get( "schedule" ) ) );
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, getBuildDefinition( buildDefinitionId ) );
+        context.put( AbstractContinuumAction.KEY_PROJECT_GROUP_ID, new Integer( projectGroupId ) );
 
-        buildDefinition.setSchedule( schedule );
+        executeAction( "remove-build-definition-from-project-group", context );
+    }
 
-        if ( convertBoolean( (String) configuration.get( "defaultForProject" ) ) )
-        {
-            buildDefinition.setDefaultForProject( true );
-        }
+    public void updateBuildDefinitionForProjectGroup( int projectGroupId, BuildDefinition buildDefinition )
+        throws ContinuumException
+    {
+        HashMap context = new HashMap();
 
-        addBuildDefinition( projectId, buildDefinition );
+        context.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        context.put( AbstractContinuumAction.KEY_PROJECT_GROUP_ID, new Integer( projectGroupId ) );
+
+        executeAction( "update-build-definition-for-project-group", context );
     }
 
     public void removeBuildDefinition( int projectId, int buildDefinitionId )
@@ -1845,9 +1978,9 @@
             perms.add( store.getPermission( "showProject" ) );
         }
 
-        if ( convertBoolean( (String) configuration.get( "group.permission.addBuildDefinition" ) ) )
+        if ( convertBoolean( (String) configuration.get( "group.permission.addBuildDefinitionToProject" ) ) )
         {
-            perms.add( store.getPermission( "addBuildDefinition" ) );
+            perms.add( store.getPermission( "addBuildDefinitionToProject" ) );
         }
 
         if ( convertBoolean( (String) configuration.get( "group.permission.editBuildDefinition" ) ) )
@@ -1942,16 +2075,16 @@
         {
             if ( !wdFile.isDirectory() )
             {
-                throw new InitializationException( "The specified working directory isn't a directory: " + "'"
-                    + wdFile.getAbsolutePath() + "'." );
+                throw new InitializationException(
+                    "The specified working directory isn't a directory: " + "'" + wdFile.getAbsolutePath() + "'." );
             }
         }
         else
         {
             if ( !wdFile.mkdirs() )
             {
-                throw new InitializationException( "Could not making the working directory: " + "'"
-                    + wdFile.getAbsolutePath() + "'." );
+                throw new InitializationException(
+                    "Could not making the working directory: " + "'" + wdFile.getAbsolutePath() + "'." );
             }
         }
 
@@ -1978,10 +2111,10 @@
                 }
             }
 
-            if ( project.getState() != ContinuumProjectState.NEW
-                && project.getState() != ContinuumProjectState.CHECKEDOUT
-                && project.getState() != ContinuumProjectState.OK && project.getState() != ContinuumProjectState.FAILED
-                && project.getState() != ContinuumProjectState.ERROR )
+            if ( project.getState() != ContinuumProjectState.NEW &&
+                project.getState() != ContinuumProjectState.CHECKEDOUT &&
+                project.getState() != ContinuumProjectState.OK && project.getState() != ContinuumProjectState.FAILED &&
+                project.getState() != ContinuumProjectState.ERROR )
             {
                 int state = project.getState();
 
@@ -1991,9 +2124,8 @@
 
                 try
                 {
-                    getLogger().info(
-                                      "Fix project state for project " + project.getId() + ":" + project.getName()
-                                          + ":" + project.getVersion() );
+                    getLogger().info( "Fix project state for project " + project.getId() + ":" + project.getName() +
+                        ":" + project.getVersion() );
 
                     store.updateProject( project );
 
@@ -2010,9 +2142,8 @@
                 }
             }
 
-            getLogger().info(
-                              " " + project.getId() + ":" + project.getName() + ":" + project.getVersion() + ":"
-                                  + project.getExecutorId() );
+            getLogger().info( " " + project.getId() + ":" + project.getName() + ":" + project.getVersion() + ":" +
+                project.getExecutorId() );
         }
     }
 
@@ -2133,6 +2264,7 @@
         }
         catch ( Exception e )
         {
+            getLogger().info( "exception", e );
             throw new ContinuumException( "Error while executing the action '" + actionName + "'.", e );
         }
     }
@@ -2269,6 +2401,23 @@
         try
         {
             return store.getProjectWithAllDetails( projectId );
+        }
+        catch ( ContinuumObjectNotFoundException e )
+        {
+            throw new ContinuumException( "Unable to find the requested project", e );
+        }
+        catch ( ContinuumStoreException e )
+        {
+            throw new ContinuumException( "Error retrieving the requested project", e );
+        }
+    }
+
+    public ProjectGroup getProjectGroupWithBuildDetails( int projectGroupId )
+        throws ContinuumException
+    {
+        try
+        {
+            return store.getProjectGroupWithBuildDetails( projectGroupId );
         }
         catch ( ContinuumObjectNotFoundException e )
         {

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,185 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.ContinuumException;
+import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.model.project.Schedule;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.store.ContinuumStore;
+import org.apache.maven.continuum.store.ContinuumStoreException;
+import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
+
+import java.util.Iterator;
+import java.util.List;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AbstractBuildDefinitionContinuumAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ */
+public abstract class AbstractBuildDefinitionContinuumAction
+    extends AbstractContinuumAction
+{
+
+    /**
+     * @plexus.requirement
+     */
+    ContinuumStore store;
+
+    protected void resolveDefaultBuildDefinitionsForProject( BuildDefinition buildDefinition, Project project )
+        throws ContinuumException
+    {
+        try
+        {
+            // if buildDefinition passed in is not default then we are done
+            if ( buildDefinition.isDefaultForProject() )
+            {
+                BuildDefinition storedDefinition =
+                    store.getDefaultBuildDefinitionForProject( project.getId() );
+
+                if ( storedDefinition != null )
+                {
+                    storedDefinition.setDefaultForProject( false );
+
+                    store.storeBuildDefinition( storedDefinition );
+                }
+            }
+        }
+        catch ( ContinuumObjectNotFoundException nfe )
+        {
+            getLogger().debug( getClass().getName() + ": safely ignoring the resetting of old build definition becuase it didn't exist" );
+        }
+        catch ( ContinuumStoreException cse )
+        {
+            throw new ContinuumException( "error updating old default build definition", cse );
+        }
+    }
+
+    /**
+     * resolves build definition defaults between project groups and projects
+     *
+     * 1) project groups have default build definitions
+     * 2) if project has default build definition, that overrides project group definition
+     * 3) changing parent default build definition does not effect project if it has a default declared
+     * 4) project groups much have a default build definition
+     *
+     * @param buildDefinition
+     * @param projectGroup
+     */
+    protected void resolveDefaultBuildDefinitionsForProjectGroup( BuildDefinition buildDefinition,
+                                                                  ProjectGroup projectGroup )
+        throws ContinuumException
+    {
+        try
+        {
+            BuildDefinition storedDefinition =
+                                store.getDefaultBuildDefinitionForProjectGroup( projectGroup.getId() );
+
+            // if buildDefinition passed in is not default then we are done
+            if ( buildDefinition.isDefaultForProject() )
+            {
+                if ( storedDefinition != null )
+                {
+                    storedDefinition.setDefaultForProject( false );
+
+                    store.storeBuildDefinition( storedDefinition );
+                }
+            }
+            else
+            {
+                //make sure we are not wacking out default build definition, that would be bad
+                if ( buildDefinition.getId() == storedDefinition.getId() )
+                {
+                    throw new ContinuumException( "processing this build definition would result in no default build definition for project group" );
+                }
+            }
+        }
+        catch ( ContinuumStoreException cse )
+        {
+            throw new ContinuumException( "error updating old default build definition", cse );
+        }
+    }
+
+    /**
+     * attempts to walk through the list of build definitions and upon finding a match update it with the
+     * information in the BuildDefinition object passed in.
+     *
+     * @param buildDefinitions
+     * @param buildDefinition
+     * @throws ContinuumException
+     */
+    protected void updateBuildDefinitionInList( List buildDefinitions, BuildDefinition buildDefinition )
+        throws ContinuumException
+    {
+        try
+        {
+            BuildDefinition storedDefinition = null;
+
+            for ( Iterator i = buildDefinitions.iterator(); i.hasNext(); )
+            {
+                BuildDefinition bd = (BuildDefinition) i.next();
+
+                if ( bd.getId() == buildDefinition.getId() )
+                {
+                    storedDefinition = bd;
+                }
+            }
+
+            if ( storedDefinition != null )
+            {
+                storedDefinition.setGoals( buildDefinition.getGoals() );
+                storedDefinition.setArguments( buildDefinition.getArguments() );
+                storedDefinition.setBuildFile( buildDefinition.getBuildFile() );
+
+                // special case of this is resolved in the resolveDefaultBuildDefinitionsForProjectGroup method
+                storedDefinition.setDefaultForProject( buildDefinition.isDefaultForProject() );
+
+                Schedule schedule;
+                if ( buildDefinition.getSchedule() == null )
+                {
+                    try
+                    {
+                        schedule = store.getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
+                    }
+                    catch ( ContinuumStoreException e )
+                    {
+                        throw new ContinuumException( "Can't get default schedule.", e );
+                    }
+                }
+                else
+                {
+                    schedule = store.getSchedule( buildDefinition.getSchedule().getId() );
+                }
+
+                storedDefinition.setSchedule( schedule );
+
+                store.storeBuildDefinition( buildDefinition );
+            }
+            else
+            {
+                throw new ContinuumException( "failed update, build definition didn't exist in project group" );
+            }
+        }
+        catch ( ContinuumStoreException cse )
+        {
+            throw new ContinuumException( "error in accessing or storing build definition" );
+        }
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractBuildDefinitionContinuumAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractContinuumAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractContinuumAction.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractContinuumAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AbstractContinuumAction.java Thu Aug 17 18:42:46 2006
@@ -95,7 +95,7 @@
 
     public static int getProjectGroupId( Map context )
     {
-        return Integer.valueOf( getString( context, KEY_PROJECT_GROUP_ID ) ).intValue();
+        return getInteger( context, KEY_PROJECT_GROUP_ID );
     }
 
     public static int getBuildDefinitionId( Map context )

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,51 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ *
+ * @plexus.component
+ *   role="org.codehaus.plexus.action.Action"
+ *   role-hint="add-build-definition-to-project"
+ */
+public class AddBuildDefinitionToProjectAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+    
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectId =  getProjectId( map );
+
+        Project project = store.getProjectWithAllDetails( projectId );
+
+        resolveDefaultBuildDefinitionsForProject( buildDefinition, project );
+
+        project.addBuildDefinition( buildDefinition );
+
+        store.updateProject( project );
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,51 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ *
+ * @plexus.component
+ *   role="org.codehaus.plexus.action.Action"
+ *   role-hint="add-build-definition-to-project-group"
+ */
+public class AddBuildDefinitionToProjectGroupAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+  
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectGroupId =  getProjectGroupId( map );
+
+        ProjectGroup projectGroup = store.getProjectGroupWithBuildDetails( projectGroupId );
+
+        resolveDefaultBuildDefinitionsForProjectGroup( buildDefinition, projectGroup );
+
+        projectGroup.addBuildDefinition( buildDefinition );
+
+        store.updateProjectGroup( projectGroup );
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,52 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ *
+ * @plexus.component
+ *   role="org.codehaus.plexus.action.Action"
+ *   role-hint="remove-build-definition-from-project"
+ */
+public class RemoveBuildDefinitionFromProjectAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectId =  getProjectId( map );
+
+        Project project = store.getProjectWithAllDetails( projectId );
+
+        // removing build definition from project doesn't effect anything if it is the default for the proejct, the
+        // default will just change automatically to the default build definition of the project group.
+
+        project.removeBuildDefinition( buildDefinition );
+
+        store.updateProject( project );
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,55 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.ContinuumException;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ *
+ * @plexus.component
+ *   role="org.codehaus.plexus.action.Action"
+ *   role-hint="remove-build-definition-from-project-group"
+ */
+public class RemoveBuildDefinitionFromProjectGroupAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectGroupId =  getProjectGroupId( map );
+
+        ProjectGroup projectGroup = store.getProjectGroupWithBuildDetails( projectGroupId );
+
+        if ( buildDefinition.isDefaultForProject() )
+        {
+            throw new ContinuumException( "can't remove default build definition from project group" );
+        }
+
+        projectGroup.removeBuildDefinition( buildDefinition );
+
+        store.updateProjectGroup( projectGroup );
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/RemoveBuildDefinitionFromProjectGroupAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/StoreProjectGroupAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/StoreProjectGroupAction.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/StoreProjectGroupAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/StoreProjectGroupAction.java Thu Aug 17 18:42:46 2006
@@ -27,6 +27,6 @@
 
         projectGroup = store.addProjectGroup( projectGroup );
 
-        context.put( KEY_PROJECT_GROUP_ID, Integer.toString( projectGroup.getId() ) );
+        context.put( KEY_PROJECT_GROUP_ID, new Integer( projectGroup.getId() ) );
     }
 }

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,48 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Project;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ * @plexus.component role="org.codehaus.plexus.action.Action"
+ * role-hint="update-build-definition-from-project"
+ */
+public class UpdateBuildDefinitionFromProjectAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectId = getProjectId( map );
+
+        Project project = store.getProjectWithAllDetails( projectId );
+
+        resolveDefaultBuildDefinitionsForProject( buildDefinition, project );
+        
+        updateBuildDefinitionInList( project.getBuildDefinitions(), buildDefinition );
+    }
+
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java?rev=432460&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java (added)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java Thu Aug 17 18:42:46 2006
@@ -0,0 +1,49 @@
+package org.apache.maven.continuum.core.action;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+
+import java.util.Map;
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+/**
+ * AddBuildDefinitionToProjectAction:
+ *
+ * @author: Jesse McConnell <jmcconnell@apache.org>
+ * @version: $ID:$
+ *
+ * @plexus.component
+ *   role="org.codehaus.plexus.action.Action"
+ *   role-hint="update-build-definition-from-project-group"
+ */
+public class UpdateBuildDefinitionFromProjectGroupAction
+    extends AbstractBuildDefinitionContinuumAction
+{
+
+    public void execute( Map map )
+        throws Exception
+    {
+        BuildDefinition buildDefinition = getBuildDefinition( map );
+        int projectGroupId =  getProjectGroupId( map );
+
+        ProjectGroup projectGroup = store.getProjectGroupWithBuildDetails( projectGroupId );
+
+        resolveDefaultBuildDefinitionsForProjectGroup( buildDefinition, projectGroup );
+
+        updateBuildDefinitionInList( projectGroup.getBuildDefinitions(), buildDefinition );
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/UpdateBuildDefinitionFromProjectGroupAction.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializer.java Thu Aug 17 18:42:46 2006
@@ -142,7 +142,7 @@
 
         createPermission( "showProject", "Show Projects" );
 
-        createPermission( "addBuildDefinition", "Add Build Definitions" );
+        createPermission( "addBuildDefinitionToProject", "Add Build Definitions" );
 
         createPermission( "editBuildDefinition", "Edit Build Definitions" );
 

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilder.java Thu Aug 17 18:42:46 2006
@@ -35,6 +35,7 @@
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
+import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.List;
 
@@ -117,45 +118,51 @@
         {
             ProjectGroup projectGroup = buildProjectGroup( mavenProject, result );
 
+            // project groups have the top lvl build definition which is the default build defintion for the sub projects
             if ( projectGroup != null )
             {
-                result.addProjectGroup( projectGroup );
-            }
-        }
+                BuildDefinition bd = new BuildDefinition();
 
-        if ( !excludedPackagingTypes.contains( mavenProject.getPackaging() ) )
-        {
-            String defaultGoal = "clean install";
+                bd.setDefaultForProject( true );
 
-            if ( mavenProject.getBuild() != null && mavenProject.getBuild().getDefaultGoal() != null )
-            {
-                defaultGoal = mavenProject.getBuild().getDefaultGoal();
-            }
+                bd.setArguments( "--batch-mode --non-recursive" );
 
-            Project continuumProject = new Project();
+                bd.setGoals( "clean install" );
 
-            BuildDefinition bd = new BuildDefinition();
+                bd.setBuildFile( "pom.xml" );
 
-            bd.setDefaultForProject( true );
+                try
+                {
+                    Schedule schedule = store.getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
 
-            bd.setArguments( "--batch-mode --non-recursive" );
+                    bd.setSchedule( schedule );
+                }
+                catch ( ContinuumStoreException e )
+                {
+                    getLogger().warn( "Can't get default schedule.", e );
+                }
 
-            bd.setGoals( defaultGoal );
+                // jdo complains that Collections.singletonList(bd) is a second class object and fails.
+                ArrayList arrayList = new ArrayList();
 
-            bd.setBuildFile( "pom.xml" );
+                arrayList.add(bd);
 
-            try
-            {
-                Schedule schedule = store.getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
+                projectGroup.setBuildDefinitions( arrayList );
 
-                bd.setSchedule( schedule );
+                result.addProjectGroup( projectGroup );
             }
-            catch ( ContinuumStoreException e )
+        }
+
+        if ( !excludedPackagingTypes.contains( mavenProject.getPackaging() ) )
+        {
+            String defaultGoal = "clean install";
+
+            if ( mavenProject.getBuild() != null && mavenProject.getBuild().getDefaultGoal() != null )
             {
-                getLogger().warn( "Can't get default schedule.", e );
+                defaultGoal = mavenProject.getBuild().getDefaultGoal();
             }
 
-            continuumProject.addBuildDefinition( bd );
+            Project continuumProject = new Project();            
 
             builderHelper.mapMavenProjectToContinuumProject( result, mavenProject, continuumProject );
 

Modified: maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml (original)
+++ maven/continuum/trunk/continuum-core/src/main/resources/META-INF/plexus/components.xml Thu Aug 17 18:42:46 2006
@@ -584,6 +584,26 @@
      -->
     <component>
       <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>add-build-definition-to-project</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.AddBuildDefinitionToProjectAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>add-build-definition-to-project-group</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.AddBuildDefinitionToProjectGroupAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
       <role-hint>add-project-to-checkout-queue</role-hint>
       <implementation>org.apache.maven.continuum.core.action.AddProjectToCheckOutQueueAction</implementation>
       <requirements>
@@ -682,6 +702,26 @@
     </component>
     <component>
       <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>remove-build-definition-from-project</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.RemoveBuildDefinitionFromProjectAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>remove-build-definition-from-project-group</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.RemoveBuildDefinitionFromProjectGroupAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
       <role-hint>store-checkout-scm-result</role-hint>
       <implementation>org.apache.maven.continuum.core.action.StoreCheckOutScmResultAction</implementation>
       <requirements>
@@ -728,6 +768,26 @@
       <role>org.codehaus.plexus.action.Action</role>
       <role-hint>validate-project-group</role-hint>
       <implementation>org.apache.maven.continuum.core.action.ValidateProjectGroup</implementation>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>update-build-definition-from-project</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.UpdateBuildDefinitionFromProjectAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.action.Action</role>
+      <role-hint>update-build-definition-from-project-group</role-hint>
+      <implementation>org.apache.maven.continuum.core.action.UpdateBuildDefinitionFromProjectGroupAction</implementation>
+      <requirements>
+        <requirement>
+          <role>org.apache.maven.continuum.store.ContinuumStore</role>
+        </requirement>
+      </requirements>
     </component>
     <component>
       <role>org.codehaus.plexus.action.Action</role>

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/DefaultContinuumTest.java Thu Aug 17 18:42:46 2006
@@ -17,7 +17,10 @@
  */
 
 import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
+import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
 
@@ -89,12 +92,17 @@
             Project project = (Project) i.next();
 
             projects.put( project.getName(), project );
+
+            // validate project in project group
+            assertTrue( "project not in project group", getStore().getProjectGroupByProjectId( project.getId() ) != null );
         }
 
         assertTrue( "no irc notifier", projects.containsKey( "Continuum IRC Notifier" ) );
 
         assertTrue( "no jabber notifier", projects.containsKey( "Continuum Jabber Notifier" ) );
-        // TODO: assert that the project is the in the group
+
+
+
     }
 
     public void testUpdateMavenTwoProject()
@@ -128,5 +136,68 @@
         continuum.updateProject( project );
 
         project = continuum.getProject( project.getId() );
+    }
+
+    public void testBuildDefinitions()
+        throws Exception
+    {
+        Continuum continuum = (Continuum) lookup( Continuum.ROLE );
+
+        String url = getTestFile( "src/test-projects/project1/pom.xml" ).toURL().toExternalForm();
+
+        ContinuumProjectBuildingResult result = continuum.addMavenTwoProject( url );
+
+        assertNotNull( result );
+
+        List projects = result.getProjects();
+
+        assertEquals( 1, projects.size() );
+
+        assertEquals( Project.class, projects.get( 0 ).getClass() );
+
+        Project project = (Project) projects.get( 0 );
+
+        // reattach
+        project = continuum.getProject( project.getId() );
+
+        ProjectGroup projectGroup  = getStore().getProjectGroupByProjectId( project.getId() );
+
+        projectGroup = getStore().getProjectGroupWithBuildDetails( projectGroup.getId() );
+
+        List buildDefs = projectGroup.getBuildDefinitions();
+
+        assertTrue ("missing project group build definition", !buildDefs.isEmpty() );
+
+        assertTrue ("more then one project group build definition on add project", buildDefs.size() == 1 );
+
+        BuildDefinition pgbd = (BuildDefinition) buildDefs.get( 0 );
+
+        assertTrue ( "project group build definition is not default", pgbd.isDefaultForProject() );
+
+        assertTrue ( "project group build definition not default for project", continuum.getDefaultBuildDefinition( project.getId() ).getId() == pgbd.getId() );
+
+        BuildDefinition nbd = new BuildDefinition();
+        nbd.setGoals("clean");
+        nbd.setArguments("");
+        nbd.setDefaultForProject( true );
+        nbd.setSchedule( getStore().getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME ) );
+
+        continuum.addBuildDefinitionToProject( project.getId(), nbd );
+
+        assertTrue ( "project lvl build definition not default for project", continuum.getDefaultBuildDefinition( project.getId() ).getId() == nbd.getId() );
+
+        continuum.removeBuildDefinitionFromProject( project.getId(), nbd.getId() );
+
+        assertTrue ( "default build definition didn't toggle back to project group level", continuum.getDefaultBuildDefinition( project.getId() ).getId() == pgbd.getId() );
+
+        try
+        {
+            continuum.removeBuildDefinitionFromProjectGroup( projectGroup.getId(), pgbd.getId() );
+            fail("we were able to remove the default build definition, and that is bad");
+        }
+        catch (ContinuumException expected)
+        {
+
+        }
     }
 }

Modified: maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java?rev=432460&r1=432459&r2=432460&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java (original)
+++ maven/continuum/trunk/continuum-store/src/main/java/org/apache/maven/continuum/store/JdoContinuumStore.java Thu Aug 17 18:42:46 2006
@@ -209,6 +209,69 @@
         return null;
     }
 
+    public Map getProjectGroupIdsAndBuildDefinitionsIdsBySchedule( int scheduleId )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( ProjectGroup.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareParameters( "int scheduleId" );
+
+            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );
+
+            query.declareVariables( "BuildDefinition buildDef" );
+
+            query.setFilter( "buildDefinitions.contains(buildDef) && buildDef.schedule.id == scheduleId" );
+
+            query.setResult( "this.id, buildDef.id" );
+
+            List result = (List) query.execute( new Integer( scheduleId ) );
+
+            Map projectGroups = new HashMap();
+
+            if ( result != null && !result.isEmpty() )
+            {
+                for ( Iterator i = result.iterator(); i.hasNext(); )
+                {
+                    Object[] obj = (Object[]) i.next();
+
+                    List buildDefinitions;
+
+                    if ( projectGroups.get( obj[0] ) != null )
+                    {
+                        buildDefinitions = (List) projectGroups.get( obj[0] );
+                    }
+                    else
+                    {
+                        buildDefinitions = new ArrayList();
+
+                        projectGroups.put( obj[0], buildDefinitions );
+                    }
+
+                    buildDefinitions.add( obj[1] );
+                }
+
+                return projectGroups;
+            }
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+        return null;
+    }
+
     public void updateBuildResult( BuildResult build )
         throws ContinuumStoreException
     {
@@ -374,54 +437,35 @@
     }
 
     public BuildDefinition getDefaultBuildDefinition( int projectId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
-        /*
-        PersistenceManager pm = getPersistenceManager();
 
-        Transaction tx = pm.currentTransaction();
+        BuildDefinition bd = null;
 
         try
         {
-            tx.begin();
-
-            Extent extent = pm.getExtent( Project.class, true );
-
-            Query query = pm.newQuery( extent );
-
-            query.declareImports( "import org.apache.maven.continuum.model.project.BuildDefinition" );
-
-            query.declareParameters( "int projectId" );
-
-            query.declareVariables( "BuildDefinition buildDef" );
-
-            query.setFilter(
-                "this.buildDefinitions.contains(buildDef) && buildDef.defaultForProject == true && this.id == projectId" );
-
-            query.setResult( "buildDef" );
-
-            List result = (List) query.execute( new Integer( projectId ) );
-
-            result = (List) pm.detachCopyAll( result );
-
-            tx.commit();
-
-            if ( result != null && !result.isEmpty() )
-            {
-                BuildDefinition bd = (BuildDefinition) result.get( 0 );
-                getLogger().info(
-                    "nb bd for project " + projectId + " : " + result.size() + " - bd id : " + bd.getId() );
-                return bd;
-            }
+            bd = getDefaultBuildDefinitionForProject( projectId );
         }
-        finally
+        catch ( ContinuumObjectNotFoundException cne )
         {
-            rollback( tx );
+            // ignore since we will try the project group
+            getLogger().debug( "no default build definition on project, trying project group" );
         }
 
-        return null;
-        */
+        //project group should have default build definition defined
+        if ( bd == null )
+        {
+            ProjectGroup projectGroup = getProjectGroupByProjectId( projectId );
+
+            bd = getDefaultBuildDefinitionForProjectGroup( projectGroup.getId() );
+        }
+
+        return bd;
+    }
 
-        // Use this code instead of code above due to an error in sql request generated by jpox for derby
+    public BuildDefinition getDefaultBuildDefinitionForProject( int projectId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException
+    {
         Project project;
 
         try
@@ -433,6 +477,7 @@
             project = null;
         }
 
+        // check if the project has a default build definition defined
         if ( project != null && project.getBuildDefinitions() != null )
         {
             for ( Iterator i = project.getBuildDefinitions().iterator(); i.hasNext(); )
@@ -446,6 +491,25 @@
             }
         }
 
+        throw new ContinuumObjectNotFoundException( "no default build definition declared for project " + projectId );
+    }
+
+
+    public BuildDefinition getDefaultBuildDefinitionForProjectGroup( int projectGroupId )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException
+    {
+        ProjectGroup projectGroup = getProjectGroupWithBuildDetails( projectGroupId );
+
+        for ( Iterator i = projectGroup.getBuildDefinitions().iterator(); i.hasNext(); )
+        {
+            BuildDefinition bd = (BuildDefinition)i.next();
+
+            // also applies to project group membership
+            if ( bd.isDefaultForProject() )
+            {
+                return bd;
+            }
+        }
         return null;
     }
 
@@ -613,6 +677,26 @@
         return getAllObjectsDetached( Project.class, "name ascending", null );
     }
 
+    // todo get this natively supported in the store
+    public List getProjectsWithDependenciesByGroupId( int projectGroupId )
+    {
+        List allProjects = getAllObjectsDetached( Project.class, "name ascending", PROJECT_DEPENDENCIES_FETCH_GROUP );
+
+        List groupProjects = new ArrayList();
+
+        for (Iterator i = allProjects.iterator(); i.hasNext(); )
+        {
+            Project project = (Project)i.next();
+
+            if (project.getProjectGroup().getId() == projectGroupId )
+            {
+                groupProjects.add( project );
+            }
+        }
+
+        return groupProjects;
+    }
+
     public List getAllProjectsByNameWithDependencies()
     {
         return getAllObjectsDetached( Project.class, "name ascending", PROJECT_DEPENDENCIES_FETCH_GROUP );
@@ -1012,6 +1096,31 @@
     {
         return (Project) getObjectById( Project.class, projectId, PROJECT_BUILD_DETAILS_FETCH_GROUP );
     }
+
+    public ProjectGroup getProjectGroupByProjectId( int projectId )
+        throws ContinuumObjectNotFoundException
+    {
+        // todo this chunk should be optimized in the store by a good query
+        Collection projectGroups = getAllProjectGroupsWithProjects();
+
+        for ( Iterator i = projectGroups.iterator(); i.hasNext(); )
+        {
+            ProjectGroup projectGroup = (ProjectGroup) i.next();
+
+            for ( Iterator j = projectGroup.getProjects().iterator(); j.hasNext(); )
+            {
+                Project project = (Project) j.next();
+
+                if ( projectId == project.getId() )
+                {
+                    return projectGroup;
+                }
+            }
+        }
+
+        throw new ContinuumObjectNotFoundException( "unable to find project group containing project with id: " + projectId );
+    }
+
 
     public ProjectGroup getDefaultProjectGroup()
         throws ContinuumStoreException



Mime
View raw message