cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r439744 - in /cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer: ./ monolithic/ utils/
Date Sun, 03 Sep 2006 08:39:07 GMT
Author: lgawron
Date: Sun Sep  3 01:39:06 2006
New Revision: 439744

URL: http://svn.apache.org/viewvc?rev=439744&view=rev
Log:
be nicer to Input/Output streams

Added:
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
  (with props)
Modified:
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
    cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java?rev=439744&r1=439743&r2=439744&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/AbstractDeployMojo.java
Sun Sep  3 01:39:06 2006
@@ -15,6 +15,7 @@
  */
 package org.apache.cocoon.maven.deployer;
 
+import java.io.BufferedInputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
@@ -29,6 +30,7 @@
 import org.apache.cocoon.maven.deployer.monolithic.DevelopmentBlock;
 import org.apache.cocoon.maven.deployer.monolithic.DevelopmentProperty;
 import org.apache.cocoon.maven.deployer.monolithic.MonolithicCocoonDeployer;
+import org.apache.cocoon.maven.deployer.utils.CopyUtils;
 import org.apache.cocoon.maven.deployer.utils.WebApplicationRewriter;
 import org.apache.cocoon.maven.deployer.utils.XMLUtils;
 import org.apache.commons.io.IOUtils;
@@ -190,7 +192,7 @@
         }
 
         // TODO XPatch web.xml here!
-        
+
         // take care of paranoid classloading
         if (this.useShieldingClassloader) {
             shieldCocoonWebapp();
@@ -323,11 +325,11 @@
                 this.getLog().info("No web.xml supplied. Will install default web.xml");
                 File outFile = org.apache.cocoon.maven.deployer.utils.FileUtils.createDirectory(new
File(
                         webappDirectory_, webInfSlashWebXml));
+
                 try {
-                    // TODO buffered stream + close stream?
-                    IOUtils.copy(readResourceFromClassloader("WEB-INF/web.xml"), new FileOutputStream(outFile));
+                    CopyUtils.copy(readResourceFromClassloader("WEB-INF/web.xml"), new FileOutputStream(outFile));
                 } catch (IOException ioex) {
-                    throw new MojoExecutionException("cannot read resource " + webXml, ioex);
+                    throw new MojoExecutionException("cannot copy resource " + webXml, ioex);
                 }
             }
             webXmlLocation = targetWebXmlLocation;
@@ -336,17 +338,27 @@
         }
         this.getLog().info("Adding shielded classloader configuration to webapp configuration.");
         this.getLog().debug("Reading web.xml: " + webXmlLocation);
+
+        InputStream is = null;
+        final Document webAppDoc;
         try {
-            // TODO buffered stream + close stream?
-            final Document webAppDoc = XMLUtils.parseXml(new FileInputStream(new File(webXmlLocation)));
-            WebApplicationRewriter.rewrite(webAppDoc);
-            this.getLog().debug("Writing web.xml: " + targetWebXmlLocation);
+            is = new BufferedInputStream(new FileInputStream(new File(webXmlLocation)));
+            webAppDoc = XMLUtils.parseXml(is);
+        } catch (Exception e) {
+            throw new MojoExecutionException("Unable to read web.xml from " + webXmlLocation,
e);
+        } finally {
+            IOUtils.closeQuietly(is);
+        }
 
-            // TODO buffered stream + close stream?
+        WebApplicationRewriter.rewrite(webAppDoc);
+        this.getLog().debug("Writing web.xml: " + targetWebXmlLocation);
+        
+        try {
             XMLUtils.write(webAppDoc, new FileOutputStream(targetWebXmlLocation));
         } catch (Exception e) {
-            throw new MojoExecutionException("Unable to read web.xml from " + webXmlLocation,
e);
+            throw new MojoExecutionException("Unable to write web.xml to " + targetWebXmlLocation,
e);
         }
+        
         if (this.useShieldingRepository) {
             this.getLog().info("Moving classes and libs to shielded location.");
             final String webInfDir = webappDirectory_.getAbsolutePath() + File.separatorChar
+ "WEB-INF";
@@ -404,7 +416,8 @@
             final File[] files = srcDirectory.listFiles();
             if (files != null && files.length > 0) {
                 for (int i = 0; i < files.length; i++) {
-                    // TODO - replace this hard-coded exlclude with something configurable
+                    // TODO - replace this hard-coded exlclude with something
+                    // configurable
                     boolean exclude = false;
                     if ("lib".equals(srcDir) && files[i].getName().startsWith("cocoon-bootstrap"))
{
                         exclude = true;

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java?rev=439744&r1=439743&r2=439744&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/MonolithicCocoonDeployer.java
Sun Sep  3 01:39:06 2006
@@ -29,6 +29,7 @@
 import java.util.Properties;
 
 import org.antlr.stringtemplate.StringTemplate;
+import org.apache.cocoon.maven.deployer.utils.CopyUtils;
 import org.apache.cocoon.maven.deployer.utils.FileUtils;
 import org.apache.commons.io.IOUtils;
 import org.apache.maven.plugin.logging.Log;
@@ -128,6 +129,7 @@
                 }
             }
 
+            // TODO close streams
             xwebPatcher.applyPatches(readResourceFromClassloader("WEB-INF/web.xml"), "WEB-INF/web.xml");
             copyFile(basedir, "WEB-INF/applicationContext.xml");
             copyFile(basedir, "WEB-INF/cocoon/properties/core.properties");
@@ -156,7 +158,7 @@
     private void copyFile(final File basedir, final String fileName) {
         try {
             File outFile = FileUtils.createDirectory(new File(basedir, fileName));
-            IOUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
+            CopyUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
             this.logger.info("Deploying resource file to " + fileName);
         } catch (FileNotFoundException e) {
             throw new DeploymentException("Can't copy to " + fileName, e);

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java?rev=439744&r1=439743&r2=439744&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/XPatchDeployer.java
Sun Sep  3 01:39:06 2006
@@ -28,6 +28,7 @@
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
+import org.apache.cocoon.maven.deployer.utils.CopyUtils;
 import org.apache.cocoon.maven.deployer.utils.FileUtils;
 import org.apache.cocoon.maven.deployer.utils.XMLUtils;
 import org.apache.commons.io.IOUtils;
@@ -59,13 +60,7 @@
     public void addPatch(File file) throws IOException {
         getLogger().debug("catching patch: " + file.getAbsolutePath());
         PatchCachingOutputStream pcis = new PatchCachingOutputStream(file.getCanonicalPath());
-        OutputStream os = new BufferedOutputStream(pcis);
-        try {
-            // TODO close input stream
-            IOUtils.copy(new BufferedInputStream(new FileInputStream(file)), os);
-        } finally {
-            os.close();
-        }
+        CopyUtils.copy(new FileInputStream(file), pcis);
         patches.add(pcis);
     }
 
@@ -122,7 +117,7 @@
 
                 if (testPath != null && testPath.length() > 0 && XPathAPI.eval(root,
testPath).bool()) {
                     // no test path or 'unless' condition is satisfied
-                    getLogger().debug( "skipping application of patch file: " + pcis.getDocumentName()
);
+                    getLogger().debug("skipping application of patch file: " + pcis.getDocumentName());
                 } else {
                     // Test if component wants us to remove
                     // a list of nodes first

Added: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java?rev=439744&view=auto
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
(added)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
Sun Sep  3 01:39:06 2006
@@ -0,0 +1,47 @@
+/*
+ * $Id$
+ *
+ * Created on 2006-09-03
+ *
+ * Copyright (c) 2006, MobileBox sp. z o.o.
+ * All rights reserved.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
+ * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
+ * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+ * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
+ * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
+ * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
+ * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
+ * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+package org.apache.cocoon.maven.deployer.utils;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+
+import org.apache.commons.io.IOUtils;
+
+public class CopyUtils {
+    public static void copy( InputStream is, OutputStream os ) throws IOException {
+        if ( !(is instanceof BufferedInputStream) ) {
+            is = new BufferedInputStream( is );
+        }
+        if ( !(os instanceof BufferedOutputStream) ) {
+            os = new BufferedOutputStream( os );
+        }
+        
+        try {
+            IOUtils.copy(is, os);
+        } finally {
+            IOUtils.closeQuietly(is);
+            IOUtils.closeQuietly(os);
+        }
+    }
+}

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/CopyUtils.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java
URL: http://svn.apache.org/viewvc/cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java?rev=439744&r1=439743&r2=439744&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java
(original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/utils/XMLUtils.java
Sun Sep  3 01:39:06 2006
@@ -27,7 +27,10 @@
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.transform.OutputKeys;
 import javax.xml.transform.Transformer;
+import javax.xml.transform.TransformerConfigurationException;
+import javax.xml.transform.TransformerException;
 import javax.xml.transform.TransformerFactory;
+import javax.xml.transform.TransformerFactoryConfigurationError;
 import javax.xml.transform.dom.DOMSource;
 import javax.xml.transform.stream.StreamResult;
 
@@ -54,7 +57,7 @@
             // allows to deploy the application offline
             docBuilder.setEntityResolver(new EntityResolver() {
                 public InputSource resolveEntity(String publicId, String systemId) throws
SAXException,
-                                java.io.IOException {
+                        java.io.IOException {
                     if (systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd")) {
                         return new InputSource(getClass().getResourceAsStream("web-app_2_3.dtd"));
                     }
@@ -68,18 +71,16 @@
         }
     }
 
-    public static void write(Document     node,
-                             OutputStream out)
-    throws Exception {
+    public static void write(Document node, OutputStream out) throws TransformerFactoryConfigurationError,
TransformerException {
         final Properties format = new Properties();
         format.put(OutputKeys.METHOD, "xml");
         format.put(OutputKeys.OMIT_XML_DECLARATION, "no");
         format.put(OutputKeys.INDENT, "yes");
-        if ( node.getDoctype() != null ) {
-            if ( node.getDoctype().getPublicId() != null ) {
+        if (node.getDoctype() != null) {
+            if (node.getDoctype().getPublicId() != null) {
                 format.put(OutputKeys.DOCTYPE_PUBLIC, node.getDoctype().getPublicId());
             }
-            if ( node.getDoctype().getSystemId() != null ) {
+            if (node.getDoctype().getSystemId() != null) {
                 format.put(OutputKeys.DOCTYPE_SYSTEM, node.getDoctype().getSystemId());
             }
         }
@@ -91,11 +92,11 @@
 
     public static List getChildNodes(Element parent, String nodeName) {
         final List nodes = new ArrayList();
-        if ( parent != null && nodeName != null ) {
+        if (parent != null && nodeName != null) {
             final NodeList children = parent.getChildNodes();
-            if ( children != null ) {
-                for(int i=0; i<children.getLength(); i++) {
-                    if ( nodeName.equals(children.item(i).getLocalName()) ) {
+            if (children != null) {
+                for (int i = 0; i < children.getLength(); i++) {
+                    if (nodeName.equals(children.item(i).getLocalName())) {
                         nodes.add(children.item(i));
                     }
                 }
@@ -103,13 +104,13 @@
         }
         return nodes;
     }
- 
+
     public static Element getChildNode(Element parent, String nodeName) {
         final List children = getChildNodes(parent, nodeName);
-        if ( children.size() > 0 ) {
-            return (Element)children.get(0);
+        if (children.size() > 0) {
+            return (Element) children.get(0);
         }
-     
+
         return null;
     }
 
@@ -135,9 +136,9 @@
     }
 
     public static void setValue(Element node, String value) {
-        if ( node != null ) {
+        if (node != null) {
             // remove all children
-            while ( node.hasChildNodes() ) {
+            while (node.hasChildNodes()) {
                 node.removeChild(node.getFirstChild());
             }
             node.appendChild(node.getOwnerDocument().createTextNode(value));



Mime
View raw message