incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r700431 - in /incubator/sling/trunk/extensions/jcrinstall: pom.xml src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
Date Tue, 30 Sep 2008 12:22:34 GMT
Author: bdelacretaz
Date: Tue Sep 30 05:22:34 2008
New Revision: 700431

URL: http://svn.apache.org/viewvc?rev=700431&view=rev
Log:
SLING-684 - support multivalued config properties in jcrinstall, contributed by Tobias Bocanegra

Added:
    incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
  (with props)
Modified:
    incubator/sling/trunk/extensions/jcrinstall/pom.xml
    incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java

Modified: incubator/sling/trunk/extensions/jcrinstall/pom.xml
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/pom.xml?rev=700431&r1=700430&r2=700431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/pom.xml (original)
+++ incubator/sling/trunk/extensions/jcrinstall/pom.xml Tue Sep 30 05:22:34 2008
@@ -72,6 +72,10 @@
       <artifactId>org.osgi.compendium</artifactId>
     </dependency>
     <dependency>
+      <groupId>org.apache.felix</groupId>
+      <artifactId>org.apache.felix.configadmin</artifactId>
+    </dependency>
+    <dependency>
       <groupId>org.apache.sling</groupId>
       <artifactId>org.apache.sling.jcr.api</artifactId>
       <version>2.0.2-incubator</version>

Modified: incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java?rev=700431&r1=700430&r2=700431&view=diff
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
(original)
+++ incubator/sling/trunk/extensions/jcrinstall/src/main/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessor.java
Tue Sep 30 05:22:34 2008
@@ -18,20 +18,21 @@
  */
 package org.apache.sling.jcr.jcrinstall.osgi.impl;
 
+import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.INSTALLED;
+import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.UPDATED;
+
 import java.io.IOException;
 import java.io.InputStream;
-import java.util.Hashtable;
+import java.util.Dictionary;
 import java.util.Map;
-import java.util.Properties;
 
+import org.apache.felix.cm.file.ConfigurationHandler;
 import org.apache.sling.jcr.jcrinstall.osgi.OsgiResourceProcessor;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.service.cm.Configuration;
 import org.osgi.service.cm.ConfigurationAdmin;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.INSTALLED;
-import static org.apache.sling.jcr.jcrinstall.osgi.InstallResultCode.UPDATED;
 
 /** Process OSGi Configuration resources */
 public class ConfigResourceProcessor implements OsgiResourceProcessor {
@@ -49,25 +50,18 @@
         return uri.endsWith(CONFIG_EXTENSION);
     }
 
+    @SuppressWarnings("unchecked")
     public int installOrUpdate(String uri, Map<String, Object> attributes, InputStream
data) throws Exception {
         
         // Load configuration properties
-        final Properties p = new Properties();
-        try {
-            p.load(data);
-        } finally {
-            data.close();
-        }
-
+        final Dictionary dict = loadDictionary(data);
+        
         // Get pids from node name
         final ConfigurationPid pid = new ConfigurationPid(uri);
         log.debug("{} created for uri {}", pid, uri);
 
-        // prepare configuration data
-        Hashtable<Object, Object> ht = new Hashtable<Object, Object>();
-        ht.putAll(p);
         if(pid.getFactoryPid() != null) {
-            ht.put(ALIAS_KEY, pid.getFactoryPid());
+            dict.put(ALIAS_KEY, pid.getFactoryPid());
         }
 
         // get or create configuration
@@ -80,10 +74,20 @@
         if (config.getBundleLocation() != null) {
             config.setBundleLocation(null);
         }
-        config.update(ht);
+        config.update(dict);
         log.info("Configuration {} {}", config.getPid(), (result == UPDATED ? "updated" :
"created"));
         return result;
     }
+    
+    Dictionary<?,?> loadDictionary(InputStream data) throws IOException {
+        Dictionary<?,?> dict = null;
+        try {
+            dict = ConfigurationHandler.read(data);
+        } finally {
+            data.close();
+        }
+        return dict;
+    }
 
     public void processResourceQueue() throws Exception {
         // TODO might need to retry installing configs, as

Added: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java?rev=700431&view=auto
==============================================================================
--- incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
(added)
+++ incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
Tue Sep 30 05:22:34 2008
@@ -0,0 +1,110 @@
+/*
+ * 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.sling.jcr.jcrinstall.osgi.impl;
+
+import java.io.ByteArrayInputStream;
+import java.util.Dictionary;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+public class ConfigResourceProcessorTest 
+{
+    @org.junit.Test public void testLoadDictionary() throws Exception {
+        final String data =
+            "one=\"a\"\n"
+            + "two=[\"b\",\"c\",\"d\"]\n"
+            + "three=\"z\"\n"
+        ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final Dictionary<?, ?> dict = new ConfigResourceProcessor(null).loadDictionary(is);
+        
+        assertNotNull("one must be found", dict.get("one"));
+        assertEquals("one must match", "a", dict.get("one"));
+        
+        assertNotNull("two must be found", dict.get("two"));
+        assertNotNull("two must be a String[]", dict.get("two") instanceof String[]);
+        assertEquals("two[0] must match", "b" , ((String[])dict.get("two"))[0]);
+        assertEquals("two[1] must match", "c" , ((String[])dict.get("two"))[1]);
+        assertEquals("two[2] must match", "d" , ((String[])dict.get("two"))[2]);
+        
+        assertNotNull("three must be found", dict.get("three"));
+        assertEquals("three must match", "z" , dict.get("three"));
+    }
+    
+    @org.junit.Test public void testComments() throws Exception {
+        final String data =
+            "one=\"a\"\n"
+            + "# some comment\n"
+            + "two=\"b\"\n"
+            + "# another comment\n"
+        ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final Dictionary<?, ?> dict = new ConfigResourceProcessor(null).loadDictionary(is);
+        
+        assertNotNull("one must be found", dict.get("one"));
+        assertEquals("one must match", "a", dict.get("one"));
+        assertNull("two is not found if following a comment", dict.get("two"));
+    }
+    
+    @org.junit.Test public void testQuotes() throws Exception {
+        final String data =
+            "0=\"0\"\n"
+            + "1=1\n"
+            ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final Dictionary<?, ?> dict = new ConfigResourceProcessor(null).loadDictionary(is);
+        
+        assertNotNull("0 must be found", dict.get("0"));
+        assertNull("1 must not be found due to missing quotes", dict.get("1"));
+    }
+    
+    @org.junit.Test public void testMissingEOL() throws Exception {
+        final String data =
+            "0=\"0\"\n"
+            + "1=\"1\""
+            ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final Dictionary<?, ?> dict = new ConfigResourceProcessor(null).loadDictionary(is);
+        
+        assertNotNull("0 must be found", dict.get("0"));
+        assertNotNull("1 must be found, although EOL is missing", dict.get("1"));
+    }
+    
+    @org.junit.Test public void testWhitespace() throws Exception {
+        final String data =
+            "0 =\"0\"\n"
+            + "1\t=\"1\"\n"
+            + "2= \"2\"\n"
+            + "3=\t\"3\"\n"
+        ;
+        
+        final ByteArrayInputStream is = new ByteArrayInputStream(data.getBytes());
+        final Dictionary<?, ?> dict = new ConfigResourceProcessor(null).loadDictionary(is);
+        
+        assertNotNull("0 must be found, whitespace before = sign works", dict.get("0"));
+        assertNotNull("1 must be found, whitespace before = sign works", dict.get("1"));
+        assertNull("2 must not be found, whitespace after = sign breaks syntax", dict.get("2"));
+        assertNull("3 must not be found, whitespace after = sign breaks syntax", dict.get("3"));
+    }
+}

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/extensions/jcrinstall/src/test/java/org/apache/sling/jcr/jcrinstall/osgi/impl/ConfigResourceProcessorTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL



Mime
View raw message