ate 2005/03/23 14:24:36
Modified: components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy
JetspeedDeployFactory.java JetspeedDeploy.java
JetspeedWebApplicationRewriter.java
Log:
Resolving http://issues.apache.org/jira/browse/JS2-210:
Adapted Deploy tool now also supports stripping of loggers (commons-logging
and/or log4j) jars as required for certain platforms like JBoss
Revision Changes Path
1.2 +4 -4
jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeployFactory.java
Index: JetspeedDeployFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeployFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- JetspeedDeployFactory.java 2 Feb 2005 03:09:50 -0000 1.1
+++ JetspeedDeployFactory.java 23 Mar 2005 22:24:36 -0000 1.2
@@ -35,11 +35,11 @@
*
* @param inputWarPath
* @param outputWarPath
- * @param registerAtInit
+ * @param stripLoggers
* @return JetspeedDeploy instance
*/
- public Deploy getInstance(String inputWarPath, String outputWarPath,
boolean registerAtInit) throws Exception
+ public Deploy getInstance(String inputWarPath, String outputWarPath,
boolean stripLoggers) throws Exception
{
- return new JetspeedDeploy(inputWarPath, outputWarPath,
registerAtInit);
+ return new JetspeedDeploy(inputWarPath, outputWarPath, stripLoggers);
}
}
1.11 +165 -164
jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java
Index: JetspeedDeploy.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedDeploy.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- JetspeedDeploy.java 1 Mar 2005 23:28:36 -0000 1.10
+++ JetspeedDeploy.java 23 Mar 2005 22:24:36 -0000 1.11
@@ -20,7 +20,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
-import java.util.jar.JarInputStream;
+import java.nio.channels.FileChannel;
+import java.util.Enumeration;
+import java.util.jar.JarFile;
import java.util.jar.JarOutputStream;
import java.util.zip.ZipEntry;
@@ -33,55 +35,49 @@
import org.xml.sax.SAXException;
/**
- * Makes a web application Deploy-ready for Jetspeed.
- *
- * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom</a>
- * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor</a>
+ * Makes a web application Deploy-ready for Jetspeed.
+ *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Dain Sundstrom </a>
+ * @author <a href="mailto:[EMAIL PROTECTED]">David Sean Taylor </a>
* @version $Id$
*/
public class JetspeedDeploy implements Deploy
{
- public static void main(String[] args) throws Exception
- {
- if (args.length < 2 || args.length > 3)
+ public static void main(String[] args) throws Exception
+ {
+ if (args.length < 2 || args.length > 3 || args.length == 3 &&
!(args[0].equalsIgnoreCase("-s")))
{
- System.out.println("Usage: java -jar jsdeploy.jar [-r] INPUT
OUTPUT");
- System.out.println(" -r Register at Init");
+ System.out.println("Usage: java -jar
jetspeed-deploy-tools-<version>.jar [-s] INPUT OUTPUT");
+ System.out.println("Options:");
+ System.out
+ .println(" -s: stripLoggers - remove
commons-logging[version].jar and/or log4j[version].jar from war");
+ System.out.println(" (required when
targetting application servers like JBoss)");
+
System.exit(1);
return;
}
- if (args.length == 3)
- {
- if (args[0].equalsIgnoreCase("-r"))
- {
- new JetspeedDeploy(args[1], args[2], true);
- }
- else
- {
- System.out.println("Usage: java -jar jsdeploy.jar [-r] INPUT
OUTPUT");
- System.out.println(" -r Register at Init");
- System.exit(1);
- return;
- }
- }
- else
- {
- new JetspeedDeploy(args[0], args[1], false);
- }
+ new JetspeedDeploy(args[0], args[1], args.length == 3 ? true :
false);
}
private final byte[] buffer = new byte[4096];
-
- public JetspeedDeploy(String inputName, String outputName, boolean
registerAtInit) throws Exception
+
+ public JetspeedDeploy(String inputName, String outputName, boolean
stripLoggers) throws Exception
{
- JarInputStream jin = null;
+ File tempFile = null;
+ JarFile jin = null;
JarOutputStream jout = null;
- try
+ FileChannel srcChannel = null;
+ FileChannel dstChannel = null;
+
+ try
{
String portletApplicationName =
getPortletApplicationName(outputName);
- jin = new JarInputStream(new FileInputStream(inputName));
- jout = new JarOutputStream(new FileOutputStream(outputName),
jin.getManifest());
-
+ tempFile = File.createTempFile(portletApplicationName, "");
+ tempFile.deleteOnExit();
+
+ jin = new JarFile(inputName);
+ jout = new JarOutputStream(new FileOutputStream(tempFile));
+
// copy over all of the files in the input war to the output
// war except for web.xml, portlet.xml, and context.xml which
// we parse for use later
@@ -89,226 +85,231 @@
Document portletXml = null;
Document contextXml = null;
ZipEntry src;
- while ((src = jin.getNextEntry()) != null)
+ InputStream source;
+ Enumeration zipEntries = jin.entries();
+ while (zipEntries.hasMoreElements())
{
- String target = src.getName();
- if ("WEB-INF/web.xml".equals(target))
- {
- System.out.println("Found web.xml");
- webXml = parseXml(jin);
- }
- else if ("WEB-INF/portlet.xml".equals(target))
+ src = (ZipEntry) zipEntries.nextElement();
+ source = jin.getInputStream(src);
+ try
{
- System.out.println("Found WEB-INF/portlet.xml");
- portletXml = parseXml(jin);
- }
- else if ("META-INF/context.xml".equals(target))
- {
- System.out.println("Found META-INF/context.xml");
- contextXml = parseXml(jin);
- }
- else
+ String target = src.getName();
+ if ("WEB-INF/web.xml".equals(target))
+ {
+ System.out.println("Found web.xml");
+ webXml = parseXml(source);
+ }
+ else if ("WEB-INF/portlet.xml".equals(target))
+ {
+ System.out.println("Found WEB-INF/portlet.xml");
+ portletXml = parseXml(source);
+ }
+ else if ("META-INF/context.xml".equals(target))
+ {
+ System.out.println("Found META-INF/context.xml");
+ contextXml = parseXml(source);
+ }
+ else
+ {
+ if ( stripLoggers && target.endsWith(".jar") &&
+
(target.startsWith("WEB-INF/lib/commons-logging") ||
target.startsWith("WEB-INF/lib/log4j")))
+ {
+ System.out.println("Stripping logger "+target);
+ continue;
+ }
+ addFile(target, source, jout);
+ }
+ }
+ finally
{
- addFile(target, jin, jout);
+ source.close();
}
}
-
- if (webXml == null)
+
+ if (webXml == null)
{
throw new IllegalArgumentException("WEB-INF/web.xml");
}
- if (portletXml == null)
+ if (portletXml == null)
{
throw new IllegalArgumentException("WEB-INF/portlet.xml");
}
-
- JetspeedWebApplicationRewriter webRewriter = new
JetspeedWebApplicationRewriter(webXml, portletApplicationName, registerAtInit);
+
+ JetspeedWebApplicationRewriter webRewriter = new
JetspeedWebApplicationRewriter(webXml,
+
portletApplicationName);
webRewriter.processWebXML();
JetspeedContextRewriter contextRewriter = new
JetspeedContextRewriter(contextXml, portletApplicationName);
contextRewriter.processContextXML();
-
+
// write the web.xml, portlet.xml, and context.xml files
addFile("WEB-INF/web.xml", webXml, jout);
addFile("WEB-INF/portlet.xml", portletXml, jout);
addFile("META-INF/context.xml", contextXml, jout);
-
- if(webRewriter.isPortletTaglibAdded())
+
+ if (webRewriter.isPortletTaglibAdded())
{
System.out.println("Attempting to add portlet.tld to
war...");
InputStream is =
this.getClass().getResourceAsStream("/org/apache/jetspeed/tools/deploy/portlet.tld");
- if(is == null)
+ if (is == null)
{
System.out.println("Failed to find portlet.tld in
classpath");
}
else
{
System.out.println("Adding portlet.tld to war...");
-
- addFile("WEB-INF/tld/portlet.tld", is, jout);
- is.close();
+
+ try
+ {
+ addFile("WEB-INF/tld/portlet.tld", is, jout);
+ }
+ finally
+ {
+ is.close();
+ }
}
}
-
+
jout.close();
- }
- catch (IOException e)
+ jin.close();
+ jin = null;
+ jout = null;
+
+ System.out.println("Creating war " + outputName + " ...");
+ System.out.flush();
+ // Now copy the new war to its destination
+ srcChannel = new FileInputStream(tempFile).getChannel();
+ dstChannel = new FileOutputStream(outputName).getChannel();
+ dstChannel.transferFrom(srcChannel, 0, srcChannel.size());
+ srcChannel.close();
+ srcChannel = null;
+ dstChannel.close();
+ dstChannel = null;
+ tempFile.delete();
+ tempFile = null;
+ System.out.println("War " + outputName + " created");
+ System.out.flush();
+ }
+ finally
{
- e.printStackTrace();
-
- if(jin != null)
+ if (srcChannel != null && srcChannel.isOpen())
{
- try
+ try
{
- jin.close();
- jin = null;
- }
- catch (IOException e1)
+ srcChannel.close();
+ }
+ catch (IOException e1)
{
// ignore
}
}
- if(jout != null) {
- try {
- jout.close();
- jout = null;
- } catch (IOException e1) {
+ if (dstChannel != null && dstChannel.isOpen())
+ {
+ try
+ {
+ dstChannel.close();
+ }
+ catch (IOException e1)
+ {
// ignore
}
}
- new File(outputName).delete();
- }
- finally
- {
- if (jin != null)
+ if (jin != null)
{
- try
+ try
{
jin.close();
jin = null;
- }
- catch (IOException e1)
+ }
+ catch (IOException e1)
{
// ignore
}
}
- if (jout != null)
+ if (jout != null)
{
- try
+ try
{
jout.close();
jout = null;
- }
- catch (IOException e1)
+ }
+ catch (IOException e1)
{
// ignore
}
- }
-
+ }
+ if (tempFile != null && tempFile.exists())
+ {
+ tempFile.delete();
+ }
}
}
-
- protected Document parseXml(InputStream jin) throws Exception
+
+ protected Document parseXml(InputStream source) throws Exception
{
// Parse using the local dtds instead of remote dtds. This
// allows to deploy the application offline
SAXBuilder saxBuilder = new SAXBuilder();
saxBuilder.setEntityResolver(new EntityResolver()
+ {
+ public InputSource resolveEntity(java.lang.String publicId,
java.lang.String systemId) throws SAXException,
+ java.io.IOException
{
- public InputSource resolveEntity( java.lang.String publicId,
java.lang.String systemId )
- throws SAXException, java.io.IOException
- {
- if
(systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
- {
- return new
InputSource(getClass().getResourceAsStream("web-app_2_3.dtd"));
- }
- return null;
+ if
(systemId.equals("http://java.sun.com/dtd/web-app_2_3.dtd"))
+ {
+ return new
InputSource(getClass().getResourceAsStream("web-app_2_3.dtd"));
}
- });
- Document document = saxBuilder.build(new
UncloseableInputStream(jin));
+ return null;
+ }
+ });
+ Document document = saxBuilder.build(source);
return document;
}
- protected void addFile(String path, InputStream source, JarOutputStream
jos) throws IOException
+ protected void addFile(String path, InputStream source, JarOutputStream
jos) throws IOException
{
jos.putNextEntry(new ZipEntry(path));
- try {
+ try
+ {
int count;
- while ((count = source.read(buffer)) > 0) {
+ while ((count = source.read(buffer)) > 0)
+ {
jos.write(buffer, 0, count);
}
- } finally {
+ }
+ finally
+ {
jos.closeEntry();
}
}
-
- protected void addFile(String path, Document source, JarOutputStream
jos) throws IOException {
+
+ protected void addFile(String path, Document source, JarOutputStream
jos) throws IOException
+ {
if (source != null)
{
jos.putNextEntry(new ZipEntry(path));
XMLOutputter xmlOutputter = new
XMLOutputter(Format.getPrettyFormat());
- try {
+ try
+ {
xmlOutputter.output(source, jos);
- } finally {
+ }
+ finally
+ {
jos.closeEntry();
}
}
}
-
+
protected String getPortletApplicationName(String path)
{
File file = new File(path);
String name = file.getName();
String portletApplicationName = name;
-
+
int index = name.lastIndexOf(".");
if (index > -1)
{
- portletApplicationName = name.substring(0, index);
+ portletApplicationName = name.substring(0, index);
}
return portletApplicationName;
}
-
- protected class UncloseableInputStream extends InputStream {
- private final InputStream in;
-
- public UncloseableInputStream(InputStream in) {
- this.in = in;
- }
-
- public int read() throws IOException {
- return in.read();
- }
-
- public int read(byte b[]) throws IOException {
- return in.read(b);
- }
-
- public int read(byte b[], int off, int len) throws IOException {
- return in.read(b, off, len);
- }
-
- public long skip(long n) throws IOException {
- return in.skip(n);
- }
-
- public int available() throws IOException {
- return in.available();
- }
-
- public void close() throws IOException {
- // not closeable
- }
-
- public void mark(int readlimit) {
- in.mark(readlimit);
- }
-
- public void reset() throws IOException {
- in.reset();
- }
-
- public boolean markSupported() {
- return in.markSupported();
- }
- }
-}
+}
\ No newline at end of file
1.13 +17 -24
jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java
Index: JetspeedWebApplicationRewriter.java
===================================================================
RCS file:
/home/cvs/jakarta-jetspeed-2/components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy/JetspeedWebApplicationRewriter.java,v
retrieving revision 1.12
retrieving revision 1.13
diff -u -r1.12 -r1.13
--- JetspeedWebApplicationRewriter.java 2 Feb 2005 03:09:50 -0000
1.12
+++ JetspeedWebApplicationRewriter.java 23 Mar 2005 22:24:36 -0000
1.13
@@ -15,8 +15,6 @@
*/
package org.apache.jetspeed.tools.deploy;
-import java.io.InputStream;
-import java.io.Writer;
import java.util.Arrays;
import java.util.List;
@@ -36,10 +34,8 @@
*/
public class JetspeedWebApplicationRewriter
{
- public static final String REGISTER_AT_INIT = "registerAtInit";
public static final String JETSPEED_CONTAINER = "JetspeedContainer";
public static final String JETSPEED_SERVLET_XPATH =
"/web-app/servlet/servlet-name[contains(child::text(), \"JetspeedContainer\")]";
- public static final String REGISTER_AT_INIT_XPATH =
"/init-param/param-name[contains(child::text(), \"registerAtInit\")]";
public static final String JETSPEED_SERVLET_MAPPING_XPATH =
"/web-app/servlet-mapping/servlet-name[contains(child::text(),
\"JetspeedContainer\")]";
public static final String PORTLET_TAGLIB_XPATH =
"/web-app/taglib/taglib-uri[contains(child::text(),
\"http://java.sun.com/portlet\")]";
protected static final String WEB_XML_PATH = "WEB-INF/web.xml";
@@ -57,14 +53,12 @@
private Document document;
private String portletApplication;
private boolean changed = false;
- private boolean registerAtInit = false;
private boolean portletTaglibAdded = false;
- public JetspeedWebApplicationRewriter(Document doc, String
portletApplication, boolean registerAtInit)
+ public JetspeedWebApplicationRewriter(Document doc, String
portletApplication)
{
this.document = doc;
this.portletApplication = portletApplication;
- this.registerAtInit = registerAtInit;
}
public JetspeedWebApplicationRewriter(Document doc)
@@ -116,22 +110,24 @@
jetspeedServletElement.addContent(servletDspName);
jetspeedServletElement.addContent(servletDesc);
jetspeedServletElement.addContent(servletClass);
- if (this.registerAtInit)
- {
- insertRegisterAtInit(jetspeedServletElement);
- }
+ insertContextNameParam(jetspeedServletElement);
+ insertLoadOnStartup(jetspeedServletElement);
insertElementCorrectly(root, jetspeedServletElement,
ELEMENTS_BEFORE_SERVLET);
changed = true;
}
else
{
// double check for register at Init
- if (this.registerAtInit && jetspeedServlet instanceof
Element)
+ if (jetspeedServlet instanceof Element)
{
Parent jetspeedServletElement
=((Element)jetspeedServlet).getParent();
- if (null ==
XPath.selectSingleNode(jetspeedServletElement, REGISTER_AT_INIT_XPATH))
+ if (null ==
XPath.selectSingleNode(jetspeedServletElement,
"init-param/param-name[contains(child::text(), \"contextName\")]"))
+ {
+
insertContextNameParam((Element)jetspeedServletElement);
+ }
+ if (null ==
XPath.selectSingleNode(jetspeedServletElement, "load-on-startup"))
{
- insertRegisterAtInit((Element)
jetspeedServletElement);
+ insertLoadOnStartup((Element)
jetspeedServletElement);
}
}
}
@@ -172,23 +168,20 @@
}
- private void insertRegisterAtInit(Element jetspeedServletElement)
+ private void insertContextNameParam(Element jetspeedServletElement)
{
- Element paramName = (Element) new
Element("param-name").addContent(REGISTER_AT_INIT);
- Element paramValue = (Element) new
Element("param-value").addContent("1");
- Element initParam = new Element("init-param");
- initParam.addContent(paramName);
- initParam.addContent(paramValue);
- jetspeedServletElement.addContent(initParam);
-
- Element param2Name = (Element) new
Element("param-name").addContent("portletApplication");
+ Element param2Name = (Element) new
Element("param-name").addContent("contextName");
Element param2Value = (Element) new
Element("param-value").addContent(portletApplication);
Element init2Param = new Element("init-param");
init2Param.addContent(param2Name);
init2Param.addContent(param2Value);
jetspeedServletElement.addContent(init2Param);
- Element loadOnStartup = (Element) new
Element("load-on-startup").addContent("100");
+ }
+
+ private void insertLoadOnStartup(Element jetspeedServletElement)
+ {
+ Element loadOnStartup = (Element) new
Element("load-on-startup").addContent("0");
jetspeedServletElement.addContent(loadOnStartup);
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]