You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by re...@apache.org on 2006/03/03 14:56:24 UTC

svn commit: r382815 - in /cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin: pom.xml src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java

Author: reinhard
Date: Fri Mar  3 05:56:23 2006
New Revision: 382815

URL: http://svn.apache.org/viewcvs?rev=382815&view=rev
Log:
first implementation of the cocoon:deploy goal 
 - accepts a property to set the deployment descriptor (default: ./cocoon-deploy.xml)
 - the DeployMojo extends the AbstractWarMojo now
   this way, the functionality of it (creating webapps) can be reused by first 
   copying all resources and then using the BlockDeployer to deploy blocks into it (+ adapting the wiring.xml)
 - make use of the BlockDeployer by passing the deployment descriptor XML
 - override the targetUrl within the deployment descriptor and use the webappDirectory used by the WarMojo

Modified:
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml
    cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml?rev=382815&r1=382814&r2=382815&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml (original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/pom.xml Fri Mar  3 05:56:23 2006
@@ -65,6 +65,11 @@
       <version>2.0.1</version>      
     </dependency> 
     <dependency>
+      <groupId>org.apache.maven.plugins</groupId>
+      <artifactId>maven-war-plugin</artifactId>
+      <version>2.0-beta-2</version>
+    </dependency>
+    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <version>3.8.1</version>

Modified: cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java
URL: http://svn.apache.org/viewcvs/cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java?rev=382815&r1=382814&r2=382815&view=diff
==============================================================================
--- cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java (original)
+++ cocoon/trunk/cocoon-block-deployer/cocoon-deployer-plugin/src/main/java/org/apache/cocoon/maven/deployer/DeployMojo.java Fri Mar  3 05:56:23 2006
@@ -15,21 +15,42 @@
  */
 package org.apache.cocoon.maven.deployer;
 
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileReader;
 import java.util.List;
 
+import org.apache.cocoon.deployer.BlockDeployer;
+import org.apache.cocoon.deployer.generated.deploy.x10.Deploy;
+import org.apache.cocoon.deployer.resolver.NullVariableResolver;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
 import org.apache.maven.artifact.resolver.ArtifactResolver;
-import org.apache.maven.plugin.AbstractMojo;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.war.AbstractWarMojo;
+import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.artifact.MavenMetadataSource;
+import org.exolab.castor.xml.MarshalException;
+import org.exolab.castor.xml.ValidationException;
 
 /**
+ * Create a Cocoon web application based on a block deployment descriptor.
+ * 
  * @goal deploy
- * @requiresProject false
- * @description
+ * @requiresProject true
+ * @phase package
+ * @description Create a Cocoon web application based on a block deployment descriptor.
  */
-public class DeployMojo extends AbstractMojo {
+public class DeployMojo extends AbstractWarMojo 
+{
+	
+    /**
+     * The project whose project files to create.
+     *
+     * @parameter expression="${project}"
+     * @required
+     */
+    private MavenProject project;		
 
     /**
      * Artifact factory, needed to download source jars for inclusion in classpath.
@@ -67,7 +88,6 @@
      */
     private ArtifactRepository localRepository;    
     
-
     /**
      * Remote repositories which will be searched for blocks.
      *
@@ -78,16 +98,100 @@
     private List remoteArtifactRepositories;  
     
     /**
-     * The source directory containing *.xsd files
+     * The deploy descriptor
      * 
-     * @parameter expression="${basedir}/deploy.xml"
+     * @parameter expression="${basedir}/cocoon-deploy.xml"
      */
-    private String deployDescriptor;    
+    private File deploymentDescriptor;     
+    
+    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+    // set properties: necessary because DeployMojo is not in the same package as AbstractWarMojo
+    /**
+     * The directory containing generated classes.
+     *
+     * @parameter expression="${project.build.outputDirectory}"
+     * @required
+     * @readonly
+     */
+    private File classesDirectory;
+
+    /**
+     * The directory where the webapp is built.
+     *
+     * @parameter expression="${project.build.directory}/${project.build.finalName}"
+     * @required
+     */
+    private File webappDirectory;
+
+    /**
+     * Single directory for extra files to include in the WAR.
+     *
+     * @parameter expression="${basedir}/src/main/webapp"
+     * @required
+     */
+    private File warSourceDirectory;
+
+    /**
+     * The path to the web.xml file to use.
+     *
+     * @parameter expression="${maven.war.webxml}"
+     */
+    private String webXml;
+    // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~    
 	
     public void execute() throws MojoExecutionException 
     {
-
-         
+    	File webappDirectory_ = getWebappDirectory();
+    	
+    	// build the web application without blocks
+        this.buildExplodedWebapp(webappDirectory_);
+        
+        // read the deployment descriptor
+    	Deploy deploy;
+    	try 
+    	{
+        	this.getLog().info("using deploymentDescriptor at " + deploymentDescriptor.getAbsolutePath());    		
+			deploy = (Deploy) Deploy.unmarshal(new FileReader(deploymentDescriptor));
+		} 
+    	catch (MarshalException e) 
+		{
+			throw new MojoExecutionException("The deployment descriptor at '" + deploymentDescriptor.getAbsolutePath() + "' can't be parsed.");
+		} 
+    	catch (ValidationException e) 
+    	{
+			throw new MojoExecutionException("The deployment descriptor at '" + deploymentDescriptor.getAbsolutePath() + "' is not valid XML.");
+		} 
+    	catch (FileNotFoundException e) 
+    	{
+			throw new MojoExecutionException("The deployment descriptor can't be found at '" + deploymentDescriptor.getAbsolutePath() + "'.");
+		}
+        
+    	// set the target directory 
+    	if(webappDirectory_ != null) {
+    		String targetUri = "file:///" + webappDirectory_.getAbsolutePath().replaceAll("\\\\", "/");
+    		this.getLog().debug("targetUrl: " + targetUri);
+    		
+    		deploy.getCocoon().setTargetUrl(targetUri);
+    		
+        	if(deploy.getCocoon().getTargetUrl() != null) {
+        		this.getLog().warn("The targetUrl set in the <cocoon> element of '" + deploymentDescriptor.getAbsolutePath() +
+        	        "' was overriden by '" + targetUri + "'");
+        	}    		
+    	}
+    	
+    	// finally use the block deployer to add blocks to the web app
+        BlockDeployer blockDeployer =
+            new BlockDeployer(new MavenArtifactProvider(this.artifactResolver, 
+            											this.artifactFactory,
+                                                        this.localRepository,
+                                                        this.remoteArtifactRepositories,
+                                                        this.metadataSource, 
+                                                        this.getLog()),
+                              new NullVariableResolver(),
+                              new MavenLoggingWrapper(this.getLog()));
+        
+        blockDeployer.deploy(deploy);
+        
     }	
-	
+    
 }