### Eclipse Workspace Patch 1.0
#P continuum-store
Index: src/main/java/org/apache/continuum/dao/BuildDefinitionDaoImpl.java
===================================================================
--- src/main/java/org/apache/continuum/dao/BuildDefinitionDaoImpl.java	(revision 756960)
+++ src/main/java/org/apache/continuum/dao/BuildDefinitionDaoImpl.java	(working copy)
@@ -19,6 +19,18 @@
  * under the License.
  */
 
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import javax.annotation.Resource;
+import javax.jdo.Extent;
+import javax.jdo.PersistenceManager;
+import javax.jdo.Query;
+import javax.jdo.Transaction;
+
 import org.apache.maven.continuum.execution.ContinuumBuildExecutorConstants;
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
@@ -30,17 +42,6 @@
 import org.slf4j.LoggerFactory;
 import org.springframework.stereotype.Repository;
 
-import javax.annotation.Resource;
-import javax.jdo.Extent;
-import javax.jdo.PersistenceManager;
-import javax.jdo.Query;
-import javax.jdo.Transaction;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
@@ -364,4 +365,34 @@
         }
     }
 
+    public List<BuildDefinition> getBuildDefinitionsByProfile( int profileId )
+    {
+        PersistenceManager pm = getPersistenceManager();
+
+        Transaction tx = pm.currentTransaction();
+
+        try
+        {
+            tx.begin();
+
+            Extent extent = pm.getExtent( BuildDefinition.class, true );
+
+            Query query = pm.newQuery( extent );
+
+            query.declareParameters( "int profileId" );
+
+            query.setFilter( "this.profile.id == profileId" );
+
+            List result = (List) query.execute( profileId );
+
+            return result == null ? Collections.EMPTY_LIST : (List) pm.detachCopyAll( result );
+        }
+        finally
+        {
+            tx.commit();
+
+            rollback( tx );
+        }
+    }
+
 }
#P continuum-api
Index: src/main/java/org/apache/maven/continuum/profile/DeleteProfileException.java
===================================================================
--- src/main/java/org/apache/maven/continuum/profile/DeleteProfileException.java	(revision 0)
+++ src/main/java/org/apache/maven/continuum/profile/DeleteProfileException.java	(revision 0)
@@ -0,0 +1,42 @@
+package org.apache.maven.continuum.profile;
+
+/*
+ * 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 org.apache.maven.continuum.ContinuumException;
+
+/**
+ * @author Jose Morales Martinez
+ * @version $Id$
+ */
+public class DeleteProfileException
+    extends ContinuumException
+{
+    private static final long serialVersionUID = -7731222239174489011L;
+
+    public DeleteProfileException( String message, Throwable throwable )
+    {
+        super( message, throwable );
+    }
+
+    public DeleteProfileException( String message )
+    {
+        super( message );
+    }
+}
Index: src/main/java/org/apache/maven/continuum/profile/ProfileService.java
===================================================================
--- src/main/java/org/apache/maven/continuum/profile/ProfileService.java	(revision 756960)
+++ src/main/java/org/apache/maven/continuum/profile/ProfileService.java	(working copy)
@@ -37,7 +37,7 @@
         throws ProfileException;
 
     public void deleteProfile( int profileId )
-        throws ProfileException;
+        throws ProfileException, DeleteProfileException;
 
     /**
      * @param profile
Index: src/main/java/org/apache/continuum/dao/BuildDefinitionDao.java
===================================================================
--- src/main/java/org/apache/continuum/dao/BuildDefinitionDao.java	(revision 756960)
+++ src/main/java/org/apache/continuum/dao/BuildDefinitionDao.java	(working copy)
@@ -19,14 +19,14 @@
  * under the License.
  */
 
+import java.util.List;
+import java.util.Map;
+
 import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.project.Project;
 import org.apache.maven.continuum.model.project.ProjectGroup;
 import org.apache.maven.continuum.store.ContinuumStoreException;
 
-import java.util.List;
-import java.util.Map;
-
 /**
  * @author <a href="mailto:evenisse@apache.org">Emmanuel Venisse</a>
  * @version $Id$
@@ -125,4 +125,6 @@
         throws ContinuumStoreException;
 
     List<BuildDefinition> getBuildDefinitionsBySchedule( int scheduleId );
+
+    List<BuildDefinition> getBuildDefinitionsByProfile( int profileId );
 }
#P continuum-webapp
Index: src/main/resources/localization/Continuum.properties
===================================================================
--- src/main/resources/localization/Continuum.properties	(revision 757431)
+++ src/main/resources/localization/Continuum.properties	(working copy)
@@ -751,7 +751,8 @@
 profile.no.installations = No installations available
 profile.name.already.exists = A Build Environment with the same name already exists
 profile.name.required = You must define a name.
-profile.remove.error = The Build Environment can't be removed, it is probably used by a build definition.
+profile.remove.error = The Build Environment can't be deleted.
+profile.remove.in.use =The Build Environment can't be delete. This profile is used by a build definition.
 profile.installation.name.label = Installation Name
 profile.actionError = Action Error
 profile.build.agent.group = Build Agent Group
Index: src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java
===================================================================
--- src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java	(revision 757431)
+++ src/main/java/org/apache/maven/continuum/web/action/admin/ProfileAction.java	(working copy)
@@ -29,6 +29,7 @@
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
 import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
+import org.apache.maven.continuum.profile.DeleteProfileException;
 import org.apache.maven.continuum.profile.ProfileException;
 import org.apache.maven.continuum.profile.ProfileService;
 import org.apache.maven.continuum.security.ContinuumRoleConstants;
@@ -161,7 +162,7 @@
                 String buildAgentGroup = profile.getBuildAgentGroup();
 
                 profile = profileService.getProfile( profile.getId() );
-                // CONTINUUM-1746 we update the profile only if the name has changed 
+                // CONTINUUM-1746 we update the profile only if the name has changed
                 // jancajas: added build agent group. updated profile if agent group is changed also.
                 if ( !StringUtils.equals( name, profile.getName() ) ||
                     !StringUtils.equals( buildAgentGroup, profile.getBuildAgentGroup() ) )
@@ -190,11 +191,15 @@
             this.profiles = profileService.getAllProfiles();
             return SUCCESS;
         }
+        catch ( DeleteProfileException e )
+        {
+            message = "profile.remove.in.use";
+        }
         catch ( ProfileException e )
         {
             message = "profile.remove.error";
-            return ERROR;
         }
+        return ERROR;
     }
 
     public String confirmDelete()
@@ -229,7 +234,7 @@
 
     // -----------------------------------------------------
     // security
-    // -----------------------------------------------------    
+    // -----------------------------------------------------
 
     public SecureActionBundle getSecureActionBundle()
         throws SecureActionException
#P continuum-commons
Index: src/main/java/org/apache/continuum/profile/DefaultProfileService.java
===================================================================
--- src/main/java/org/apache/continuum/profile/DefaultProfileService.java	(revision 756960)
+++ src/main/java/org/apache/continuum/profile/DefaultProfileService.java	(working copy)
@@ -25,11 +25,14 @@
 import javax.annotation.Resource;
 
 import org.apache.commons.lang.StringUtils;
+import org.apache.continuum.dao.BuildDefinitionDao;
 import org.apache.continuum.dao.ProfileDao;
 import org.apache.maven.continuum.installation.InstallationService;
+import org.apache.maven.continuum.model.project.BuildDefinition;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.model.system.Profile;
 import org.apache.maven.continuum.profile.AlreadyExistsProfileException;
+import org.apache.maven.continuum.profile.DeleteProfileException;
 import org.apache.maven.continuum.profile.ProfileException;
 import org.apache.maven.continuum.profile.ProfileService;
 import org.apache.maven.continuum.store.ContinuumObjectNotFoundException;
@@ -49,6 +52,9 @@
     @Resource
     private ProfileDao profileDao;
 
+    @Resource
+    private BuildDefinitionDao buildDefinitionDao;
+
     /**
      * @see org.apache.maven.continuum.profile.ProfileService#updateProfile(org.apache.maven.continuum.model.system.Profile)
      */
@@ -136,8 +142,13 @@
      * @see org.apache.maven.continuum.profile.ProfileService#deleteProfile(int)
      */
     public void deleteProfile( int profileId )
-        throws ProfileException
+        throws ProfileException, DeleteProfileException
     {
+        List<BuildDefinition> buildDefinitions = buildDefinitionDao.getBuildDefinitionsByProfile( profileId );
+        if ( !buildDefinitions.isEmpty() )
+        {
+            throw new DeleteProfileException( "Profile used by Build Definitions" );
+        }
         try
         {
             profileDao.removeProfile( getProfile( profileId ) );
Index: src/main/java/org/apache/continuum/installation/DefaultInstallationService.java
===================================================================
--- src/main/java/org/apache/continuum/installation/DefaultInstallationService.java	(revision 756960)
+++ src/main/java/org/apache/continuum/installation/DefaultInstallationService.java	(working copy)
@@ -117,6 +117,23 @@
             throw new AlreadyExistsInstallationException(
                 "Installation with name " + installation.getName() + " already exists" );
         }
+        else if ( automaticProfile )
+        {
+            Profile profile = new Profile();
+            profile.setName( installation.getName() );
+            try
+            {
+                if ( profileService.alreadyExistsProfileName( profile ) )
+                {
+                    throw new AlreadyExistsProfileException( "Profile with name " + installation.getName()
+                        + " already exists" );
+                }
+            }
+            catch ( ProfileException e )
+            {
+                throw new InstallationException( "failed to search Profile " + e.getMessage(), e );
+            }
+        }
         // TODO must be done in the same transaction
         Installation storedOne;
         try

