You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by lg...@apache.org on 2006/09/02 23:06:05 UTC

svn commit: r439653 - in /cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer: ./ monolithic/

Author: lgawron
Date: Sat Sep  2 14:06:04 2006
New Revision: 439653

URL: http://svn.apache.org/viewvc?rev=439653&view=rev
Log:
xpatches applied also for development blocks mounted directly (excluded from deployment)
further refactoring

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/DevelopmentBlock.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=439653&r1=439652&r2=439653&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 Sat Sep  2 14:06:04 2006
@@ -207,8 +207,7 @@
 
         // add current block to the development blocks
         // it is important that the current block is put at the end of the array
-        // - the
-        // MonotlithicCocoonDeployer expects this
+        // - the MonotlithicCocoonDeployer expects this
         DevelopmentBlock curBlock = new DevelopmentBlock();
         curBlock.artifactId = this.getProject().getArtifactId();
         curBlock.groupId = this.getProject().getGroupId();
@@ -225,8 +224,6 @@
         MonolithicCocoonDeployer deployer = new MonolithicCocoonDeployer(this.getLog());
         deployer.deploy(getBlockArtifactsAsMap(blocks), webappDirectory_, blocksdir, extBlocks, properties);
 
-        // deploy all libraries to WEB-INF/cocoon/lib and cocoon-bootstrap to
-        // WEB-INF/lib
         copyLibs();
 
         if (useShieldingClassloader)
@@ -342,7 +339,7 @@
             final Document webAppDoc = XMLUtils.parseXml(new FileInputStream(new File(webXmlLocation)));
             WebApplicationRewriter.rewrite(webAppDoc);
             this.getLog().debug("Writing web.xml: " + targetWebXmlLocation);
-            
+
             // TODO buffered stream + close stream?
             XMLUtils.write(webAppDoc, new FileOutputStream(targetWebXmlLocation));
         } catch (Exception e) {

Modified: cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/DevelopmentBlock.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/DevelopmentBlock.java?rev=439653&r1=439652&r2=439653&view=diff
==============================================================================
--- cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/DevelopmentBlock.java (original)
+++ cocoon/trunk/tools/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/monolithic/DevelopmentBlock.java Sat Sep  2 14:06:04 2006
@@ -19,42 +19,44 @@
 import java.io.FileNotFoundException;
 
 /**
- * A container for configuration parameters. Depending on the localPath parameter,
- * all other 'path' parameters are set.
+ * A container for configuration parameters. Depending on the localPath
+ * parameter, all other 'path' parameters are set.
  * 
  * @version $Id$
  */
 public class DevelopmentBlock {
-
+    // TODO this won't work if user chooses a different resources directory in
+    // pom.xml. There should be a way to get this path using Maven API.
     private static final String RESOURCES_DIR = "src/main/resources/";
-    
-	public String artifactId;
+    public String artifactId;
     public String groupId;
-    
+
     public String springConfPath;
-    public String xconfConfPath; 
+    public String xconfConfPath;
     public String sitemapAdditionsConfPath;
     public String targetClassesPath;
     public String cobInfPath;
-    
+    public String xPatchPath;
+
     public void setLocalPath(String localPath) throws FileNotFoundException {
-    	File localPathDir = new File(localPath);
-    	if(!localPathDir.exists()) {
-    		throw new FileNotFoundException("Directory '" + localPath + "' does not exist!");
-    	}
-    	
-    	springConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/spring"));    	
-    	xconfConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/legacy/xconf"));    	
-    	sitemapAdditionsConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/legacy/sitemap-additions"));    	
-    	targetClassesPath = checkDir(new File(localPath, "target/classes"));    	
-    	cobInfPath = checkDir(new File(localPath, RESOURCES_DIR + "COB-INF"));    	    	
+        File localPathDir = new File(localPath);
+        if (!localPathDir.exists()) {
+            throw new FileNotFoundException("Directory '" + localPath + "' does not exist!");
+        }
+
+        springConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/spring"));
+        xconfConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/legacy/xconf"));
+        sitemapAdditionsConfPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/legacy/sitemap-additions"));
+        xPatchPath = checkDir(new File(localPath, RESOURCES_DIR + "META-INF/xpatch"));
+        targetClassesPath = checkDir(new File(localPath, "target/classes"));
+        cobInfPath = checkDir(new File(localPath, RESOURCES_DIR + "COB-INF"));
+    }
+
+    private String checkDir(File dir) {
+        if (dir.exists()) {
+            return dir.toURI().toString();
+        }
+        return null;
     }
 
-	private String checkDir(File dir) {
-		if(dir.exists()) {
-    		return dir.toURI().toString();
-    	}
-		return null;
-	}
-	
 }

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=439653&r1=439652&r2=439653&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 Sat Sep  2 14:06:04 2006
@@ -16,10 +16,13 @@
 package org.apache.cocoon.maven.deployer.monolithic;
 
 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.net.URI;
+import java.net.URISyntaxException;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.Map;
@@ -92,6 +95,40 @@
             copyFile(basedir, "blocks/sitemap.xmap");
             copyFile(basedir, "WEB-INF/cocoon/log4j.xconf");
             // copyFile(basedir, "WEB-INF/web.xml");
+
+            for (int i = 0; i < developmentBlocks.length; ++i) {
+                DevelopmentBlock currentBlock = developmentBlocks[i];
+                if (currentBlock.xPatchPath != null) {
+                    URI uri = null;
+                    try {
+                        uri = new URI(currentBlock.xPatchPath);
+                    } catch (URISyntaxException e) {
+                        throw new RuntimeException( "should not happen", e );
+                    }
+                    
+                    File xPatchDir = new File(uri);
+                    File[] xPatchFiles = xPatchDir.listFiles(new FileFilter() {
+                        public boolean accept(File pathname) {
+                            if (pathname.isDirectory())
+                                return false;
+                            if (pathname.getName().endsWith(".xweb"))
+                                return true;
+                            return false;
+                        }
+                    });
+
+                    for (int j = 0; j < xPatchFiles.length; ++j) {
+                        File currentFile = xPatchFiles[j];
+                        try {
+                            xpatchDeployer.addPatch(currentFile);
+                        } catch (IOException e) {
+                            throw new DeploymentException("Can't process patch file '" + currentFile.getAbsolutePath()
+                                    + "'.", e);
+                        }
+                    }
+                }
+            }
+
             xpatchDeployer.applyPatches(basedir, "WEB-INF/web.xml");
             copyFile(basedir, "WEB-INF/applicationContext.xml");
             copyFile(basedir, "WEB-INF/cocoon/properties/core.properties");

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=439653&r1=439652&r2=439653&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 Sat Sep  2 14:06:04 2006
@@ -15,14 +15,7 @@
  */
 package org.apache.cocoon.maven.deployer.monolithic;
 
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-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 +32,7 @@
 
 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;
@@ -63,6 +57,19 @@
         return out;
     }
 
+    public void addPatch(File file) throws IOException {
+        getLogger().debug("catching patch: " + file.getAbsolutePath());
+        PatchCachingOutputStream pcis = new PatchCachingOutputStream();
+        OutputStream os = new BufferedOutputStream(pcis);
+        try {
+            // TODO close input stream
+            IOUtils.copy(new BufferedInputStream(new FileInputStream(file)), os);
+        } finally {
+            os.close();
+        }
+        patches.add(pcis);
+    }
+
     public void applyPatches(final File basedir, final String fileName) {
         if (patches.size() == 0) {
             // TODO should just copy the file without any transform
@@ -70,17 +77,7 @@
         try {
             getLogger().info("Applying patches to: " + fileName);
             File outFile = FileUtils.createDirectory(new File(basedir, fileName));
-
-            // TODO code duplication
-            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-            factory.setValidating(false);
-            factory.setExpandEntityReferences(false);
-            factory.setNamespaceAware(false);
-            factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
-
-            DocumentBuilder builder = factory.newDocumentBuilder();
-            InputStream is = readResourceFromClassloader(fileName);
-            Document original = builder.parse(is);
+            Document original = XMLUtils.parseXml(readResourceFromClassloader(fileName));
 
             Iterator it = patches.iterator();
             while (it.hasNext()) {
@@ -218,12 +215,6 @@
 
     private class PatchCachingOutputStream extends ByteArrayOutputStream {
         public Document getPatch() throws SAXException, IOException, ParserConfigurationException {
-//            DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
-//            factory.setValidating(false);
-//            factory.setExpandEntityReferences(false);
-//            factory.setNamespaceAware(false);
-//            factory.setAttribute("http://apache.org/xml/features/nonvalidating/load-external-dtd", Boolean.FALSE);
-//            DocumentBuilder builder = factory.newDocumentBuilder();
             return XMLUtils.parseXml(new ByteArrayInputStream(this.buf, 0, this.count));
         }
     }