You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2006/12/07 14:01:02 UTC

svn commit: r483439 - in /cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin: ./ src/main/java/org/apache/cocoon/maven/rcl/ src/test/java/org/apache/cocoon/maven/rcl/ src/test/resources/org/apache/cocoon/maven/rcl/

Author: reinhard
Date: Thu Dec  7 05:00:58 2006
New Revision: 483439

URL: http://svn.apache.org/viewvc?view=rev&rev=483439
Log:
use commons-configuration as it supports property arrays and variable interpolation; all %classes-dir property values are added to the reloading classloader

Modified:
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/pom.xml
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/RwmProperties.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/java/org/apache/cocoon/maven/rcl/RwmPropertiesTest.java
    cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/resources/org/apache/cocoon/maven/rcl/rcl.properties

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/pom.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/pom.xml?view=diff&rev=483439&r1=483438&r2=483439
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/pom.xml (original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/pom.xml Thu Dec  7 05:00:58 2006
@@ -44,6 +44,11 @@
       <version>1.2</version>
     </dependency>
     <dependency>
+      <groupId>commons-configuration</groupId>
+      <artifactId>commons-configuration</artifactId>
+      <version>1.3</version>
+    </dependency>    
+    <dependency>
       <groupId>commons-lang</groupId>
       <artifactId>commons-lang</artifactId>
       <version>2.1</version>

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java?view=diff&rev=483439&r1=483438&r2=483439
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java (original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/ReloadingWebappMojo.java Thu Dec  7 05:00:58 2006
@@ -37,6 +37,7 @@
 import java.util.Set;
 
 import org.antlr.stringtemplate.StringTemplate;
+import org.apache.commons.configuration.ConfigurationException;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.commons.lang.Validate;
@@ -195,7 +196,7 @@
         RwmProperties props = null;
         try {
             props  = new RwmProperties(this.rclPropertiesFile);
-        } catch (IOException e) {
+        } catch (ConfigurationException e) {
             throw new MojoExecutionException("Can't read " + this.rclPropertiesFile.getAbsolutePath(), e);
         }
         return props;

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/RwmProperties.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/RwmProperties.java?view=diff&rev=483439&r1=483438&r2=483439
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/RwmProperties.java (original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/java/org/apache/cocoon/maven/rcl/RwmProperties.java Thu Dec  7 05:00:58 2006
@@ -17,36 +17,27 @@
 package org.apache.cocoon.maven.rcl;
 
 import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.io.InputStream;
 import java.net.MalformedURLException;
-import java.util.Enumeration;
 import java.util.HashSet;
+import java.util.Iterator;
 import java.util.Properties;
 import java.util.Set;
 
+import org.apache.commons.configuration.Configuration;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.PropertiesConfiguration;
 import org.apache.maven.plugin.MojoExecutionException;
 
 public class RwmProperties {
 
     private static final String COB_INF_DIR = "/COB-INF";
     private static final String BLOCK_CONTEXT_URL_PARAM = "/blockContextURL";
-    private static final String ARTIFACT = "%artifact";
     private static final String CLASSES_DIR = "%classes-dir";    
     
-    private Properties rclProps = new Properties();
+    private Configuration props;
 
-    public RwmProperties(InputStream propsIs) throws IOException {
-        this.rclProps.load(propsIs);
-    }
-    
-    public RwmProperties(File propsFile) throws IOException {
-        this(new FileInputStream(propsFile));
-    }
-
-    public Set getArtifacts() {
-        return getFilteredPropertiesValuesAsSet(ARTIFACT);
+    public RwmProperties(File propsFile) throws ConfigurationException {
+        props = new PropertiesConfiguration(propsFile);
     }
     
     public Set getClassesDirs() {
@@ -55,14 +46,14 @@
     
     public Properties getSpringProperties() throws MojoExecutionException {
         Properties springProps = new Properties();
-        for(Enumeration rclEnum = rclProps.keys(); rclEnum.hasMoreElements();) {
-            String key = (String) rclEnum.nextElement();
-            if(!key.endsWith(ARTIFACT) && !key.endsWith(CLASSES_DIR)) {
-                springProps.put(key, this.rclProps.getProperty(key));
+        for(Iterator rclIt = props.getKeys(); rclIt.hasNext();) {
+            String key = (String) rclIt.next();
+            if(!key.endsWith(CLASSES_DIR)) {
+                springProps.put(key, this.props.getString(key));
             }
-            if(key.endsWith(CLASSES_DIR)) {
+            if(key.endsWith(CLASSES_DIR) && !CLASSES_DIR.equals(key)) {
                 String newKey = key.substring(0, key.length() - CLASSES_DIR.length()) + BLOCK_CONTEXT_URL_PARAM;
-                File blockContext = new File(this.rclProps.getProperty(key) + COB_INF_DIR);
+                File blockContext = new File(this.props.getString(key) + COB_INF_DIR);
                 try {
                     springProps.put(newKey, blockContext.toURL().toExternalForm());
                 } catch (MalformedURLException e) {
@@ -75,10 +66,13 @@
     
     private Set getFilteredPropertiesValuesAsSet(String filter) {
         Set returnSet = new HashSet();
-        for(Enumeration rclEnum = rclProps.keys(); rclEnum.hasMoreElements();) {
-            String key = (String) rclEnum.nextElement();
-            if(key.endsWith(filter)) {
-                returnSet.add(this.rclProps.getProperty(key));
+        for (Iterator rclIt = props.getKeys(); rclIt.hasNext();) {
+            String key = (String) rclIt.next();
+            if (key.endsWith(filter)) {
+                String[] values = this.props.getStringArray(key);
+                for (int i = 0; i < values.length; i++) {
+                    returnSet.add(values[i]);
+                }
             }
         }        
         return returnSet;

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/java/org/apache/cocoon/maven/rcl/RwmPropertiesTest.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/java/org/apache/cocoon/maven/rcl/RwmPropertiesTest.java?view=diff&rev=483439&r1=483438&r2=483439
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/java/org/apache/cocoon/maven/rcl/RwmPropertiesTest.java (original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/java/org/apache/cocoon/maven/rcl/RwmPropertiesTest.java Thu Dec  7 05:00:58 2006
@@ -16,41 +16,51 @@
  */
 package org.apache.cocoon.maven.rcl;
 
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
 import java.io.InputStream;
 import java.util.Properties;
 import java.util.Set;
 
 import junit.framework.TestCase;
 
-public class RwmPropertiesTest extends TestCase {
+import org.apache.commons.io.IOUtils;
 
+public class RwmPropertiesTest extends TestCase {
+    
     public void testLoadingSpringProps() throws Exception {
         RwmProperties p = createTestProperties();
         Properties springProps = p.getSpringProperties();
-        assertEquals(5, springProps.size());
+        assertEquals(7, springProps.size());
+        // test variable interpolation
+        assertEquals("interpolatedValue:A", springProps.getProperty("b"));
+        // test setting the correct context URL if a *%classes-dir property was set
         assertTrue(springProps.containsKey("org.apache.cocoon.cocoon-rcl-plugin-demo.block/blockContextURL"));
         assertTrue(springProps.getProperty("org.apache.cocoon.cocoon-rcl-plugin-demo.block1/blockContextURL")
                 .indexOf("target/classes/COB-INF") > 0);
     }
-    
-    public void testLoadingArtifactValues() throws Exception {
-        RwmProperties p = createTestProperties();
-        Set as = p.getArtifacts();
-        assertEquals(2, as.size());
-        assertTrue(as.contains("org.apache.cocoon:cocoon-myBlock"));
-        assertTrue(as.contains("org.apache.cocoon:cocoon-myBlock1"));    
-    }   
 
     public void testLoadingBasedirs() throws Exception {
         RwmProperties p = createTestProperties();
         Set as = p.getClassesDirs();
-        assertEquals(3, as.size());
+        assertEquals(5, as.size());
         assertTrue(as.contains("file:/F:/blocks/myBlock/target/classes"));
-        assertTrue(as.contains("file:/F:/blocks/myBlock1/target/classes"));        
+        assertTrue(as.contains("file:/F:/blocks/myBlock1/target/classes"));      
     }      
     
     protected RwmProperties createTestProperties() throws Exception {    
-        return new RwmProperties(readResourceFromClassloader("rcl.properties"));
+        return new RwmProperties(getResourcesFromClassLoaderAsFile("rcl.properties"));
+    }
+    
+    protected File getResourcesFromClassLoaderAsFile(String fileName) throws IOException {
+        File tempFile = File.createTempFile(
+                fileName, ".conf");
+        FileOutputStream tempFileFos = new FileOutputStream(tempFile);
+        IOUtils.copy(readResourceFromClassloader(fileName), tempFileFos);
+        tempFileFos.close();
+        tempFile.deleteOnExit();
+        return tempFile;
     }
     
     protected InputStream readResourceFromClassloader(String fileName) {

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/resources/org/apache/cocoon/maven/rcl/rcl.properties
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/resources/org/apache/cocoon/maven/rcl/rcl.properties?view=diff&rev=483439&r1=483438&r2=483439
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/resources/org/apache/cocoon/maven/rcl/rcl.properties (original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/test/resources/org/apache/cocoon/maven/rcl/rcl.properties Thu Dec  7 05:00:58 2006
@@ -15,9 +15,11 @@
 # limitations under the License.
 #
 org.apache.cocoon.cocoon-rcl-plugin-demo.block/123=456
-org.apache.cocoon.cocoon-rcl-plugin-demo.block%artifact=org.apache.cocoon:cocoon-myBlock
 org.apache.cocoon.cocoon-rcl-plugin-demo.block%classes-dir=file:/F:/blocks/myBlock/target/classes
 org.apache.cocoon.cocoon-rcl-plugin-demo.block/xyz=abc
-org.apache.cocoon.cocoon-rcl-plugin-demo.block1%artifact=org.apache.cocoon:cocoon-myBlock1
 org.apache.cocoon.cocoon-rcl-plugin-demo.block1%classes-dir=file:/F:/blocks/myBlock1/target/classes
 org.apache.cocoon.cocoon-rcl-plugin-demo.block2%classes-dir=file:/F:/blocks/myBlock2/target/classes
+%classes-dir=file:/C:/blah
+%classes-dir=file:/X:/foo
+b=interpolatedValue:${a}
+a=A
\ No newline at end of file