geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@apache.org
Subject svn commit: rev 47203 - in geronimo/trunk/modules: client-builder/src/java/org/apache/geronimo/client/builder connector/src/java/org/apache/geronimo/connector/deployment connector/src/test/org/apache/geronimo/connector/deployment deployment/src/java/org/apache/geronimo/deployment deployment/src/java/org/apache/geronimo/deployment/service deployment/src/java/org/apache/geronimo/deployment/util j2ee-schema/src/java/org/apache/geronimo/schema j2ee/src/java/org/apache/geronimo/j2ee/deployment j2ee/src/test/org/apache/geronimo/j2ee/deployment jetty/src/java/org/apache/geronimo/jetty/deployment
Date Sat, 25 Sep 2004 16:30:11 GMT
Author: dain
Date: Sat Sep 25 09:30:09 2004
New Revision: 47203

Modified:
   geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
   geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
   geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java
   geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilderTest.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/FileUtil.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/JarUtil.java
   geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/NestedJarFile.java
   geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java
   geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
   geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java
   geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java
   geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java
   geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java
   geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java
   geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
Log:
Changed all module builders to not work directly with document objects
Changed module builders to work of JarFiles instead of URLs. We are always working with files and this
prevents lots fo extra complexity in the deployment code


Modified: geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java	(original)
+++ geronimo/trunk/modules/client-builder/src/java/org/apache/geronimo/client/builder/AppClientModuleBuilder.java	Sat Sep 25 09:30:09 2004
@@ -37,13 +37,12 @@
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
-import org.apache.geronimo.common.xml.XmlBeansUtil;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.DeploymentException;
 import org.apache.geronimo.deployment.service.GBeanHelper;
 import org.apache.geronimo.deployment.util.FileUtil;
-import org.apache.geronimo.deployment.util.JarUtil;
 import org.apache.geronimo.deployment.util.IOUtil;
+import org.apache.geronimo.deployment.util.JarUtil;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoFactory;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
@@ -59,7 +58,6 @@
 import org.apache.geronimo.naming.deployment.ENCConfigBuilder;
 import org.apache.geronimo.naming.java.ReadOnlyContext;
 import org.apache.geronimo.schema.SchemaConversionUtils;
-import org.apache.geronimo.xbeans.geronimo.client.GerApplicationClientDocument;
 import org.apache.geronimo.xbeans.geronimo.client.GerApplicationClientType;
 import org.apache.geronimo.xbeans.geronimo.client.GerDependencyType;
 import org.apache.geronimo.xbeans.geronimo.client.GerGbeanType;
@@ -69,8 +67,8 @@
 import org.apache.geronimo.xbeans.j2ee.EjbLocalRefType;
 import org.apache.xmlbeans.SchemaTypeLoader;
 import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
 
 
 /**
@@ -79,7 +77,7 @@
 public class AppClientModuleBuilder implements ModuleBuilder {
     static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{
 //        XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()),
-//        XmlBeans.typeLoaderForClassLoader(GerApplicationClientDocument.class.getClassLoader())
+//        XmlBeans.typeLoaderForClassLoader(GerApplicationClientType.class.getClassLoader())
     });
 
     private final Kernel kernel;
@@ -94,24 +92,12 @@
     }
 
     public XmlObject parseSpecDD(URL path) throws DeploymentException {
-        InputStream in = null;
         try {
             // check if we have an alt spec dd
-            in = path.openStream();
-//            XmlObject dd = SchemaConversionUtils.parse(in);
-//            ApplicationClientDocument applicationClientDoc = SchemaConversionUtils.convertToApplicationClientSchema(dd);
             ApplicationClientDocument applicationClientDoc = ApplicationClientDocument.Factory.parse(path);
             return applicationClientDoc.getApplicationClient();
         } catch (Exception e) {
             throw new DeploymentException("Unable to parse " + path, e);
-        } finally {
-            if (in != null) {
-                try {
-                    in.close();
-                } catch (IOException e) {
-                    // ignore
-                }
-            }
         }
     }
 
@@ -125,20 +111,13 @@
         }
     }
 
-    public XmlObject getDeploymentPlan(URL module) throws DeploymentException {
+    public XmlObject getDeploymentPlan(JarFile module) throws DeploymentException {
         try {
-            URL moduleBase;
-            if (module.toString().endsWith("/")) {
-                moduleBase = module;
-            } else {
-                moduleBase = new URL("jar:" + module.toString() + "!/");
-            }
-            URL path = new URL(moduleBase, "META-INF/geronimo-application-client.xml");
-            XmlObject dd = SchemaConversionUtils.parse(path.openStream());
-
-            GerApplicationClientDocument plan = (GerApplicationClientDocument) validateVendorDD(dd);
+            URL path = JarUtil.createJarURL(module, "META-INF/geronimo-application-client.xml");
+            XmlObject vendorDD = SchemaConversionUtils.parse(path);
+            GerApplicationClientType plan = (GerApplicationClientType) validateVendorDD(vendorDD);
             if (plan == null) {
-                return createDefaultPlan(moduleBase);
+                return createDefaultPlan(module);
             }
             return plan;
         } catch (MalformedURLException e) {
@@ -152,19 +131,21 @@
 
     public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException {
         try {
+            dd = SchemaConversionUtils.getNestedObjectAsType(dd, "application-client", GerApplicationClientType.type);
             dd = SchemaConversionUtils.convertToGeronimoNamingSchema(dd);
-            return dd.changeType(GerApplicationClientDocument.type);
+            SchemaConversionUtils.validateDD(dd);
+            return dd;
         } catch (Exception e) {
             throw new DeploymentException(e);
         }
     }
 
-    private GerApplicationClientDocument createDefaultPlan(URL moduleBase) {
+    private GerApplicationClientType createDefaultPlan(JarFile module) {
         // load the application-client.xml
         URL appClientXmlUrl = null;
         try {
-            appClientXmlUrl = new URL(moduleBase, "META-INF/application-client.xml");
-        } catch (MalformedURLException e) {
+            appClientXmlUrl = JarUtil.createJarURL(module, "META-INF/application-client.xml");
+        } catch (DeploymentException e) {
             return null;
         }
 
@@ -176,7 +157,8 @@
         }
         String id = appClient.getId();
         if (id == null) {
-            id = moduleBase.getFile();
+            // TODO this name is not necessairly the original name specified on the command line which is what we want
+            id = module.getName();
             if (id.endsWith("!/")) {
                 id = id.substring(0, id.length() - 2);
             }
@@ -188,27 +170,26 @@
             }
             id = id.substring(id.lastIndexOf('/') + 1);
         }
-        return newGerApplicationClientDocument(appClient, id);
+        return newGerApplicationClientType(appClient, id);
     }
 
-    private GerApplicationClientDocument newGerApplicationClientDocument(ApplicationClientType appClient, String id) {
-        GerApplicationClientDocument geronimoAppClientDoc = GerApplicationClientDocument.Factory.newInstance();
-        GerApplicationClientType geronimoAppClient = geronimoAppClientDoc.addNewApplicationClient();
+    private GerApplicationClientType newGerApplicationClientType(ApplicationClientType appClient, String id) {
+        GerApplicationClientType geronimoAppClient = GerApplicationClientType.Factory.newInstance();
 
         // set the parentId, configId and context root
         if (null != appClient.getId()) {
             id = appClient.getId();
         }
         geronimoAppClient.setConfigId(id);
-        return geronimoAppClientDoc;
+        return geronimoAppClient;
     }
 
     public boolean canHandlePlan(XmlObject plan) {
-        return plan instanceof GerApplicationClientDocument;
+        return plan instanceof GerApplicationClientType;
     }
 
     public URI getParentId(XmlObject plan) throws DeploymentException {
-        GerApplicationClientType geronimoAppClient = ((GerApplicationClientDocument) plan).getApplicationClient();
+        GerApplicationClientType geronimoAppClient = (GerApplicationClientType) plan;
         try {
             return new URI(geronimoAppClient.getParentId());
         } catch (URISyntaxException e) {
@@ -217,7 +198,7 @@
     }
 
     public URI getConfigId(XmlObject plan) throws DeploymentException {
-        GerApplicationClientType geronimoAppClient = ((GerApplicationClientDocument) plan).getApplicationClient();
+        GerApplicationClientType geronimoAppClient = (GerApplicationClientType) plan;
         try {
             return new URI(geronimoAppClient.getConfigId());
         } catch (URISyntaxException e) {
@@ -253,24 +234,27 @@
         ApplicationClientType appClient = (ApplicationClientType) parseSpecDD(specDD);
 
         if (vendorDD == null) {
+            InputStream in = null;
             try {
                 JarEntry entry = moduleFile.getJarEntry("META-INF/geronimo-application-client.xml");
                 if (entry != null) {
-                    InputStream in = moduleFile.getInputStream(entry);
+                    in = moduleFile.getInputStream(entry);
                     if (in != null) {
-                        vendorDD = XmlBeansUtil.parse(in, GerApplicationClientDocument.type);
+                        XmlObject dd = SchemaConversionUtils.parse(in);
+                        vendorDD = validateVendorDD(dd);
                     }
                 }
             } catch (Exception e) {
                 throw new DeploymentException("Unable to parse META-INF/geronimo-application-client.xml", e);
+            } finally {
+                IOUtil.close(in);
             }
         }
         if (vendorDD == null) {
-            vendorDD = newGerApplicationClientDocument(appClient, name);
+            vendorDD = newGerApplicationClientType(appClient, name);
         }
 
-        GerApplicationClientDocument geronimoAppClientDoc = (GerApplicationClientDocument) vendorDD;
-        GerApplicationClientType geronimoAppClient = geronimoAppClientDoc.getApplicationClient();
+        GerApplicationClientType geronimoAppClient = (GerApplicationClientType) vendorDD;
 
         return new AppClientModule(name, moduleURI, moduleFile, targetPath, appClient, geronimoAppClient);
     }

Modified: geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java	(original)
+++ geronimo/trunk/modules/connector/src/java/org/apache/geronimo/connector/deployment/ConnectorModuleBuilder.java	Sat Sep 25 09:30:09 2004
@@ -19,7 +19,6 @@
 import java.beans.PropertyEditor;
 import java.io.IOException;
 import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -145,21 +144,14 @@
         }
     }
 
-    public XmlObject getDeploymentPlan(URL module) throws DeploymentException {
+    public XmlObject getDeploymentPlan(JarFile module) throws DeploymentException {
+        URL path = null;
         try {
-            URL moduleBase;
-            if (module.toString().endsWith("/")) {
-                moduleBase = module;
-            } else {
-                moduleBase = new URL("jar:" + module.toString() + "!/");
-            }
-            URL path = new URL(moduleBase, "META-INF/geronimo-ra.xml");
-            return getGerConnector(path);
-        } catch (MalformedURLException e) {
-            return null;
-        } catch (IOException e) {
+            path = JarUtil.createJarURL(module, "META-INF/geronimo-ra.xml");
+        } catch (DeploymentException e) {
             return null;
         }
+        return getGerConnector(path);
     }
 
     GerConnectorType getGerConnector(URL path) throws DeploymentException {

Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java
==============================================================================
--- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java	(original)
+++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_0ConfigBuilderTest.java	Sat Sep 25 09:30:09 2004
@@ -283,15 +283,13 @@
     public void testBuildEar() throws Exception {
         String j2eeDomainName = "geronimo.server";
         String j2eeServerName = "TestGeronimoServer";
-        String j2eeApplicationName = "TestEar";
-        String j2eeModuleName = "org/apache/geronimo/j2ee/deployment/test";
         ObjectName connectionTrackerName = new ObjectName("geronimo.connector:service=ConnectionTracker");
         ObjectName j2eeServer = new ObjectName(j2eeDomainName + ":name=" + j2eeServerName);
         Kernel kernel = new Kernel("blah");
         kernel.boot();
         try {
             EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, null, connectionTrackerName, null, null, null, null, null, null, new ConnectorModuleBuilder(), null, kernel);
-            File rarFile = new File(basedir, "target/test-ear-noger.ear");
+            JarFile rarFile = JarUtil.createJarFile(new File(basedir, "target/test-ear-noger.ear"));
             File outFile = File.createTempFile("EARTest", ".car");
             try {
                 File planFile = new File(basedir, "src/test-data/data/external-application-plan.xml");

Modified: geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilderTest.java
==============================================================================
--- geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilderTest.java	(original)
+++ geronimo/trunk/modules/connector/src/test/org/apache/geronimo/connector/deployment/RAR_1_5ConfigBuilderTest.java	Sat Sep 25 09:30:09 2004
@@ -129,7 +129,7 @@
 
         Thread.currentThread().setContextClassLoader(cl);
 
-        XmlObject plan = moduleBuilder.getDeploymentPlan(rarFile.toURL());
+        XmlObject plan = moduleBuilder.getDeploymentPlan(JarUtil.createJarFile(rarFile));
         URI parentId = moduleBuilder.getParentId(plan);
         URI configId = moduleBuilder.getConfigId(plan);
         assertEquals(j2eeModuleName, configId.toString());

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Bootstrap.java	Sat Sep 25 09:30:09 2004
@@ -31,8 +31,6 @@
 import org.apache.geronimo.system.configuration.LocalConfigStore;
 import org.apache.geronimo.system.main.CommandLineManifest;
 import org.apache.geronimo.system.repository.ReadOnlyRepository;
-import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
 
 /**
  * Helper class to bootstrap the Geronimo deployer.
@@ -118,9 +116,8 @@
         Thread.currentThread().setContextClassLoader(Bootstrap.class.getClassLoader());
         try {
             // parse the deployment-system and j2ee-deployer plans
-            XmlObject deployerSystemXML = XmlBeans.getContextTypeLoader().parse(new File(deployerSystemPlan), null, null);
-            XmlObject j2eeDeployerXML = XmlBeans.getContextTypeLoader().parse(new File(j2eeDeployerPlan), null, null);
-            ConfigurationType j2eeDeployerConfig = ((ConfigurationDocument) j2eeDeployerXML).getConfiguration();
+            ConfigurationType deployerSystemConfig = ConfigurationDocument.Factory.parse(new File(deployerSystemPlan)).getConfiguration();
+            ConfigurationType j2eeDeployerConfig = ConfigurationDocument.Factory.parse(new File(j2eeDeployerPlan)).getConfiguration();
 
             // create the service builder, repository and config store objects
             LocalConfigStore configStore = new LocalConfigStore(new File(storeDir));
@@ -150,7 +147,7 @@
                 jos.closeEntry();
 
                 // add the deployment system configuration to the jar
-                builder.buildConfiguration(jos, deployerSystemXML);
+                builder.buildConfiguration(jos, deployerSystemConfig);
             } finally {
                 jos.close();
             }
@@ -159,7 +156,7 @@
             // build and install the j2ee-deployer configuration
             File tempFile = File.createTempFile("j2ee-deployer", ".car");
             try {
-                builder.buildConfiguration(tempFile, manifest, null, j2eeDeployerXML);
+                builder.buildConfiguration(tempFile, manifest, null, j2eeDeployerConfig);
                 configStore.install(tempFile.toURL());
             } finally {
                 tempFile.delete();

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationBuilder.java	Sat Sep 25 09:30:09 2004
@@ -19,8 +19,8 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.net.URL;
 import java.util.jar.Manifest;
+import java.util.jar.JarFile;
 
 import org.apache.xmlbeans.SchemaTypeLoader;
 import org.apache.xmlbeans.XmlObject;
@@ -46,7 +46,7 @@
      * @param module the URL of the module to examine
      * @return the deployment plan, or null if this module can not handle it
      */
-    XmlObject getDeploymentPlan(URL module) throws DeploymentException;
+    XmlObject getDeploymentPlan(JarFile module) throws DeploymentException;
 
     /**
      * Build a configuration from a local file
@@ -56,5 +56,5 @@
      * @throws IOException if there was a problem reading or writing the files
      * @throws DeploymentException if there was a problem with the configuration
      */
-    void buildConfiguration(File outfile, Manifest manifest, File module, XmlObject plan) throws IOException, DeploymentException;
+    void buildConfiguration(File outfile, Manifest manifest, JarFile module, XmlObject plan) throws IOException, DeploymentException;
 }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/Deployer.java	Sat Sep 25 09:30:09 2004
@@ -19,9 +19,7 @@
 
 import java.io.File;
 import java.io.IOException;
-import java.net.MalformedURLException;
 import java.net.URI;
-import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collection;
@@ -30,6 +28,7 @@
 import java.util.Properties;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
+import java.util.jar.JarFile;
 import javax.management.MalformedObjectNameException;
 import javax.management.ObjectName;
 
@@ -39,15 +38,16 @@
 import org.apache.commons.cli.ParseException;
 import org.apache.commons.cli.PosixParser;
 import org.apache.geronimo.deployment.util.FileUtil;
+import org.apache.geronimo.deployment.util.JarUtil;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoFactory;
 import org.apache.geronimo.kernel.config.ConfigurationStore;
 import org.apache.geronimo.kernel.config.InvalidConfigException;
 import org.apache.xmlbeans.SchemaTypeLoader;
 import org.apache.xmlbeans.XmlBeans;
+import org.apache.xmlbeans.XmlCursor;
 import org.apache.xmlbeans.XmlException;
 import org.apache.xmlbeans.XmlObject;
-import org.apache.xmlbeans.XmlCursor;
 
 /**
  * Command line based deployment utility which combines multiple deployable modules
@@ -68,12 +68,9 @@
         ConfigurationBuilder builder = null;
 
         XmlObject plan = null;
+        JarFile moduleJarFile = null;
         if (deploymentPlan != null) {
-            try {
-                plan = getPlan(deploymentPlan.toURL());
-            } catch (MalformedURLException e) {
-                throw new DeploymentException(e);
-            }
+            plan = getPlan(deploymentPlan);
             for (Iterator i = builders.iterator(); i.hasNext();) {
                 ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
                 if (candidate.canConfigure(plan)) {
@@ -85,15 +82,14 @@
                 throw new DeploymentException("No deployer found for this plan type: " + deploymentPlan);
             }
         } else if (moduleFile != null) {
-            URL moduleURL;
             try {
-                moduleURL = moduleFile.toURL();
-            } catch (MalformedURLException e) {
-                throw new DeploymentException(e);
+                moduleJarFile = JarUtil.createJarFile(moduleFile);
+            } catch (IOException e) {
+                throw new DeploymentException("Could not open module file: " + moduleFile.getAbsolutePath());
             }
             for (Iterator i = builders.iterator(); i.hasNext();) {
                 ConfigurationBuilder candidate = (ConfigurationBuilder) i.next();
-                plan = candidate.getDeploymentPlan(moduleURL);
+                plan = candidate.getDeploymentPlan(moduleJarFile);
                 if (plan != null) {
                     builder = candidate;
                     break;
@@ -110,7 +106,7 @@
                 Manifest manifest = new Manifest();
                 Attributes mainAttributes = manifest.getMainAttributes();
                 mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0");
-                builder.buildConfiguration(carfile, manifest, moduleFile, plan);
+                builder.buildConfiguration(carfile, manifest, moduleJarFile, plan);
                 return store.install(carfile.toURL());
             } catch (InvalidConfigException e) {
                 throw new DeploymentException(e);
@@ -122,7 +118,7 @@
         }
     }
 
-    private XmlObject getPlan(URL deploymentPlan) throws DeploymentException {
+    private XmlObject getPlan(File deploymentPlan) throws DeploymentException {
         try {
             XmlObject plan = getLoader().parse(deploymentPlan, null, null);
             XmlCursor cursor = plan.newCursor();
@@ -198,16 +194,7 @@
 
 
         try {
-            if (cmd.module == null) {
-                builder.buildConfiguration(cmd.carfile, manifest, null, plan);
-            } else if ("file".equals(cmd.module.getProtocol())) {
-                File module = new File(new URI(cmd.module.toString()));
-                builder.buildConfiguration(cmd.carfile, manifest, module, plan);
-            } else if (cmd.module.toString().endsWith("/")) {
-                throw new DeploymentException("Unpacked modules must be files");
-            } else {
-                builder.buildConfiguration(cmd.carfile, manifest, FileUtil.toTempFile(cmd.module.openStream(), true), plan);
-            }
+            builder.buildConfiguration(cmd.carfile, manifest, cmd.module, plan);
 
             try {
                 if (cmd.install) {
@@ -245,7 +232,7 @@
         return new ObjectName("geronimo.deployment", props);
     }
 
-    public static Command parseArgs(String[] args) throws ParseException {
+    public static Command parseArgs(String[] args) throws ParseException, DeploymentException {
         Options options = new Options();
         options.addOption("h", "help", false, "print this message");
         options.addOption("I", "install", false, "install configuration in store");
@@ -263,46 +250,57 @@
 
         Command command = new Command();
         command.install = cmd.hasOption('I');
-        command.carfile = cmd.hasOption('o') ? new File(cmd.getOptionValue('o')) : null;
-        try {
-            command.plan = cmd.hasOption('p') ? getURL(cmd.getOptionValue('p')) : null;
-        } catch (MalformedURLException e) {
-            System.err.println("Invalid URL for plan: " + cmd.getOptionValue('p'));
-            return null;
+        if (cmd.hasOption('o')) {
+            command.carfile = new File(cmd.getOptionValue('o'));
         }
-        try {
-            command.module = cmd.hasOption('m') ? getURL(cmd.getOptionValue('m')) : null;
-        } catch (MalformedURLException e) {
-            System.err.println("Invalid URL for module: " + cmd.getOptionValue('m'));
-            return null;
+        if (cmd.hasOption('p')) {
+            command.plan = getFile(cmd.getOptionValue('p'));
         }
+        if (cmd.hasOption('m')) {
+            try {
+                 command.module = JarUtil.createJarFile(getFile(cmd.getOptionValue('m')));
+            } catch (IOException e) {
+                throw new DeploymentException("Could not open module file: " + cmd.getOptionValue('m'));
+            }
+        }
+
         if (command.module == null && command.plan == null) {
             System.err.println("No plan or module specified");
             return null;
         }
-        command.mainClass = cmd.hasOption("mainClass") ? cmd.getOptionValue("mainClass") : null;
-        command.classPath = cmd.hasOption("classPath") ? cmd.getOptionValue("classPath") : null;
+        if (cmd.hasOption("mainClass")) {
+            command.mainClass = cmd.getOptionValue("mainClass");
+        }
+        if (cmd.hasOption("classPath")) {
+            command.classPath = cmd.getOptionValue("classPath");
+        }
         return command;
     }
 
-    private static URL getURL(String location) throws MalformedURLException {
+    private static File getFile(String location) throws DeploymentException {
         File f = new File(location);
         if (f.exists() && f.canRead()) {
-            return f.toURI().toURL();
-        }
-        try {
-            return new File(".").toURI().resolve(location).toURL();
-        } catch (IllegalArgumentException e) {
-            // thrown by URI.resolve if the location is not valid
-            throw (MalformedURLException) new MalformedURLException("Invalid location: " + location).initCause(e);
+            return f;
         }
+            URI uri = new File(".").toURI().resolve(location);
+            if ("file".equals(uri.getScheme())) {
+                return new File(uri);
+            } else if (uri.getPath().endsWith("/")) {
+                throw new DeploymentException("Unpacked modules can only be loaded from the local file system");
+            } else {
+                try {
+                    return FileUtil.toTempFile(uri.toURL());
+                } catch (IOException e) {
+                    throw new DeploymentException("Could not open url: " + uri);
+                }
+            }
     }
 
     private static class Command {
         private boolean install;
         private File carfile;
-        private URL module;
-        private URL plan;
+        private JarFile module;
+        private File plan;
         private String mainClass;
         private String classPath;
     }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceConfigBuilder.java	Sat Sep 25 09:30:09 2004
@@ -28,6 +28,7 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.jar.Attributes;
+import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
 import java.util.zip.ZipEntry;
@@ -36,7 +37,6 @@
 import org.apache.geronimo.deployment.ConfigurationBuilder;
 import org.apache.geronimo.deployment.DeploymentContext;
 import org.apache.geronimo.deployment.DeploymentException;
-import org.apache.geronimo.deployment.xbeans.ConfigurationDocument;
 import org.apache.geronimo.deployment.xbeans.ConfigurationType;
 import org.apache.geronimo.deployment.xbeans.DependencyType;
 import org.apache.geronimo.deployment.xbeans.GbeanType;
@@ -71,14 +71,14 @@
     }
 
     public boolean canConfigure(XmlObject plan) {
-        return plan instanceof ConfigurationDocument;
+        return plan instanceof ConfigurationType;
     }
 
-    public XmlObject getDeploymentPlan(URL module) {
+    public XmlObject getDeploymentPlan(JarFile module) {
         return null;
     }
 
-    public void buildConfiguration(File outfile, Manifest manifest, File unused, XmlObject plan) throws IOException, DeploymentException {
+    public void buildConfiguration(File outfile, Manifest manifest, JarFile unused, XmlObject plan) throws IOException, DeploymentException {
         FileOutputStream fos = new FileOutputStream(outfile);
         try {
             JarOutputStream os = new JarOutputStream(new BufferedOutputStream(fos), manifest);
@@ -98,7 +98,7 @@
     }
 
     public void buildConfiguration(JarOutputStream os, XmlObject plan) throws DeploymentException, IOException {
-        ConfigurationType configType = ((ConfigurationDocument) plan).getConfiguration();
+        ConfigurationType configType = (ConfigurationType) plan;
         URI configID;
         try {
             configID = new URI(configType.getConfigId());

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/FileUtil.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/FileUtil.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/FileUtil.java	Sat Sep 25 09:30:09 2004
@@ -25,6 +25,7 @@
 import java.util.Collection;
 import java.util.Collections;
 import java.util.LinkedList;
+import java.net.URL;
 
 /**
  *
@@ -40,6 +41,16 @@
         return tempFile;
     }
 
+    public static File toTempFile(URL url) throws IOException {
+        InputStream is = null;
+        try {
+            is = url.openStream();
+            return toTempFile(is, false);
+        } finally {
+            IOUtil.close(is);
+        }
+    }
+
     public static File toTempFile(InputStream is) throws IOException {
         return toTempFile(is, false);
     }
@@ -59,18 +70,10 @@
             out.flush();
             return tempFile;
         } finally {
-            try {
+            if (close) {
                 in.close();
-            } catch (IOException e) {
-                // ignore
-            }
-            if (close && out != null) {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                    // ignore
-                }
             }
+            out.close();
         }
     }
 

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/JarUtil.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/JarUtil.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/JarUtil.java	Sat Sep 25 09:30:09 2004
@@ -104,18 +104,12 @@
                             out.closeEntry();
                         }
                     } finally {
-                        try {
-                            in.close();
-                        } catch (IOException e) {
-                        }
+                        IOUtil.close(in);
                     }
                 }
                 return jarFile;
             } finally {
-                try {
-                    out.close();
-                } catch (IOException e) {
-                }
+                IOUtil.close(out);
             }
         }
     }

Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/NestedJarFile.java
==============================================================================
--- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/NestedJarFile.java	(original)
+++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/NestedJarFile.java	Sat Sep 25 09:30:09 2004
@@ -39,7 +39,7 @@
     private Manifest manifest;
 
     public NestedJarFile(JarFile jarFile, String path) throws IOException {
-        super(JarUtil.DUMMY_JAR_FILE);
+        super(JarUtil.DUMMY_JAR_FILE);  this.close();
 
         // verify that the jar actually contains that path
         JarEntry targetEntry = jarFile.getJarEntry(path + "/");

Modified: geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java
==============================================================================
--- geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java	(original)
+++ geronimo/trunk/modules/j2ee-schema/src/java/org/apache/geronimo/schema/SchemaConversionUtils.java	Sat Sep 25 09:30:09 2004
@@ -21,6 +21,7 @@
 import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Collection;
+import java.net.URL;
 import javax.xml.namespace.QName;
 
 import org.apache.geronimo.xbeans.j2ee.ApplicationDocument;
@@ -46,12 +47,18 @@
     private SchemaConversionUtils() {
     }
 
+    public static XmlObject parse(URL url) throws IOException, XmlException {
+        ArrayList errors = new ArrayList();
+        XmlObject parsed = XmlObject.Factory.parse(url, createXmlOptions(errors));
+        if (errors.size() != 0) {
+            throw new XmlException(errors.toArray().toString());
+        }
+        return parsed;
+    }
+
     public static XmlObject parse(InputStream is) throws IOException, XmlException {
         ArrayList errors = new ArrayList();
-        XmlOptions options = new XmlOptions();
-        options.setLoadLineNumbers();
-        options.setErrorListener(errors);
-        XmlObject parsed = XmlObject.Factory.parse(is, options);
+        XmlObject parsed = XmlObject.Factory.parse(is, createXmlOptions(errors));
         if (errors.size() != 0) {
             throw new XmlException(errors.toArray().toString());
         }
@@ -60,14 +67,18 @@
 
     public static XmlObject parse(String xml) throws XmlException {
         ArrayList errors = new ArrayList();
-        XmlOptions options = new XmlOptions();
-        options.setLoadLineNumbers();
-        options.setErrorListener(errors);
-        XmlObject parsed = XmlObject.Factory.parse(xml, options);
+        XmlObject parsed = XmlObject.Factory.parse(xml, createXmlOptions(errors));
         if (errors.size() != 0) {
             throw new XmlException(errors.toArray().toString());
         }
         return parsed;
+    }
+
+    private static XmlOptions createXmlOptions(ArrayList errors) {
+        XmlOptions options = new XmlOptions();
+        options.setLoadLineNumbers();
+        options.setErrorListener(errors);
+        return options;
     }
 
     public static ApplicationDocument convertToApplicationSchema(XmlObject xmlObject) throws XmlException {

Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java	(original)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARConfigBuilder.java	Sat Sep 25 09:30:09 2004
@@ -20,8 +20,6 @@
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.IOException;
-import java.io.InputStream;
-import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -35,7 +33,6 @@
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
-import java.util.jar.JarEntry;
 import java.util.jar.JarFile;
 import java.util.jar.JarOutputStream;
 import java.util.jar.Manifest;
@@ -48,7 +45,6 @@
 import org.apache.geronimo.deployment.service.GBeanHelper;
 import org.apache.geronimo.deployment.util.JarUtil;
 import org.apache.geronimo.deployment.util.NestedJarFile;
-import org.apache.geronimo.deployment.util.UnpackedJarFile;
 import org.apache.geronimo.gbean.GBeanInfo;
 import org.apache.geronimo.gbean.GBeanInfoFactory;
 import org.apache.geronimo.gbean.jmx.GBeanMBean;
@@ -62,14 +58,13 @@
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerDependencyType;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerGbeanType;
 import org.apache.geronimo.xbeans.geronimo.j2ee.GerModuleType;
-import org.apache.geronimo.xbeans.j2ee.ApplicationDocument;
 import org.apache.geronimo.xbeans.j2ee.ApplicationType;
 import org.apache.geronimo.xbeans.j2ee.ModuleType;
 import org.apache.geronimo.xbeans.j2ee.WebType;
 import org.apache.xmlbeans.SchemaTypeLoader;
 import org.apache.xmlbeans.XmlBeans;
-import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlException;
+import org.apache.xmlbeans.XmlObject;
 import org.apache.xmlbeans.XmlCursor;
 
 /**
@@ -155,53 +150,49 @@
         return (SchemaTypeLoader[]) typeLoaders.toArray(new SchemaTypeLoader[typeLoaders.size()]);
     }
 
-    public XmlObject getDeploymentPlan(URL deploymentURL) throws DeploymentException {
-        try {
-            URL moduleBase;
-            if (deploymentURL.toString().endsWith("/")) {
-                moduleBase = deploymentURL;
-            } else {
-                moduleBase = new URL("jar:" + deploymentURL.toString() + "!/");
-            }
+    public XmlObject getDeploymentPlan(JarFile module) throws DeploymentException {
+        URL path = JarUtil.createJarURL(module, "META-INF/geronimo-application.xml");
 
-            URL path = new URL(moduleBase, "META-INF/geronimo-application.xml");
-            XmlObject plan = null;
-            plan = getGerConnector(path);
-            if (plan != null) {
-                return plan;
-            }
+        try {
+            XmlObject xmlObject = SchemaConversionUtils.parse(path);
+            xmlObject = SchemaConversionUtils.getNestedObjectAsType(xmlObject, "application", GerApplicationType.type);
+            SchemaConversionUtils.validateDD(xmlObject);
+            return (GerApplicationType) xmlObject;
+        } catch (IOException e) {
+        } catch (XmlException e) {
+            throw new DeploymentException(e);
+        }
 
-            // try to create a default plan (will return null if this is not an ear file)
-            GerApplicationType defaultPlan = createDefaultPlan(moduleBase);
-            if (defaultPlan != null) {
-                return defaultPlan;
-            }
-        } catch (MalformedURLException e) {
+        // try to create a default plan (will return null if this is not an ear file)
+        GerApplicationType defaultPlan = createDefaultPlan(module);
+        if (defaultPlan != null) {
+            return defaultPlan;
         }
+
         // support a naked modules
         if (webConfigBuilder != null) {
-            XmlObject plan = webConfigBuilder.getDeploymentPlan(deploymentURL);
+            XmlObject plan = webConfigBuilder.getDeploymentPlan(module);
             if (plan != null) {
                 return plan;
             }
         }
 
         if (ejbConfigBuilder != null) {
-            XmlObject plan = ejbConfigBuilder.getDeploymentPlan(deploymentURL);
+            XmlObject plan = ejbConfigBuilder.getDeploymentPlan(module);
             if (plan != null) {
                 return plan;
             }
         }
 
         if (connectorConfigBuilder != null) {
-            XmlObject plan = connectorConfigBuilder.getDeploymentPlan(deploymentURL);
+            XmlObject plan = connectorConfigBuilder.getDeploymentPlan(module);
             if (plan != null) {
                 return plan;
             }
         }
 
         if (appClientConfigBuilder != null) {
-            XmlObject plan = appClientConfigBuilder.getDeploymentPlan(deploymentURL);
+            XmlObject plan = appClientConfigBuilder.getDeploymentPlan(module);
             if (plan != null) {
                 return plan;
             }
@@ -210,46 +201,16 @@
         return null;
     }
 
-    private GerApplicationType getGerConnector(URL path) throws DeploymentException {
-        try {
-            XmlObject dd = SchemaConversionUtils.parse(path.openStream());
-            return (GerApplicationType) validateVendorDD(dd);
-        } catch (IOException e) {
-            //todo should this throw an exception? we have already opened the stream!
-            return null;
-        } catch (XmlException e) {
-            throw new DeploymentException(e);
-        }
-    }
-
-    private XmlObject validateVendorDD(XmlObject dd) throws DeploymentException {
-        try {
-            dd = SchemaConversionUtils.getNestedObjectAsType(dd, "application", GerApplicationType.type);
-            SchemaConversionUtils.validateDD(dd);
-            return dd;
-        } catch (Exception e) {
-            throw new DeploymentException(e);
-        }
-    }
-
-    private GerApplicationType createDefaultPlan(URL deploymentURL) {
+    private GerApplicationType createDefaultPlan(JarFile module) throws DeploymentException {
         // load the web.xml
-        URL applicationXmlUrl = null;
-        try {
-            applicationXmlUrl = new URL(deploymentURL, "META-INF/application.xml");
-        } catch (MalformedURLException e) {
-            return null;
-        }
-        ApplicationDocument applicationDoc;
+        URL applicationXmlUrl = JarUtil.createJarURL(module, "META-INF/application.xml");
+
+        ApplicationType application = null;
         try {
-            InputStream ddInputStream = applicationXmlUrl.openStream();
-            applicationDoc = getApplicationDocument(ddInputStream);
-        } catch (IOException e) {
-            return null;
+            application = parseSpecDD(applicationXmlUrl);
         } catch (DeploymentException e) {
-            return null;
         }
-        if (applicationDoc == null) {
+        if (application == null) {
             return null;
         }
 
@@ -258,9 +219,10 @@
 
         // set the parentId and configId
         gerApplication.setParentId(PARENT_ID);
-        String id = applicationDoc.getApplication().getId();
+        String id = application.getId();
         if (id == null) {
-            id = deploymentURL.getFile();
+            // TODO this name is not necessairly the original name specified on the command line which is what we want
+            id = module.getName();
             if (id.endsWith("!/")) {
                 id = id.substring(0, id.length() - 2);
             }
@@ -277,14 +239,7 @@
         return gerApplication;
     }
 
-    public void buildConfiguration(File outfile, Manifest manifest, final File earFolder, final XmlObject plan) throws IOException, DeploymentException {
-        JarFile earFile = null;
-        if (earFolder.isDirectory()) {
-            earFile = new UnpackedJarFile(earFolder);
-        } else {
-            earFile = new JarFile(earFolder);
-        }
-
+    public void buildConfiguration(File outfile, Manifest manifest, JarFile earFile, XmlObject plan) throws IOException, DeploymentException {
         FileOutputStream fos = new FileOutputStream(outfile);
         try {
             // get the ids from either the application plan or for a stand alone module from the specific deployer
@@ -388,25 +343,22 @@
             earContext.close();
             os.flush();
         } finally {
-            if (earFile != null) {
-                try {
-                    earFile.close();
-                } catch (IOException ignored) {
-                }
-            }
             fos.close();
         }
     }
 
-    private ApplicationType addModules(final JarFile earFile, XmlObject plan, URI configId, Set moduleLocations, Set modules) throws IOException, DeploymentException {
+    private ApplicationType addModules(JarFile earFile, XmlObject plan, URI configId, Set moduleLocations, Set modules) throws IOException, DeploymentException {
         if (plan instanceof GerApplicationType) {
-            ApplicationType application;
-            JarEntry appXMLEntry = earFile.getJarEntry("META-INF/application.xml");
-            if (appXMLEntry == null) {
-                throw new DeploymentException("Did not find META-INF/application.xml in earFile");
+            URL applicationXmlUrl = JarUtil.createJarURL(earFile, "META-INF/application.xml");
+
+            ApplicationType application = null;
+            try {
+                application = parseSpecDD(applicationXmlUrl);
+            } catch (DeploymentException e) {
+            }
+            if (application == null) {
+                return null;
             }
-            InputStream ddInputStream = earFile.getInputStream(appXMLEntry);
-            application = getApplicationDocument(ddInputStream).getApplication();
 
             // build map from module path to alt vendor dd
             Map altVendorDDs = new HashMap();
@@ -493,12 +445,11 @@
                         altSpecDD = JarUtil.createJarURL(earFile, moduleXml.getAltDd().getStringValue());
                     }
 
-                    XmlObject vendorDD = null;
-                    XmlObject altVendorDD = (XmlObject) altVendorDDs.get(modulePath);
-                    if (altVendorDD != null) {
-                        vendorDD = builder.validateVendorDD(altVendorDD);
+                    XmlObject vendorDD = (XmlObject) altVendorDDs.get(modulePath);
+                    if (vendorDD != null) {
+                        vendorDD = builder.validateVendorDD(vendorDD);
                         if (vendorDD == null) {
-                            throw new DeploymentException("Invalid alt vendor dd: modulePath=" + modulePath + ", url=" + altVendorDD);
+                            throw new DeploymentException("Invalid alt vendor dd: modulePath=" + modulePath);
                         }
                     }
 
@@ -552,11 +503,10 @@
         throw new IllegalArgumentException("Unknown module type: " + module.getClass().getName());
     }
 
-    private ApplicationDocument getApplicationDocument(InputStream ddInputStream) throws DeploymentException {
-        XmlObject dd;
+    private ApplicationType parseSpecDD(URL url) throws DeploymentException {
         try {
-            dd = SchemaConversionUtils.parse(ddInputStream);
-            return SchemaConversionUtils.convertToApplicationSchema(dd);
+            XmlObject xmlObject = SchemaConversionUtils.parse(url);
+            return SchemaConversionUtils.convertToApplicationSchema(xmlObject).getApplication();
         } catch (Exception e) {
             throw new DeploymentException(e);
         }

Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java	(original)
+++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/ModuleBuilder.java	Sat Sep 25 09:30:09 2004
@@ -32,7 +32,7 @@
 
     XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException;
 
-    XmlObject getDeploymentPlan(URL module) throws DeploymentException;
+    XmlObject getDeploymentPlan(JarFile module) throws DeploymentException;
 
     boolean canHandlePlan(XmlObject plan);
 

Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java	(original)
+++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EARConfigBuilderTest.java	Sat Sep 25 09:30:09 2004
@@ -19,6 +19,7 @@
 
 import java.io.File;
 import java.net.URI;
+import java.util.jar.JarFile;
 import javax.management.ObjectName;
 
 import junit.extensions.TestSetup;
@@ -26,6 +27,7 @@
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
 import org.apache.geronimo.deployment.DeploymentException;
+import org.apache.geronimo.deployment.util.JarUtil;
 import org.apache.geronimo.kernel.jmx.JMXUtil;
 import org.apache.xmlbeans.XmlObject;
 
@@ -35,7 +37,7 @@
 public class EARConfigBuilderTest extends TestCase {
     private static final File basedir = new File(System.getProperty("basedir", System.getProperty("user.dir")));
 
-    private static File earFile;
+    private static JarFile earFile;
     private static MockEJBConfigBuilder ejbConfigBuilder = new MockEJBConfigBuilder();
     private static MockWARConfigBuilder webConfigBuilder = new MockWARConfigBuilder();
     private static MockConnectorConfigBuilder connectorConfigBuilder = new MockConnectorConfigBuilder();
@@ -51,8 +53,8 @@
     public static Test suite() throws Exception {
         TestSuite inner = new TestSuite(EARConfigBuilderTest.class);
         TestSetup setup14 = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir,  "target/test-ear14/test-ear.ear");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-ear14/test-ear.ear"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar", URI.create("test-ejb-jar.jar"), null, "test-ejb-jar.jar", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war", URI.create("test-war.war"), null, "test-war.war", null, null, null);
@@ -64,8 +66,8 @@
             }
         };
         TestSetup setupNaked14 = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir,  "target/test-ear14/test-naked-ear.ear");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-ear14/test-naked-ear.ear"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar", URI.create("test-ejb-jar.jar"), null, "test-ejb-jar.jar", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war", URI.create("test-war.war"), null, "test-war.war", null, null, null);
@@ -77,8 +79,8 @@
             }
         };
         TestSetup setup13 = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir,  "target/test-ear13/test-ear.ear");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-ear13/test-ear.ear"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar", URI.create("test-ejb-jar.jar"), null, "test-ejb-jar.jar", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war", URI.create("test-war.war"), null, "test-war.war", null, null, null);
@@ -90,8 +92,8 @@
             }
         };
         TestSetup setupNaked13 = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir, "target/test-ear13/test-naked-ear.ear");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir, "target/test-ear13/test-naked-ear.ear"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar", URI.create("test-ejb-jar.jar"), null, "test-ejb-jar.jar", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war", URI.create("test-war.war"), null, "test-war.war", null, null, null);
@@ -103,8 +105,8 @@
             }
         };
         TestSetup setupUnpacked = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir,  "target/test-unpacked-ear/full/");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-unpacked-ear/full/"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar/", URI.create("test-ejb-jar.jar/"), null, "test-ejb-jar.jar/", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war/", URI.create("test-war.war/"), null, "test-war.war/", null, null, null);
@@ -116,8 +118,8 @@
             }
         };
         TestSetup setupUnpackedNaked = new TestSetup(inner) {
-            protected void setUp() {
-                earFile = new File(basedir,  "target/test-unpacked-ear/naked/");
+            protected void setUp() throws Exception {
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-unpacked-ear/naked/"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar/", URI.create("test-ejb-jar.jar/"), null, "test-ejb-jar.jar/", null, null, null);
                 webConfigBuilder.contextRoot = "test";
                 webConfigBuilder.webModule = new WebModule("test-war.war/", URI.create("test-war.war/"), null, "test-war.war", null, null, null);
@@ -130,7 +132,7 @@
         };
         TestSetup setupUnpackedAltDD = new TestSetup(inner) {
             protected void setUp() throws Exception {
-                earFile = new File(basedir,  "target/test-unpacked-ear/alt-dd/");
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-unpacked-ear/alt-dd/"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar/", URI.create("test-ejb-jar.jar/"), null, "test-ejb-jar.jar/", null, null, null);
 //                ejbConfigBuilder.ejbModule.setAltSpecDD(new File(earFile, "alt-ejb-jar.xml").toURL());
 //                ejbConfigBuilder.ejbModule.setAltVendorDD(new File(earFile, "alt-ger-ejb-jar.xml").toURL());
@@ -149,7 +151,7 @@
         };
         TestSetup setupPackedAltDD = new TestSetup(inner) {
             protected void setUp() throws Exception {
-                earFile = new File(basedir,  "target/test-unpacked-ear/alt-dd.ear");
+                earFile = JarUtil.createJarFile(new File(basedir,  "target/test-unpacked-ear/alt-dd.ear"));
                 ejbConfigBuilder.ejbModule = new EJBModule("test-ejb-jar.jar/", URI.create("test-ejb-jar.jar/"), null, "test-ejb-jar.jar/", null, null, null);
 //                String baseURI = "jar:" + earFile.toURL() + "!/";
 //                ejbConfigBuilder.ejbModule.setAltSpecDD(new URL(baseURI + "alt-ejb-jar.xml"));
@@ -185,7 +187,7 @@
 
         File carFile = File.createTempFile("EARTest", ".car");
         try {
-            XmlObject plan = configBuilder.getDeploymentPlan(earFile.toURL());
+            XmlObject plan = configBuilder.getDeploymentPlan(earFile);
             configBuilder.buildConfiguration(carFile, null, earFile, plan);
         } finally {
             carFile.delete();
@@ -197,7 +199,7 @@
 
         File carFile = File.createTempFile("EARTest", ".car");
         try {
-            XmlObject plan = configBuilder.getDeploymentPlan(earFile.toURL());
+            XmlObject plan = configBuilder.getDeploymentPlan(earFile);
             configBuilder.buildConfiguration(carFile, null, earFile, plan);
             fail("Should have thrown a DeploymentException");
         } catch (DeploymentException e) {
@@ -212,7 +214,7 @@
 
         File carFile = File.createTempFile("EARTest", ".car");
         try {
-            XmlObject plan = configBuilder.getDeploymentPlan(earFile.toURL());
+            XmlObject plan = configBuilder.getDeploymentPlan(earFile);
             configBuilder.buildConfiguration(carFile, null, earFile, plan);
             fail("Should have thrown a DeploymentException");
         } catch (DeploymentException e) {
@@ -227,7 +229,7 @@
 
         File carFile = File.createTempFile("EARTest", ".car");
         try {
-            XmlObject plan = configBuilder.getDeploymentPlan(earFile.toURL());
+            XmlObject plan = configBuilder.getDeploymentPlan(earFile);
             configBuilder.buildConfiguration(carFile, null, earFile, plan);
             fail("Should have thrown a DeploymentException");
         } catch (DeploymentException e) {

Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java	(original)
+++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockConnectorConfigBuilder.java	Sat Sep 25 09:30:09 2004
@@ -35,7 +35,7 @@
     public Module connectorModule;
     public ClassLoader cl;
 
-    public XmlObject getDeploymentPlan(URL module) {
+    public XmlObject getDeploymentPlan(JarFile module) {
         return null;
     }
 

Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java	(original)
+++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockEJBConfigBuilder.java	Sat Sep 25 09:30:09 2004
@@ -35,7 +35,7 @@
     public EJBModule ejbModule;
     public ClassLoader cl;
 
-    public XmlObject getDeploymentPlan(URL module) {
+    public XmlObject getDeploymentPlan(JarFile module) {
         return null;
     }
 

Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java
==============================================================================
--- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java	(original)
+++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/MockWARConfigBuilder.java	Sat Sep 25 09:30:09 2004
@@ -36,7 +36,7 @@
     public ClassLoader cl;
     public String contextRoot;
 
-    public XmlObject getDeploymentPlan(URL module) {
+    public XmlObject getDeploymentPlan(JarFile module) {
         return null;
     }
 

Modified: geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java
==============================================================================
--- geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java	(original)
+++ geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java	Sat Sep 25 09:30:09 2004
@@ -17,9 +17,9 @@
 
 package org.apache.geronimo.jetty.deployment;
 
+import java.io.ByteArrayInputStream;
 import java.io.IOException;
 import java.io.InputStream;
-import java.io.ByteArrayInputStream;
 import java.net.MalformedURLException;
 import java.net.URI;
 import java.net.URISyntaxException;
@@ -65,15 +65,15 @@
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyDefaultPrincipalType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyDependencyType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyGbeanType;
-import org.apache.geronimo.xbeans.geronimo.naming.GerLocalRefType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyPrincipalType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyRealmType;
-import org.apache.geronimo.xbeans.geronimo.naming.GerRemoteRefType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyRoleMappingsType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyRoleType;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettySecurityType;
-import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
 import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppType;
+import org.apache.geronimo.xbeans.geronimo.jetty.JettyWebAppDocument;
+import org.apache.geronimo.xbeans.geronimo.naming.GerLocalRefType;
+import org.apache.geronimo.xbeans.geronimo.naming.GerRemoteRefType;
 import org.apache.geronimo.xbeans.j2ee.ResourceRefType;
 import org.apache.geronimo.xbeans.j2ee.WebAppDocument;
 import org.apache.geronimo.xbeans.j2ee.WebAppType;
@@ -89,7 +89,7 @@
 public class JettyModuleBuilder implements ModuleBuilder {
     static final SchemaTypeLoader SCHEMA_TYPE_LOADER = XmlBeans.typeLoaderUnion(new SchemaTypeLoader[]{
         XmlBeans.typeLoaderForClassLoader(org.apache.geronimo.xbeans.j2ee.String.class.getClassLoader()),
-        XmlBeans.typeLoaderForClassLoader(JettyWebAppDocument.class.getClassLoader())
+        XmlBeans.typeLoaderForClassLoader(JettyWebAppType.class.getClassLoader())
     });
 
     private static final String PARENT_ID = "org/apache/geronimo/Server";
@@ -97,7 +97,7 @@
     public XmlObject parseSpecDD(URL path) throws DeploymentException {
         try {
             // check if we have an alt spec dd
-            return parseSpecDD(SchemaConversionUtils.parse(path.openStream()));
+            return parseSpecDD(SchemaConversionUtils.parse(path));
         } catch (Exception e) {
             throw new DeploymentException("Unable to parse " + path, e);
         }
@@ -117,30 +117,32 @@
         return webAppDoc.getWebApp();
     }
 
-    public XmlObject validateVendorDD(XmlObject dd) throws DeploymentException {
+    public XmlObject validateVendorDD(XmlObject vendorDD) throws DeploymentException {
         try {
-            dd = SchemaConversionUtils.convertToGeronimoNamingSchema(dd);
-            dd = dd.changeType(JettyWebAppDocument.type);
-            SchemaConversionUtils.validateDD(dd);
-            return dd;
+            // TODO this is totally wrong but works
+//            vendorDD = SchemaConversionUtils.getNestedObjectAsType(vendorDD, "web-app", JettyWebAppType.type);
+//            SchemaConversionUtils.validateDD(vendorDD);
+            vendorDD = ((JettyWebAppDocument)vendorDD).getWebApp();
+            vendorDD = SchemaConversionUtils.convertToGeronimoNamingSchema(vendorDD);
+            return vendorDD;
         } catch (Exception e) {
             throw new DeploymentException(e);
         }
     }
 
-    public XmlObject getDeploymentPlan(URL module) throws DeploymentException {
+    public XmlObject getDeploymentPlan(JarFile module) throws DeploymentException {
+        URL path = null;
         try {
-            URL moduleBase;
-            if (module.toString().endsWith("/")) {
-                moduleBase = module;
-            } else {
-                moduleBase = new URL("jar:" + module.toString() + "!/");
-            }
-            URL path = new URL(moduleBase, "WEB-INF/geronimo-jetty.xml");
-            XmlObject dd = SchemaConversionUtils.parse(path.openStream());
-            JettyWebAppDocument plan = (JettyWebAppDocument) validateVendorDD(dd);
+            path = JarUtil.createJarURL(module, "WEB-INF/geronimo-jetty.xml");
+        } catch (DeploymentException e) {
+            return null;
+        }
+
+        try {
+            JettyWebAppDocument dd = JettyWebAppDocument.Factory.parse(path);
+            JettyWebAppType plan = (JettyWebAppType) validateVendorDD(dd);
             if (plan == null) {
-                return createDefaultPlan(moduleBase);
+                return createDefaultPlan(module);
             }
             return plan;
         } catch (MalformedURLException e) {
@@ -152,12 +154,12 @@
         }
     }
 
-    private JettyWebAppDocument createDefaultPlan(URL moduleBase) {
+    private JettyWebAppType createDefaultPlan(JarFile module) {
         // load the web.xml
-        URL webXmlUrl = null;
+        URL webXmlUrl;
         try {
-            webXmlUrl = new URL(moduleBase, "WEB-INF/web.xml");
-        } catch (MalformedURLException e) {
+            webXmlUrl = JarUtil.createJarURL(module, "WEB-INF/web.xml");
+        } catch (DeploymentException e) {
             return null;
         }
 
@@ -170,7 +172,8 @@
 
         String id = webApp.getId();
         if (id == null) {
-            id = moduleBase.getFile();
+            // TODO this name is not necessairly the original name specified on the command line which is what we want
+            id = module.getName();
             if (id.endsWith("!/")) {
                 id = id.substring(0, id.length() - 2);
             }
@@ -182,12 +185,11 @@
             }
             id = id.substring(id.lastIndexOf('/') + 1);
         }
-        return newJettyWebAppDocument(webApp, id);
+        return newJettyWebAppType(webApp, id);
     }
 
-    private JettyWebAppDocument newJettyWebAppDocument(WebAppType webApp, String id) {
-        JettyWebAppDocument jettyWebAppDocument = JettyWebAppDocument.Factory.newInstance();
-        JettyWebAppType jettyWebApp = jettyWebAppDocument.addNewWebApp();
+    private JettyWebAppType newJettyWebAppType(WebAppType webApp, String id) {
+        JettyWebAppType jettyWebApp = JettyWebAppType.Factory.newInstance();
 
         // set the parentId, configId and context root
         jettyWebApp.setParentId(PARENT_ID);
@@ -196,15 +198,15 @@
         }
         jettyWebApp.setConfigId(id);
         jettyWebApp.setContextRoot(id);
-        return jettyWebAppDocument;
+        return jettyWebApp;
     }
 
     public boolean canHandlePlan(XmlObject plan) {
-        return plan instanceof JettyWebAppDocument;
+        return plan instanceof JettyWebAppType;
     }
 
     public URI getParentId(XmlObject plan) throws DeploymentException {
-        JettyWebAppType jettyWebApp = ((JettyWebAppDocument) plan).getWebApp();
+        JettyWebAppType jettyWebApp = (JettyWebAppType) plan;
         try {
             return new URI(jettyWebApp.getParentId());
         } catch (URISyntaxException e) {
@@ -213,7 +215,7 @@
     }
 
     public URI getConfigId(XmlObject plan) throws DeploymentException {
-        JettyWebAppType jettyWebApp = ((JettyWebAppDocument) plan).getWebApp();
+        JettyWebAppType jettyWebApp = (JettyWebAppType) plan;
         try {
             return new URI(jettyWebApp.getConfigId());
         } catch (URISyntaxException e) {
@@ -256,7 +258,7 @@
                 if (entry != null) {
                     InputStream in = moduleFile.getInputStream(entry);
                     if (in != null) {
-                        vendorDD = XmlBeansUtil.parse(in, JettyWebAppDocument.type);
+                        vendorDD = XmlBeansUtil.parse(in, JettyWebAppType.type);
                     }
                 }
             } catch (Exception e) {
@@ -264,11 +266,10 @@
             }
         }
         if (vendorDD == null) {
-            vendorDD = newJettyWebAppDocument(webApp, name);
+            vendorDD = newJettyWebAppType(webApp, name);
         }
 
-        JettyWebAppDocument jettyWebAppDoc = (JettyWebAppDocument) vendorDD;
-        JettyWebAppType jettyWebApp = jettyWebAppDoc.getWebApp();
+        JettyWebAppType jettyWebApp = (JettyWebAppType) vendorDD;
 
         WebModule module = new WebModule(name, moduleURI, moduleFile, targetPath, webApp, jettyWebApp, specDD);
         module.setContextRoot(jettyWebApp.getContextRoot());

Mime
View raw message