geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ammul...@apache.org
Subject svn commit: r413342 - in /geronimo/branches/1.1/modules/system/src: java/org/apache/geronimo/system/configuration/ test/org/apache/geronimo/system/configuration/
Date Sat, 10 Jun 2006 18:12:02 GMT
Author: ammulder
Date: Sat Jun 10 11:12:01 2006
New Revision: 413342

URL: http://svn.apache.org/viewvc?rev=413342&view=rev
Log:
When a module with no version is redeployed and config.xml settings are
  migrated to the newer version, make sure to update the version numbers
  embedded in GBean names as well as the one for the module as a whole.
  Added test for the problem too.  GERONIMO-2105

Modified:
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
    geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java
    geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java?rev=413342&r1=413341&r2=413342&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/ConfigurationOverride.java
Sat Jun 10 11:12:01 2006
@@ -41,10 +41,20 @@
         this.load = load;
     }
 
+    /**
+     * Create a copy of a ConfigurationOverride with a new Artifact name
+     * @param base The original
+     * @param name The new Artifact name
+     */
     public ConfigurationOverride(ConfigurationOverride base, Artifact name) {
         this.name = name;
         this.load = base.load;
-        this.gbeans.putAll(base.gbeans);
+        for (Iterator it = base.gbeans.keySet().iterator(); it.hasNext();) {
+            Object gbeanName = it.next();
+            GBeanOverride gbean = (GBeanOverride) base.gbeans.get(gbeanName);
+            GBeanOverride replacement = new GBeanOverride(gbean, base.name.toString(), name.toString());
+            gbeans.put(replacement.getName(), replacement);
+        }
     }
 
     public ConfigurationOverride(Element element) throws InvalidGBeanException {

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java?rev=413342&r1=413341&r2=413342&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/GBeanOverride.java
Sat Jun 10 11:12:01 2006
@@ -71,6 +71,42 @@
         gbeanInfo = null;
     }
 
+    public GBeanOverride(GBeanOverride original, String oldArtifact, String newArtifact)
{
+        Object name = original.name;
+        if(name instanceof String) {
+            name = replace((String)name, oldArtifact, newArtifact);
+        } else if(name instanceof AbstractName) {
+            String value = name.toString();
+            value = replace(value, oldArtifact, newArtifact);
+            name = new AbstractName(URI.create(value));
+        }
+        this.name = name;
+        this.load = original.load;
+        this.attributes.putAll(original.attributes);
+        this.references.putAll(original.references);
+        this.clearAttributes.addAll(original.clearAttributes);
+        this.nullAttributes.addAll(original.nullAttributes);
+        this.clearReferences.addAll(original.clearReferences);
+        this.gbeanInfo = original.gbeanInfo;
+    }
+
+    private static String replace(String original, String oldArtifact, String newArtifact)
{
+        int pos = original.indexOf(oldArtifact);
+        if(pos == -1) {
+            return original;
+        }
+        int last = -1;
+        StringBuffer buf = new StringBuffer();
+        while(pos > -1) {
+            buf.append(original.substring(last+1, pos));
+            buf.append(newArtifact);
+            last = pos+oldArtifact.length()-1;
+            pos = original.indexOf(oldArtifact, last);
+        }
+        buf.append(original.substring(last+1));
+        return buf.toString();
+    }
+
     public GBeanOverride(GBeanData gbeanData) throws InvalidAttributeException {
         GBeanInfo gbeanInfo = gbeanData.getGBeanInfo();
         this.gbeanInfo = gbeanInfo.getSourceClass();

Modified: geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java?rev=413342&r1=413341&r2=413342&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java
(original)
+++ geronimo/branches/1.1/modules/system/src/java/org/apache/geronimo/system/configuration/RepositoryConfigurationStore.java
Sat Jun 10 11:12:01 2006
@@ -27,6 +27,7 @@
 import java.util.List;
 import java.util.SortedSet;
 import java.util.Set;
+import java.util.Collections;
 import java.util.jar.JarFile;
 import java.util.zip.ZipEntry;
 import java.util.zip.ZipOutputStream;
@@ -200,12 +201,16 @@
                 location = new File(location, moduleName);
             }
 
-            if (location.isDirectory()) {
-                Set matches = IOUtil.search(location, path);
-                return matches;
+            if(path == null) {
+                return Collections.singleton(location.toURL());
             } else {
-                Set matches = IOUtil.search(location, path);
-                return matches;
+                if (location.isDirectory()) {
+                    Set matches = IOUtil.search(location, path);
+                    return matches;
+                } else {
+                    Set matches = IOUtil.search(location, path);
+                    return matches;
+                }
             }
         } else {
             Set matches = IOUtil.search(location, moduleName + "/" +path);

Modified: geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
URL: http://svn.apache.org/viewvc/geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java?rev=413342&r1=413341&r2=413342&view=diff
==============================================================================
--- geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
(original)
+++ geronimo/branches/1.1/modules/system/src/test/org/apache/geronimo/system/configuration/LocalAttributeManagerTest.java
Sat Jun 10 11:12:01 2006
@@ -191,11 +191,36 @@
         }
     }
 
+    public void testMigrate() throws Exception {
+        String attributeValue = "attribute value";
+        AbstractNameQuery referencePattern = new AbstractNameQuery(LocalAttributeManagerTest.class.getName());
+
+        localAttributeManager.addConfiguration(configurationName);
+        localAttributeManager.setValue(configurationName, gbeanName, attributeInfo, attributeValue);
+
+        Collection gbeanDatas = new ArrayList();
+        GBeanData gbeanData = new GBeanData(gbeanName, GBEAN_INFO);
+        gbeanDatas.add(gbeanData);
+        gbeanDatas = localAttributeManager.applyOverrides(configurationName, gbeanDatas,
getClass().getClassLoader());
+        assertEquals(attributeValue, gbeanData.getAttribute(attributeInfo.getName()));
+
+        Artifact newArtifact = Artifact.create("configuration/name/2/car");
+        localAttributeManager.migrateConfiguration(configurationName, newArtifact, null);
+        ObjectName objectName = ObjectName.getInstance(":name=gbean,parent="+newArtifact+",foo=bar");
+        AbstractName newGBeanName = new AbstractName(newArtifact, objectName.getKeyPropertyList(),
objectName);
+
+        gbeanDatas = new ArrayList();
+        gbeanData = new GBeanData(newGBeanName, GBEAN_INFO);
+        gbeanDatas.add(gbeanData);
+        gbeanDatas = localAttributeManager.applyOverrides(newArtifact, gbeanDatas, getClass().getClassLoader());
+        assertEquals(attributeValue, gbeanData.getAttribute(attributeInfo.getName()));
+    }
+
     protected void setUp() throws Exception {
         super.setUp();
         localAttributeManager = new LocalAttributeManager("target/test-config.xml", false,
new BasicServerInfo(basedir));
         configurationName = Artifact.create("configuration/name/1/car");
-        ObjectName objectName = ObjectName.getInstance(":name=gbean");
+        ObjectName objectName = ObjectName.getInstance(":name=gbean,parent="+configurationName+",foo=bar");
         gbeanName = new AbstractName(configurationName, objectName.getKeyPropertyList(),
objectName);
         attributeInfo = GBEAN_INFO.getAttribute("attribute");
         referenceInfo = GBEAN_INFO.getReference("reference");



Mime
View raw message