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 ed...@apache.org on 2010/10/13 04:50:34 UTC
svn commit: r1021977 -
/portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java
Author: edalquist
Date: Wed Oct 13 02:50:34 2010
New Revision: 1021977
URL: http://svn.apache.org/viewvc?rev=1021977&view=rev
Log:
PLUTO-314 Adding back in assembler task enhancements from 1.1 branch
Modified:
portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java
Modified: portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java
URL: http://svn.apache.org/viewvc/portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java?rev=1021977&r1=1021976&r2=1021977&view=diff
==============================================================================
--- portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java (original)
+++ portals/pluto/trunk/pluto-ant-tasks/src/main/java/org/apache/pluto/ant/AssembleTask.java Wed Oct 13 02:50:34 2010
@@ -17,31 +17,72 @@
package org.apache.pluto.ant;
import java.io.File;
+import java.util.Collection;
+import java.util.Iterator;
+import java.util.LinkedList;
import org.apache.pluto.util.UtilityException;
import org.apache.pluto.util.assemble.Assembler;
import org.apache.pluto.util.assemble.AssemblerConfig;
import org.apache.pluto.util.assemble.AssemblerFactory;
import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.DirectoryScanner;
import org.apache.tools.ant.Task;
+import org.apache.tools.ant.types.FileSet;
/**
* TODO JavaDoc
*
- * @author <a href="mailto:ddewolf@apache.org">David H. DeWolf</a>:
* @version 1.0
* @since Nov 23, 2005
*/
public class AssembleTask extends Task {
-
+
+ /**
+ * Path to the portlet descriptor
+ * (normally <code>WEB-INF/portlet.xml</code>)
+ * <p/>
+ * If <code>webapp</code> is specified, this File will
+ * be resolved relative to <code>webapp</code>
+ */
private File portletxml;
+ /**
+ * Path to the unassembled servlet descriptor
+ * (normally <code>WEB-INF/web.xml</code>)
+ * <p/>
+ * If <code>webapp</code> is specified, this File will
+ * be resolved relative to <code>webapp</code>
+ */
private File webxml;
+ /**
+ * Path the assembled servlet descriptor will
+ * be written to.
+ */
private File destfile;
+ /**
+ * The base directory of the exploded web application to assemble.
+ * If set, <code>webXml</code> and <code>portletXml</code>
+ * will be resolved relative to this directory.
+ */
private File webapp;
+ /**
+ * Path to the archive to assemble. EAR and WAR
+ * packaging formats are supported.
+ */
+ private File archive;
+
+ /**
+ * Destination directory the assembled archives
+ * are written out to.
+ */
+ private File destdir;
+
+ private final Collection archiveFileSets = new LinkedList();
+
public File getPortletxml() {
if(webapp != null)
return new File(webapp, "WEB-INF/portlet.xml");
@@ -80,20 +121,106 @@ public class AssembleTask extends Task {
this.webapp = webapp;
}
+ /**
+ * Note this methods remains to support
+ * backwards compatiblity.
+ *
+ * @deprecated see <code>getArchive()</code>
+ */
+ public File getWar() {
+ return this.archive;
+ }
+
+ /**
+ * Note this methods remains to support
+ * backwards compatiblity.
+ *
+ * @param war
+ * @deprecated see <code>setArchive(File)</code>
+ */
+ public void setWar(File war) {
+ this.archive = war;
+ }
+
+ public File getArchive() {
+ return this.archive;
+ }
+
+ public void setArchive(File archive) {
+ this.archive = archive;
+ }
+
+ public File getDestdir() {
+ if (destdir == null) {
+ return (archive != null ? archive.getParentFile() : null);
+ }
+ return this.destdir;
+ }
+
+ public void setDestdir(File destDir) {
+ this.destdir = destDir;
+ }
+
+ /**
+ * Note this method remains to support
+ * backwards compatiblity.
+ *
+ * @param fileSet
+ * @deprecated use addArchives instead
+ */
+ public void addWars(FileSet fileSet) {
+ this.archiveFileSets.add(fileSet);
+ }
+
+ public void addArchives(FileSet fileSet) {
+ this.archiveFileSets.add(fileSet);
+ }
+
public void execute() throws BuildException {
validateArgs();
try {
- AssemblerConfig config = new AssemblerConfig();
- config.setPortletDescriptor(getPortletxml());
- config.setWebappDescriptor(getWebxml());
- config.setDestination(getDestfile());
+ if (this.archiveFileSets.size() > 0) {
+ for (final Iterator fileSetItr = this.archiveFileSets.iterator(); fileSetItr.hasNext();) {
+ final FileSet fileSet = (FileSet)fileSetItr.next();
+ final DirectoryScanner directoryScanner = fileSet.getDirectoryScanner(this.getProject());
+
+ final File basedir = directoryScanner.getBasedir();
+ final String[] includedFiles = directoryScanner.getIncludedFiles();
+
+ for (int index = 0; index < includedFiles.length; index++) {
+ AssemblerConfig config = new AssemblerConfig();
+
+ final File archiveSource = new File(basedir, includedFiles[index]);
+ config.setSource(archiveSource);
+ config.setDestination(getDestdir());
+
+ this.log("Assembling '" + archiveSource + "' to '" + getDestdir() + "'");
+ Assembler assembler = AssemblerFactory.getFactory().createAssembler(config);
+ assembler.assemble(config);
+ }
+ }
+ }
+ else {
+ AssemblerConfig config = new AssemblerConfig();
- Assembler assembler =
- AssemblerFactory.getFactory().createAssemblerAnt(config);
+ final File archiveSource = getArchive();
+ if (archiveSource != null) {
+ config.setSource(archiveSource);
+ config.setDestination(getDestdir());
+ this.log("Assembling '" + archiveSource + "' to '" + getDestdir() + "'");
+ }
+ else {
+ config.setPortletDescriptor(getPortletxml());
+ config.setWebappDescriptor(getWebxml());
+ config.setDestination(getDestfile());
+ this.log("Assembling '" + getWebxml() + "' to '" + getDestfile() + "'");
+ }
- assembler.assemble(config);
+ Assembler assembler = AssemblerFactory.getFactory().createAssembler(config);
+ assembler.assemble(config);
+ }
}
catch(UtilityException ue) {
@@ -102,19 +229,88 @@ public class AssembleTask extends Task {
}
private void validateArgs() throws BuildException {
+ //Check if running with webapp arg
if(webapp != null) {
if(!webapp.exists()) {
throw new BuildException("webapp "+webapp.getAbsolutePath()+ " does not exist");
}
+
+ if (archive != null) {
+ throw new BuildException("archive (or war) should not be specified if webapp is specified");
+ }
+ if (this.archiveFileSets.size() > 0) {
+ throw new BuildException("archive (or wars) should not be specified if webapp is specified");
+ }
+ // TODO check this
+ if (destdir != null) {
+ throw new BuildException("destfile should not be specified if webapp is specified");
+ }
+
+ return;
+ }
+
+ //Check if running with war arg
+ if (archive != null) {
+ if(!archive.exists()) {
+ throw new BuildException("Archive file "+archive.getAbsolutePath()+ " does not exist");
+ }
+
+ if (this.archiveFileSets.size() > 0) {
+ throw new BuildException("archives (or wars) should not be specified if archive (or war) is specified");
+ }
+ if (webapp != null) {
+ throw new BuildException("webapp should not be specified if archive (or war) is specified");
+ }
+ if (destfile != null) {
+ throw new BuildException("destfile should not be specified if archive (or war) is specified");
+ }
+ if (portletxml != null) {
+ throw new BuildException("portletxml should not be specified if archive (or war) is specified");
+ }
+ if (webxml != null) {
+ throw new BuildException("webxml should not be specified if archive (or war) is specified");
+ }
+
+ return;
+ }
+
+ //Check if running with archives or wars arg
+ if (this.archiveFileSets.size() > 0) {
+ if (archive != null) {
+ throw new BuildException("archives (or wars) should not be specified if archive (or war) is specified");
+ }
+ if (webapp != null) {
+ throw new BuildException("webapp should not be specified if archives (or wars) is specified");
+ }
+ if (destfile != null) {
+ throw new BuildException("destfile should not be specified if archives (or wars) is specified");
+ }
+ if (portletxml != null) {
+ throw new BuildException("portletxml should not be specified if archive (or wars) is specified");
+ }
+ if (webxml != null) {
+ throw new BuildException("webxml should not be specified if archives (or wars) is specified");
+ }
+
return;
}
+ //Check if running with portletxml && webxml args
if(portletxml == null || !portletxml.exists()) {
throw new BuildException("portletxml "+portletxml+" does not exist");
}
-
if(webxml == null || !webxml.exists()) {
throw new BuildException("webxml "+webxml + " does not exist");
}
+ if (archive != null) {
+ throw new BuildException("archive (or war) should not be specified if portletxml and webxml are specified");
+ }
+ if (this.archiveFileSets.size() > 0) {
+ throw new BuildException("archives (or wars) should not be specified if portletxml and webxml are specified");
+ }
+ if (destdir != null) {
+ // TODO check this
+ throw new BuildException("destfile should not be specified if portletxml and webxml are aspecified");
+ }
}
}