continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r578318 [2/3] - in /maven/continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/ continuum-api/src/main/java/org/apache/maven/continuum/builddefinition/ continuum-api/src/main/java/org/apache/maven/continuum/configuration/...
Date Fri, 21 Sep 2007 23:20:55 GMT
Modified: 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=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectAction.java Fri Sep 21 16:20:52 2007
@@ -1,29 +1,27 @@
 package org.apache.maven.continuum.core.action;
 
 /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements.  See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership.  The ASF licenses this file
- * to you 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.
+ * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
+ * agreements. See the NOTICE file distributed with this work for additional information regarding
+ * copyright ownership. The ASF licenses this file to you 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.
  */
 
+import java.util.Iterator;
+import java.util.Map;
+
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.Project;
 
-import java.util.Map;
-
 /**
  * AddBuildDefinitionToProjectAction:
  *
@@ -39,17 +37,37 @@
     public void execute( Map map )
         throws Exception
     {
-        BuildDefinition buildDefinition = getBuildDefinition( map );
         int projectId = getProjectId( map );
-
         Project project = store.getProjectWithAllDetails( projectId );
+        
+        BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate( map );
 
-        resolveDefaultBuildDefinitionsForProject( buildDefinition, project );
-
-        project.addBuildDefinition( buildDefinition );
-
-        store.updateProject( project );
-
-        map.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        if (buildDefinitionTemplate != null)
+        {
+            for ( Iterator<BuildDefinition> iterator = buildDefinitionTemplate.getBuildDefinitions().iterator(); iterator
+                .hasNext(); )
+            {
+                BuildDefinition buildDefinition = iterator.next();
+                resolveDefaultBuildDefinitionsForProject( buildDefinition, project );
+
+                project.addBuildDefinition( buildDefinition );
+
+                store.updateProject( project );
+                if (buildDefinition.isDefaultForProject())
+                {
+                    map.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+                }
+            }
+        } else
+        {
+            BuildDefinition buildDefinition = getBuildDefinition( map );
+            resolveDefaultBuildDefinitionsForProject( buildDefinition, project );
+
+            project.addBuildDefinition( buildDefinition );
+
+            store.updateProject( project );
+            map.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        }
+        
     }
 }

Modified: 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=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/AddBuildDefinitionToProjectGroupAction.java Fri Sep 21 16:20:52 2007
@@ -20,8 +20,10 @@
  */
 
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 
+import java.util.Iterator;
 import java.util.Map;
 
 /**
@@ -39,17 +41,32 @@
     public void execute( Map map )
         throws Exception
     {
-        BuildDefinition buildDefinition = getBuildDefinition( map );
         int projectGroupId = getProjectGroupId( map );
-
         ProjectGroup projectGroup = store.getProjectGroupWithBuildDetailsByProjectGroupId( projectGroupId );
-
-        resolveDefaultBuildDefinitionsForProjectGroup( buildDefinition, projectGroup );
-
-        projectGroup.addBuildDefinition( buildDefinition );
-
-        store.updateProjectGroup( projectGroup );
-
-        map.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
+        BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate( map );
+        if ( buildDefinitionTemplate != null )
+        {
+            for ( Iterator<BuildDefinition> iterator = buildDefinitionTemplate.getBuildDefinitions().iterator(); iterator
+                .hasNext(); )
+            {
+                BuildDefinition buildDefinition = iterator.next();
+                resolveDefaultBuildDefinitionsForProjectGroup( buildDefinition, projectGroup );
+
+                projectGroup.addBuildDefinition( buildDefinition );
+
+                store.updateProjectGroup( projectGroup );
+            }
+        }
+        else
+        {
+            BuildDefinition buildDefinition = getBuildDefinition( map );
+
+            resolveDefaultBuildDefinitionsForProjectGroup( buildDefinition, projectGroup );
+
+            projectGroup.addBuildDefinition( buildDefinition );
+
+            store.updateProjectGroup( projectGroup );
+        }
+        //map.put( AbstractContinuumAction.KEY_BUILD_DEFINITION, buildDefinition );
     }
 }

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataAction.java Fri Sep 21 16:20:52 2007
@@ -21,6 +21,8 @@
 
 import org.apache.maven.continuum.ContinuumException;
 import org.apache.maven.continuum.execution.maven.m2.SettingsConfigurationException;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilderException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
@@ -142,8 +144,13 @@
                 {
                     url = mungedURL.getURL();
 
-                    result = projectBuilder
-                        .buildProjectsFromMetadata( url, username, password, loadRecursiveProjects );
+                    BuildDefinitionTemplate buildDefinitionTemplate = getBuildDefinitionTemplate( context );
+                    if ( buildDefinitionTemplate == null )
+                    {
+                        buildDefinitionTemplate = projectBuilder.getDefaultBuildDefinitionTemplate();
+                    }
+                    result = projectBuilder.buildProjectsFromMetadata( url, username, password, loadRecursiveProjects,
+                                                                       buildDefinitionTemplate );
 
                 }
                 else

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=578318&r1=578317&r2=578318&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 Fri Sep 21 16:20:52 2007
@@ -20,9 +20,9 @@
  */
 
 import org.apache.maven.continuum.Continuum;
-import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionServiceException;
 import org.apache.maven.continuum.model.project.ProjectGroup;
-import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.SystemConfiguration;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
 import org.apache.maven.continuum.store.ContinuumStore;
@@ -55,11 +55,11 @@
      * @plexus.requirement role-hint="jdo"
      */
     private ContinuumStore store;
-
+    
     /**
-     * @plexus.requirement role-hint="default"
-     */
-    private ConfigurationService configurationService;
+     * @plexus.requirement
+     */    
+    private BuildDefinitionService buildDefinitionService;    
 
     // ----------------------------------------------------------------------
     //
@@ -96,53 +96,35 @@
                 systemConf = store.addSystemConfiguration( systemConf );
             }
 
-            // Schedule
-            Schedule s = store.getScheduleByName( DEFAULT_SCHEDULE_NAME );
-
-            if ( s == null )
-            {
-                Schedule defaultSchedule = createDefaultSchedule();
-
-                store.addSchedule( defaultSchedule );
-            }
-
             createDefaultProjectGroup();
         }
         catch ( ContinuumStoreException e )
         {
             throw new ContinuumInitializationException( "Can't initialize default schedule.", e );
         }
+        catch (BuildDefinitionServiceException e)
+        {
+            throw new ContinuumInitializationException( "Can't get default build definition", e );
+        }
+        getLogger().info( "Continuum initializer end running ..." );
     }
-
-    // ----------------------------------------------------------------------
-    //
-    // ----------------------------------------------------------------------
-
-    public Schedule createDefaultSchedule()
-    {
-        Schedule schedule = new Schedule();
-
-        schedule.setName( DEFAULT_SCHEDULE_NAME );
-
-        schedule.setDescription( systemConf.getDefaultScheduleDescription() );
-
-        schedule.setCronExpression( systemConf.getDefaultScheduleCronExpression() );
-
-        schedule.setActive( true );
-
-        return schedule;
-    }
+    
+    
 
     private void createDefaultProjectGroup()
-        throws ContinuumStoreException
+        throws ContinuumStoreException, BuildDefinitionServiceException
     {
         ProjectGroup group;
         try
         {
             group = store.getProjectGroupByGroupId( Continuum.DEFAULT_PROJECT_GROUP_GROUP_ID );
+            getLogger().info( "Default Project Group exists" );
         }
         catch ( ContinuumObjectNotFoundException e )
         {
+            
+            getLogger().info( "create Default Project Group" );
+            
             group = new ProjectGroup();
 
             group.setName( "Default Project Group" );
@@ -151,7 +133,7 @@
 
             group.setDescription( "Contains all projects that do not have a group of their own" );
 
-            group.getBuildDefinitions().add( configurationService.getDefaultMavenTwoBuildDefinition() );
+            group.getBuildDefinitions().addAll( buildDefinitionService.getDefaultMavenTwoBuildDefinitionTemplate().getBuildDefinitions() );
 
             group = store.addProjectGroup( group );
         }

Modified: maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilder.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilder.java (original)
+++ maven/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilder.java Fri Sep 21 16:20:52 2007
@@ -19,26 +19,26 @@
  * under the License.
  */
 
-import org.apache.maven.continuum.configuration.ConfigurationService;
+import java.io.File;
+import java.net.URL;
+import java.util.Iterator;
+
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionServiceException;
 import org.apache.maven.continuum.execution.maven.m1.MavenOneBuildExecutor;
 import org.apache.maven.continuum.execution.maven.m1.MavenOneMetadataHelper;
 import org.apache.maven.continuum.execution.maven.m1.MavenOneMetadataHelperException;
-import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
-import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.project.builder.AbstractContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilderException;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.store.ContinuumStore;
-import org.apache.maven.continuum.store.ContinuumStoreException;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.File;
-import java.net.URL;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -50,11 +50,11 @@
     implements ContinuumProjectBuilder
 {
     public static final String ID = "maven-one-builder";
-
+   
     /**
      * @plexus.requirement
-     */
-    private ConfigurationService configurationService;
+     */    
+    private BuildDefinitionService buildDefinitionService;    
 
     /**
      * @plexus.requirement
@@ -80,6 +80,22 @@
                                                                      boolean recursiveProjects )
         throws ContinuumProjectBuilderException
     {
+        try
+        {
+            return buildProjectsFromMetadata( url, username, password, recursiveProjects, buildDefinitionService
+                .getDefaultMavenOneBuildDefinitionTemplate() );
+        }
+        catch ( BuildDefinitionServiceException e )
+        {
+            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+        }
+    }
+
+    public ContinuumProjectBuildingResult buildProjectsFromMetadata( URL url, String username, String password,
+                                                                     boolean recursiveProjects,
+                                                                     BuildDefinitionTemplate buildDefinitionTemplate )
+        throws ContinuumProjectBuilderException
+    {
         ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
 
         File pomFile;
@@ -101,11 +117,11 @@
             {
                 return result;
             }
-
-            BuildDefinition bd = configurationService.getDefaultMavenOneBuildDefinition();
-
-            project.addBuildDefinition( bd );
-
+            for ( Iterator<BuildDefinition> iterator = buildDefinitionTemplate.getBuildDefinitions().iterator(); iterator
+                .hasNext(); )
+            {
+                project.addBuildDefinition( iterator.next() );
+            }
             result.addProject( project, MavenOneBuildExecutor.ID );
         }
         catch ( MavenOneMetadataHelperException e )
@@ -114,10 +130,7 @@
 
             result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
         }
-        catch ( ContinuumStoreException e )
-        {
-            throw new ContinuumProjectBuilderException( e.getMessage(), e );
-        }
+        
 
         ProjectGroup projectGroup = new ProjectGroup();
 
@@ -154,5 +167,18 @@
         result.addProjectGroup( projectGroup );
 
         return result;
+    }
+
+    public BuildDefinitionTemplate getDefaultBuildDefinitionTemplate()
+        throws ContinuumProjectBuilderException
+    {
+        try
+        {
+            return buildDefinitionService.getDefaultMavenOneBuildDefinitionTemplate();
+        }
+        catch ( BuildDefinitionServiceException e )
+        {
+            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+        }
     }
 }

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=578318&r1=578317&r2=578318&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 Fri Sep 21 16:20:52 2007
@@ -19,11 +19,22 @@
  * under the License.
  */
 
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.net.ConnectException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionServiceException;
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.execution.maven.m2.MavenBuilderHelper;
 import org.apache.maven.continuum.execution.maven.m2.MavenTwoBuildExecutor;
-import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.model.project.Schedule;
@@ -36,15 +47,6 @@
 import org.apache.maven.project.MavenProject;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.net.ConnectException;
-import java.net.MalformedURLException;
-import java.net.URL;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -67,11 +69,11 @@
      * @plexus.requirement role-hint="jdo"
      */
     private ContinuumStore store;
-
+    
     /**
      * @plexus.requirement
-     */
-    private ConfigurationService configurationService;
+     */    
+    private BuildDefinitionService buildDefinitionService;    
 
     /**
      * @plexus.configuration
@@ -87,19 +89,39 @@
         return buildProjectsFromMetadata( url, username, password, true );
     }
 
-
     public ContinuumProjectBuildingResult buildProjectsFromMetadata( URL url, String username, String password,
                                                                      boolean loadRecursiveProjects )
         throws ContinuumProjectBuilderException
     {
+        try
+        {
+            return buildProjectsFromMetadata( url, username, password, loadRecursiveProjects, buildDefinitionService
+                .getDefaultMavenTwoBuildDefinitionTemplate() );
+        }
+        catch ( BuildDefinitionServiceException e )
+        {
+            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+        }
+    }
+    
+    public ContinuumProjectBuildingResult buildProjectsFromMetadata( URL url, String username, String password,
+                                                                     boolean loadRecursiveProjects, BuildDefinitionTemplate buildDefinitionTemplate )
+        throws ContinuumProjectBuilderException
+    {
         // ----------------------------------------------------------------------
         // We need to roll the project data into a file so that we can use it
         // ----------------------------------------------------------------------
 
         ContinuumProjectBuildingResult result = new ContinuumProjectBuildingResult();
 
-        readModules( url, result, true, username, password, null, loadRecursiveProjects );
-
+        try
+        {
+            readModules( url, result, true, username, password, null, loadRecursiveProjects, buildDefinitionTemplate );
+        }
+        catch ( BuildDefinitionServiceException e )
+        {
+            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+        }
         return result;
     }
 
@@ -108,8 +130,8 @@
     // ----------------------------------------------------------------------
 
     private void readModules( URL url, ContinuumProjectBuildingResult result, boolean groupPom, String username,
-                              String password, String scmUrl, boolean loadRecursiveProjects )
-        throws ContinuumProjectBuilderException
+                              String password, String scmUrl, boolean loadRecursiveProjects, BuildDefinitionTemplate buildDefinitionTemplate  )
+        throws ContinuumProjectBuilderException, BuildDefinitionServiceException
     {
 
         MavenProject mavenProject;
@@ -156,41 +178,54 @@
             result.addError( ContinuumProjectBuildingResult.ERROR_UNKNOWN );
             return;
         }
-
+        getLogger().debug( "groupPom " + groupPom );
         if ( groupPom )
         {
             ProjectGroup projectGroup = buildProjectGroup( mavenProject, result );
 
             // project groups have the top lvl build definition which is the default build defintion for the sub
             // projects
+            getLogger().debug( "projectGroup != null" + ( projectGroup != null ) );
             if ( projectGroup != null )
             {
-                BuildDefinition buildDefinition = getDefaultBuildDefinition( loadRecursiveProjects );
-                //CONTINUUM-1296
-                String defaultGoal = mavenProject.getBuild().getDefaultGoal();
-                if ( StringUtils.isNotEmpty( defaultGoal ) )
+                List<BuildDefinition> buildDefinitions = getBuildDefinitions( buildDefinitionTemplate,
+                                                                              loadRecursiveProjects );
+                boolean defaultSetted = false;   
+                for ( BuildDefinition buildDefinition : buildDefinitions )
                 {
-                    buildDefinition.setGoals( defaultGoal );
-                }
+                    if ( !defaultSetted && buildDefinition.isDefaultForProject() )
+                    {
+                        buildDefinition.setDefaultForProject( true );
+                        defaultSetted = true;
+                    }
+                    buildDefinition = buildDefinitionService.addBuildDefinition( buildDefinitionService.cloneBuildDefinition(buildDefinition) );
+                    //CONTINUUM-1296
+                    String defaultGoal = mavenProject.getBuild().getDefaultGoal();
+                    if ( StringUtils.isNotEmpty( defaultGoal ) )
+                    {
+                        buildDefinition.setGoals( defaultGoal );
+                    }
+                    if ( buildDefinition.getSchedule() == null )
+                    {
+                        try
+                        {
+                            Schedule schedule = store.getScheduleByName( ConfigurationService.DEFAULT_SCHEDULE_NAME );
+
+                            buildDefinition.setSchedule( schedule );
+                        }
+                        catch ( ContinuumStoreException e )
+                        {
+                            getLogger().warn( "Can't get default schedule.", e );
+                        }
+                    }
+                    // jdo complains that Collections.singletonList(bd) is a second class object and fails.
+                    //ArrayList arrayList = new ArrayList();
 
-                try
-                {
-                    Schedule schedule = store.getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
+                    //arrayList.add( buildDefinition );
 
-                    buildDefinition.setSchedule( schedule );
+                    projectGroup.addBuildDefinition( buildDefinition );
+                    // .setBuildDefinitions( arrayList );
                 }
-                catch ( ContinuumStoreException e )
-                {
-                    getLogger().warn( "Can't get default schedule.", e );
-                }
-
-                // jdo complains that Collections.singletonList(bd) is a second class object and fails.
-                ArrayList arrayList = new ArrayList();
-
-                arrayList.add( buildDefinition );
-
-                projectGroup.setBuildDefinitions( arrayList );
-
                 result.addProjectGroup( projectGroup );
             }
         }
@@ -286,20 +321,21 @@
                         continue;
                     }
                     // we are in recursive loading mode
-                    readModules( moduleUrl, result, false, username, password, scmUrl + "/" + module, true );
+                    readModules( moduleUrl, result, false, username, password, scmUrl + "/" + module, true, buildDefinitionTemplate  );
                 }
             }
         }
     }
 
-    private BuildDefinition getDefaultBuildDefinition( boolean loadRecursiveProjects )
-        throws ContinuumProjectBuilderException
+    private List<BuildDefinition> getBuildDefinitions(BuildDefinitionTemplate template, boolean loadRecursiveProjects )
+        throws ContinuumProjectBuilderException, BuildDefinitionServiceException
     {
-        try
+        List<BuildDefinition> buildDefinitions = new ArrayList<BuildDefinition>();
+        for (Iterator<BuildDefinition> iterator = template.getBuildDefinitions().iterator();iterator.hasNext();)
         {
-            // due to CONTINUUM-1207 user can do what they with arguments
+            BuildDefinition buildDefinition = iterator.next();
+            // due to CONTINUUM-1207 CONTINUUM-1436 user can do what they want with arguments
             // we must remove if exists --non-recursive or -N
-            BuildDefinition buildDefinition = configurationService.getDefaultMavenTwoBuildDefinition();
             if ( !loadRecursiveProjects )
             {
                 if ( StringUtils.isEmpty( buildDefinition.getArguments() ) )
@@ -313,14 +349,12 @@
                     arguments = arguments.replace( "-N", "" );
                     buildDefinition.setArguments( arguments );
                 }
-
             }
-            return buildDefinition;
-        }
-        catch ( ContinuumStoreException e )
-        {
-            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+            buildDefinition.setTemplate( false );
+            buildDefinitions.add( buildDefinition );            
         }
+        return buildDefinitions;
+               
     }
 
     private ProjectGroup buildProjectGroup( MavenProject mavenProject, ContinuumProjectBuildingResult result )
@@ -361,4 +395,20 @@
 
         return projectGroup;
     }
+    
+    
+    
+    public BuildDefinitionTemplate getDefaultBuildDefinitionTemplate()
+        throws ContinuumProjectBuilderException
+    {
+        try
+        {
+            return buildDefinitionService.getDefaultMavenTwoBuildDefinitionTemplate();
+        }
+        catch ( BuildDefinitionServiceException e )
+        {
+            throw new ContinuumProjectBuilderException( e.getMessage(), e );
+        }
+    }
+
 }

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=578318&r1=578317&r2=578318&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 Fri Sep 21 16:20:52 2007
@@ -19,7 +19,16 @@
  * under the License.
  */
 
-import org.apache.maven.continuum.initialization.DefaultContinuumInitializer;
+import java.io.File;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.configuration.ConfigurationService;
+import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
@@ -29,13 +38,6 @@
 import org.codehaus.plexus.taskqueue.TaskQueue;
 import org.codehaus.plexus.taskqueue.execution.TaskQueueExecutor;
 
-import java.io.File;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -204,7 +206,7 @@
         nbd.setGoals( "clean" );
         nbd.setArguments( "" );
         nbd.setDefaultForProject( true );
-        nbd.setSchedule( getStore().getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME ) );
+        nbd.setSchedule( getStore().getScheduleByName( ConfigurationService.DEFAULT_SCHEDULE_NAME ) );
 
         continuum.addBuildDefinitionToProject( project.getId(), nbd );
 
@@ -359,5 +361,39 @@
         assertTrue( "project missing from the checkout queue", continuum.removeProjectFromCheckoutQueue( project.getId() ) );
 
         assertFalse( "project still exist on the checkout queue", continuum.removeProjectFromCheckoutQueue( project.getId() ) );
+    }
+
+    public void testAddAntProjectWithdefaultBuildDef()
+        throws Exception
+    {
+        Continuum continuum = getContinuum();
+
+        Project project = new Project();
+        int projectId = continuum.addProject( project, ContinuumBuildExecutorConstants.ANT_BUILD_EXECUTOR );
+        ProjectGroup defaultProjectGroup = continuum
+            .getProjectGroupByGroupId( Continuum.DEFAULT_PROJECT_GROUP_GROUP_ID );
+        assertEquals( 1, continuum.getProjectGroupWithProjects( defaultProjectGroup.getId() ).getProjects().size() );
+        project = continuum.getProjectWithAllDetails( projectId );
+        assertNotNull( project );
+        
+        BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
+        assertEquals( 4, service.getAllBuildDefinitionTemplate().size() );
+        assertEquals( 5, service.getAllBuildDefinitions().size() );
+        
+        BuildDefinition buildDef = (BuildDefinition) service.getDefaultAntBuildDefinitionTemplate()
+            .getBuildDefinitions().get( 0 );
+        buildDef = service.cloneBuildDefinition( buildDef );
+        buildDef.setTemplate( false );
+        continuum.addBuildDefinitionToProject( project.getId(), buildDef );
+        project = continuum.getProjectWithAllDetails( project.getId() );
+        assertEquals( 2, project.getBuildDefinitions().size() );
+        assertEquals( 4, service.getAllBuildDefinitionTemplate().size() );
+        assertEquals( 6, service.getAllBuildDefinitions().size() );
+    }
+    
+    private Continuum getContinuum()
+        throws Exception
+    {
+        return (Continuum) lookup( Continuum.ROLE );
     }
 }

Added: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java?rev=578318&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java (added)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java Fri Sep 21 16:20:52 2007
@@ -0,0 +1,170 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.maven.continuum.builddefinition;
+
+import java.util.List;
+
+import org.apache.log4j.Logger;
+import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
+import org.apache.maven.continuum.model.project.Project;
+import org.apache.maven.continuum.model.project.ProjectGroup;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 15 sept. 07
+ * @version $Id$
+ */
+public class DefaultBuildDefinitionServiceTest
+    extends AbstractContinuumTest
+{
+    
+    private Logger logger = Logger.getLogger( getClass() );
+
+    private ProjectGroup projectGroup;
+
+    private Project project;
+
+    private BuildDefinition buildDefinition;
+    
+    private BuildDefinitionTemplate buildDefinitionTemplate;
+
+    protected void setUp()
+        throws Exception
+    {
+        super.setUp();
+        getStore().eraseDatabase();
+
+        projectGroup = new ProjectGroup();
+        projectGroup.setName( "test" );
+        projectGroup = getStore().addProjectGroup( projectGroup );
+
+        project = new Project();
+        project.setGroupId( "foo" );
+        project.setArtifactId( "bar" );
+        project.setVersion( "0.1-alpha-1-SNAPSHOT" );
+        projectGroup.addProject( project );
+        getStore().updateProjectGroup( projectGroup );
+
+        buildDefinition = new BuildDefinition();
+        buildDefinition.setTemplate( true );
+        buildDefinition.setArguments( "-N" );
+        buildDefinition.setGoals( "clean test-compile" );
+        buildDefinition.setBuildFile( "pom.xml" );
+        buildDefinition.setDescription( "desc template" );
+        buildDefinition = getBuildDefinitionService().addBuildDefinition( buildDefinition );
+        
+        buildDefinitionTemplate = new BuildDefinitionTemplate();
+        buildDefinitionTemplate.setName( "test" );
+        buildDefinitionTemplate = getBuildDefinitionService().addBuildDefinitionTemplate( buildDefinitionTemplate );
+        buildDefinitionTemplate = getBuildDefinitionService().addBuildDefinitionInTemplate( buildDefinitionTemplate,
+                                                                                            buildDefinition, false );
+        
+
+    }
+
+    protected BuildDefinitionService getBuildDefinitionService()
+        throws Exception
+    {
+        return (BuildDefinitionService) lookup( BuildDefinitionService.class );
+    }
+
+    public void testaddTemplateInProject()
+        throws Exception
+    {
+        try
+        {
+            List<BuildDefinitionTemplate> templates = getBuildDefinitionService().getAllBuildDefinitionTemplate();
+            assertEquals( 5, templates.size() );
+            assertEquals( 5, getBuildDefinitionService().getAllBuildDefinitions().size() );
+            
+            getBuildDefinitionService().addTemplateInProject( buildDefinitionTemplate.getId(), project );
+            project = getStore().getProjectWithAllDetails( project.getId() );
+            templates = getBuildDefinitionService().getAllBuildDefinitionTemplate();
+            assertEquals( 1, project.getBuildDefinitions().size() );
+            assertEquals( 5, templates.size() );
+            List<BuildDefinition> all = getBuildDefinitionService().getAllBuildDefinitions();
+            assertEquals( 6, all.size() );
+
+            getBuildDefinitionService().addTemplateInProject( buildDefinitionTemplate.getId(), project );
+
+            project = getStore().getProjectWithAllDetails( project.getId() );
+            templates = getBuildDefinitionService().getAllBuildDefinitionTemplate();
+            assertEquals( 2, project.getBuildDefinitions().size() );
+            assertEquals( 5, templates.size() );
+            all = getBuildDefinitionService().getAllBuildDefinitions();
+            assertEquals( 7, all.size() );
+
+        }
+        catch ( Exception e )
+        {
+            logger.error( e.getMessage(), e );
+            throw e;
+        }
+    }
+   
+    
+    public void testGetDefaultBuildDef()
+        throws Exception
+    {
+        BuildDefinition bd = (BuildDefinition) getBuildDefinitionService().getDefaultAntBuildDefinitionTemplate()
+            .getBuildDefinitions().get( 0 );
+        assertNotNull( bd );
+        assertEquals( "build.xml", bd.getBuildFile() );
+
+        bd = (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate()
+            .getBuildDefinitions().get( 0 );
+        BuildDefinitionService buildDefinitionService = (BuildDefinitionService) lookup( BuildDefinitionService.class );
+
+        assertEquals( 5, buildDefinitionService.getAllBuildDefinitionTemplate().size() );
+        assertNotNull( bd );
+        assertEquals( "pom.xml", bd.getBuildFile() );
+        assertEquals( "clean install", bd.getGoals() );
+    }    
+    
+    
+    public void testAddBuildDefinitionTemplate()
+        throws Exception
+    {
+        BuildDefinitionTemplate template = new BuildDefinitionTemplate();
+        template.setName( "test" );
+
+        template = getBuildDefinitionService().addBuildDefinitionTemplate( template );
+        template = getBuildDefinitionService().getBuildDefinitionTemplate( template.getId() );
+        assertNotNull( template );
+        assertEquals( "test", template.getName() );
+        List<BuildDefinition> all = getBuildDefinitionService().getAllBuildDefinitions();
+        assertEquals( 5, all.size() );
+        BuildDefinition bd = (BuildDefinition) getBuildDefinitionService().getDefaultMavenTwoBuildDefinitionTemplate()
+            .getBuildDefinitions().get( 0 );
+        template = getBuildDefinitionService().addBuildDefinitionInTemplate( template, bd, false );
+        assertEquals( 1, template.getBuildDefinitions().size() );
+        all = getBuildDefinitionService().getAllBuildDefinitions();
+        assertEquals( 5, all.size() );
+
+        template = getBuildDefinitionService().getBuildDefinitionTemplate( template.getId() );
+        template = getBuildDefinitionService().updateBuildDefinitionTemplate( template );
+        template = getBuildDefinitionService().removeBuildDefinitionFromTemplate( template, bd );
+        assertEquals( 0, template.getBuildDefinitions().size() );
+        all = getBuildDefinitionService().getAllBuildDefinitions();
+        assertEquals( 5, all.size() );
+        
+    }
+}

Propchange: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
------------------------------------------------------------------------------
    svn:eol-style = LF

Propchange: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/builddefinition/DefaultBuildDefinitionServiceTest.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri Sep 21 16:20:52 2007
@@ -0,0 +1 @@
+URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/core/action/CreateProjectsFromMetadataTest.java Fri Sep 21 16:20:52 2007
@@ -19,6 +19,12 @@
  * under the License.
  */
 
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
 import org.apache.maven.continuum.project.builder.manager.ContinuumProjectBuilderManager;
@@ -29,9 +35,6 @@
 import org.jmock.Mock;
 import org.jmock.MockObjectTestCase;
 
-import java.util.HashMap;
-import java.util.Map;
-
 public class CreateProjectsFromMetadataTest
     extends MockObjectTestCase
 {
@@ -57,10 +60,33 @@
         projectBuilder.expects( once() ).method( "buildProjectsFromMetadata" )
             .will( returnValue( new ContinuumProjectBuildingResult() ) );
 
-        mavenSettingsBuilderMock.expects( once() ).method( "buildSettings" )
-            .will( returnValue( new Settings() ) );
+        projectBuilder.expects( once() ).method( "getDefaultBuildDefinitionTemplate" )
+            .will( returnValue( getDefaultBuildDefinitionTemplate() ) );
+
+        mavenSettingsBuilderMock.expects( once() ).method( "buildSettings" ).will( returnValue( new Settings() ) );
+        
     }
 
+    private BuildDefinitionTemplate getDefaultBuildDefinitionTemplate()
+    throws Exception
+    {
+        BuildDefinition bd = new BuildDefinition();
+
+        bd.setDefaultForProject( true );
+
+        bd.setGoals( "clean install" );
+
+        bd.setArguments( "-B" );
+
+        bd.setBuildFile( "pom.xml" );
+
+        bd.setType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
+        
+        BuildDefinitionTemplate bdt = new BuildDefinitionTemplate();
+        bdt.addBuildDefinition( bd );
+        return bdt;
+    }
+    
     public void testExecuteWithNonRecursiveMode()
         throws Exception
     {
@@ -70,6 +96,7 @@
         context.put( CreateProjectsFromMetadataAction.KEY_PROJECT_BUILDER_ID, "id" );
         context.put( CreateProjectsFromMetadataAction.KEY_LOAD_RECURSIVE_PROJECTS, new Boolean( true ) );
 
+        
         action.execute( context );
 
         ContinuumProjectBuildingResult result = (ContinuumProjectBuildingResult) context

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/initialization/DefaultContinuumInitializerTest.java Fri Sep 21 16:20:52 2007
@@ -20,6 +20,7 @@
  */
 
 import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.store.ContinuumStore;
 
@@ -36,6 +37,7 @@
         throws Exception
     {
         super.setUp();
+        getContinuumStore().eraseDatabase();
         ContinuumInitializer continuumInitializer =
             (ContinuumInitializer) lookup( ContinuumInitializer.ROLE, "default" );
         continuumInitializer.initialize();
@@ -50,7 +52,7 @@
     public void testDefaultSchedule()
         throws Exception
     {
-        Schedule schedule = getContinuumStore().getScheduleByName( DefaultContinuumInitializer.DEFAULT_SCHEDULE_NAME );
+        Schedule schedule = getContinuumStore().getScheduleByName( ConfigurationService.DEFAULT_SCHEDULE_NAME );
         assertNotNull( schedule );
     }
 

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenOneContinuumProjectBuilderTest.java Fri Sep 21 16:20:52 2007
@@ -20,6 +20,10 @@
  */
 
 import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
@@ -40,9 +44,54 @@
         ContinuumProjectBuilder projectBuilder =
             (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, MavenOneContinuumProjectBuilder.ID );
 
-        ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata(
-            getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null, null );
+        
+        BuildDefinition bd = new BuildDefinition();
 
+        bd.setDefaultForProject( true );
+
+        bd.setGoals( "clean:clean jar:install" );
+
+        bd.setBuildFile( "project.xml" );
+
+        bd.setType( ContinuumBuildExecutorConstants.MAVEN_ONE_BUILD_EXECUTOR );
+        
+        bd.setTemplate( true );
+        
+        BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
+        
+        BuildDefinitionTemplate bdt = new BuildDefinitionTemplate();
+        bdt.setName( "maven1" );
+        bd = service.addBuildDefinition( bd );
+        bdt = service.addBuildDefinitionTemplate( bdt );
+        bdt = service.addBuildDefinitionInTemplate( bdt, bd, false );
+        
+        ContinuumProjectBuildingResult result = projectBuilder
+            .buildProjectsFromMetadata( getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null,
+                                        null, false, bdt );
+
+
+        assertOnResult( result );
+        
+    }
+    
+    public void testBuildingAProjectFromMetadataWithACompleteMaven1PomWithDefaultBuildDef()
+        throws Exception
+    {
+        ContinuumProjectBuilder projectBuilder = (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE,
+                                                                                   MavenOneContinuumProjectBuilder.ID );
+
+        BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
+
+        ContinuumProjectBuildingResult result = projectBuilder
+            .buildProjectsFromMetadata( getTestFile( "src/test/resources/projects/maven-1.pom.xml" ).toURL(), null,
+                                        null, false, service.getDefaultMavenOneBuildDefinitionTemplate() );
+
+        assertOnResult( result );
+
+    }    
+    
+    protected void assertOnResult( ContinuumProjectBuildingResult result )
+    {
         assertNotNull( result.getWarnings() );
 
         assertNotNull( result.getProjects() );

Modified: maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java (original)
+++ maven/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/project/builder/maven/MavenTwoContinuumProjectBuilderTest.java Fri Sep 21 16:20:52 2007
@@ -19,23 +19,27 @@
  * under the License.
  */
 
+import java.io.File;
+import java.net.URL;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.apache.log4j.Logger;
 import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.builddefinition.BuildDefinitionService;
+import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectDependency;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.model.project.ProjectNotifier;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuilder;
 import org.apache.maven.continuum.project.builder.ContinuumProjectBuildingResult;
+import org.apache.maven.continuum.store.ContinuumStore;
 import org.codehaus.plexus.util.StringUtils;
 
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.PrintStream;
-import java.net.URL;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:trygvis@inamo.no">Trygve Laugst&oslash;l</a>
  * @version $Id$
@@ -43,6 +47,22 @@
 public class MavenTwoContinuumProjectBuilderTest
     extends AbstractContinuumTest
 {
+    
+    private Logger logger = Logger.getLogger( getClass() );
+
+    /*
+    protected String getConfigurationName( String subname )
+        throws Exception
+    {
+        return super.getConfigurationName( subname );
+    }
+    */
+
+    protected String getCustomConfigurationName()
+    {
+        return "plexus.xml";
+    }
+
     public void testGetEmailAddressWhenTypeIsSetToEmail()
         throws Exception
     {
@@ -166,21 +186,9 @@
 
         URL url = getClass().getClassLoader().getResource( "projects/continuum/pom.xml" );
 
-        // Eat System.out
-        //PrintStream ps = System.out;
 
-        ContinuumProjectBuildingResult result;
+        ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( url, null, null );
 
-        //try
-        //{
-            //System.setOut( new PrintStream( new ByteArrayOutputStream() ) );
-
-            result = projectBuilder.buildProjectsFromMetadata( url, null, null );
-        //}
-        //finally
-        //{
-            //System.setOut( ps );
-        //}
 
         assertNotNull( result );
 
@@ -260,21 +268,7 @@
 
         URL url = getClass().getClassLoader().getResource( "projects/continuum/pom_ci.xml" );
 
-        // Eat System.out
-        //PrintStream ps = System.out;
-
-        ContinuumProjectBuildingResult result;
-
-        //try
-        //{
-            //System.setOut( new PrintStream( new ByteArrayOutputStream() ) );
-
-            result = projectBuilder.buildProjectsFromMetadata( url, null, null );
-        //}
-        //finally
-        //{
-            //System.setOut( ps );
-        //}
+        ContinuumProjectBuildingResult result = projectBuilder.buildProjectsFromMetadata( url, null, null );
 
         assertNotNull( result );
 
@@ -349,27 +343,48 @@
     public void testCreateProjectWithoutModules()
         throws Exception
     {
+        
+        
         ContinuumProjectBuilder projectBuilder =
             (ContinuumProjectBuilder) lookup( ContinuumProjectBuilder.ROLE, MavenTwoContinuumProjectBuilder.ID );
 
         URL url = getClass().getClassLoader().getResource( "projects/continuum/continuum-core/pom.xml" );
 
-        // Eat System.out
-        //PrintStream ps = System.out;
+        BuildDefinition bd = new BuildDefinition();
+
+        bd.setDefaultForProject( true );
 
+        bd.setGoals( "clean test-compile" );
+
+        bd.setArguments( "-N" );
+
+        bd.setBuildFile( "pom.xml" );
+
+        bd.setType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
+        
+        BuildDefinitionService service = (BuildDefinitionService) lookup( BuildDefinitionService.class );
+        
+        bd = service.addBuildDefinition( bd );
+        BuildDefinitionTemplate bdt = new BuildDefinitionTemplate();
+        bdt.setName( "maven2" );
+        bdt = service.addBuildDefinitionTemplate( bdt );
+        bdt = service.addBuildDefinitionInTemplate( bdt, bd, false );
+        assertEquals( 5, service.getAllBuildDefinitionTemplate().size() );
+        logger.debug( "templates number " + service.getAllBuildDefinitionTemplate().size() );
+
+        ContinuumStore store = (ContinuumStore) lookup( ContinuumStore.class , "jdo" );
+        logger.debug( "projectGroups number " + store.getAllProjectGroups().size() );        
+        
+        int all = service.getAllBuildDefinitions().size();
+        
         ContinuumProjectBuildingResult result;
+        
+        result = projectBuilder.buildProjectsFromMetadata( url, null, null, false, bdt );
 
-        //try
-        //{
-            //System.setOut( new PrintStream( new ByteArrayOutputStream() ) );
-
-            result = projectBuilder.buildProjectsFromMetadata( url, null, null );
-        //}
-        //finally
-        //{
-            //System.setOut( ps );
-        //}
+        assertEquals( 5, service.getAllBuildDefinitionTemplate().size() );
 
+        assertEquals( all + 1, service.getAllBuildDefinitions().size() );
+        
         assertNotNull( result );
 
         assertNotNull( result.getErrors() );
@@ -420,7 +435,7 @@
 
         assertFalse( true );
     }
-
+    
     // ----------------------------------------------------------------------
     //
     // ----------------------------------------------------------------------

Added: maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml?rev=578318&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml (added)
+++ maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml Fri Sep 21 16:20:52 2007
@@ -0,0 +1,176 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+  ~ Licensed to the Apache Software Foundation (ASF) under one
+  ~ or more contributor license agreements.  See the NOTICE file
+  ~ distributed with this work for additional information
+  ~ regarding copyright ownership.  The ASF licenses this file
+  ~ to you 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.
+  -->
+<plexus>
+  <components>
+    <component>
+      <role>org.codehaus.plexus.jdo.JdoFactory</role>
+      <role-hint>continuum</role-hint>
+      <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
+      <configuration>
+        <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
+      </configuration>
+    </component>
+    <component>
+      <role>org.codehaus.plexus.jdo.JdoFactory</role>
+      <role-hint>users</role-hint>
+      <implementation>org.codehaus.plexus.jdo.DefaultConfigurableJdoFactory</implementation>
+      <configuration>
+        <!-- Database Configuration -->
+        <driverName>org.hsqldb.jdbcDriver</driverName>
+        <url>jdbc:hsqldb:${plexus.home}/database</url>
+        <userName>sa</userName>
+        <password></password>
+        <persistenceManagerFactoryClass>org.jpox.PersistenceManagerFactoryImpl</persistenceManagerFactoryClass>
+
+        <otherProperties>
+          <!-- JPOX and JDO configuration -->
+          <property>
+            <name>org.jpox.autoCreateSchema</name>
+            <value>true</value>
+          </property>
+          <property>
+            <name>org.jpox.validateTables</name>
+            <value>false</value>
+          </property>
+          <property>
+            <name>org.jpox.validateColumns</name>
+            <value>false</value>
+          </property>
+          <property>
+            <name>org.jpox.validateConstraints</name>
+            <value>false</value>
+          </property>
+
+          <property>
+            <name>org.jpox.autoStartMechanism</name>
+            <value>SchemaTable</value>
+          </property>
+          <property>
+            <name>org.jpox.autoStartMechanismMode</name>
+            <value>Ignored</value>
+          </property>
+          <property>
+            <name>org.jpox.transactionIsolation</name>
+            <value>READ_COMMITTED</value>
+          </property>
+          <property>
+            <name>org.jpox.poid.transactionIsolation</name>
+            <value>READ_COMMITTED</value>
+          </property>
+        </otherProperties>
+      </configuration>
+    </component>
+    <!--
+     | Logger manager
+     -->
+    <component>
+      <role>org.codehaus.plexus.logging.LoggerManager</role>
+      <implementation>org.codehaus.plexus.logging.log4j.Log4JLoggerManager</implementation>
+      <lifecycle-handler>basic</lifecycle-handler>
+
+      <configuration>
+        <threshold>INFO</threshold>
+        <default-appender>console</default-appender>
+
+        <appenders>
+          <appender>
+            <id>console</id>
+            <type>org.apache.log4j.ConsoleAppender</type>
+            <conversion-pattern>%d [%t] %-5p %c - %m%n</conversion-pattern>
+          </appender>
+        </appenders>
+
+        <levels>
+          <!-- Help identify bugs during testing -->
+          <level>
+            <hierarchy>org.apache.maven.continuum</hierarchy>
+            <level>DEBUG</level>
+          </level>
+          <level>
+            <hierarchy>org.apache.maven</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>org.apache.maven.continuum.project.builder.maven.MavenTwoContinuumProjectBuilder:maven-two-builder</hierarchy>
+            <level>DEBUG</level>
+          </level>          
+          <level>
+            <hierarchy>org.codehaus.plexus.redback</hierarchy>
+            <level>INFO</level>
+          </level>
+          <!-- squelch noisy objects (for now) -->
+          <level>
+            <hierarchy>org.codehaus.plexus.mailsender.MailSender</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>org.quartz</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>org.apache.jasper</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>com.opensymphony.xwork</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <!-- CONTINUUM-1228 -->
+            <hierarchy>com.opensymphony.xwork.util.OgnlUtil</hierarchy>
+            <level>ERROR</level>
+          </level>
+          <level>
+            <hierarchy>com.opensymphony.webwork</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>org.codehaus.plexus.PlexusContainer</hierarchy>
+            <level>INFO</level>
+          </level>
+          <level>
+            <hierarchy>JPOX</hierarchy>
+            <level>WARN</level>
+          </level>
+          <level>
+            <hierarchy>JPOX.MetaData</hierarchy>
+            <level>ERROR</level>
+          </level>
+          <level>
+            <hierarchy>JPOX.RDBMS.SQL</hierarchy>
+            <level>ERROR</level>
+          </level>
+          <level>
+            <hierarchy>SQL</hierarchy>
+            <level>ERROR</level>
+          </level>
+          <level>
+            <hierarchy>freemarker</hierarchy>
+            <level>WARN</level>
+          </level>
+          <level>
+            <hierarchy>org.codehaus.plexus.component.manager.ClassicSingletonComponentManager</hierarchy>
+            <level>ERROR</level>
+          </level>
+        </levels>
+      </configuration>
+    </component>    
+  </components>
+</plexus>
\ No newline at end of file

Propchange: maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml
------------------------------------------------------------------------------
    svn:eol-style = LF

Propchange: maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml
------------------------------------------------------------------------------
    svn:executable = *

Propchange: maven/continuum/trunk/continuum-core/src/test/resources/plexus.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/continuum/trunk/continuum-model/src/main/mdo/continuum.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-model/src/main/mdo/continuum.xml?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-model/src/main/mdo/continuum.xml (original)
+++ maven/continuum/trunk/continuum-model/src/main/mdo/continuum.xml Fri Sep 21 16:20:52 2007
@@ -1042,10 +1042,10 @@
           <type>String</type>
           <description>type of the buid BuildDefinitionTemplate use for default</description>          
         </field>                                
-        <field xml.reference="true" stash.part="true" jpox.dependent="false" jpox.fetch-groups="build-template-build-definitions">
+        <field xml.reference="true" stash.part="true" jpox.fetch-groups="build-template-build-definitions">
           <name>buildDefinitions</name>
           <version>1.1.0+</version>
-          <association>
+          <association xml.reference="true" stash.part="true" jpox.dependent="false">
             <type>BuildDefinition</type>
             <multiplicity>*</multiplicity>
           </association>

Modified: maven/continuum/trunk/continuum-notifiers/continuum-notifier-wagon/src/test/java/org/apache/maven/continuum/wagon/MockConfigurationService.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-notifiers/continuum-notifier-wagon/src/test/java/org/apache/maven/continuum/wagon/MockConfigurationService.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-notifiers/continuum-notifier-wagon/src/test/java/org/apache/maven/continuum/wagon/MockConfigurationService.java (original)
+++ maven/continuum/trunk/continuum-notifiers/continuum-notifier-wagon/src/test/java/org/apache/maven/continuum/wagon/MockConfigurationService.java Fri Sep 21 16:20:52 2007
@@ -19,16 +19,16 @@
  * under the License.
  */
 
+import java.io.File;
+import java.util.Map;
+
 import org.apache.maven.continuum.configuration.ConfigurationException;
 import org.apache.maven.continuum.configuration.ConfigurationLoadingException;
 import org.apache.maven.continuum.configuration.ConfigurationService;
 import org.apache.maven.continuum.configuration.ConfigurationStoringException;
-import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 
-import java.io.File;
-import java.util.Map;
-
 /**
  * Mock class for testing WagonContinuumNotifier's call to ConfigurationService.getBuildOutputFile()
  *
@@ -192,51 +192,11 @@
     {
     }
 
-    public BuildDefinition getDefaultAntBuildDefinition()
-        throws ContinuumStoreException
-    {
-        return null;
-    }
-
-    public String getDefaultAntGoals()
-    {
-        return null;
-    }
-
-    public String getDefaultAntArguments()
-    {
-        return null;
-    }
-
-    public BuildDefinition getDefaultMavenOneBuildDefinition()
+    public Schedule getDefaultSchedule()
         throws ContinuumStoreException
     {
+        // TODO Auto-generated method stub
         return null;
     }
 
-    public String getDefaultMavenOneGoals()
-    {
-        return null;
-    }
-
-    public String getDefaultMavenOneArguments()
-    {
-        return null;
-    }
-
-    public String getDefaultMavenTwoArguments()
-    {
-        return null;
-    }
-
-    public String getDefaultMavenTwoGoals()
-    {
-        return null;
-    }
-
-    public BuildDefinition getDefaultMavenTwoBuildDefinition()
-        throws ContinuumStoreException
-    {
-        return null;
-    }
 }

Modified: maven/continuum/trunk/continuum-security/src/main/java/org/apache/maven/continuum/security/ContinuumRoleConstants.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-security/src/main/java/org/apache/maven/continuum/security/ContinuumRoleConstants.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-security/src/main/java/org/apache/maven/continuum/security/ContinuumRoleConstants.java (original)
+++ maven/continuum/trunk/continuum-security/src/main/java/org/apache/maven/continuum/security/ContinuumRoleConstants.java Fri Sep 21 16:20:52 2007
@@ -111,4 +111,6 @@
     public static final String CONTINUUM_MANAGE_INSTALLATIONS = "continuum-manage-installations";
     
     public static final String CONTINUUM_MANAGE_PROFILES = "continuum-manage-profiles";
+    
+    public static final String CONTINUUM_MANAGE_BUILD_TEMPLATES = "continuum-manage-build-templates";
 }

Modified: maven/continuum/trunk/continuum-security/src/main/resources/META-INF/redback/redback.xml
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-security/src/main/resources/META-INF/redback/redback.xml?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-security/src/main/resources/META-INF/redback/redback.xml (original)
+++ maven/continuum/trunk/continuum-security/src/main/resources/META-INF/redback/redback.xml Fri Sep 21 16:20:52 2007
@@ -3,6 +3,11 @@
   <application>Continuum</application>
   <operations>
     <operation>
+      <id>continuum-manage-build-templates</id>
+      <name>continuum-manage-build-templates</name>
+      <description>Manage Continuum Build Definition Templates</description>
+    </operation>    
+    <operation>
       <id>continuum-manage-schedules</id>
       <name>continuum-manage-schedules</name>
       <description>Manage Continuum Scheduling</description>
@@ -161,6 +166,7 @@
         <childRole>continuum-manage-installations</childRole>
         <childRole>continuum-manage-profiles</childRole>
         <childRole>continuum-manage-schedules</childRole>
+        <childRole>continuum-manage-build-templates</childRole>
       </childRoles>
     </role>
     <role>
@@ -283,7 +289,22 @@
           <resource>global</resource>
         </permission>
       </permissions>		
-	  </role>       
+	  </role>
+    <role>
+      <id>continuum-manage-build-templates</id>
+      <name>continuum-manage-build-templates</name>
+      <assignable>true</assignable>
+      <permanent>true</permanent>
+      <permissions>
+        <permission>
+          <id>continuum-manage-build-templates</id>
+          <name>Manage Continuum Build Definition Templates</name>
+          <permanent>true</permanent>
+          <operation>continuum-manage-build-templates</operation>
+          <resource>global</resource>
+        </permission>  
+      </permissions>
+    </role>       
   </roles>
   <templates>
   	<template>

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=578318&r1=578317&r2=578318&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 Fri Sep 21 16:20:52 2007
@@ -21,6 +21,7 @@
 
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectDependency;
@@ -57,6 +58,7 @@
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
@@ -101,6 +103,8 @@
     private static final String PROJECT_DEPENDENCIES_FETCH_GROUP = "project-dependencies";
 
     private static final String PROJECTGROUP_PROJECTS_FETCH_GROUP = "projectgroup-projects";
+    
+    private static final String BUILD_TEMPLATE_BUILD_DEFINITIONS = "build-template-build-definitions";
 
     // ----------------------------------------------------------------------
     // Component Lifecycle
@@ -613,6 +617,10 @@
         return notifier;
     }
 
+    // ------------------------------------------------------
+    //  BuildDefinition
+    // ------------------------------------------------------    
+    
     public BuildDefinition getDefaultBuildDefinition( int projectId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
@@ -752,6 +760,121 @@
         return null;
     }
 
+    
+    public List<BuildDefinitionTemplate> getContinuumBuildDefinitionTemplates()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
+
+            Query query = pm.newQuery( extent );
+            query.setFilter( "continuumDefault == true" );
+            pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
+            List result = (List) query.execute();
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }    
+    
+    
+    public BuildDefinitionTemplate getContinuumBuildDefinitionTemplateWithType( String type )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
+
+            Query query = pm.newQuery( extent );
+            query.declareImports( "import java.lang.String" );
+            query.declareParameters( "String type" );
+            query.setFilter( "continuumDefault == true && this.type == type" );
+            pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
+            List result = (List) query.execute( type );
+            if ( result == null || result.isEmpty() )
+            {
+                return null;
+            }
+            return (BuildDefinitionTemplate) pm.detachCopy( result.get( 0 ) );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+
+    public List<BuildDefinition> getAllTemplates()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinition.class, true );
+
+            Query query = pm.newQuery( extent );
+            query.setFilter( "this.template == true" );
+            List result = (List) query.execute();
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+
+    public List<BuildDefinition> getAllBuildDefinitions()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinition.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            List result = (List) query.execute();
+
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+
     public BuildDefinition getBuildDefinition( int buildDefinitionId )
         throws ContinuumStoreException, ContinuumObjectNotFoundException
     {
@@ -761,7 +884,7 @@
     public void removeBuildDefinition( BuildDefinition buildDefinition )
         throws ContinuumStoreException
     {
-        attachAndDelete( buildDefinition );
+        removeObject( buildDefinition );
     }
 
     public BuildDefinition storeBuildDefinition( BuildDefinition buildDefinition )
@@ -771,7 +894,111 @@
 
         return buildDefinition;
     }
+    
+    
+
+    public BuildDefinition addBuildDefinition( BuildDefinition buildDefinition )
+        throws ContinuumStoreException
+    {
+        return (BuildDefinition) addObject( buildDefinition );
+    }
+
+    
+    // ------------------------------------------------------
+    //  BuildDefinitionTemplate
+    // ------------------------------------------------------      
+    
+    
+    public BuildDefinitionTemplate addBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
+        throws ContinuumStoreException
+    {
+        return (BuildDefinitionTemplate) addObject( buildDefinitionTemplate );
+    }
+
+    public List<BuildDefinitionTemplate> getAllBuildDefinitionTemplate()
+        throws ContinuumStoreException
+    {
+        return getAllObjectsDetached( BuildDefinitionTemplate.class, BUILD_TEMPLATE_BUILD_DEFINITIONS );
+    }
+
+    public BuildDefinitionTemplate getBuildDefinitionTemplate( int id )
+        throws ContinuumStoreException, ContinuumObjectNotFoundException
+    {
+        return (BuildDefinitionTemplate) getObjectById( BuildDefinitionTemplate.class, id, BUILD_TEMPLATE_BUILD_DEFINITIONS );
+    }
+
+    public void removeBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
+        throws ContinuumStoreException
+    {
+        removeObject( buildDefinitionTemplate );
+    }
+
+    public BuildDefinitionTemplate updateBuildDefinitionTemplate( BuildDefinitionTemplate buildDefinitionTemplate )
+        throws ContinuumStoreException
+    {
+        updateObject( buildDefinitionTemplate );
+
+        return buildDefinitionTemplate;
+    }
+
+    public List<BuildDefinitionTemplate> getContinuumDefaultdDefinitions()
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
+
+            Query query = pm.newQuery( extent );
+            query.setFilter( "continuumDefault == true" );
+
+            List result = (List) query.execute();
+
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+    
+    public List<BuildDefinitionTemplate> getBuildDefinitionTemplatesWithType( String type )
+        throws ContinuumStoreException
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinitionTemplate.class, true );
 
+            Query query = pm.newQuery( extent );
+            query.declareImports( "import java.lang.String" );
+            query.declareParameters( "String type" );
+            query.setFilter( "this.type == type" );
+            pm.getFetchPlan().addGroup( BUILD_TEMPLATE_BUILD_DEFINITIONS );
+            List result = (List) query.execute( type );
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+    
+    
     private Object makePersistent( PersistenceManager pm, Object object, boolean detach )
     {
         return PlexusJdoUtils.makePersistent( pm, object, detach );
@@ -1707,6 +1934,7 @@
         PlexusJdoUtils.removeAll( getPersistenceManager(), ProjectDependency.class );
         PlexusJdoUtils.removeAll( getPersistenceManager(), ChangeSet.class );
         PlexusJdoUtils.removeAll( getPersistenceManager(), ChangeFile.class );
+        PlexusJdoUtils.removeAll( getPersistenceManager(), BuildDefinitionTemplate.class );
         PlexusJdoUtils.removeAll( getPersistenceManager(), BuildDefinition.class );
     }
 

Modified: maven/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java?rev=578318&r1=578317&r2=578318&view=diff
==============================================================================
--- maven/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java (original)
+++ maven/continuum/trunk/continuum-store/src/test/java/org/apache/maven/continuum/store/ContinuumStoreTest.java Fri Sep 21 16:20:52 2007
@@ -27,8 +27,10 @@
 
 import javax.jdo.JDODetachedFieldAccessException;
 
+import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.model.project.BuildDefinitionTemplate;
 import org.apache.maven.continuum.model.project.BuildResult;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectDependency;
@@ -38,7 +40,6 @@
 import org.apache.maven.continuum.model.project.Schedule;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
-import org.codehaus.plexus.logging.LoggerManager;
 
 /**
  * @author <a href="mailto:brett@apache.org">Brett Porter</a>
@@ -1059,7 +1060,42 @@
         // TODO: test the def was physically deleted
         // TODO: test the schedule/profile was NOT physically deleted
     }
+    
+    public void testgetTemplatesBuildDefinitions()
+        throws Exception
+    {
+
+        int all = store.getAllBuildDefinitions().size();
+        BuildDefinition buildDefinition = new BuildDefinition();
+        buildDefinition.setBuildFile( "pom.xml" );
+        buildDefinition.setGoals( "clean" );
+        buildDefinition.setTemplate( true );
+        BuildDefinitionTemplate template = new BuildDefinitionTemplate();
+        template.setName( "test" );
+        template.setContinuumDefault( true );
+        template.setType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
+        template = store.addBuildDefinitionTemplate( template );
+        buildDefinition = store.addBuildDefinition( buildDefinition );
+
+        template.addBuildDefinition( buildDefinition );
+        
+        template = store.updateBuildDefinitionTemplate( template );
 
+        assertEquals( "test", template.getName() );
+        assertTrue( template.isContinuumDefault() );
+        assertEquals( 1, template.getBuildDefinitions().size() );
+        assertEquals( all + 1, store.getAllBuildDefinitions().size() );
+        assertEquals( 1, store.getAllBuildDefinitionTemplate().size() );
+
+        template = store
+            .getContinuumBuildDefinitionTemplateWithType( ContinuumBuildExecutorConstants.MAVEN_TWO_BUILD_EXECUTOR );
+
+        assertNotNull( template );
+        assertEquals( 1, template.getBuildDefinitions().size() );
+        
+        assertEquals( 1, store.getAllBuildDefinitionTemplate().size() );
+    }
+    
     // ----------------------------------------------------------------------
     //  HELPER METHODS
     // ----------------------------------------------------------------------

Added: maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildDefinitionAction.java
URL: http://svn.apache.org/viewvc/maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildDefinitionAction.java?rev=578318&view=auto
==============================================================================
--- maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildDefinitionAction.java (added)
+++ maven/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/AbstractBuildDefinitionAction.java Fri Sep 21 16:20:52 2007
@@ -0,0 +1,68 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you 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.
+ */
+package org.apache.maven.continuum.web.action;
+
+import java.util.LinkedList;
+import java.util.List;
+
+import org.apache.maven.continuum.model.project.BuildDefinition;
+import org.apache.maven.continuum.web.model.BuildDefinitionSummary;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 16 sept. 07
+ * @version $Id$
+ */
+public abstract class AbstractBuildDefinitionAction
+    extends ContinuumActionSupport
+{
+
+    protected BuildDefinitionSummary generateBuildDefinitionSummary( BuildDefinition buildDefinition )
+    {
+        BuildDefinitionSummary bds = new BuildDefinitionSummary();
+
+        bds.setGoals( buildDefinition.getGoals() );
+        bds.setId( buildDefinition.getId() );
+        bds.setArguments( buildDefinition.getArguments() );
+        bds.setBuildFile( buildDefinition.getBuildFile() );
+        bds.setScheduleId( buildDefinition.getSchedule().getId() );
+        bds.setScheduleName( buildDefinition.getSchedule().getName() );
+        bds.setIsDefault( buildDefinition.isDefaultForProject() );
+        bds.setIsBuildFresh( buildDefinition.isBuildFresh() );
+        if ( buildDefinition.getProfile() != null )
+        {
+            bds.setProfileName( buildDefinition.getProfile().getName() );
+            bds.setProfileId( buildDefinition.getProfile().getId() );
+        }
+        bds.setDescription( buildDefinition.getDescription() );
+        bds.setType( buildDefinition.getType() );
+        bds.setAlwaysBuild( buildDefinition.isAlwaysBuild() );
+        return bds;
+    }
+
+    protected List<BuildDefinitionSummary> generateBuildDefinitionSummaries( List<BuildDefinition> buildDefinitions )
+    {
+        List<BuildDefinitionSummary> buildDefinitionSummaries = new LinkedList<BuildDefinitionSummary>();
+        for ( BuildDefinition buildDefinition : buildDefinitions )
+        {
+            buildDefinitionSummaries.add( generateBuildDefinitionSummary( buildDefinition ) );
+        }
+        return buildDefinitionSummaries;
+    }
+}



Mime
View raw message