cocoon-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lgaw...@apache.org
Subject svn commit: r439774 - in /cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer: AbstractDeployMojo.java monolithic/MonolithicCocoonDeployer.java monolithic/XPatchDeployer.java
Date Sun, 03 Sep 2006 13:18:52 GMT
Author: lgawron
Date: Sun Sep  3 06:18:50 2006
New Revision: 439774

URL: http://svn.apache.org/viewvc?rev=439774&view=rev
Log:
refactoring, stream handling

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

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=439774&r1=439773&r2=439774&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 06:18:50 2006
@@ -311,7 +311,6 @@
         String webInfSlashWebXml = "WEB-INF" + File.separatorChar + "web.xml";
 
         String webXmlLocation = this.getWebXml();
-        // TODO sprawdzic czy byc moze w targecie jest juz taki web.xml
         if (webXmlLocation == null) {
             webXmlLocation = getWarSourceDirectory().getAbsolutePath() + File.separatorChar
+ webInfSlashWebXml;
         }

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=439774&r1=439773&r2=439774&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 06:18:50 2006
@@ -15,12 +15,14 @@
  */
 package org.apache.cocoon.maven.deployer.monolithic;
 
+import java.io.BufferedOutputStream;
 import java.io.File;
 import java.io.FileFilter;
 import java.io.FileNotFoundException;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
+import java.io.OutputStream;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.util.HashMap;
@@ -134,8 +136,12 @@
                 }
             }
 
-            // TODO close streams
-            xwebPatcher.applyPatches(readResourceFromClassloader("WEB-INF/web.xml"), "WEB-INF/web.xml");
+            InputStream sourceWebXmlFile = readResourceFromClassloader("WEB-INF/web.xml");
+            try {
+                xwebPatcher.applyPatches(sourceWebXmlFile, "WEB-INF/web.xml");
+            } finally { 
+                IOUtils.closeQuietly(sourceWebXmlFile);
+            }
             copyFile(basedir, "WEB-INF/applicationContext.xml");
             copyFile(basedir, "WEB-INF/cocoon/properties/core.properties");
         }
@@ -151,21 +157,24 @@
     }
 
     private void writeProperties(final File basedir, final String propertiesFile, final Properties
properties) {
+        File outFile = new File(basedir, propertiesFile);
+        OutputStream os = null;
         try {
-            File outFile = new File(basedir, propertiesFile);
-            //TODO close stream!
-            properties.store(new FileOutputStream(FileUtils.createPath(outFile)), null);
+            os = new FileOutputStream(FileUtils.createPath(outFile));
             this.logger.info("Deploying dev properties to " + propertiesFile);
+            properties.store(os, null);
         } catch (IOException e) {
             throw new DeploymentException("Can't save properties to " + propertiesFile, e);
+        } finally {
+            IOUtils.closeQuietly(os);
         }
     }
 
     private void copyFile(final File basedir, final String fileName) {
         try {
             File outFile = FileUtils.createPath(new File(basedir, fileName));
-            CopyUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
             this.logger.info("Deploying resource file to " + fileName);
+            CopyUtils.copy(readResourceFromClassloader(fileName), new FileOutputStream(outFile));
         } catch (FileNotFoundException e) {
             throw new DeploymentException("Can't copy to " + fileName, e);
         } catch (IOException e) {
@@ -174,19 +183,18 @@
     }
 
     private void writeStringTemplateToFile(final File basedir, final String fileName, final
Map templateObjects) {
-        FileOutputStream fos = null;
+        OutputStream fos = null;
         try {
             File outFile = FileUtils.createPath(new File(basedir, fileName));
-            // TODO buffered stream!
-            fos = new FileOutputStream(outFile);
+            fos = new BufferedOutputStream(new FileOutputStream(outFile));
             InputStream fileIs = readResourceFromClassloader(fileName);
             StringTemplate stringTemplate = new StringTemplate(IOUtils.toString(fileIs));
             for (Iterator templateObjectsIt = templateObjects.keySet().iterator(); templateObjectsIt.hasNext();)
{
                 Object key = templateObjectsIt.next();
                 stringTemplate.setAttribute((String) key, templateObjects.get(key));
             }
-            IOUtils.write(stringTemplate.toString(), fos);
             this.logger.info("Deploying string-template to " + fileName);
+            IOUtils.write(stringTemplate.toString(), fos);
         } catch (FileNotFoundException e) {
             throw new DeploymentException(fileName + " not found.", e);
         } catch (IOException 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=439774&r1=439773&r2=439774&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 06:18:50 2006
@@ -15,15 +15,7 @@
  */
 package org.apache.cocoon.maven.deployer.monolithic;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.*;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Vector;
@@ -39,6 +31,7 @@
 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;
 import org.apache.xpath.XPathAPI;
 import org.w3c.dom.Attr;
 import org.w3c.dom.Document;
@@ -195,8 +188,13 @@
 
             TransformerFactory tFactory = TransformerFactory.newInstance();
             Transformer transformer = tFactory.newTransformer();
-            transformer.transform(new DOMSource(original), new StreamResult(new FileOutputStream(outFile)));
-            getLogger().debug("Deploying resource file to " + fileName);
+            OutputStream os = new BufferedOutputStream(new FileOutputStream(outFile));
+            try {
+                getLogger().debug("Deploying resource file to " + fileName);
+                transformer.transform(new DOMSource(original), new StreamResult(os));
+            } finally {
+                IOUtils.closeQuietly(os);
+            }
         } catch (FileNotFoundException e) {
             throw new DeploymentException("Can't write to nonexistant file " + fileName,
e);
         } catch (IOException e) {



Mime
View raw message