You are viewing a plain text version of this content. The canonical link for it is here.
Posted to pluto-scm@portals.apache.org by es...@apache.org on 2007/03/14 06:44:55 UTC
svn commit: r518029 -
/portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java
Author: esm
Date: Tue Mar 13 22:44:54 2007
New Revision: 518029
URL: http://svn.apache.org/viewvc?view=rev&rev=518029
Log:
[PLUTO-344]: added war file assembly support to the maven pluto plugin.
Modified:
portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java
Modified: portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java?view=diff&rev=518029&r1=518028&r2=518029
==============================================================================
--- portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java (original)
+++ portals/pluto/trunk/maven-pluto-plugin/src/main/java/org/apache/pluto/maven/AssembleMojo.java Tue Mar 13 22:44:54 2007
@@ -17,6 +17,8 @@
package org.apache.pluto.maven;
import java.io.File;
+import java.util.Iterator;
+import java.util.List;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.logging.Log;
@@ -64,6 +66,19 @@
* @parameter
*/
private String dispatchServletClass;
+
+ /**
+ * A list of war files to assemble. Mutually exclusive with portletXml, webXml,
+ * and webXmlDestination parameters.
+ * @parameter
+ */
+ private List warFiles;
+
+ /**
+ * Destination directory the assembled war files are written out to.
+ * @parameter expression="${project.build.directory}/pluto-assembled-wars"
+ */
+ private File warFilesDestination;
// AbstractPlutoMojo Impl --------------------------------------------------
@@ -71,23 +86,119 @@
// Log parameter values.
Log log = getLog();
if (log.isInfoEnabled()) {
- log.info("Reading web.xml from :" + webXml.getAbsolutePath());
- log.info("Reading portlet.xml from: " + portletXml.getAbsolutePath());
- log.info("Writing web.xml to: " + webXmlDestination.getAbsolutePath());
+ if (warFiles == null || warFiles.isEmpty()) {
+ log.info("Reading web.xml from :" + webXml.getAbsolutePath());
+ log.info("Reading portlet.xml from: " + portletXml.getAbsolutePath());
+ log.info("Writing web.xml to: " + webXmlDestination.getAbsolutePath());
+ } else {
+ final String nl = System.getProperty("line.separator");
+ StringBuffer buf = new StringBuffer("Attempting to assemble the following war files to destination directory " +
+ warFilesDestination.getAbsolutePath() + " : " + nl);
+ for (Iterator i = warFiles.iterator(); i.hasNext();) {
+ File f = new File(i.next().toString());
+ buf.append(" " + f.getAbsolutePath());
+ if (i.hasNext()) {
+ buf.append(nl);
+ }
+ }
+ buf.append(nl);
+ log.info(buf.toString());
+ }
}
+
// Assemble portlet app by updating web.xml.
- AssemblerConfig config = createAssemblerConfig();
- Assembler assembler = AssemblerFactory.getFactory()
- .createAssembler(config);
- assembler.assemble(config);
+ if (warFiles == null || warFiles.isEmpty()) {
+ AssemblerConfig config = createAssemblerConfig();
+ Assembler assembler = AssemblerFactory.getFactory()
+ .createAssembler(config);
+ assembler.assemble(config);
+ } else {
+ for (Iterator i = warFiles.iterator(); i.hasNext();) {
+ File warFile = new File(i.next().toString());
+ if (log.isInfoEnabled()) {
+ log.info("Assembling war file " + warFile.getAbsolutePath() + " to directory " + warFilesDestination.getAbsolutePath());
+ }
+ AssemblerConfig config = createWarFileAssemblerConfig(warFile, warFilesDestination);
+ Assembler assembler = AssemblerFactory.getFactory()
+ .createAssembler(config);
+ assembler.assemble(config);
+ }
+ }
}
protected void doValidate() throws MojoExecutionException {
- if (webXml == null || !webXml.exists()) {
- throw new MojoExecutionException("Web application descriptor must be a valid web.xml");
- }
- if (portletXml == null || !portletXml.exists()) {
- throw new MojoExecutionException("Portlet descriptor must be a valid portlet.xml");
+ Log log = getLog();
+
+ // If a list of war files are supplied:
+ // 1) webXml, portletXml, and webXmlDestination parameters are ignored
+ // 2) verify the files in the List exist.
+ // 3) verify the destination is a directory, or create it if it doesn't exist.
+
+ // A list of files was supplied so we ignore other parameters.
+ if (warFiles != null && !warFiles.isEmpty()) {
+ if (webXml != null) {
+ log.debug("warFiles parameter and webXml parameter are mutually exclusive. Ignoring webXml parameter.");
+ }
+ if (portletXml != null) {
+ log.debug("warFiles parameter and portletXml parameter are mutually exclusive. Ignoring portletXml parameter.");
+ }
+ if (webXmlDestination != null) {
+ log.debug("warFiles parameter and webXmlDestination parameter are mutually exclusive. Ignoring webXmlDestination parameter.");
+ }
+
+ // verify each file can be found
+ for (Iterator i = warFiles.iterator(); i.hasNext();) {
+ File f = new File(i.next().toString());
+ if (!f.exists()) {
+ log.warn("File " + f.getAbsolutePath() + " does not exist.");
+ i.remove();
+ continue;
+ }
+ if (!f.canRead()) {
+ log.warn("File " + f.getAbsolutePath() + " exists but cannot be read.");
+ i.remove();
+ continue;
+ }
+ }
+
+ // check to see if the warFiles list is now empty
+ if (warFiles.isEmpty()) {
+ throw new MojoExecutionException("No war files could be installed due errors.");
+ }
+
+ // check to see if the dest dir exists or create it.
+ if (!warFilesDestination.exists()) {
+ if (log.isDebugEnabled()) {
+ log.debug("Creating destination directory for assembled war files: " + warFilesDestination.getAbsolutePath());
+ }
+ try {
+ if(!warFilesDestination.mkdirs()) {
+ throw new MojoExecutionException("Unable to create destination directory for assembled war files: " +
+ warFilesDestination.getAbsolutePath());
+ }
+ } catch (SecurityException e) {
+ throw new MojoExecutionException("Unable to create destination directory for assembled war files: " + e.getMessage(), e);
+ }
+ } else {
+ if (!warFilesDestination.isDirectory()) {
+ throw new MojoExecutionException("Specified destination for assembled war files " +
+ warFilesDestination.getAbsolutePath() + " is not a directory!");
+ }
+ if (!warFilesDestination.canRead()||!warFilesDestination.canWrite()) {
+ throw new MojoExecutionException("Unable to read or write to destination directory for assembed war files. " +
+ "Check permissions on the directory " + warFilesDestination.getAbsolutePath());
+ }
+ }
+
+ // A list of war files was not provided, so use the other parameters instead.
+
+ } else {
+ if (webXml == null || !webXml.exists()) {
+ throw new MojoExecutionException("Web application descriptor must be a valid web.xml");
+ }
+ if (portletXml == null || !portletXml.exists()) {
+ throw new MojoExecutionException("Portlet descriptor must be a valid portlet.xml");
+ }
}
}
@@ -99,6 +210,14 @@
config.setWebappDescriptor(webXml);
config.setDestination(webXmlDestination);
config.setDispatchServletClass(dispatchServletClass);
+ return config;
+ }
+
+ private AssemblerConfig createWarFileAssemblerConfig(File warFile, File destinationDirectory) {
+ AssemblerConfig config = new AssemblerConfig();
+ config.setDispatchServletClass(dispatchServletClass);
+ config.setWarSource(warFile);
+ config.setDestination(destinationDirectory);
return config;
}