continuum-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r654976 - in /continuum/trunk: continuum-api/src/main/java/org/apache/maven/continuum/installation/ continuum-core/src/main/java/org/apache/maven/continuum/installation/ continuum-core/src/test/java/org/apache/maven/continuum/installation/ ...
Date Fri, 09 May 2008 23:09:48 GMT
Author: olamy
Date: Fri May  9 16:09:48 2008
New Revision: 654976

URL: http://svn.apache.org/viewvc?rev=654976&view=rev
Log:
[CONTINUUM-1748] Duplicate Installation names are accepted



Added:
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
  (with props)
Modified:
    continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
    continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
    continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java
    continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
    continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties

Added: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java?rev=654976&view=auto
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
(added)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
Fri May  9 16:09:48 2008
@@ -0,0 +1,50 @@
+/*
+ * 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.installation;
+
+import org.apache.maven.continuum.ContinuumException;
+
+/**
+ * @author <a href="mailto:olamy@apache.org">olamy</a>
+ * @since 9 mai 2008
+ * @version $Id$
+ * @since 1.2
+ */
+public class AlreadyExistsInstallationException
+    extends ContinuumException
+{
+
+    /**
+     * @param message
+     */
+    public AlreadyExistsInstallationException( String message )
+    {
+        super( message );
+    }
+
+    /**
+     * @param message
+     * @param cause
+     */
+    public AlreadyExistsInstallationException( String message, Throwable cause )
+    {
+        super( message, cause );
+    }
+
+}

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
------------------------------------------------------------------------------
    svn:executable = *

Propchange: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/AlreadyExistsInstallationException.java
------------------------------------------------------------------------------
--- svn:keywords (added)
+++ svn:keywords Fri May  9 16:09:48 2008
@@ -0,0 +1 @@
+URL HeadURL Author LastChangedBy Date LastChangedDate Rev Revision LastChangedRevision Id

Modified: continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
(original)
+++ continuum/trunk/continuum-api/src/main/java/org/apache/maven/continuum/installation/InstallationService.java
Fri May  9 16:09:48 2008
@@ -46,13 +46,13 @@
     String ENVVAR_TYPE = "envvar";
 
     public Installation add( Installation installation, boolean automaticProfile )
-        throws InstallationException, AlreadyExistsProfileException;
-    
+        throws InstallationException, AlreadyExistsProfileException, AlreadyExistsInstallationException;
+
     public Installation add( Installation installation )
-        throws InstallationException;
+        throws InstallationException, AlreadyExistsInstallationException;
 
     public void update( Installation installation )
-        throws InstallationException;
+        throws InstallationException, AlreadyExistsInstallationException;
 
     public void delete( Installation installation )
         throws InstallationException;

Modified: continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
(original)
+++ continuum/trunk/continuum-core/src/main/java/org/apache/maven/continuum/installation/DefaultInstallationService.java
Fri May  9 16:09:48 2008
@@ -93,7 +93,7 @@
      * @see org.apache.maven.continuum.installation.InstallationService#add(org.apache.maven.continuum.model.system.Installation)
      */
     public Installation add( Installation installation )
-        throws InstallationException
+        throws InstallationException, AlreadyExistsInstallationException
     {
         try
         {
@@ -107,9 +107,13 @@
     }
 
     public Installation add( Installation installation, boolean automaticProfile )
-        throws InstallationException, AlreadyExistsProfileException
+        throws InstallationException, AlreadyExistsProfileException, AlreadyExistsInstallationException
     {
-
+        if ( alreadyExistInstallationName( installation ) )
+        {
+            throw new AlreadyExistsInstallationException( "Installation with name " + installation.getName()
+                + " already exists" );
+        }
         // TODO must be done in the same transaction
         Installation storedOne = null;
         try
@@ -438,5 +442,19 @@
             throw new InstallationException( e.getMessage(), e );
         }
     }
+    
+    private boolean alreadyExistInstallationName( Installation installation )
+        throws InstallationException
+    {
+        List<Installation> all = getAllInstallations();
+        for ( Installation install : all )
+        {
+            if ( org.apache.commons.lang.StringUtils.equals( installation.getName(), install.getName()
) )
+            {
+                return true;
+            }
+        }
+        return false;
+    }
 
 }

Modified: continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java
(original)
+++ continuum/trunk/continuum-core/src/test/java/org/apache/maven/continuum/installation/DefaultInstallationServiceTest.java
Fri May  9 16:09:48 2008
@@ -1,15 +1,5 @@
 package org.apache.maven.continuum.installation;
 
-import org.apache.maven.continuum.AbstractContinuumTest;
-import org.apache.maven.continuum.execution.ExecutorConfigurator;
-import org.apache.maven.continuum.model.system.Installation;
-import org.apache.maven.continuum.model.system.Profile;
-import org.apache.maven.continuum.profile.ProfileService;
-import org.apache.maven.continuum.store.ContinuumStore;
-import org.codehaus.plexus.util.StringUtils;
-
-import java.util.List;
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one
  * or more contributor license agreements.  See the NOTICE file
@@ -29,6 +19,15 @@
  * under the License.
  */
 
+import java.util.List;
+
+import org.apache.maven.continuum.AbstractContinuumTest;
+import org.apache.maven.continuum.execution.ExecutorConfigurator;
+import org.apache.maven.continuum.model.system.Installation;
+import org.apache.maven.continuum.model.system.Profile;
+import org.apache.maven.continuum.profile.ProfileService;
+import org.codehaus.plexus.util.StringUtils;
+
 /**
  * @author <a href="mailto:olamy@codehaus.org">olamy</a>
  * @version $Id$
@@ -94,7 +93,28 @@
         assertNotNull( getted );
         assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ),
getted.getVarName() );
         assertEquals( "bar", getted.getVarValue() );
+        assertEquals( 1, getInstallationService().getAllInstallations().size() );
     }
+    
+    public void testAddDuplicateInstallation()
+        throws Exception
+    {
+        Installation added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE
);
+        Installation getted = getInstallationService().getInstallation( added.getInstallationId()
);
+        assertNotNull( getted );
+        assertEquals( getInstallationService().getEnvVar( InstallationService.JDK_TYPE ),
getted.getVarName() );
+        assertEquals( "bar", getted.getVarValue() );
+        try
+        {
+            added = this.addInstallation( NEW_INSTALLATION_NAME, null, "bar", InstallationService.JDK_TYPE
);
+            fail( "not in AlreadyExistsInstallationException" );
+        }
+        catch ( AlreadyExistsInstallationException e )
+        {
+            // we must be here
+        }
+        assertEquals( 1, getInstallationService().getAllInstallations().size() );
+    }    
 
     public void testRemove()
         throws Exception

Modified: continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java
(original)
+++ continuum/trunk/continuum-webapp/src/main/java/org/apache/maven/continuum/web/action/admin/InstallationAction.java
Fri May  9 16:09:48 2008
@@ -6,6 +6,7 @@
 import java.util.Map;
 import java.util.ResourceBundle;
 
+import org.apache.maven.continuum.installation.AlreadyExistsInstallationException;
 import org.apache.maven.continuum.installation.InstallationService;
 import org.apache.maven.continuum.model.system.Installation;
 import org.apache.maven.continuum.security.ContinuumRoleConstants;
@@ -124,7 +125,15 @@
         }
         if ( installation.getInstallationId() == 0 )
         {
-            installationService.add( installation, this.automaticProfile );
+            try
+            {
+                installationService.add( installation, this.automaticProfile );
+            }
+            catch ( AlreadyExistsInstallationException e )
+            {
+                this.addActionError( getResourceBundle().getString( "installation.name.duplicate"
) );
+                return INPUT;
+            }
         }
         else
         {

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum.properties
Fri May  9 16:09:48 2008
@@ -706,6 +706,7 @@
 installation.envvar.type.label = Environment Variable
 installation.ant.type.label = ANT
 installation.automaticProfile.label=Create a Profile with the installation name
+installation.name.duplicate = Installation name already exists.
 
 # ----------------------------------------------------------------------
 # Page: Installations Type Choice

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_fr.properties
Fri May  9 16:09:48 2008
@@ -684,7 +684,7 @@
 profile.jdk.path.label = Chemin du JDK
 profile.jdk.path.message = Le Chemin du JDK (Valeur de JAVA_HOME)
 profile.no.installations = Aucune installation disponible
-profile.name.already.exists = Un Profile avec le meme nom existe deja
+profile.name.already.exists = Un Profile avec le meme nom existe deja.
 
 # ----------------------------------------------------------------------
 # Page: Installations List
@@ -707,6 +707,7 @@
 installation.envvar.type.label = ariable d''environnement
 installation.ant.type.label = ANT
 installation.automaticProfile.label=Cr\u00e9er un Profil avec le nom de l''installation
+installation.name.duplicate = Une Installation avec le meme nom existe deja.
 
 # ----------------------------------------------------------------------
 # Page: Installations Type Choice

Modified: continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
URL: http://svn.apache.org/viewvc/continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties?rev=654976&r1=654975&r2=654976&view=diff
==============================================================================
--- continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
(original)
+++ continuum/trunk/continuum-webapp/src/main/resources/localization/Continuum_pt_BR.properties
Fri May  9 16:09:48 2008
@@ -313,6 +313,7 @@
 installation.type.label              = Tipo
 installation.value.label             = Valor/Caminho
 installation.varName.label           = Nome da Vari\u00E1vel de Ambiente
+installation.name.duplicate = Installation name already exists.
 
 installationTypeChoice.action.label  = Tipo de Instala\u00E7\u00E3o
 installationTypeChoice.envar.label   = Vari\u00E1vel de Ambiente 



Mime
View raw message