cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cziege...@apache.org
Subject svn commit: r490171 - in /cocoon/trunk/core: cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/ cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/
Date Mon, 25 Dec 2006 20:52:37 GMT
Author: cziegeler
Date: Mon Dec 25 12:52:36 2006
New Revision: 490171

URL: http://svn.apache.org/viewvc?view=rev&rev=490171
Log:
Make deployment util more reusable

Modified:
    cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
    cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java

Modified: cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java?view=diff&rev=490171&r1=490170&r2=490171
==============================================================================
--- cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
(original)
+++ cocoon/trunk/core/cocoon-configuration/cocoon-configuration-impl/src/main/java/org/apache/cocoon/configuration/impl/DeploymentUtil.java
Mon Dec 25 12:52:36 2006
@@ -43,20 +43,19 @@
 
     protected static final Log logger = LogFactory.getLog(DeploymentUtil.class);
 
-    protected static final String RESOURCES_PATH = "COB-INF";
+    protected static final String BLOCK_RESOURCES_PATH = "COB-INF";
 
-    protected final String destinationDirectory;
-    
     protected static final Map blockContexts = new HashMap(); 
 
-    public DeploymentUtil(String destination) {
-        if ( destination == null ) {
-            throw new IllegalArgumentException("Destination must not be null.");
-        }
-        this.destinationDirectory = destination;
-    }
-
-    protected void deploy(JarFile jarFile, String prefix, String destination)
+    /**
+     * Deploy all files with a given prefix from a jar file to a directory
+     * in the file system.
+     * @param jarFile      The jar file containing the resources.
+     * @param prefix       The common prefix for the files.
+     * @param destination  The destination directory.
+     * @throws IOException
+     */
+    public static void deploy(JarFile jarFile, String prefix, String destination)
     throws IOException {
         if ( logger.isDebugEnabled() ) {
             logger.debug("Deploying jar " + jarFile + " to " + destination);
@@ -75,15 +74,16 @@
         }        
     }
 
-    protected void deployBlockResources(String resourcePattern, String relativeDirectory)
+    protected static void deployBlockResources(String relativeDirectory,
+                                               String destinationDirectory)
     throws IOException {
-        final Enumeration jarUrls = this.getClass().getClassLoader().getResources(resourcePattern);
+        final Enumeration jarUrls = DeploymentUtil.class.getClassLoader().getResources(BLOCK_RESOURCES_PATH);
         while ( jarUrls.hasMoreElements() ) {
             final URL resourceUrl = (URL)jarUrls.nextElement();
 
             String url = resourceUrl.toExternalForm();
             if ( "file".equals(resourceUrl.getProtocol()) ) {
-                // FIXME: This only cover the siuation when the project is Maven generated
+                // FIXME: This only covers the siuation when the project is Maven generated
                 // if this is a file url generated by the Maven,
                 // it has this form "file:{url}/{block name}/target/classes/COB-INF
                 int pos = url.indexOf("/target/classes/COB-INF");
@@ -95,7 +95,7 @@
                     DeploymentUtil.blockContexts.put(blockName, url);
                 }
             } else if ( "jar".equals(resourceUrl.getProtocol()) ) {
-                // if this is a jar url, it has this form "jar:{url-to-jar}!/{resource-path}
+                // if this is a jar url, it has this form: "jar:{url-to-jar}!/{resource-path}"
                 // to open the jar, we can simply remove everything after "!/"
                 int pos = url.indexOf('!');
                 url = url.substring(0, pos+2); // +2 as we include "!/"
@@ -111,13 +111,13 @@
                     blockName = jarName.substring(0, jarName.lastIndexOf('.'));
                     // TODO how do we strip version from blockName?
                 }
-                final StringBuffer buffer = new StringBuffer(this.destinationDirectory);
+                final StringBuffer buffer = new StringBuffer(destinationDirectory);
                 buffer.append(File.separatorChar);
                 buffer.append(relativeDirectory);
                 buffer.append(File.separatorChar);
                 buffer.append(blockName);
                 String destination = buffer.toString();
-                this.deploy(jarFile, resourcePattern, destination);
+                deploy(jarFile, BLOCK_RESOURCES_PATH, destination);
                 // register the root URL for the block resources
                 DeploymentUtil.blockContexts.put(blockName, destination);
             }
@@ -126,13 +126,13 @@
         }        
     }
 
-    public void deploy()
+    public static void deployBlockArtifacts(String destinationDirectory)
     throws IOException {
-        // Check if we run unexpanded
-        if ( this.destinationDirectory != null ) {
-            // deploy all artifacts containing block resources
-            this.deployBlockResources(DeploymentUtil.RESOURCES_PATH, "blocks");
+        if ( destinationDirectory == null ) {
+            throw new IllegalArgumentException("Destination must not be null.");
         }
+        // deploy all artifacts containing block resources
+        deployBlockResources("blocks", destinationDirectory);
     }
 
     /**

Modified: cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java?view=diff&rev=490171&r1=490170&r2=490171
==============================================================================
--- cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
(original)
+++ cocoon/trunk/core/cocoon-spring/src/main/java/org/apache/cocoon/core/container/spring/SettingsBeanFactoryPostProcessor.java
Mon Dec 25 12:52:36 2006
@@ -70,8 +70,7 @@
         this.forceLoad();
 
         // finally deploy block artifacts!
-        final DeploymentUtil deployer = new DeploymentUtil(this.settings.getWorkDirectory());
-        deployer.deploy();
+        DeploymentUtil.deployBlockArtifacts(this.settings.getWorkDirectory());
     }
 
     /**



Mime
View raw message