ate 2005/03/01 18:34:15
Modified: components/deploy-tool/src/java/org/apache/jetspeed/tools/deploy
Tag: deployment-refactoring
JetspeedDeployFactory.java JetspeedDeploy.java
JetspeedWebApplicationRewriter.java
Log:
Deploy tool changes. Note: now it only supports/accepts two arguments:
inputName outputName.
Revision Changes Path
No revision
No revision
1.1.2.1 +3 -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.1.2.1
diff -u -r1.1 -r1.1.2.1
--- JetspeedDeployFactory.java 2 Feb 2005 03:09:50 -0000 1.1
+++ JetspeedDeployFactory.java 2 Mar 2005 02:34:15 -0000 1.1.2.1
@@ -35,11 +35,10 @@
*
* @param inputWarPath
* @param outputWarPath
- * @param registerAtInit
* @return JetspeedDeploy instance
*/
- public Deploy getInstance(String inputWarPath, String outputWarPath,
boolean registerAtInit) throws Exception
+ public Deploy getInstance(String inputWarPath, String outputWarPath)
throws Exception
{
- return new JetspeedDeploy(inputWarPath, outputWarPath,
registerAtInit);
+ return new JetspeedDeploy(inputWarPath, outputWarPath);
}
}
1.10.2.1 +76 -96
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.10.2.1
diff -u -r1.10 -r1.10.2.1
--- JetspeedDeploy.java 1 Mar 2005 23:28:36 -0000 1.10
+++ JetspeedDeploy.java 2 Mar 2005 02:34:15 -0000 1.10.2.1
@@ -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;
@@ -43,44 +45,33 @@
{
public static void main(String[] args) throws Exception
{
- if (args.length < 2 || args.length > 3)
+ if (args.length != 2)
{
- System.out.println("Usage: java -jar jsdeploy.jar [-r] INPUT
OUTPUT");
- System.out.println(" -r Register at Init");
- 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.out.println("Usage: java -jar
jetspeed-deploy-tools-<version>.jar INPUT OUTPUT");
System.exit(1);
return;
}
- }
- else
- {
- new JetspeedDeploy(args[0], args[1], false);
- }
+ new JetspeedDeploy(args[0], args[1]);
}
private final byte[] buffer = new byte[4096];
- public JetspeedDeploy(String inputName, String outputName, boolean
registerAtInit) throws Exception
+ public JetspeedDeploy(String inputName, String outputName) throws
Exception
{
- JarInputStream jin = null;
+ File tempFile = null;
+ JarFile jin = null;
JarOutputStream jout = null;
+ 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
@@ -89,27 +80,38 @@
Document portletXml = null;
Document contextXml = null;
ZipEntry src;
- while ((src = jin.getNextEntry()) != null)
+ InputStream source;
+ Enumeration zipEntries = jin.entries();
+ while (zipEntries.hasMoreElements())
+ {
+ src = (ZipEntry)zipEntries.nextElement();
+ source = jin.getInputStream(src);
+ try
{
String target = src.getName();
if ("WEB-INF/web.xml".equals(target))
{
System.out.println("Found web.xml");
- webXml = parseXml(jin);
+ webXml = parseXml(source);
}
else if ("WEB-INF/portlet.xml".equals(target))
{
System.out.println("Found WEB-INF/portlet.xml");
- portletXml = parseXml(jin);
+ portletXml = parseXml(source);
}
else if ("META-INF/context.xml".equals(target))
{
System.out.println("Found META-INF/context.xml");
- contextXml = parseXml(jin);
+ contextXml = parseXml(source);
}
else
{
- addFile(target, jin, jout);
+ addFile(target, source, jout);
+ }
+ }
+ finally
+ {
+ source.close();
}
}
@@ -122,7 +124,7 @@
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();
@@ -144,41 +146,61 @@
{
System.out.println("Adding portlet.tld to war...");
+ try
+ {
addFile("WEB-INF/tld/portlet.tld", is, jout);
+ }
+ finally
+ {
is.close();
}
}
+ }
jout.close();
+ 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();
}
- catch (IOException e)
+ finally
{
- e.printStackTrace();
-
- if(jin != null)
+ if ( srcChannel != null && srcChannel.isOpen() )
{
try
{
- jin.close();
- jin = null;
+ 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)
{
try
@@ -203,12 +225,14 @@
// 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();
@@ -224,7 +248,7 @@
return null;
}
});
- Document document = saxBuilder.build(new
UncloseableInputStream(jin));
+ Document document = saxBuilder.build(source);
return document;
}
@@ -267,48 +291,4 @@
}
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();
- }
- }
}
1.12.2.1 +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.12.2.1
diff -u -r1.12 -r1.12.2.1
--- JetspeedWebApplicationRewriter.java 2 Feb 2005 03:09:50 -0000
1.12
+++ JetspeedWebApplicationRewriter.java 2 Mar 2005 02:34:15 -0000
1.12.2.1
@@ -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]