Return-Path: Delivered-To: apmail-cocoon-cvs-archive@www.apache.org Received: (qmail 896 invoked from network); 25 Dec 2006 20:53:30 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 25 Dec 2006 20:53:30 -0000 Received: (qmail 87959 invoked by uid 500); 25 Dec 2006 20:53:37 -0000 Delivered-To: apmail-cocoon-cvs-archive@cocoon.apache.org Received: (qmail 87894 invoked by uid 500); 25 Dec 2006 20:53:36 -0000 Mailing-List: contact cvs-help@cocoon.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@cocoon.apache.org list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list cvs@cocoon.apache.org Received: (qmail 87883 invoked by uid 99); 25 Dec 2006 20:53:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Dec 2006 12:53:36 -0800 X-ASF-Spam-Status: No, hits=-9.4 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Mon, 25 Dec 2006 12:53:29 -0800 Received: by eris.apache.org (Postfix, from userid 65534) id 743301A981A; Mon, 25 Dec 2006 12:52:37 -0800 (PST) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: cvs@cocoon.apache.org From: cziegeler@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20061225205237.743301A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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()); } /**