incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r792880 - in /sling/trunk/contrib: extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ extensions/jcrinstall/service/src/m...
Date Fri, 10 Jul 2009 10:54:08 GMT
Author: bdelacretaz
Date: Fri Jul 10 10:54:07 2009
New Revision: 792880

URL: http://svn.apache.org/viewvc?rev=792880&view=rev
Log:
SLING-1044 - jcrinstall should only accept .jar, .cfg and .properties files as installable
resources

Added:
    sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/
    sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.cfg
    sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties
  (with props)
Modified:
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
    sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
    sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
    sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
    sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigInstallRemoveTask.java
Fri Jul 10 10:54:07 2009
@@ -37,7 +37,7 @@
 
     static final String ALIAS_KEY = "_alias_factory_pid";
     static final String CONFIG_PATH_KEY = "_jcr_config_path";
-    static final String CONFIG_EXTENSION = ".cfg";
+    static final String [] CONFIG_EXTENSIONS = { ".cfg", ".properties" };
     
     private final DictionaryReader reader = new DictionaryReader();
     

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/main/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPid.java
Fri Jul 10 10:54:07 2009
@@ -34,11 +34,14 @@
             pid = path.substring(lastSlash + 1);
         }
         
-        // cut off extension if it's .cfg
-        if(pid.endsWith(ConfigInstallRemoveTask.CONFIG_EXTENSION)) {
-            final int lastDot = pid.lastIndexOf('.');
-            if(lastDot >= 0) {
-                pid = pid.substring(0, lastDot);
+        // cut off extension if it's one of our config extensions
+        for(String ext : ConfigInstallRemoveTask.CONFIG_EXTENSIONS) {
+            if(pid.endsWith(ext)) {
+                final int lastDot = pid.lastIndexOf('.');
+                if(lastDot >= 0) {
+                    pid = pid.substring(0, lastDot);
+                }
+                break;
             }
         }
 

Modified: sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/osgi/src/test/java/org/apache/sling/osgi/installer/impl/tasks/ConfigurationPidTest.java
Fri Jul 10 10:54:07 2009
@@ -30,11 +30,17 @@
     
     @org.junit.Test public void testNonFactory() {
         assertPid("o.a.s.foo.bar.cfg", "o.a.s.foo.bar", null);
+        assertPid("o.a.s.foo.bar.properties", "o.a.s.foo.bar", null);
+        assertPid("o.a.s.foo.bar.cfg.properties", "o.a.s.foo.bar.cfg", null);
+        assertPid("o.a.s.foo.bar.properties.cfg", "o.a.s.foo.bar.properties", null);
         assertPid("/somepath/o.a.s.foo.bar.cfg", "o.a.s.foo.bar", null);
+        assertPid("/somepath/o.a.s.foo.bar.properties", "o.a.s.foo.bar", null);
     }
 
     @org.junit.Test public void testFactory() {
         assertPid("o.a.s.foo.bar-a.cfg", "o.a.s.foo.bar", "a");
+        assertPid("o.a.s.foo.bar-a.properties", "o.a.s.foo.bar", "a");
         assertPid("/somepath/o.a.s.foo.bar-a.cfg", "o.a.s.foo.bar", "a");
+        assertPid("/somepath/o.a.s.foo.bar-a.properties", "o.a.s.foo.bar", "a");
     }
 }

Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/main/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverter.java
Fri Jul 10 10:54:07 2009
@@ -27,7 +27,7 @@
 /** Convert a Node that is a file to a FileInstallableData */ 
  public class FileNodeConverter implements NodeConverter {
     // regexp for filenames that we accept
-    public static final String FILENAME_REGEXP = "[a-zA-Z0-9].*\\.[a-zA-Z][a-zA-Z][a-zA-Z]?";
+    public static final String FILENAME_REGEXP = "[a-zA-Z0-9].*\\.(jar|cfg|properties)";
     
     private final RegexpFilter filenameFilter = new RegexpFilter(FILENAME_REGEXP);
     private final Logger log = LoggerFactory.getLogger(getClass());

Modified: sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
(original)
+++ sling/trunk/contrib/extensions/jcrinstall/service/src/test/java/org/apache/sling/jcr/jcrinstall/jcr/impl/FileNodeConverterTest.java
Fri Jul 10 10:54:07 2009
@@ -24,9 +24,11 @@
     public void testAcceptedFilenames() {
         final String [] filenames = {
                 "a.cfg",
+                "a.jar",
+                "a.properties",
                 "longername.cfg",
+                "someproperties.properties",
                 "longername-with_various.things-And-CASES-9123456789.cfg",
-                "a.js",
                 "abc.cfg",
                 "a.b.c.cfg",
                 "1-2-3.cfg"
@@ -39,12 +41,14 @@
     
     public void testRejectedFilenames() {
         final String [] filenames = {
+                "a.js",
+                "a.config",
+                "a.sh",
+                "a.bat",
+                ".DS_Store",
+                ".DS_Store.cfg",
+                ".something.cfg",
                 "noextension",
-                "toolongextension.1234",
-                "toolongextension..properties",
-                "numericextension.123",
-                "numericextension.12",
-                "tooshortextension.a"
         };
         
         for(String f : filenames) {

Modified: sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java?rev=792880&r1=792879&r2=792880&view=diff
==============================================================================
--- sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
(original)
+++ sling/trunk/contrib/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/jcrinstall/SimpleConfigTest.java
Fri Jul 10 10:54:07 2009
@@ -18,17 +18,18 @@
 
 import java.io.IOException;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
+import java.util.Set;
 
 /** Simple test of the jcrinstall configuration feature: create 
- * 	sling:OsgiConfig nodes and check that the corresponding configs
+ * 	sling:OsgiConfig nodes, or config files, and check that the corresponding configs
  *  are available at /system/console/config
- *
  */
 public class SimpleConfigTest extends JcrinstallTestBase {
 	
 	static final String CONFIG_URL = HTTP_BASE_URL + "/system/console/config";
-	static final int timeoutSeconds = 4;
+	static final int TIMEOUT_SECONDS = 4;
 
 	static class ConfigCondition implements JcrinstallTestBase.StringCondition {
 		private final String expectedValue;
@@ -55,7 +56,7 @@
 		return testClient.createNode(HTTP_BASE_URL + configPath + "/" + configPid, properties);
 	}
 	
-	public void testSimpleConfig() throws IOException {
+	public void testConfigNodes() throws IOException {
 		final String uniqueId = getClass().getName() + ".A." + System.currentTimeMillis(); 
 		final String key = getClass().getName() + ".key";
 		final String value = getClass().getName() + "." + uniqueId;
@@ -64,14 +65,14 @@
 		final String contentType = CONTENT_TYPE_HTML;
 		
 		assertContentWithTimeout("Before test, config must not exist", CONFIG_URL, 
-				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+				contentType, new ConfigCondition(keyValue, false), TIMEOUT_SECONDS);
 		
 		// Create an OSGi config using a sling:OsgiConfig node
 		final Map<String, String> props = new HashMap<String, String>();
 		props.put(key, value);
 		final String toDelete = createConfig(uniqueId, props);
 		assertContentWithTimeout("Config must be present after creating config node", CONFIG_URL,

-				contentType, new ConfigCondition(keyValue, true), timeoutSeconds);
+				contentType, new ConfigCondition(keyValue, true), TIMEOUT_SECONDS);
 		
 		// Update config node, verify that config is updated
 		final String newValue = getClass().getName() + ".NEW." + System.currentTimeMillis();
@@ -79,42 +80,66 @@
 		props.put(key, newValue);
 		createConfig(uniqueId, props);
 		assertContentWithTimeout("Config must be modified after node update", CONFIG_URL, 
-				contentType, new ConfigCondition(newKeyValue, true), timeoutSeconds);
+				contentType, new ConfigCondition(newKeyValue, true), TIMEOUT_SECONDS);
 		assertContentWithTimeout("Old value must be gone after update", CONFIG_URL, 
-				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+				contentType, new ConfigCondition(keyValue, false), TIMEOUT_SECONDS);
 		
 		// Delete and verify that the config is gone
 		testClient.delete(toDelete);
 		assertContentWithTimeout("Old config must be gone after removing config node", CONFIG_URL,

-				contentType, new ConfigCondition(keyValue, false), timeoutSeconds);
+				contentType, new ConfigCondition(keyValue, false), TIMEOUT_SECONDS);
 		assertContentWithTimeout("New config must be gone after removing config node", CONFIG_URL,

-				contentType, new ConfigCondition(newKeyValue, false), timeoutSeconds);
+				contentType, new ConfigCondition(newKeyValue, false), TIMEOUT_SECONDS);
 	}
 	
-	public void testAppsOverridesLibs() throws IOException {
+	public void testAppsOverridesLibsNodes() throws IOException {
 		final String uniqueId = getClass().getName() + ".B." + System.currentTimeMillis(); 
 		final Map<String, String> props = new HashMap<String, String>();
 		props.put("foo", "barONE");
 		final String toDeleteA = createConfig("/libs", uniqueId, props);
 		assertContentWithTimeout("Config must be present after creating /libs config node", CONFIG_URL,

-				CONTENT_TYPE_HTML, new ConfigCondition("barONE", true), timeoutSeconds);
+				CONTENT_TYPE_HTML, new ConfigCondition("barONE", true), TIMEOUT_SECONDS);
 		
 		props.put("foo", "barTWO");
 		final String toDeleteB = createConfig("/apps", uniqueId, props);
 		assertContentWithTimeout("Config must be updated after creating /apps config node", CONFIG_URL,

-				CONTENT_TYPE_HTML, new ConfigCondition("barTWO", true), timeoutSeconds);
+				CONTENT_TYPE_HTML, new ConfigCondition("barTWO", true), TIMEOUT_SECONDS);
 		
 		props.put("foo", "barTHREE");
 		createConfig("/libs", uniqueId, props);
 		assertContentWithTimeout("Config must NOT be updated after updating /libs config node",
CONFIG_URL, 
-				CONTENT_TYPE_HTML, new ConfigCondition("barTWO", true), timeoutSeconds);
+				CONTENT_TYPE_HTML, new ConfigCondition("barTWO", true), TIMEOUT_SECONDS);
 		
 		props.put("foo", "barFOUR");
 		createConfig("/apps", uniqueId, props);
 		assertContentWithTimeout("Config must be updated after updating /apps config node", CONFIG_URL,

-				CONTENT_TYPE_HTML, new ConfigCondition("barFOUR", true), timeoutSeconds);
+				CONTENT_TYPE_HTML, new ConfigCondition("barFOUR", true), TIMEOUT_SECONDS);
 		
 		testClient.delete(toDeleteA);
 		testClient.delete(toDeleteB);
 	}
+	
+	   /** Test creating configs from files */
+    public void testConfigFiles() throws IOException {
+        final Set<String> toDelete = new HashSet<String>();
+        final String CFG_PATH = "/apps/" + getClass().getSimpleName() + "_" + System.currentTimeMillis()
+ "/install";
+        testClient.mkdirs(WEBDAV_BASE_URL,CFG_PATH);
+        toDelete.add(uploadTestScript(CFG_PATH, "jcrinstall/cfg1.cfg", "cfg1.cfg"));
+        assertContentWithTimeout("cfg1 must be installed", CONFIG_URL, 
+                CONTENT_TYPE_HTML, new ConfigCondition("cfg1value=from.cfg1.cfg", true),
TIMEOUT_SECONDS);
+        
+        toDelete.add(uploadTestScript(CFG_PATH, "jcrinstall/cfg1.properties", "cfg1.properties"));
+        assertContentWithTimeout("cfg1 must be updated", CONFIG_URL, 
+                CONTENT_TYPE_HTML, new ConfigCondition("cfg1value=from.cfg1.properties",
true), TIMEOUT_SECONDS);
+        assertContentWithTimeout("old cfg1 value must be gone", CONFIG_URL, 
+                CONTENT_TYPE_HTML, new ConfigCondition("cfg1value=from.cfg1.cfg", false),
TIMEOUT_SECONDS);
+        
+        for(String url : toDelete) {
+            testClient.delete(url);
+        }
+        
+        assertContentWithTimeout("cfg1 must be gone", CONFIG_URL, 
+                CONTENT_TYPE_HTML, new ConfigCondition("cfg1value=from.cfg1.properties",
false), TIMEOUT_SECONDS);
+    }
+
 }

Added: sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.cfg
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.cfg?rev=792880&view=auto
==============================================================================
--- sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.cfg
(added)
+++ sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.cfg
Fri Jul 10 10:54:07 2009
@@ -0,0 +1,2 @@
+# Used by SimpleConfigTest
+cfg1value=from.cfg1.cfg
\ No newline at end of file

Added: sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties
URL: http://svn.apache.org/viewvc/sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties?rev=792880&view=auto
==============================================================================
--- sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties
(added)
+++ sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties
Fri Jul 10 10:54:07 2009
@@ -0,0 +1,2 @@
+# Used by SimpleConfigTest
+cfg1value=from.cfg1.properties
\ No newline at end of file

Propchange: sling/trunk/contrib/launchpad/testing/src/test/resources/integration-test/jcrinstall/cfg1.properties
------------------------------------------------------------------------------
    svn:eol-style = native



Mime
View raw message