cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From reinh...@apache.org
Subject svn commit: r510135 - in /cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src: main/java/org/apache/cocoon/maven/rcl/ main/resources/org/apache/cocoon/maven/rcl/WEB-INF/ test/java/org/apache/cocoon/maven/rcl/ test/resources/org/apache/cocoon/maven/rcl/
Date Wed, 21 Feb 2007 18:22:51 GMT
Author: reinhard
Date: Wed Feb 21 10:22:50 2007
New Revision: 510135

URL: http://svn.apache.org/viewvc?view=rev&rev=510135
Log:
- the rcl.properties have to contain filesystem paths now
- the create properties files that configure the ReloadingClassloader
  contain file: URLs
- expect that the Maven standard directory structure is used
  (if somebody needs more flexibility, patches are welcome)
- more tests for properties conversion

Modified:
    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/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml
    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/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=510135&r1=510134&r2=510135
==============================================================================
--- 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
Wed Feb 21 10:22:50 2007
@@ -208,12 +208,12 @@
             FileWriter fw = new FileWriter(urlClConfFile);
             for(Iterator aIt = props.getClassesDirs().iterator(); aIt.hasNext();) {
                 String dir = (String) aIt.next();
-                fw.write(new File(dir).getCanonicalPath() + "\n");            
+                fw.write(dir + "\n");            
                 this.getLog().debug("Adding classes-dir to RCLClassLoader configuration:
" + dir);
             }
             fw.close();
         } catch(IOException e) {
-            throw new MojoExecutionException("Error while writing to " + urlClConfFile);
+            throw new MojoExecutionException("Error while writing to " + urlClConfFile, e);
         }
     }
 

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=510135&r1=510134&r2=510135
==============================================================================
--- 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
Wed Feb 21 10:22:50 2007
@@ -18,6 +18,7 @@
 
 import java.io.File;
 import java.net.MalformedURLException;
+import java.net.URL;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.Properties;
@@ -30,9 +31,10 @@
 
 public class RwmProperties {
 
-    private static final String COB_INF_DIR = "/COB-INF";
+    private static final String COB_INF_DIR = "src/main/resources/COB-INF";
     private static final String BLOCK_CONTEXT_URL_PARAM = "/contextPath";
-    private static final String CLASSES_DIR = "%classes-dir";    
+    private static final String CLASSES_DIR = "%classes-dir"; 
+    private static final String TARGET_CLASSES_DIR = "target/classes";
     
     private Configuration props;
 
@@ -40,7 +42,7 @@
         props = new PropertiesConfiguration(propsFile);
     }
     
-    public Set getClassesDirs() {
+    public Set getClassesDirs() throws MojoExecutionException {
         return getFilteredPropertiesValuesAsSet(CLASSES_DIR);
     }
     
@@ -48,30 +50,70 @@
         Properties springProps = new Properties();
         for(Iterator rclIt = props.getKeys(); rclIt.hasNext();) {
             String key = (String) rclIt.next();
-            if(!key.endsWith(CLASSES_DIR)) {
-                springProps.put(key, this.props.getString(key));
+            
+            // a [block-id]/COB-INF property was set explicitly
+            if(key.endsWith(BLOCK_CONTEXT_URL_PARAM)) {
+                String path = null;
+                try {
+                    path = new File(this.props.getString(key)).toURL().toExternalForm();
+                } catch (MalformedURLException e) {
+                    throw new MojoExecutionException("Can't create URL to  " + path, e);
+                }            
+                springProps.put(key, path);
             }
-            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.props.getString(key) + COB_INF_DIR);
+            
+            // a %CLASSES_DIR property --> generate a */COB-INF property out of it
+            else if(key.endsWith(CLASSES_DIR) && !CLASSES_DIR.equals(key)) {
+                String path = null;
                 try {
-                    springProps.put(newKey, blockContext.toURL().toExternalForm());
+                    path = new File(this.props.getString(key)).toURL().toExternalForm();
                 } catch (MalformedURLException e) {
-                    throw new MojoExecutionException("Can't create URL to  " + blockContext,
e);
+                    throw new MojoExecutionException("Can't create URL to  " + this.props.getString(key),
e);
+                }  
+                
+                if(path.endsWith(TARGET_CLASSES_DIR)) {
+                    path = path + "/";
+                }
+                
+                if(!path.endsWith(TARGET_CLASSES_DIR + "/")) {
+                    throw new MojoExecutionException("A */" + CLASSES_DIR + 
+                            " property can only point to a directory that ends with " + TARGET_CLASSES_DIR
+ ".");
                 }
+                
+                // path calculation
+                if(path.endsWith("/")) {
+                    path = path.substring(0, path.length() - 1);
+                }
+                path = path.substring(0, path.length() - "target/classes".length());
+                
+                String newKey = key.substring(0, key.length() - CLASSES_DIR.length()) + BLOCK_CONTEXT_URL_PARAM;
               
+                springProps.put(newKey, path + COB_INF_DIR);
+            }
+            
+            // copy all other properties
+            else if(!key.endsWith(CLASSES_DIR)) {
+                springProps.put(key, this.props.getString(key));
             }
+            
         } 
         return springProps;
     }    
     
-    private Set getFilteredPropertiesValuesAsSet(String filter) {
+    private Set getFilteredPropertiesValuesAsSet(String filter) throws MojoExecutionException
{
         Set returnSet = new HashSet();
         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]);
+                    String path = values[i];
+                    String url = null;
+                    try {
+                        url = new File(path).toURL().toExternalForm();
+                    } catch (MalformedURLException e) {
+                        throw new MojoExecutionException("Can't create URL to  " + path,
e);
+                    }
+                    returnSet.add(url);
                 }
             }
         }        
@@ -81,3 +123,5 @@
 }
 
     
+
+    
\ No newline at end of file

Modified: cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml?view=diff&rev=510135&r1=510134&r2=510135
==============================================================================
--- cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml
(original)
+++ cocoon/trunk/tools/cocoon-rcl/cocoon-rcl-plugin/src/main/resources/org/apache/cocoon/maven/rcl/WEB-INF/web.xml
Wed Feb 21 10:22:50 2007
@@ -17,7 +17,8 @@
 -->
 <!--+
     | This is the Cocoon web-app configurations file
-    +--><!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
+    +-->
+    <!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">
     <web-app>
       <context-param>
         <param-name>org.apache.cocoon.servlet.ReloadingListener</param-name>
@@ -26,7 +27,7 @@
         </param-value>
       </context-param>
       
-      <!--filter>
+      <filter>
         <filter-name>ReloadingSpringFilter</filter-name>
         <display-name>ReloadingSpringFilter</display-name>
         <description>Reloads the Spring application context if a classloader change
was detected.</description>
@@ -35,7 +36,7 @@
           <param-name>filter-class</param-name>
           <param-value>org.apache.cocoon.servlet.ReloadingSpringFilter</param-value>
         </init-param>
-      </filter-->         
+      </filter>         
       <filter>
         <filter-name>RequestContextFilter</filter-name>
         <display-name>Request context filter</display-name>
@@ -67,10 +68,10 @@
         </init-param>
       </filter>     
                   
-      <!--filter-mapping>
+      <filter-mapping>
         <filter-name>ReloadingSpringFilter</filter-name>
-        <servlet-name>Cocoon</servlet-name>
-      </filter-mapping-->                    
+        <servlet-name>DispatcherServlet</servlet-name>
+      </filter-mapping>                    
       <filter-mapping>
         <filter-name>RequestContextFilter</filter-name>
         <servlet-name>DispatcherServlet</servlet-name>

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=510135&r1=510134&r2=510135
==============================================================================
--- 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
Wed Feb 21 10:22:50 2007
@@ -32,19 +32,21 @@
     public void testLoadingSpringProps() throws Exception {
         RwmProperties p = createTestProperties();
         Properties springProps = p.getSpringProperties();
-        assertEquals(7, springProps.size());
+        assertEquals(8, 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/contextPath"));
-        assertTrue(springProps.getProperty("org.apache.cocoon.cocoon-rcl-plugin-demo.block1/contextPath")
-                .indexOf("target/classes/COB-INF") > 0);
+        assertEquals("file:/F:/blocks/myBlock1/src/main/resources/COB-INF", springProps.getProperty("org.apache.cocoon.cocoon-rcl-plugin-demo.block1/contextPath"));
+        assertEquals("file:/F:/blocks/myBlock2/src/main/resources/COB-INF", 
+                springProps.getProperty("org.apache.cocoon.cocoon-rcl-plugin-demo.block2/contextPath"));
    
+        assertTrue(springProps.getProperty("org.apache.cocoon.cocoon-rcl-plugin-demo.block3/contextPath").endsWith("src/main/resources/COB-INF"));
     }
 
     public void testLoadingBasedirs() throws Exception {
         RwmProperties p = createTestProperties();
         Set as = p.getClassesDirs();
-        assertEquals(5, as.size());
+        assertEquals(6, as.size());
         assertTrue(as.contains("file:/F:/blocks/myBlock/target/classes"));
         assertTrue(as.contains("file:/F:/blocks/myBlock1/target/classes"));      
     }      

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=510135&r1=510134&r2=510135
==============================================================================
--- 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
Wed Feb 21 10:22:50 2007
@@ -15,11 +15,13 @@
 # limitations under the License.
 #
 org.apache.cocoon.cocoon-rcl-plugin-demo.block/123=456
-org.apache.cocoon.cocoon-rcl-plugin-demo.block%classes-dir=file:/F:/blocks/myBlock/target/classes
+org.apache.cocoon.cocoon-rcl-plugin-demo.block%classes-dir=F:/blocks/myBlock/target/classes
 org.apache.cocoon.cocoon-rcl-plugin-demo.block/xyz=abc
-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
+org.apache.cocoon.cocoon-rcl-plugin-demo.block1%classes-dir=F:/blocks/myBlock1/target/classes
+org.apache.cocoon.cocoon-rcl-plugin-demo.block2%classes-dir=F:/blocks/myBlock2/target/classes
+org.apache.cocoon.cocoon-rcl-plugin-demo.block2/contextPath=F:/blocks/myBlock2/src/main/resources/COB-INF
+org.apache.cocoon.cocoon-rcl-plugin-demo.block3%classes-dir=./target/classes
+%classes-dir=C:/blah
+%classes-dir=X:/foo
 b=interpolatedValue:${a}
 a=A



Mime
View raw message