Author: dain Date: Mon Oct 4 15:54:53 2004 New Revision: 53762 Added: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java Removed: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/FileUtil.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/IOUtil.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/JarUtil.java Modified: geronimo/trunk/modules/assembly/ (props changed) geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/WebServiceDeployer.java geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/DynamicEJBDeploymentTest.java 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/DeploymentContext.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.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/NestedJarFile.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/URLType.java geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/UnpackedJarFile.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/AppClientModule.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/EARContext.java geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/Module.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/EJBRefContextTest.java geronimo/trunk/modules/jetty/src/java/org/apache/geronimo/jetty/deployment/JettyModuleBuilder.java geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/config/RunTest.java geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/url/file/FileProtocolTest.java Log: Rewrote deployment to build output into a temp directory instead of into a packed jar file This will make adding support for manifest classpath entries trivial Changed entire system to meticulously track temp files and delete them asap
Modified: geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/WebServiceDeployer.java ============================================================================== --- geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/WebServiceDeployer.java (original) +++ geronimo/trunk/modules/axis/src/java/org/apache/geronimo/axis/WebServiceDeployer.java Mon Oct 4 15:54:53 2004 @@ -369,8 +369,7 @@ XmlObject plan = earConfigBuilder.getDeploymentPlan(earFile.toURL()); - earConfigBuilder.buildConfiguration(carFile, null, earFile, - plan); + earConfigBuilder.buildConfiguration(earFile, plan, carFile); LocalConfigStore.unpack(unpackedDir, new FileInputStream(carFile)); ///////////////////////////////////////////////////////////////////////////////// Modified: geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/DynamicEJBDeploymentTest.java ============================================================================== --- geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/DynamicEJBDeploymentTest.java (original) +++ geronimo/trunk/modules/axis/src/test/org/apache/geronimo/axis/DynamicEJBDeploymentTest.java Mon Oct 4 15:54:53 2004 @@ -148,7 +148,7 @@ // transactionManagerObjectName, connectionTrackerObjectName); XmlObject plan = earConfigBuilder.getDeploymentPlan(earFile.toURL()); - earConfigBuilder.buildConfiguration(carFile, null, earFile, plan); + earConfigBuilder.buildConfiguration(earFile, plan, carFile); File unpackedDir = new File(tempDir, "OpenEJBTest-ear-Unpacked"); LocalConfigStore.unpack(unpackedDir, new FileInputStream(carFile)); } finally { 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 Mon Oct 4 15:54:53 2004 @@ -16,9 +16,7 @@ */ package org.apache.geronimo.client.builder; -import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; @@ -29,9 +27,9 @@ import java.util.Iterator; import java.util.Map; import java.util.Properties; +import java.util.HashSet; import java.util.jar.Attributes; import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; import java.util.jar.Manifest; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -39,10 +37,8 @@ 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.IOUtil; -import org.apache.geronimo.deployment.util.JarUtil; import org.apache.geronimo.deployment.util.NestedJarFile; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.jmx.GBeanMBean; @@ -117,12 +113,12 @@ ApplicationClientType appClient; try { if (specDDUrl == null) { - specDDUrl = JarUtil.createJarURL(moduleFile, "META-INF/application-client.xml"); + specDDUrl = DeploymentUtil.createJarURL(moduleFile, "META-INF/application-client.xml"); } // read in the entire specDD as a string, we need this for getDeploymentDescriptor // on the J2ee management object - specDD = IOUtil.readAll(specDDUrl); + specDD = DeploymentUtil.readAll(specDDUrl); // parse it XmlObject xmlObject = SchemaConversionUtils.parse(specDD); @@ -172,7 +168,7 @@ if (plan != null) { gerAppClientDoc = GerApplicationClientDocument.Factory.parse((File)plan); } else { - URL path = JarUtil.createJarURL(moduleFile, "META-INF/geronimo-application-client.xml"); + URL path = DeploymentUtil.createJarURL(moduleFile, "META-INF/geronimo-application-client.xml"); gerAppClientDoc = GerApplicationClientDocument.Factory.parse(path); } if (gerAppClientDoc != null) { @@ -233,8 +229,7 @@ // extract the ejbJar file into a standalone packed jar file and add the contents to the output JarFile moduleFile = module.getModuleFile(); try { - File appClientJarFile = JarUtil.extractToPackedJar(moduleFile); - earContext.addInclude(URI.create(module.getTargetPath()), appClientJarFile.toURL()); + earContext.addIncludeAsPackedJar(URI.create(module.getTargetPath()), moduleFile); } catch (IOException e) { throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName()); } @@ -306,170 +301,185 @@ EARContext appClientDeploymentContext = null; File appClientConfiguration = null; try { - appClientConfiguration = FileUtil.createTempFile(); - JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(appClientConfiguration))); - - // construct the app client deployment context... this is the same class used by the ear context try { - EJBReferenceBuilder ejbReferenceBuilder = new EJBReferenceBuilder() { - public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) { - throw new UnsupportedOperationException("Application client cannot have a local ejb ref"); - } + appClientConfiguration = DeploymentUtil.createTempDir(); - public Reference createEJBRemoteReference(String objectName, boolean isSession, String home, String remote) { - RemoteEJBRefAddr addr = new RemoteEJBRefAddr(objectName); - Reference reference = new Reference(null, addr, RemoteEJBObjectFactory.class.getName(), null); - return reference; - } - }; + // construct the app client deployment context... this is the same class used by the ear context + try { + EJBReferenceBuilder ejbReferenceBuilder = new EJBReferenceBuilder() { + public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) { + throw new UnsupportedOperationException("Application client cannot have a local ejb ref"); + } - URI clientConfigId = URI.create(geronimoAppClient.getClientConfigId()); - URI clientParentId; - if (geronimoAppClient.isSetClientParentId()) { - clientParentId = URI.create(geronimoAppClient.getClientParentId()); - } else { - clientParentId = CLIENT_PARENT_ID; - } - appClientDeploymentContext = new EARContext(jos, - clientConfigId, - ConfigurationModuleType.APP_CLIENT, - clientParentId, - kernel, - clientDomainName, - clientServerName, - clientApplicationName, - transactionContextManagerObjectName, - connectionTrackerObjectName, - null, - null, - new EJBRefContext(earContext.getEJBRefContext(), ejbReferenceBuilder)); - } catch (Exception e) { - throw new DeploymentException("Could not create a deployment context for the app client", e); - } + public Reference createEJBRemoteReference(String objectName, boolean isSession, String home, String remote) { + RemoteEJBRefAddr addr = new RemoteEJBRefAddr(objectName); + Reference reference = new Reference(null, addr, RemoteEJBObjectFactory.class.getName(), null); + return reference; + } + }; - // extract the client Jar file into a standalone packed jar file and add the contents to the output - File appClientJarFile = JarUtil.extractToPackedJar(moduleFile); - URI moduleBase = new URI(appClientModule.getTargetPath()); - appClientDeploymentContext.addInclude(moduleBase, appClientJarFile.toURL()); - - // add the includes - GerDependencyType[] includes = geronimoAppClient.getIncludeArray(); - for (int i = 0; i < includes.length; i++) { - GerDependencyType include = includes[i]; - URI uri = getDependencyURI(include); - String name = uri.toString(); - int idx = name.lastIndexOf('/'); - if (idx != -1) { - name = name.substring(idx + 1); - } - URI path; - try { - path = new URI(name); - } catch (URISyntaxException e) { - throw new DeploymentException("Unable to generate path for include: " + uri, e); + URI clientConfigId = URI.create(geronimoAppClient.getClientConfigId()); + URI clientParentId; + if (geronimoAppClient.isSetClientParentId()) { + clientParentId = URI.create(geronimoAppClient.getClientParentId()); + } else { + clientParentId = CLIENT_PARENT_ID; + } + appClientDeploymentContext = new EARContext(appClientConfiguration, + clientConfigId, + ConfigurationModuleType.APP_CLIENT, + clientParentId, + kernel, + clientDomainName, + clientServerName, + clientApplicationName, + transactionContextManagerObjectName, + connectionTrackerObjectName, + null, + null, + new EJBRefContext(earContext.getEJBRefContext(), ejbReferenceBuilder)); + } catch (Exception e) { + throw new DeploymentException("Could not create a deployment context for the app client", e); } + + // extract the client Jar file into a standalone packed jar file and add the contents to the output + URI moduleBase = new URI(appClientModule.getTargetPath()); try { - URL url = repository.getURL(uri); - appClientDeploymentContext.addInclude(path, url); + appClientDeploymentContext.addIncludeAsPackedJar(moduleBase, moduleFile); } catch (IOException e) { - throw new DeploymentException("Unable to add include: " + uri, e); + throw new DeploymentException("Unable to copy app client module jar into configuration: " + moduleFile.getName()); } - } - // add the dependencies - GerDependencyType[] dependencies = geronimoAppClient.getDependencyArray(); - for (int i = 0; i < dependencies.length; i++) { - appClientDeploymentContext.addDependency(getDependencyURI(dependencies[i])); - } + // add the includes + GerDependencyType[] includes = geronimoAppClient.getIncludeArray(); + for (int i = 0; i < includes.length; i++) { + GerDependencyType include = includes[i]; + URI uri = getDependencyURI(include); + String name = uri.toString(); + int idx = name.lastIndexOf('/'); + if (idx != -1) { + name = name.substring(idx + 1); + } + URI path; + try { + path = new URI(name); + } catch (URISyntaxException e) { + throw new DeploymentException("Unable to generate path for include: " + uri, e); + } + try { + URL url = repository.getURL(uri); + appClientDeploymentContext.addInclude(path, url); + } catch (IOException e) { + throw new DeploymentException("Unable to add include: " + uri, e); + } + } - appClientDeploymentContext.addManifestClassPath(appClientModule.getEarFile(), appClientModule, moduleFile, moduleBase); + // add the dependencies + GerDependencyType[] dependencies = geronimoAppClient.getDependencyArray(); + for (int i = 0; i < dependencies.length; i++) { + appClientDeploymentContext.addDependency(getDependencyURI(dependencies[i])); + } + appClientDeploymentContext.addManifestClassPath(appClientModule.getEarFile(), appClientModule, moduleFile, moduleBase); - // get the classloader - ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader(repository); - // pop in all the gbeans declared in the geronimo app client file - if (geronimoAppClient != null) { - GerGbeanType[] gbeans = geronimoAppClient.getGbeanArray(); - for (int i = 0; i < gbeans.length; i++) { - GBeanHelper.addGbean(new AppClientGBeanAdapter(gbeans[i]), appClientClassLoader, appClientDeploymentContext); - } - //deploy the resource adapters specified in the geronimo-application.xml - Collection resourceModules = appClientModule.getResourceModules(); - GerResourceType[] resources = geronimoAppClient.getResourceArray(); - for (int i = 0; i < resources.length; i++) { - GerResourceType resource = resources[i]; - String path; - JarFile connectorFile; - if (resource.isSetExternalRar()) { - path = resource.getExternalRar(); - URI pathURI = new URI(path); - if (!repository.hasURI(pathURI)) { - throw new DeploymentException("Missing rar in repository: " + path); - } - URL pathURL = repository.getURL(pathURI); - connectorFile = new JarFile(pathURL.getFile()); - } else { - path = resource.getInternalRar(); - connectorFile = new NestedJarFile(appClientModule.getEarFile(), path); + // get the classloader + ClassLoader appClientClassLoader = appClientDeploymentContext.getClassLoader(repository); + + // pop in all the gbeans declared in the geronimo app client file + if (geronimoAppClient != null) { + GerGbeanType[] gbeans = geronimoAppClient.getGbeanArray(); + for (int i = 0; i < gbeans.length; i++) { + GBeanHelper.addGbean(new AppClientGBeanAdapter(gbeans[i]), appClientClassLoader, appClientDeploymentContext); } - XmlObject connectorPlan = resource.getConnector(); - Module connectorModule = connectorModuleBuilder.createModule(connectorPlan, connectorFile, path, null, null); - resourceModules.add(connectorModule); - connectorModuleBuilder.installModule(connectorFile, appClientDeploymentContext, connectorModule); - } - ClassLoader cl = appClientDeploymentContext.getClassLoader(repository); - for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) { - Module connectorModule = (Module) iterator.next(); - connectorModuleBuilder.initContext(appClientDeploymentContext, connectorModule, cl); - } + //deploy the resource adapters specified in the geronimo-application.xml + Collection resourceModules = new HashSet(); + try { + GerResourceType[] resources = geronimoAppClient.getResourceArray(); + for (int i = 0; i < resources.length; i++) { + GerResourceType resource = resources[i]; + String path; + JarFile connectorFile; + if (resource.isSetExternalRar()) { + path = resource.getExternalRar(); + URI pathURI = new URI(path); + if (!repository.hasURI(pathURI)) { + throw new DeploymentException("Missing rar in repository: " + path); + } + URL pathURL = repository.getURL(pathURI); + connectorFile = new JarFile(pathURL.getFile()); + } else { + path = resource.getInternalRar(); + connectorFile = new NestedJarFile(appClientModule.getEarFile(), path); + } + XmlObject connectorPlan = resource.getConnector(); + Module connectorModule = connectorModuleBuilder.createModule(connectorPlan, connectorFile, path, null, null); + resourceModules.add(connectorModule); + connectorModuleBuilder.installModule(connectorFile, appClientDeploymentContext, connectorModule); + } + ClassLoader cl = appClientDeploymentContext.getClassLoader(repository); + for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) { + Module connectorModule = (Module) iterator.next(); + connectorModuleBuilder.initContext(appClientDeploymentContext, connectorModule, cl); + } - for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) { - Module connectorModule = (Module) iterator.next(); - connectorModuleBuilder.addGBeans(appClientDeploymentContext, connectorModule, cl); + for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) { + Module connectorModule = (Module) iterator.next(); + connectorModuleBuilder.addGBeans(appClientDeploymentContext, connectorModule, cl); + } + } finally { + for (Iterator iterator = resourceModules.iterator(); iterator.hasNext();) { + Module connectorModule = (Module) iterator.next(); + connectorModule.close(); + } + } } - } - - // add the app client static jndi provider - ObjectName jndiContextName = ObjectName.getInstance("geronimo.client:type=StaticJndiContext"); - GBeanMBean jndiContextGBean = new GBeanMBean("org.apache.geronimo.client.StaticJndiContextPlugin", appClientClassLoader); - try { + // add the app client static jndi provider + ObjectName jndiContextName = ObjectName.getInstance("geronimo.client:type=StaticJndiContext"); + GBeanMBean jndiContextGBean = new GBeanMBean("org.apache.geronimo.client.StaticJndiContextPlugin", appClientClassLoader); + try { - componentContext = buildComponentContext(appClientDeploymentContext, appClientModule, appClient, geronimoAppClient, earClassLoader); - jndiContextGBean.setAttribute("context", componentContext); - } catch (Exception e) { - throw new DeploymentException("Unable to initialize AppClientModule GBean", e); + componentContext = buildComponentContext(appClientDeploymentContext, appClientModule, appClient, geronimoAppClient, earClassLoader); + jndiContextGBean.setAttribute("context", componentContext); + } catch (Exception e) { + throw new DeploymentException("Unable to initialize AppClientModule GBean", e); + } + appClientDeploymentContext.addGBean(jndiContextName, jndiContextGBean); + + // finally add the app client container + ObjectName appClienContainerName = ObjectName.getInstance("geronimo.client:type=ClientContainer"); + GBeanMBean appClienContainerGBean = new GBeanMBean("org.apache.geronimo.client.AppClientContainer", appClientClassLoader); + try { + appClienContainerGBean.setAttribute("mainClassName", mainClasss); + appClienContainerGBean.setAttribute("appClientModuleName", appClientModuleName); + appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=StaticJndiContext")); + } catch (Exception e) { + throw new DeploymentException("Unable to initialize AppClientModule GBean", e); + } + appClientDeploymentContext.addGBean(appClienContainerName, appClienContainerGBean); + } finally { + if (appClientDeploymentContext != null) { + try { + appClientDeploymentContext.close(); + } catch (IOException e) { + } + } } - appClientDeploymentContext.addGBean(jndiContextName, jndiContextGBean); - // finally add the app client container - ObjectName appClienContainerName = ObjectName.getInstance("geronimo.client:type=ClientContainer"); - GBeanMBean appClienContainerGBean = new GBeanMBean("org.apache.geronimo.client.AppClientContainer", appClientClassLoader); try { - appClienContainerGBean.setAttribute("mainClassName", mainClasss); - appClienContainerGBean.setAttribute("appClientModuleName", appClientModuleName); - appClienContainerGBean.setReferencePattern("JNDIContext", new ObjectName("geronimo.client:type=StaticJndiContext")); + return store.install(appClientConfiguration).toString(); } catch (Exception e) { - throw new DeploymentException("Unable to initialize AppClientModule GBean", e); + throw new DeploymentException(e); } - appClientDeploymentContext.addGBean(appClienContainerName, appClienContainerGBean); + } catch (DeploymentException e) { + throw e; } catch (Exception e) { throw new DeploymentException(e); } finally { - if (appClientDeploymentContext != null) { - try { - appClientDeploymentContext.close(); - } catch (IOException e) { - } - } + DeploymentUtil.recursiveDelete(appClientConfiguration); } - try { - return store.install(appClientConfiguration.toURL()).toString(); - } catch (Exception e) { - throw new DeploymentException(e); - } } private ReadOnlyContext buildComponentContext(EARContext earContext, AppClientModule appClientModule, ApplicationClientType appClient, GerApplicationClientType geronimoAppClient, ClassLoader cl) throws DeploymentException { 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 Mon Oct 4 15:54:53 2004 @@ -19,7 +19,6 @@ import java.beans.PropertyEditor; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -49,8 +48,7 @@ import org.apache.geronimo.connector.outbound.security.PasswordCredentialRealm; import org.apache.geronimo.deployment.DeploymentException; import org.apache.geronimo.deployment.service.GBeanHelper; -import org.apache.geronimo.deployment.util.IOUtil; -import org.apache.geronimo.deployment.util.JarUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.DynamicGAttributeInfo; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; @@ -113,12 +111,12 @@ XmlObject connector; try { if (specDDUrl == null) { - specDDUrl = JarUtil.createJarURL(moduleFile, "META-INF/ra.xml"); + specDDUrl = DeploymentUtil.createJarURL(moduleFile, "META-INF/ra.xml"); } // read in the entire specDD as a string, we need this for getDeploymentDescriptor // on the J2ee management object - specDD = IOUtil.readAll(specDDUrl); + specDD = DeploymentUtil.readAll(specDDUrl); // parse it try { @@ -150,7 +148,7 @@ if (plan != null) { gerConnectorDoc = GerConnectorDocument.Factory.parse((File)plan); } else { - URL path = JarUtil.createJarURL(moduleFile, "META-INF/geronimo-ra.xml"); + URL path = DeploymentUtil.createJarURL(moduleFile, "META-INF/geronimo-ra.xml"); gerConnectorDoc = GerConnectorDocument.Factory.parse(path); } if (gerConnectorDoc != null) { @@ -199,18 +197,10 @@ while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); URI target = targetURI.resolve(entry.getName()); - InputStream in = moduleFile.getInputStream(entry); - try { - if (entry.getName().endsWith(".jar")) { - earContext.addStreamInclude(target, in); - } else { - earContext.addFile(target, in); - } - } finally { - try { - in.close(); - } catch (IOException e) { - } + if (entry.getName().endsWith(".jar")) { + earContext.addInclude(target, moduleFile, entry); + } else { + earContext.addFile(target, moduleFile, entry); } } 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 Mon Oct 4 15:54:53 2004 @@ -20,7 +20,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.ObjectInputStream; import java.net.MalformedURLException; @@ -33,13 +32,12 @@ import java.util.List; import java.util.Set; import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; import javax.management.ObjectName; import javax.sql.DataSource; import junit.framework.TestCase; import org.apache.geronimo.deployment.DeploymentException; -import org.apache.geronimo.deployment.util.JarUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.jmx.GBeanMBean; import org.apache.geronimo.j2ee.deployment.EARConfigBuilder; @@ -50,7 +48,6 @@ import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.Configuration; import org.apache.geronimo.kernel.management.State; -import org.apache.geronimo.system.configuration.LocalConfigStore; import org.apache.geronimo.system.serverinfo.ServerInfo; import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; import org.apache.geronimo.xbeans.j2ee.connector_1_0.ConnectorDocument10; @@ -180,15 +177,16 @@ Thread.currentThread().setContextClassLoader(cl); - JarFile rarJarFile = JarUtil.createJarFile(rarFile); + JarFile rarJarFile = DeploymentUtil.createJarFile(rarFile); Module module = moduleBuilder.createModule(action.getVendorDD(), rarJarFile, j2eeModuleName, action.getSpecDD(), null); if (module == null) { throw new DeploymentException("Was not a connector module"); } - File carFile = File.createTempFile("RARTest", ".car"); + File tempDir = null; try { - EARContext earContext = new EARContext(new JarOutputStream(new FileOutputStream(carFile)), + tempDir = DeploymentUtil.createTempDir(); + EARContext earContext = new EARContext(tempDir, module.getConfigId(), module.getType(), module.getParentId(), @@ -208,13 +206,10 @@ moduleBuilder.addGBeans(earContext, module, cl); earContext.close(); - File tempdir = new File(System.getProperty("java.io.tmpdir")); - File unpackedDir = new File(tempdir, "OpenEJBTest-Unpacked"); - LocalConfigStore.unpack(unpackedDir, new FileInputStream(carFile)); - - verifyDeployment(unpackedDir, oldCl, j2eeDomainName, j2eeServerName, j2eeApplicationName, j2eeModuleName); + verifyDeployment(tempDir, oldCl, j2eeDomainName, j2eeServerName, j2eeApplicationName, j2eeModuleName); } finally { - carFile.delete(); + module.close(); + DeploymentUtil.recursiveDelete(tempDir); } } @@ -225,19 +220,22 @@ ObjectName j2eeServer = new ObjectName(j2eeDomainName + ":name=" + j2eeServerName); Kernel kernel = new Kernel("blah"); kernel.boot(); + JarFile rarFile = null; try { + rarFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear-noger.ear")); EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, null, connectionTrackerName, null, null, null, null, null, null, new ConnectorModuleBuilder(), null, kernel); - JarFile rarFile = JarUtil.createJarFile(new File(basedir, "target/test-ear-noger.ear")); - File outFile = File.createTempFile("EARTest", ".car"); + File tempDir = null; try { + tempDir = DeploymentUtil.createTempDir(); File planFile = new File(basedir, "src/test-data/data/external-application-plan.xml"); Object plan = configBuilder.getDeploymentPlan(planFile, rarFile); - configBuilder.buildConfiguration(outFile, null, plan, rarFile); + configBuilder.buildConfiguration(plan, rarFile, tempDir); } finally { - outFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } finally { kernel.shutdown(); + DeploymentUtil.close(rarFile); } } @@ -413,7 +411,7 @@ public abstract File getRARFile(); public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { - moduleBuilder.installModule(JarUtil.createJarFile(getRARFile()), earContext, module); + moduleBuilder.installModule(module.getModuleFile(), earContext, module); } } 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 Mon Oct 4 15:54:53 2004 @@ -20,7 +20,6 @@ import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; import java.io.InputStream; import java.io.ObjectInputStream; import java.net.URL; @@ -32,13 +31,12 @@ import java.util.List; import java.util.Map; import java.util.Set; -import java.util.jar.JarOutputStream; import javax.management.ObjectName; import javax.sql.DataSource; import junit.framework.TestCase; import org.apache.geronimo.connector.ActivationSpecInfo; -import org.apache.geronimo.deployment.util.JarUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.jmx.GBeanMBean; import org.apache.geronimo.j2ee.deployment.EARContext; @@ -48,7 +46,6 @@ import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.Configuration; import org.apache.geronimo.kernel.management.State; -import org.apache.geronimo.system.configuration.LocalConfigStore; import org.apache.geronimo.system.serverinfo.ServerInfo; import org.apache.geronimo.xbeans.geronimo.GerConnectorDocument; import org.apache.geronimo.xbeans.j2ee.ConnectorDocument; @@ -90,7 +87,7 @@ return rarFile; } public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { - moduleBuilder.installModule(JarUtil.createJarFile(rarFile), earContext, module); + moduleBuilder.installModule(module.getModuleFile(), earContext, module); } }; executeTestBuildModule(action); @@ -104,7 +101,7 @@ return rarFile; } public void install(ModuleBuilder moduleBuilder, EARContext earContext, Module module) throws Exception { - moduleBuilder.installModule(JarUtil.createJarFile(rarFile), earContext, module); + moduleBuilder.installModule(module.getModuleFile(), earContext, module); } }; executeTestBuildModule(action); @@ -126,12 +123,13 @@ Thread.currentThread().setContextClassLoader(cl); - Module module = moduleBuilder.createModule(null, JarUtil.createJarFile(action.getRARFile())); + Module module = moduleBuilder.createModule(null, DeploymentUtil.createJarFile(action.getRARFile())); assertEquals(j2eeModuleName, module.getConfigId().toString()); - File carFile = File.createTempFile("RARTest", ".car"); + File tempDir = null; try { - EARContext earContext = new EARContext(new JarOutputStream(new FileOutputStream(carFile)), + tempDir = DeploymentUtil.createTempDir(); + EARContext earContext = new EARContext(tempDir, module.getConfigId(), module.getType(), module.getParentId(), @@ -151,13 +149,10 @@ moduleBuilder.addGBeans(earContext, module, cl); earContext.close(); - File tempdir = new File(System.getProperty("java.io.tmpdir")); - File unpackedDir = new File(tempdir, "OpenEJBTest-Unpacked"); - LocalConfigStore.unpack(unpackedDir, new FileInputStream(carFile)); - - verifyDeployment(unpackedDir, oldCl, j2eeDomainName, j2eeServerName, j2eeApplicationName, j2eeModuleName, resourceAdapterName); + verifyDeployment(tempDir, oldCl, j2eeDomainName, j2eeServerName, j2eeApplicationName, j2eeModuleName, resourceAdapterName); } finally { - carFile.delete(); + module.close(); + DeploymentUtil.recursiveDelete(tempDir); } } 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 Mon Oct 4 15:54:53 2004 @@ -17,15 +17,13 @@ package org.apache.geronimo.deployment; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.jar.Attributes; -import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -import java.util.zip.ZipEntry; import org.apache.geronimo.deployment.service.ServiceConfigBuilder; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.deployment.xbeans.ConfigurationDocument; import org.apache.geronimo.deployment.xbeans.ConfigurationType; import org.apache.geronimo.system.configuration.LocalConfigStore; @@ -137,29 +135,54 @@ // attribute that indicates to a JSR-88 tool that we have a Deployment factory mainAttributes.putValue("J2EE-DeploymentFactory-Implementation-Class", deploymentFactory); - // build and install the deployer-system configuration // write the deployer system out to a jar - File outputFile = new File(deployerJar); - JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(outputFile)), manifest); + + // create a temp directory to build into + File tempDir = null; try { - // add the startup jar entry which allows us to locate the startup directory - jos.putNextEntry(new ZipEntry("META-INF/startup-jar")); - jos.closeEntry(); + tempDir = DeploymentUtil.createTempDir(); + + // build the deployer-system configuration into the tempDir + builder.buildConfiguration(deployerSystemConfig, null, tempDir); + + // Write the manifest + File metaInf = new File(tempDir, "META-INF"); + metaInf.mkdirs(); + FileOutputStream out = null; + try { + out = new FileOutputStream(new File(metaInf, "MANIFEST.MF")); + manifest.write(out); + } finally { + DeploymentUtil.close(out); + } + + // add the startup file which allows us to locate the startup directory + File startupJarTag = new File(metaInf, "startup-jar"); + startupJarTag.createNewFile(); + + // jar up the directory + DeploymentUtil.jarDirectory(tempDir, new File(deployerJar)); - // add the deployment system configuration to the jar - builder.buildConfiguration(jos, deployerSystemConfig); + // delete the startup file before moving this to the config store + startupJarTag.delete(); + + // install the configuration + configStore.install(tempDir); } finally { - jos.close(); + DeploymentUtil.recursiveDelete(tempDir); } - configStore.install(outputFile.toURL()); // build and install the j2ee-deployer configuration - File tempFile = File.createTempFile("j2ee-deployer", ".car"); try { - builder.buildConfiguration(tempFile, manifest, j2eeDeployerConfig, null); - configStore.install(tempFile.toURL()); + tempDir = DeploymentUtil.createTempDir(); + + // build the j2ee-deployer configuration into the tempDir + builder.buildConfiguration(j2eeDeployerConfig, null, tempDir); + + // install the configuration + configStore.install(tempDir); } finally { - tempFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } finally { Thread.currentThread().setContextClassLoader(oldCL); 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 Mon Oct 4 15:54:53 2004 @@ -19,9 +19,8 @@ import java.io.File; import java.io.IOException; -import java.util.jar.JarFile; -import java.util.jar.Manifest; import java.util.List; +import java.util.jar.JarFile; /** * @version $Rev$ $Date$ @@ -40,12 +39,11 @@ /** * Build a configuration from a local file * - * @param outfile the file to write the configuration to - * @param manifest the manifest to add to the output file * @param plan the deployment plan * @param module the module to build + * @param outfile the file to write the configuration to * @throws IOException if there was a problem reading or writing the files * @throws DeploymentException if there was a problem with the configuration */ - List buildConfiguration(File outfile, Manifest manifest, Object plan, JarFile module) throws IOException, DeploymentException; + List buildConfiguration(Object plan, JarFile module, File outfile) 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 Mon Oct 4 15:54:53 2004 @@ -19,6 +19,7 @@ import java.io.File; import java.io.IOException; +import java.io.FileOutputStream; import java.net.URI; import java.util.Collection; import java.util.Iterator; @@ -34,8 +35,7 @@ import org.apache.commons.cli.Options; 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.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.kernel.config.ConfigurationStore; @@ -67,29 +67,38 @@ */ public void deploy(String[] args) throws Exception { Command cmd = parseArgs(args); - if (cmd == null) { - return; - } + try { + if (cmd == null) { + return; + } - File planFile = cmd.planFile; - File module = cmd.module; - File carfile = cmd.carfile; - boolean install = cmd.install; - String mainClass = cmd.mainClass; - String classPath = cmd.classPath; + File planFile = cmd.planFile; + File module = cmd.moduleFile; + File carfile = cmd.carFile; + boolean install = cmd.install; + String mainClass = cmd.mainClass; + String classPath = cmd.classPath; - List objectNames = deploy(planFile, module, carfile, install, mainClass, classPath); - if (!objectNames.isEmpty()) { - Iterator iterator = objectNames.iterator(); - System.out.println("Deployed " + iterator.next()); - while (iterator.hasNext()) { - System.out.println(" " + iterator.next()); + List objectNames = deploy(planFile, module, carfile, install, mainClass, classPath); + if (!objectNames.isEmpty()) { + Iterator iterator = objectNames.iterator(); + System.out.println("Server URI: " + iterator.next()); + while (iterator.hasNext()) { + System.out.println("Client URI: " + iterator.next()); + } + } + } finally { + if (cmd.isPlanFileTemp) { + cmd.planFile.delete(); + } + if (cmd.isModuleFileTemp) { + cmd.moduleFile.delete(); } } } - public List deploy(File planFile, File moduleFile, File carfile, boolean install, String mainClass, String classPath) throws DeploymentException { + public List deploy(File planFile, File moduleFile, File targetFile, boolean install, String mainClass, String classPath) throws DeploymentException { if (planFile == null && moduleFile == null) { throw new DeploymentException("No plan or module specified"); } @@ -97,56 +106,79 @@ JarFile module = null; if (moduleFile != null) { try { - module = JarUtil.createJarFile(moduleFile); + module = DeploymentUtil.createJarFile(moduleFile); } catch (IOException e) { throw new DeploymentException("Cound not open module file: " + moduleFile.getAbsolutePath(), e); } } - Object plan = null; - ConfigurationBuilder builder = null; - for (Iterator i = builders.iterator(); i.hasNext();) { - ConfigurationBuilder candidate = (ConfigurationBuilder) i.next(); - plan = candidate.getDeploymentPlan(planFile, module); - if (plan != null) { - builder = candidate; - break; - } - } - if (builder == null) { - throw new DeploymentException("No deployer found for this plan type: " + planFile); - } - - boolean saveOutput; - if (carfile == null) { - saveOutput = false; + File tempDir = null; + try { + Object plan = null; + ConfigurationBuilder builder = null; + for (Iterator i = builders.iterator(); i.hasNext();) { + ConfigurationBuilder candidate = (ConfigurationBuilder) i.next(); + plan = candidate.getDeploymentPlan(planFile, module); + if (plan != null) { + builder = candidate; + break; + } + } + if (builder == null) { + throw new DeploymentException("No deployer found for this plan type: " + planFile); + } + + // create a temp dir to write the configuration during the building proces try { - carfile = FileUtil.createTempFile(); + tempDir = DeploymentUtil.createTempDir(); } catch (IOException e) { throw new DeploymentException("Unable to create temp file for deployment", e); } - } else { - saveOutput = true; - } - Manifest manifest = new Manifest(); - Attributes mainAttributes = manifest.getMainAttributes(); - mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); - if (mainClass != null) { - mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), mainClass); - } - if (classPath != null) { - mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), classPath); - } + // create te meta-inf dir + File metaInf = new File(tempDir, "META-INF"); + metaInf.mkdirs(); + + // create the manifest + Manifest manifest = new Manifest(); + Attributes mainAttributes = manifest.getMainAttributes(); + mainAttributes.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + if (mainClass != null) { + mainAttributes.putValue(Attributes.Name.MAIN_CLASS.toString(), mainClass); + } + if (classPath != null) { + mainAttributes.putValue(Attributes.Name.CLASS_PATH.toString(), classPath); + } + + // Write the manifest + FileOutputStream out = null; + try { + out = new FileOutputStream(new File(metaInf, "MANIFEST.MF")); + manifest.write(out); + } finally { + DeploymentUtil.close(out); + } - try { // this is a bit weird and should be rethougth but it works - List childURIs = builder.buildConfiguration(carfile, manifest, plan, module); + List childURIs = builder.buildConfiguration(plan, module, tempDir); try { + if (targetFile != null) { + // add the startup tag file which allows us to locate the startup directory + File startupJarTag = new File(metaInf, "startup-jar"); + if (mainClass != null) { + startupJarTag.createNewFile(); + } + + // jar up the directory + DeploymentUtil.jarDirectory(tempDir, targetFile); + + // remove the startup tag file so it doesn't accidently leak into a normal classloader + startupJarTag.delete(); + } if (install) { - URI uri = store.install(carfile.toURL()); + URI uri = store.install(tempDir); List deployedURIs = new ArrayList(childURIs.size() + 1); deployedURIs.add(uri.toString()); deployedURIs.addAll(childURIs); @@ -158,15 +190,18 @@ throw new DeploymentException(e); } } catch (DeploymentException e) { - saveOutput = false; + if (targetFile != null) { + targetFile.delete(); + } throw e; } catch (Exception e) { - saveOutput = false; + if (targetFile != null) { + targetFile.delete(); + } throw new DeploymentException(e); } finally { - if (!saveOutput) { - carfile.delete(); - } + DeploymentUtil.recursiveDelete(tempDir); + DeploymentUtil.close(module); } } @@ -187,54 +222,89 @@ } Command command = new Command(); - command.install = cmd.hasOption('I'); - if (cmd.hasOption('o')) { - command.carfile = new File(cmd.getOptionValue('o')); - } - if (cmd.hasOption('p')) { - command.planFile = getFile(cmd.getOptionValue('p')); - } - if (cmd.hasOption('m')) { - command.module = getFile(cmd.getOptionValue('m')); - } + try { + command.install = cmd.hasOption('I'); + if (cmd.hasOption('o')) { + URI uri = getURI(cmd.getOptionValue('o')); + if (!"file".equals(uri.getScheme())) { + throw new DeploymentException("Output file can only be written to the local file system"); + } + command.carFile = new File(uri); + } + if (cmd.hasOption('p')) { + URI uri = getURI(cmd.getOptionValue('p')); + if ("file".equals(uri.getScheme())) { + command.planFile = new File(uri); + command.isPlanFileTemp = false; + } else { + try { + command.planFile = DeploymentUtil.toTempFile(uri.toURL()); + } catch (IOException e) { + throw new DeploymentException("Invalid plan file location: " + uri, e); + } + command.isPlanFileTemp = true; + } + } + if (cmd.hasOption('m')) { + URI uri = getURI(cmd.getOptionValue('m')); + if ("file".equals(uri.getScheme())) { + command.moduleFile = new File(uri); + command.isModuleFileTemp = false; + } else { + try { + command.moduleFile = DeploymentUtil.toTempFile(uri.toURL()); + } catch (IOException e) { + throw new DeploymentException("Invalid module file location: " + uri, e); + } + command.isModuleFileTemp = true; + } + } - if (command.module == null && command.planFile == null) { - System.err.println("No plan or module specified"); - return null; - } - if (cmd.hasOption("mainClass")) { - command.mainClass = cmd.getOptionValue("mainClass"); - } - if (cmd.hasOption("classPath")) { - command.classPath = cmd.getOptionValue("classPath"); + if (command.moduleFile == null && command.planFile == null) { + System.err.println("No plan or module specified"); + return null; + } + if (cmd.hasOption("mainClass")) { + command.mainClass = cmd.getOptionValue("mainClass"); + } + if (cmd.hasOption("classPath")) { + command.classPath = cmd.getOptionValue("classPath"); + } + return command; + } catch (Throwable e) { + if (command.isPlanFileTemp) { + command.planFile.delete(); + } + if (command.isModuleFileTemp) { + command.moduleFile.delete(); + } + + if (e instanceof DeploymentException) { + throw (DeploymentException) e; + } else if (e instanceof RuntimeException) { + throw (RuntimeException) e; + } else if (e instanceof Error) { + throw (Error) e; + } + throw new DeploymentException(e); } - return command; } - private static File getFile(String location) throws DeploymentException { - File f = new File(location); - if (f.exists() && f.canRead()) { - 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 URI getURI(String location) throws DeploymentException { + URI uri = new File(".").toURI().resolve(location); + if (!"file".equals(uri.getScheme()) && uri.getPath().endsWith("/")) { + throw new DeploymentException("Unpacked modules can only be loaded from the local file system"); + } + return uri; } private static class Command { private boolean install; - private File carfile; - private File module; + private File carFile; + private File moduleFile; + private boolean isModuleFileTemp = false; private File planFile; + private boolean isPlanFileTemp = false; private String mainClass; private String classPath; } Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java ============================================================================== --- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java (original) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentContext.java Mon Oct 4 15:54:53 2004 @@ -17,39 +17,39 @@ package org.apache.geronimo.deployment; +import java.io.ByteArrayInputStream; import java.io.File; import java.io.FileInputStream; +import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.io.ObjectOutputStream; -import java.net.MalformedURLException; +import java.io.OutputStream; import java.net.URI; import java.net.URL; +import java.net.MalformedURLException; import java.net.URLClassLoader; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; -import java.util.LinkedList; import java.util.List; import java.util.Map; import java.util.Set; -import java.util.jar.JarOutputStream; +import java.util.ArrayList; +import java.util.jar.JarFile; import java.util.zip.ZipEntry; -import java.util.zip.ZipInputStream; - +import java.util.zip.ZipFile; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; -import org.apache.geronimo.deployment.util.FileUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.jmx.GBeanMBean; import org.apache.geronimo.kernel.Kernel; +import org.apache.geronimo.kernel.repository.Repository; import org.apache.geronimo.kernel.config.Configuration; import org.apache.geronimo.kernel.config.ConfigurationManager; import org.apache.geronimo.kernel.config.ConfigurationModuleType; -import org.apache.geronimo.kernel.repository.Repository; /** * @version $Rev$ $Date$ @@ -64,24 +64,35 @@ private final GBeanMBean config; private final Map gbeans = new HashMap(); private final Set dependencies = new LinkedHashSet(); - private final Set classPath = new LinkedHashSet(); - private final Map includes = new HashMap(); - private final LinkedList outputStreams = new LinkedList(); + private final LinkedHashSet classPath = new LinkedHashSet(); + private final File baseDir; + private final URI baseUri; private final byte[] buffer = new byte[4096]; private final List ancestors; private final ClassLoader parentCL; - private final Collection tmpfiles = new ArrayList(); - public DeploymentContext(JarOutputStream jos, URI id, ConfigurationModuleType type, URI parentID, Kernel kernel) throws MalformedObjectNameException, DeploymentException { - this.configID = id; + public DeploymentContext(File baseDir, URI configID, ConfigurationModuleType type, URI parentID, Kernel kernel) throws MalformedObjectNameException, DeploymentException { + assert baseDir != null: "baseDir is null"; + assert configID != null: "configID is null"; + assert type != null: "type is null"; + + this.configID = configID; this.type = type; - outputStreams.addLast(jos); this.kernel = kernel; + if (!baseDir.exists()) { + baseDir.mkdirs(); + } + if (!baseDir.isDirectory()) { + throw new DeploymentException("Base directory is not a directory: " + baseDir.getAbsolutePath()); + } + this.baseDir = baseDir; + this.baseUri = baseDir.toURI(); + config = new GBeanMBean(Configuration.GBEAN_INFO); try { - config.setAttribute("ID", id); + config.setAttribute("ID", configID); config.setAttribute("type", type); config.setAttribute("parentID", parentID); } catch (Exception e) { @@ -130,12 +141,9 @@ public ConfigurationModuleType getType() { return type; } - - public JarOutputStream getJos() { - if (outputStreams.isEmpty()) { - throw new IllegalStateException(); - } - return (JarOutputStream) outputStreams.getLast(); + + public File getBaseDir() { + return baseDir; } public void addGBean(ObjectName name, GBeanMBean gbean) { @@ -146,126 +154,132 @@ dependencies.add(uri); } - public void addInclude(URI path, URL url) throws IOException { - InputStream is = url.openStream(); - try { - addFile(path, is); - } finally { - is.close(); - } - addToClassPath(path, url); + public void addIncludeAsPackedJar(URI targetPath, JarFile jarFile) throws IOException { + File targetFile = getTargetFile(targetPath); + DeploymentUtil.copyToPackedJar(jarFile, targetFile); + classPath.add(targetPath); } - public File addStreamInclude(URI path, InputStream is) throws IOException { - File tmp = FileUtil.toTempFile(is); - addInclude(path, tmp.toURL()); - tmpfiles.add(tmp); - return tmp; + public void addInclude(URI targetPath, ZipFile zipFile, ZipEntry zipEntry) throws IOException { + File targetFile = getTargetFile(targetPath); + addFile(targetFile, zipFile, zipEntry); + classPath.add(targetPath); } - public void addArchive(URI path, ZipInputStream archive) throws IOException { - ZipEntry src; - while ((src = archive.getNextEntry()) != null) { - URI target = path.resolve(src.getName()); - addFile(target, archive); - } + public void addInclude(URI targetPath, URL source) throws IOException { + File targetFile = getTargetFile(targetPath); + addFile(targetFile, source); + classPath.add(targetPath); } - public void addToClassPath(URI path, URL url) { - classPath.add(path); - includes.put(path, url); + public void addInclude(URI targetPath, File source) throws IOException { + File targetFile = getTargetFile(targetPath); + addFile(targetFile, source); + classPath.add(targetPath); } - public ClassLoader getClassLoader(Repository repository) throws DeploymentException { - // save the dependencies and classpath - try { - config.setReferencePatterns("Repositories", Collections.singleton(new ObjectName("*:role=Repository,*"))); - config.setAttribute("dependencies", new ArrayList(dependencies)); - config.setAttribute("classPath", new ArrayList(classPath)); - } catch (Exception e) { - throw new DeploymentException("Unable to initialize Configuration", e); - } - - URL[] urls = new URL[dependencies.size() + classPath.size()]; - int j = 0; - for (Iterator i = dependencies.iterator(); i.hasNext();) { - URI uri = (URI) i.next(); - try { - urls[j++] = repository.getURL(uri); - } catch (MalformedURLException e) { - throw new DeploymentException(e); - } - } + public void addFile(URI targetPath, ZipFile zipFile, ZipEntry zipEntry) throws IOException { + addFile(getTargetFile(targetPath), zipFile, zipEntry); + } - for (Iterator i = classPath.iterator(); i.hasNext();) { - URI uri = (URI) i.next(); - urls[j++] = (URL) includes.get(uri); - } + public void addFile(URI targetPath, URL source) throws IOException { + addFile(getTargetFile(targetPath), source); + } - return new URLClassLoader(urls, parentCL); + public void addFile(URI targetPath, File source) throws IOException { + addFile(getTargetFile(targetPath), source); } - public void nest(URI path) throws IOException { - JarOutputStream jos = getJos(); - jos.putNextEntry(new ZipEntry(path.getPath())); - JarOutputStream nestedStream = new JarOutputStream(jos); - outputStreams.addLast(nestedStream); + public void addFile(URI targetPath, String source) throws IOException { + addFile(getTargetFile(targetPath), new ByteArrayInputStream(source.getBytes())); } - public void unnest() throws IOException { - if (outputStreams.size() < 2) { - throw new IllegalStateException("Conext is not currently nested"); + private void addFile(File targetFile, ZipFile zipFile, ZipEntry zipEntry) throws IOException { + if (zipEntry.isDirectory()) { + targetFile.mkdirs(); + } else { + InputStream is = zipFile.getInputStream(zipEntry); + try { + addFile(targetFile, is); + } finally { + DeploymentUtil.close(is); + } } - JarOutputStream jos = (JarOutputStream) outputStreams.removeLast(); + } + + private void addFile(File targetFile, URL source) throws IOException { + InputStream in = null; try { - jos.flush(); + in = source.openStream(); + addFile(targetFile, in); } finally { - jos.close(); + DeploymentUtil.close(in); } } - public void addFile(URI path, File source) throws IOException { - InputStream in = new FileInputStream(source); + private void addFile(File targetFile, File source) throws IOException { + InputStream in = null; try { - addFile(path, in); + in = new FileInputStream(source); + addFile(targetFile, in); } finally { - in.close(); + DeploymentUtil.close(in); } } - - public void addFile(URI path, InputStream source) throws IOException { - JarOutputStream jos = getJos(); - jos.putNextEntry(new ZipEntry(path.getPath())); + + private void addFile(File targetFile, InputStream source) throws IOException { + targetFile.getParentFile().mkdirs(); + OutputStream out = null; try { + out = new FileOutputStream(targetFile); int count; while ((count = source.read(buffer)) > 0) { - jos.write(buffer, 0, count); + out.write(buffer, 0, count); } } finally { - jos.closeEntry(); + DeploymentUtil.close(out); } } - public void close() throws IOException, DeploymentException { - if (outputStreams.size() != 1) { - throw new IllegalStateException("Context must be unnested before being closed"); - } + private File getTargetFile(URI targetPath) { + assert !targetPath.isAbsolute() : "targetPath is absolute"; + assert !targetPath.isOpaque() : "targetPath is opaque"; + return new File(baseUri.resolve(targetPath)); + } - JarOutputStream jos = getJos(); - saveConfiguration(); + public ClassLoader getClassLoader(Repository repository) throws DeploymentException { + // save the dependencies and classpath try { - jos.flush(); - } finally { - jos.close(); + config.setReferencePatterns("Repositories", Collections.singleton(new ObjectName("*:role=Repository,*"))); + config.setAttribute("dependencies", new ArrayList(dependencies)); + config.setAttribute("classPath", new ArrayList(classPath)); + } catch (Exception e) { + throw new DeploymentException("Unable to initialize Configuration", e); } - for (Iterator iterator = tmpfiles.iterator(); iterator.hasNext();) { - try { - ((File) iterator.next()).delete(); - } catch (Exception e) { + // shouldn't user classpath come before dependencies? + URL[] urls = new URL[dependencies.size() + classPath.size()]; + try { + int index = 0; + for (Iterator iterator = dependencies.iterator(); iterator.hasNext();) { + URI uri = (URI) iterator.next(); + urls[index++] = repository.getURL(uri); + } + + for (Iterator i = classPath.iterator(); i.hasNext();) { + URI path = (URI) i.next(); + urls[index++] = getTargetFile(path).toURL(); } + } catch (MalformedURLException e) { + throw new DeploymentException(e); } + return new URLClassLoader(urls, parentCL); + } + + public void close() throws IOException, DeploymentException { + saveConfiguration(); + if (kernel != null && ancestors != null && ancestors.size() > 0) { try { kernel.stopGBean((ObjectName) ancestors.get(0)); @@ -276,8 +290,6 @@ } private void saveConfiguration() throws IOException, DeploymentException { - JarOutputStream jos = getJos(); - // persist all the GBeans in this Configuration try { config.setAttribute("gBeanState", Configuration.storeGBeans(gbeans)); @@ -286,19 +298,23 @@ } // save the persisted form in the archive - jos.putNextEntry(new ZipEntry("META-INF/config.ser")); + File metaInf = new File(baseDir, "META-INF"); + metaInf.mkdirs(); + File configSer = new File(metaInf, "config.ser"); + + ObjectOutputStream out = null; try { - ObjectOutputStream oos = new ObjectOutputStream(jos); + out = new ObjectOutputStream(new FileOutputStream(configSer)); try { - Configuration.storeGMBeanState(config, oos); + Configuration.storeGMBeanState(config, out); } catch (IOException e) { throw e; } catch (Exception e) { throw new DeploymentException("Unable to save Configuration state", e); } - oos.flush(); } finally { - jos.closeEntry(); + DeploymentUtil.flush(out); + DeploymentUtil.close(out); } } } Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java ============================================================================== --- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java (original) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/plugin/local/DistributeCommand.java Mon Oct 4 15:54:53 2004 @@ -25,15 +25,14 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import java.net.URI; import javax.enterprise.deploy.shared.CommandType; import javax.enterprise.deploy.spi.Target; import javax.enterprise.deploy.spi.TargetModuleID; import javax.management.ObjectName; -import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; -import org.apache.geronimo.deployment.util.FileUtil; import org.apache.geronimo.deployment.DeploymentException; +import org.apache.geronimo.deployment.plugin.TargetModuleIDImpl; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.kernel.KernelMBean; /** @@ -73,11 +72,11 @@ try { if (spool) { if (moduleStream != null) { - moduleArchive = FileUtil.createTempFile(); + moduleArchive = DeploymentUtil.createTempFile(); copyTo(moduleArchive, moduleStream); } if (deploymentStream != null) { - deploymentPlan = FileUtil.createTempFile(); + deploymentPlan = DeploymentUtil.createTempFile(); copyTo(deploymentPlan, deploymentStream); } } 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 Mon Oct 4 15:54:53 2004 @@ -17,9 +17,7 @@ package org.apache.geronimo.deployment.service; -import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.io.InputStream; import java.net.MalformedURLException; @@ -27,13 +25,10 @@ import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; -import java.util.jar.Attributes; +import java.util.Collections; +import java.util.List; import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; import java.util.jar.Manifest; -import java.util.zip.ZipEntry; -import java.util.List; -import java.util.Collections; import javax.management.MalformedObjectNameException; import org.apache.geronimo.deployment.ConfigurationBuilder; @@ -49,7 +44,6 @@ import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.ConfigurationModuleType; import org.apache.geronimo.kernel.repository.Repository; -import org.apache.xmlbeans.XmlObject; import org.apache.xmlbeans.XmlException; /** @@ -84,29 +78,7 @@ } } - public List buildConfiguration(File outfile, Manifest manifest, Object plan, JarFile unused) throws IOException, DeploymentException { - FileOutputStream fos = new FileOutputStream(outfile); - try { - JarOutputStream os = new JarOutputStream(new BufferedOutputStream(fos), manifest); - - // if this is an executable jar add the startup jar finder file - if (manifest.getMainAttributes().containsKey(Attributes.Name.MAIN_CLASS)) { - os.putNextEntry(new ZipEntry("META-INF/startup-jar")); - os.closeEntry(); - } - - buildConfiguration(os, (XmlObject) plan); - return Collections.EMPTY_LIST; - } finally { - fos.close(); - } - - } - - // - // For use by the bootstrap deployer - // - public void buildConfiguration(JarOutputStream os, XmlObject plan) throws DeploymentException, IOException { + public List buildConfiguration(Object plan, JarFile unused, File outfile) throws IOException, DeploymentException { ConfigurationType configType = (ConfigurationType) plan; URI configID; try { @@ -127,7 +99,7 @@ DeploymentContext context = null; try { - context = new DeploymentContext(os, configID, ConfigurationModuleType.SERVICE, parentID, kernel); + context = new DeploymentContext(outfile, configID, ConfigurationModuleType.SERVICE, parentID, kernel); } catch (MalformedObjectNameException e) { throw new DeploymentException(e); } @@ -140,7 +112,8 @@ } context.close(); - os.flush(); + + return Collections.EMPTY_LIST; } private void addIncludes(DeploymentContext context, ConfigurationType configType) throws DeploymentException { Added: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java ============================================================================== --- (empty file) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/DeploymentUtil.java Mon Oct 4 15:54:53 2004 @@ -0,0 +1,356 @@ +/** + * + * Copyright 2004 The Apache Software Foundation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.geronimo.deployment.util; + +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.Reader; +import java.io.Writer; +import java.net.URL; +import java.net.MalformedURLException; +import java.util.Collection; +import java.util.Collections; +import java.util.Enumeration; +import java.util.LinkedList; +import java.util.jar.JarFile; +import java.util.jar.JarOutputStream; +import java.util.jar.Manifest; +import java.util.zip.ZipEntry; + +/** + * @version $Revision$ $Date$ + */ +public final class DeploymentUtil { + private DeploymentUtil() { + } + + public static final File DUMMY_JAR_FILE; + static { + try { + DUMMY_JAR_FILE = DeploymentUtil.createTempFile(); + new JarOutputStream(new FileOutputStream(DeploymentUtil.DUMMY_JAR_FILE), new Manifest()).close(); + } catch (IOException e) { + throw new ExceptionInInitializerError(e); + } + } + + // be careful to clean up the temp directory + public static File createTempDir() throws IOException { + File tempDir = File.createTempFile("geronimo-deployment-", ".tmp"); + tempDir.delete(); + tempDir.mkdirs(); + return tempDir; + } + + // be careful to clean up the temp file... we tell the vm to delete this on exit + // but VMs can't be trusted to acutally delete the file + public static File createTempFile() throws IOException { + File tempFile = File.createTempFile("geronimo-deployment-", "tmp"); + tempFile.deleteOnExit(); + return tempFile; + } + + public static void copyFile(File source, File destination) throws IOException { + InputStream in = null; + OutputStream out = null; + try { + in = new FileInputStream(source); + out = new FileOutputStream(destination); + writeAll(in, out); + } finally { + close(in); + close(out); + } + } + + private static void writeAll(InputStream in, OutputStream out) throws IOException { + byte[] buffer = new byte[4096]; + int count; + while ((count = in.read(buffer)) > 0) { + out.write(buffer, 0, count); + } + out.flush(); + } + public static File toTempFile(JarFile jarFile, String path) throws IOException { + return toTempFile(createJarURL(jarFile, path)); + } + + public static File toTempFile(URL url) throws IOException { + InputStream in = null; + OutputStream out = null; + try { + in = url.openStream(); + + File tempFile = createTempFile(); + out = new FileOutputStream(tempFile); + + writeAll(in, out); + return tempFile; + } finally { + close(out); + close(in); + } + } + + public static String readAll(URL url) throws IOException { + Reader reader = null; + try { + reader = new InputStreamReader(url.openStream()); + + char[] buffer = new char[4000]; + StringBuffer out = new StringBuffer(); + for(int count = reader.read(buffer); count >= 0; count = reader.read(buffer)) { + out.append(buffer, 0, count); + } + return out.toString(); + } finally { + close(reader); + } + } + + // be careful with this method as it can leave a temp lying around + public static File toFile(JarFile jarFile, String path) throws IOException { + if (jarFile instanceof UnpackedJarFile) { + File baseDir = ((UnpackedJarFile) jarFile).getBaseDir(); + File file = new File(baseDir, path); + if (!file.isFile()) { + throw new IOException("No such file: " + file.getAbsolutePath()); + } + return file; + } else { + String urlString = "jar:" + new File(jarFile.getName()).toURL() + "!/" + path; + return toTempFile(new URL(urlString)); + } + } + + public static URL createJarURL(JarFile jarFile, String path) throws MalformedURLException { + if (jarFile instanceof UnpackedJarFile) { + File baseDir = ((UnpackedJarFile) jarFile).getBaseDir(); + return new File(baseDir, path).toURL(); + } else { + String urlString = "jar:" + new File(jarFile.getName()).toURL() + "!/" + path; + return new URL(urlString); + } + } + + public static JarFile createJarFile(File jarFile) throws IOException { + if (jarFile.isDirectory()) { + return new UnpackedJarFile(jarFile); + } else { + return new JarFile(jarFile); + } + } + + public static void copyToPackedJar(JarFile inputJar, File outputFile) throws IOException { + if (inputJar.getClass() == JarFile.class) { + // this is a plain old jar... nothign special + copyFile(new File(inputJar.getName()), outputFile); + } else if (inputJar instanceof NestedJarFile && ((NestedJarFile)inputJar).isPacked()) { + NestedJarFile nestedJarFile = (NestedJarFile)inputJar; + JarFile baseJar = nestedJarFile.getBaseJar(); + String basePath = nestedJarFile.getBasePath(); + if (baseJar instanceof UnpackedJarFile) { + // our target jar is just a file in upacked jar (a plain old directory)... now + // we just need to find where it is and copy it to the outptu + copyFile(((UnpackedJarFile)baseJar).getFile(basePath), outputFile); + } else { + // out target is just a plain old jar file directly accessabel from the file system + copyFile(new File(baseJar.getName()), outputFile); + } + } else { + // copy out the module contents to a standalone jar file (entry by entry) + JarOutputStream out = null; + try { + out = new JarOutputStream(new FileOutputStream(outputFile)); + byte[] buffer = new byte[4096]; + Enumeration entries = inputJar.entries(); + while (entries.hasMoreElements()) { + ZipEntry entry = (ZipEntry) entries.nextElement(); + InputStream in = inputJar.getInputStream(entry); + try { + out.putNextEntry(new ZipEntry(entry.getName())); + try { + int count; + while ((count = in.read(buffer)) > 0) { + out.write(buffer, 0, count); + } + } finally { + out.closeEntry(); + } + } finally { + close(in); + } + } + } finally { + close(out); + } + } + } + + public static void jarDirectory(File sourceDirecotry, File destinationFile) throws IOException { + JarFile inputJar = new UnpackedJarFile(sourceDirecotry); + try { + copyToPackedJar(inputJar, destinationFile); + } finally { + close(inputJar); + } + } + + public static void recursiveDelete(File root) { + if (root == null) { + return; + } + + if (root.isDirectory()) { + File[] files = root.listFiles(); + if (files != null) { + for (int i = 0; i < files.length; i++) { + File file = files[i]; + if (file.isDirectory()) { + recursiveDelete(file); + } else { + file.delete(); + } + } + } + } + root.delete(); + } + + public static Collection listRecursiveFiles(File file) { + LinkedList list = new LinkedList(); + listRecursiveFiles(file, list); + return Collections.unmodifiableCollection(list); + } + + public static void listRecursiveFiles(File file, Collection collection) { + File[] files = file.listFiles(); + if ( null == files ) { + return; + } + for (int i = 0; i < files.length; i++) { + if (files[i].isDirectory()) { + listRecursiveFiles(files[i], collection); + } else { + collection.add(files[i]); + } + } + } + + public static void flush(OutputStream thing) { + if (thing != null) { + try { + thing.flush(); + } catch(Exception ignored) { + } + } + } + + public static void flush(Writer thing) { + if (thing != null) { + try { + thing.flush(); + } catch(Exception ignored) { + } + } + } + + public static void close(JarFile thing) { + if (thing != null) { + try { + thing.close(); + } catch(Exception ignored) { + } + } + } + + public static void close(InputStream thing) { + if (thing != null) { + try { + thing.close(); + } catch(Exception ignored) { + } + } + } + + public static void close(OutputStream thing) { + if (thing != null) { + try { + thing.close(); + } catch(Exception ignored) { + } + } + } + + public static void close(Reader thing) { + if (thing != null) { + try { + thing.close(); + } catch(Exception ignored) { + } + } + } + + public static void close(Writer thing) { + if (thing != null) { + try { + thing.close(); + } catch(Exception ignored) { + } + } + } + + public static final class EmptyInputStream extends InputStream { + public int read() { + return -1; + } + + public int read(byte b[]) { + return -1; + } + + public int read(byte b[], int off, int len) { + return -1; + } + + public long skip(long n) { + return 0; + } + + public int available() { + return 0; + } + + public void close() { + } + + public synchronized void mark(int readlimit) { + } + + public synchronized void reset() { + } + + public boolean markSupported() { + return false; + } + } +} 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 Mon Oct 4 15:54:53 2004 @@ -33,13 +33,15 @@ * @version $Rev$ $Date$ */ public class NestedJarFile extends JarFile { - private final JarFile baseJar; - private final String basePath; + private JarFile baseJar; + private String basePath; + private boolean isClosed = false; private boolean manifestLoaded = false; private Manifest manifest; + private File tempFile; public NestedJarFile(JarFile jarFile, String path) throws IOException { - super(JarUtil.DUMMY_JAR_FILE); this.close(); + super(DeploymentUtil.DUMMY_JAR_FILE); // verify that the jar actually contains that path JarEntry targetEntry = jarFile.getJarEntry(path + "/"); @@ -65,7 +67,7 @@ baseJar = new JarFile(targetFile); basePath = ""; } else { - File tempFile = FileUtil.toTempFile(jarFile.getInputStream(targetEntry), true); + tempFile = DeploymentUtil.toFile(jarFile, targetEntry.getName()); baseJar = new JarFile(tempFile); basePath = ""; } @@ -73,22 +75,38 @@ } public boolean isUnpacked() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } return basePath.length() > 0; } public boolean isPacked() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } return basePath.length() == 0; } public JarFile getBaseJar() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } return baseJar; } public String getBasePath() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } return basePath; } public Manifest getManifest() throws IOException { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + if (!manifestLoaded) { JarEntry manifestEntry = getBaseEntry("META-INF/MANIFEST.MF"); @@ -113,6 +131,10 @@ } public NestedJarEntry getNestedJarEntry(String name) { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + JarEntry baseEntry = getBaseEntry(name); if (baseEntry == null) { return null; @@ -121,14 +143,26 @@ } public JarEntry getJarEntry(String name) { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + return getNestedJarEntry(name); } public ZipEntry getEntry(String name) { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + return getNestedJarEntry(name); } public Enumeration entries() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + Collection baseEntries = Collections.list(baseJar.entries()); Collection entries = new LinkedList(); for (Iterator iterator = baseEntries.iterator(); iterator.hasNext();) { @@ -142,6 +176,10 @@ } public InputStream getInputStream(ZipEntry zipEntry) throws IOException { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } + JarEntry baseEntry; if (zipEntry instanceof NestedJarEntry) { baseEntry = ((NestedJarEntry)zipEntry).getBaseEntry(); @@ -152,7 +190,7 @@ if (baseEntry == null) { throw new IOException("Entry not found: name=" + baseEntry.getName()); } else if (baseEntry.isDirectory()) { - return new JarUtil.EmptyInputStream(); + return new DeploymentUtil.EmptyInputStream(); } return baseJar.getInputStream(baseEntry); } @@ -166,13 +204,36 @@ * @return -1 */ public int size() { + if (isClosed) { + throw new IllegalStateException("NestedJarFile is closed"); + } return -1; } public void close() throws IOException { + if (isClosed) { + return; + } + + isClosed = true; + try { + if (baseJar != null && isPacked()) { + baseJar.close(); + } + } finally { + baseJar = null; + basePath = null; + manifestLoaded = false; + manifest = null; + if (tempFile != null) { + tempFile.delete(); + tempFile = null; + } + } } protected void finalize() throws IOException { + close(); } private JarEntry getBaseEntry(String name) { Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/URLType.java ============================================================================== --- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/URLType.java (original) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/URLType.java Mon Oct 4 15:54:53 2004 @@ -59,9 +59,15 @@ } else { // we have a regular file - see if it contains a manifest try { - JarFile jar = new JarFile(file); - jar.getManifest(); - jar.close(); + JarFile jar = null; + try { + jar = new JarFile(file); + jar.getManifest(); + } finally { + if (jar != null) { + jar.close(); + } + } return PACKED_ARCHIVE; } catch (ZipException e) { return RESOURCE; Modified: geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/UnpackedJarFile.java ============================================================================== --- geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/UnpackedJarFile.java (original) +++ geronimo/trunk/modules/deployment/src/java/org/apache/geronimo/deployment/util/UnpackedJarFile.java Mon Oct 4 15:54:53 2004 @@ -39,12 +39,8 @@ private boolean manifestLoaded = false; private Manifest manifest; - public UnpackedJarFile(String name) throws IOException { - this(new File(name)); - } - public UnpackedJarFile(File baseDir) throws IOException { - super(JarUtil.DUMMY_JAR_FILE); + super(DeploymentUtil.DUMMY_JAR_FILE); this.baseDir = baseDir; if (!baseDir.isDirectory()) { throw new IOException("File must be a directory: file=" + baseDir.getAbsolutePath()); @@ -96,7 +92,7 @@ } public Enumeration entries() { - Collection files = FileUtil.listRecursiveFiles(baseDir); + Collection files = DeploymentUtil.listRecursiveFiles(baseDir); Manifest manifest = getManifestSafe(); LinkedList entries = new LinkedList(); @@ -121,7 +117,7 @@ if (file == null) { throw new IOException("Entry not found: name=" + file.getAbsolutePath()); } else if (file.isDirectory()) { - return new JarUtil.EmptyInputStream(); + return new DeploymentUtil.EmptyInputStream(); } return new FileInputStream(file); } Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/AppClientModule.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/AppClientModule.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/AppClientModule.java Mon Oct 4 15:54:53 2004 @@ -17,8 +17,6 @@ package org.apache.geronimo.j2ee.deployment; import java.net.URI; -import java.util.Collection; -import java.util.HashSet; import java.util.jar.JarFile; import org.apache.geronimo.kernel.config.ConfigurationModuleType; @@ -28,9 +26,6 @@ * @version $Rev: 46019 $ $Date: 2004-09-14 02:56:06 -0700 (Tue, 14 Sep 2004) $ */ public class AppClientModule extends Module { - - private final Collection resourceModules = new HashSet(); - private JarFile earFile; public AppClientModule(boolean standAlone, URI configId, URI parentId, JarFile moduleFile, String targetPath, XmlObject specDD, XmlObject vendorDD, String originalSpecDD) { @@ -47,10 +42,6 @@ public void setEarFile(JarFile earFile) { this.earFile = earFile; - } - - public Collection getResourceModules() { - return resourceModules; } } 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 Mon Oct 4 15:54:53 2004 @@ -16,13 +16,12 @@ */ package org.apache.geronimo.j2ee.deployment; -import java.io.BufferedOutputStream; import java.io.File; -import java.io.FileOutputStream; import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; +import java.net.MalformedURLException; import java.util.Collections; import java.util.Enumeration; import java.util.HashMap; @@ -30,12 +29,10 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.LinkedList; +import java.util.List; import java.util.Map; import java.util.Set; -import java.util.List; import java.util.jar.JarFile; -import java.util.jar.JarOutputStream; -import java.util.jar.Manifest; import java.util.zip.ZipEntry; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; @@ -43,8 +40,8 @@ import org.apache.geronimo.deployment.ConfigurationBuilder; import org.apache.geronimo.deployment.DeploymentException; 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.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.jmx.GBeanMBean; @@ -145,10 +142,9 @@ } private Object getEarPlan(File planFile, JarFile earFile) throws DeploymentException { - URL applicationXmlUrl = JarUtil.createJarURL(earFile, "META-INF/application.xml"); - ApplicationType application; try { + URL applicationXmlUrl = DeploymentUtil.createJarURL(earFile, "META-INF/application.xml"); XmlObject xmlObject = SchemaConversionUtils.parse(applicationXmlUrl); application = SchemaConversionUtils.convertToApplicationSchema(xmlObject).getApplication(); } catch (Exception e) { @@ -166,7 +162,7 @@ if (planFile != null) { gerApplicationDoc = GerApplicationDocument.Factory.parse(planFile); } else { - URL path = JarUtil.createJarURL(earFile, "META-INF/geronimo-application.xml"); + URL path = DeploymentUtil.createJarURL(earFile, "META-INF/geronimo-application.xml"); gerApplicationDoc = GerApplicationDocument.Factory.parse(path); } } catch (IOException e) { @@ -201,11 +197,26 @@ } // get the modules either the application plan or for a stand alone module from the specific deployer + // todo change module so you can extract the real module path back out.. then we can eliminate + // the moduleLocations and have addModules return the modules Set moduleLocations = new HashSet(); Set modules = new LinkedHashSet(); try { addModules(earFile, application, gerApplication, moduleLocations, modules); - } catch (IOException e) { + } catch (Throwable e) { + // close al the modules + for (Iterator iterator = modules.iterator(); iterator.hasNext();) { + Module module = (Module) iterator.next(); + module.close(); + } + + if (e instanceof DeploymentException) { + throw (DeploymentException)e; + } else if (e instanceof RuntimeException) { + throw (RuntimeException)e; + } else if (e instanceof Error) { + throw (Error)e; + } throw new DeploymentException(e); } @@ -243,18 +254,16 @@ return gerApplication; } - public List buildConfiguration(File outfile, Manifest manifest, Object plan, JarFile earFile) throws IOException, DeploymentException { + public List buildConfiguration(Object plan, JarFile earFile, File outfile) throws IOException, DeploymentException { ApplicationInfo applicationInfo = (ApplicationInfo) plan; - FileOutputStream fos = new FileOutputStream(outfile); try { List moduleIDs = new LinkedList(); // Create the output ear context - JarOutputStream os = new JarOutputStream(new BufferedOutputStream(fos)); EARContext earContext = null; ConfigurationModuleType applicationType = applicationInfo.getType(); try { - earContext = new EARContext(os, + earContext = new EARContext(outfile, applicationInfo.getConfigId(), applicationType, applicationInfo.getParentId(), @@ -277,7 +286,7 @@ for (Enumeration e = earFile.entries(); e.hasMoreElements();) { ZipEntry entry = (ZipEntry) e.nextElement(); if (!moduleLocations.contains(entry.getName())) { - earContext.addFile(URI.create(entry.getName()), earFile.getInputStream(entry)); + earContext.addFile(URI.create(entry.getName()), earFile, entry); } } } @@ -338,112 +347,140 @@ } earContext.close(); - os.flush(); return moduleIDs; } finally { - fos.close(); + Set modules = applicationInfo.getModules(); + for (Iterator iterator = modules.iterator(); iterator.hasNext();) { + Module module = (Module) iterator.next(); + module.close(); + } } } - private void addModules(JarFile earFile, ApplicationType application, GerApplicationType gerApplication, Set moduleLocations, Set modules) throws IOException, DeploymentException { - // build map from module path to alt vendor dd + private void addModules(JarFile earFile, ApplicationType application, GerApplicationType gerApplication, Set moduleLocations, Set modules) throws DeploymentException { Map altVendorDDs = new HashMap(); - GerModuleType gerModuleTypes[] = gerApplication.getModuleArray(); - for (int i = 0; i < gerModuleTypes.length; i++) { - GerModuleType gerModule = gerModuleTypes[i]; - String path = null; - if (gerModule.isSetEjb()) { - path = gerModule.getEjb().getStringValue(); - } else if (gerModule.isSetWeb()) { - path = gerModule.getWeb().getStringValue(); - } else if (gerModule.isSetConnector()) { - path = gerModule.getConnector().getStringValue(); - } else if (gerModule.isSetJava()) { - path = gerModule.getJava().getStringValue(); - } - - if (gerModule.isSetAltDd()) { - // the the url of the alt dd - altVendorDDs.put(path, JarUtil.toFile(earFile, gerModule.getAltDd().getStringValue())); - } else { - //dd is included explicitly - XmlCursor cursor = gerModule.newCursor(); - try { - cursor.toFirstChild(); - cursor.toNextSibling(); - //should be at the "any" element - XmlObject any = cursor.getObject(); - altVendorDDs.put(path, any); - } finally { - cursor.dispose(); + try { + // build map from module path to alt vendor dd + GerModuleType gerModuleTypes[] = gerApplication.getModuleArray(); + for (int i = 0; i < gerModuleTypes.length; i++) { + GerModuleType gerModule = gerModuleTypes[i]; + String path = null; + if (gerModule.isSetEjb()) { + path = gerModule.getEjb().getStringValue(); + } else if (gerModule.isSetWeb()) { + path = gerModule.getWeb().getStringValue(); + } else if (gerModule.isSetConnector()) { + path = gerModule.getConnector().getStringValue(); + } else if (gerModule.isSetJava()) { + path = gerModule.getJava().getStringValue(); + } + + if (gerModule.isSetAltDd()) { + // the the url of the alt dd + try { + altVendorDDs.put(path, DeploymentUtil.toTempFile(earFile, gerModule.getAltDd().getStringValue())); + } catch (IOException e) { + throw new DeploymentException("Invalid alt vendor dd url: " + gerModule.getAltDd().getStringValue(), e); + } + } else { + //dd is included explicitly + XmlCursor cursor = gerModule.newCursor(); + try { + cursor.toFirstChild(); + cursor.toNextSibling(); + //should be at the "any" element + XmlObject any = cursor.getObject(); + altVendorDDs.put(path, any); + } finally { + cursor.dispose(); + } } } - } - // get a set containing all of the files in the ear that are actually modules - ModuleType[] moduleTypes = application.getModuleArray(); - for (int i = 0; i < moduleTypes.length; i++) { - ModuleType moduleXml = moduleTypes[i]; - - String modulePath; - ModuleBuilder builder; - - String moduleTypeName; - if (moduleXml.isSetEjb()) { - modulePath = moduleXml.getEjb().getStringValue(); - if (ejbConfigBuilder == null) { - throw new DeploymentException("Can not deploy ejb application; No ejb deployer defined: " + modulePath); - } - builder = ejbConfigBuilder; - moduleTypeName = "an EJB"; - } else if (moduleXml.isSetWeb()) { - modulePath = moduleXml.getWeb().getWebUri().getStringValue(); - if (webConfigBuilder == null) { - throw new DeploymentException("Can not deploy web application; No war deployer defined: " + modulePath); - } - builder = webConfigBuilder; - moduleTypeName = "a war"; - } else if (moduleXml.isSetConnector()) { - modulePath = moduleXml.getConnector().getStringValue(); - if (connectorConfigBuilder == null) { - throw new DeploymentException("Can not deploy resource adapter; No rar deployer defined: " + modulePath); - } - builder = connectorConfigBuilder; - moduleTypeName = "a connector"; - } else if (moduleXml.isSetJava()) { - modulePath = moduleXml.getJava().getStringValue(); - if (appClientConfigBuilder == null) { - throw new DeploymentException("Can not deploy app client; No app client deployer defined: " + modulePath); + // get a set containing all of the files in the ear that are actually modules + ModuleType[] moduleTypes = application.getModuleArray(); + for (int i = 0; i < moduleTypes.length; i++) { + ModuleType moduleXml = moduleTypes[i]; + + String modulePath; + ModuleBuilder builder; + + String moduleTypeName; + if (moduleXml.isSetEjb()) { + modulePath = moduleXml.getEjb().getStringValue(); + if (ejbConfigBuilder == null) { + throw new DeploymentException("Can not deploy ejb application; No ejb deployer defined: " + modulePath); + } + builder = ejbConfigBuilder; + moduleTypeName = "an EJB"; + } else if (moduleXml.isSetWeb()) { + modulePath = moduleXml.getWeb().getWebUri().getStringValue(); + if (webConfigBuilder == null) { + throw new DeploymentException("Can not deploy web application; No war deployer defined: " + modulePath); + } + builder = webConfigBuilder; + moduleTypeName = "a war"; + } else if (moduleXml.isSetConnector()) { + modulePath = moduleXml.getConnector().getStringValue(); + if (connectorConfigBuilder == null) { + throw new DeploymentException("Can not deploy resource adapter; No rar deployer defined: " + modulePath); + } + builder = connectorConfigBuilder; + moduleTypeName = "a connector"; + } else if (moduleXml.isSetJava()) { + modulePath = moduleXml.getJava().getStringValue(); + if (appClientConfigBuilder == null) { + throw new DeploymentException("Can not deploy app client; No app client deployer defined: " + modulePath); + } + builder = appClientConfigBuilder; + moduleTypeName = "an application client"; + } else { + throw new DeploymentException("Could not find a module builder for module: " + moduleXml); + } + + moduleLocations.add(modulePath); + + URL altSpecDD = null; + if (moduleXml.isSetAltDd()) { + try { + altSpecDD = DeploymentUtil.createJarURL(earFile, moduleXml.getAltDd().getStringValue()); + } catch (MalformedURLException e) { + throw new DeploymentException("Invalid alt sped dd url: " + moduleXml.getAltDd().getStringValue(), e); + } } - builder = appClientConfigBuilder; - moduleTypeName = "an application client"; - } else { - throw new DeploymentException("Could not find a module builder for module: " + moduleXml); - } - moduleLocations.add(modulePath); + NestedJarFile moduleFile = null; + try { + moduleFile = new NestedJarFile(earFile, modulePath); + } catch (IOException e) { + throw new DeploymentException("Invalid moduleFile: " + modulePath, e); + } - URL altSpecDD = null; - if (moduleXml.isSetAltDd()) { - altSpecDD = JarUtil.createJarURL(earFile, moduleXml.getAltDd().getStringValue()); - } + Module module = builder.createModule(altVendorDDs.get(modulePath), + moduleFile, + modulePath, + altSpecDD, + URI.create(gerApplication.getConfigId())); - Module module = builder.createModule(altVendorDDs.get(modulePath), - new NestedJarFile(earFile, modulePath), - modulePath, - altSpecDD, - URI.create(gerApplication.getConfigId())); + if (module == null) { + throw new DeploymentException("Module was not " + moduleTypeName + ": " + modulePath); + } - if (module == null) { - throw new DeploymentException("Module was not " + moduleTypeName + ": " + modulePath); - } + if (module instanceof WebModule) { + ((WebModule) module).setContextRoot(moduleXml.getWeb().getContextRoot().getStringValue()); + } - if (module instanceof WebModule) { - ((WebModule) module).setContextRoot(moduleXml.getWeb().getContextRoot().getStringValue()); + modules.add(module); + } + } finally { + // delete all the temp files created for alt vendor dds + for (Iterator iterator = altVendorDDs.values().iterator(); iterator.hasNext();) { + Object altVendorDD = iterator.next(); + if (altVendorDD instanceof File) { + ((File)altVendorDD).delete(); + } } - - modules.add(module); } } Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/EARContext.java Mon Oct 4 15:54:53 2004 @@ -16,24 +16,23 @@ */ package org.apache.geronimo.j2ee.deployment; +import java.io.File; +import java.io.IOException; import java.net.URI; import java.net.URISyntaxException; import java.util.HashMap; import java.util.Map; import java.util.Properties; import java.util.StringTokenizer; -import java.util.jar.JarOutputStream; +import java.util.jar.Attributes; import java.util.jar.JarFile; import java.util.jar.Manifest; -import java.util.jar.Attributes; -import java.io.IOException; -import java.io.File; import javax.management.MalformedObjectNameException; import javax.management.ObjectName; import org.apache.geronimo.deployment.DeploymentContext; import org.apache.geronimo.deployment.DeploymentException; -import org.apache.geronimo.deployment.util.JarUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.kernel.Kernel; import org.apache.geronimo.kernel.config.ConfigurationModuleType; @@ -58,8 +57,8 @@ private final EJBRefContext ejbRefContext; - public EARContext(JarOutputStream jos, URI id, ConfigurationModuleType moduleType, URI parentID, Kernel kernel, String j2eeDomainName, String j2eeServerName, String j2eeApplicationName, ObjectName transactionContextManagerObjectName, ObjectName connectionTrackerObjectName, ObjectName transactedTimerName, ObjectName nonTransactedTimerName, EJBRefContext ejbRefContext) throws MalformedObjectNameException, DeploymentException { - super(jos, id, moduleType, parentID, kernel); + public EARContext(File baseDir, URI id, ConfigurationModuleType moduleType, URI parentID, Kernel kernel, String j2eeDomainName, String j2eeServerName, String j2eeApplicationName, ObjectName transactionContextManagerObjectName, ObjectName connectionTrackerObjectName, ObjectName transactedTimerName, ObjectName nonTransactedTimerName, EJBRefContext ejbRefContext) throws MalformedObjectNameException, DeploymentException { + super(baseDir, id, moduleType, parentID, kernel); this.j2eeDomainName = j2eeDomainName; this.j2eeServerName = j2eeServerName; @@ -190,22 +189,24 @@ } URI path = baseUri.resolve(uri); - File classPathFile = JarUtil.toFile(earFile, path.getPath()); + // todo no need to copy this into a temp file... + File classPathFile = DeploymentUtil.toFile(earFile, path.getPath()); // before going to the work of adding this file, let's make sure it really is a jar file - JarFile classPathJar; + JarFile classPathJar = null; try { classPathJar = new JarFile(classPathFile); + + // add this class path jar to the output context + addInclude(path, classPathFile); + + // add the client jars of this class path jar + addManifestClassPath(earFile, module, classPathJar, path); } catch (IOException e) { throw new DeploymentException("Manifest class path entries must be a valid jar file (J2EE 1.4 Section 8.2)", e); + } finally { + DeploymentUtil.close(classPathJar); } - - // add this class path jar to the output context - addInclude(path, classPathFile.toURL()); - - // add the client jars of this class path jar - addManifestClassPath(earFile, module, classPathJar, path); } } - } Modified: geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/Module.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/Module.java (original) +++ geronimo/trunk/modules/j2ee/src/java/org/apache/geronimo/j2ee/deployment/Module.java Mon Oct 4 15:54:53 2004 @@ -21,6 +21,7 @@ import org.apache.xmlbeans.XmlObject; import org.apache.geronimo.kernel.config.ConfigurationModuleType; +import org.apache.geronimo.deployment.util.DeploymentUtil; /** * @version $Rev$ $Date$ @@ -111,5 +112,9 @@ return name.equals(module.name); } return false; + } + + public void close() { + DeploymentUtil.close(moduleFile); } } 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 Mon Oct 4 15:54:53 2004 @@ -26,7 +26,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.deployment.util.DeploymentUtil; import org.apache.geronimo.kernel.jmx.JMXUtil; /** @@ -52,7 +52,7 @@ TestSuite inner = new TestSuite(EARConfigBuilderTest.class); TestSetup setup14 = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-ear14/test-ear.ear")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear14/test-ear.ear")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war", null, null, null); @@ -61,11 +61,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupNaked14 = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-ear14/test-naked-ear.ear")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear14/test-naked-ear.ear")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war", null, null, null); @@ -74,11 +78,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setup13 = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-ear13/test-ear.ear")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear13/test-ear.ear")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war", null, null, null); @@ -87,11 +95,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupNaked13 = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-ear13/test-naked-ear.ear")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-ear13/test-naked-ear.ear")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war", null, null, null); @@ -100,11 +112,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupUnpacked = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/full/")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/full/")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar/", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war/", null, null, null); @@ -113,11 +129,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupUnpackedNaked = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/naked/")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/naked/")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar/", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war", null, null, null); @@ -126,11 +146,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupUnpackedAltDD = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/alt-dd/")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/alt-dd/")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar/", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war/", null, null, null); @@ -139,11 +163,15 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; TestSetup setupPackedAltDD = new TestSetup(inner) { protected void setUp() throws Exception { - earFile = JarUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/alt-dd.ear")); + earFile = DeploymentUtil.createJarFile(new File(basedir, "target/test-unpacked-ear/alt-dd.ear")); ejbConfigBuilder.ejbModule = new EJBModule(false, null, null, null, "test-ejb-jar.jar/", null, null, null); webConfigBuilder.contextRoot = "test"; webConfigBuilder.webModule = new WebModule(false, null, null, null, "test-war.war/", null, null, null); @@ -152,6 +180,10 @@ } protected void tearDown() { + DeploymentUtil.close(earFile); + close(ejbConfigBuilder.ejbModule); + close(webConfigBuilder.webModule); + close(connectorConfigBuilder.connectorModule); } }; @@ -170,58 +202,67 @@ public void testBuildConfiguration() throws Exception { EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, transactionManagerObjectName, connectionTrackerObjectName, transactionalTimerObjectName, nonTransactionalTimerObjectName, null, ejbConfigBuilder, null, webConfigBuilder, connectorConfigBuilder, appClientConfigBuilder, null); - File carFile = File.createTempFile("EARTest", ".car"); + File tempDir = null; try { + tempDir = DeploymentUtil.createTempDir(); Object plan = configBuilder.getDeploymentPlan(null, earFile); - configBuilder.buildConfiguration(carFile, null, plan, earFile); + configBuilder.buildConfiguration(plan, earFile, tempDir); } finally { - carFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } public void testNoEJBDeployer() throws Exception { EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, transactionManagerObjectName, connectionTrackerObjectName, transactionalTimerObjectName, nonTransactionalTimerObjectName, null, null, null, webConfigBuilder, connectorConfigBuilder, appClientConfigBuilder, null); - File carFile = File.createTempFile("EARTest", ".car"); + File tempDir = null; try { + tempDir = DeploymentUtil.createTempDir(); Object plan = configBuilder.getDeploymentPlan(null, earFile); - configBuilder.buildConfiguration(carFile, null, plan, earFile); + configBuilder.buildConfiguration(plan, earFile, tempDir); fail("Should have thrown a DeploymentException"); } catch (DeploymentException e) { // expected } finally { - carFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } public void testNoWARDeployer() throws Exception { EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, transactionManagerObjectName, connectionTrackerObjectName, transactionalTimerObjectName, nonTransactionalTimerObjectName, null, ejbConfigBuilder, null, null, connectorConfigBuilder, appClientConfigBuilder, null); - File carFile = File.createTempFile("EARTest", ".car"); + File tempDir = null; try { + tempDir = DeploymentUtil.createTempDir(); Object plan = configBuilder.getDeploymentPlan(null, earFile); - configBuilder.buildConfiguration(carFile, null, plan, earFile); + configBuilder.buildConfiguration(plan, earFile, tempDir); fail("Should have thrown a DeploymentException"); } catch (DeploymentException e) { // expected } finally { - carFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } public void testNoConnectorDeployer() throws Exception { EARConfigBuilder configBuilder = new EARConfigBuilder(j2eeServer, transactionManagerObjectName, connectionTrackerObjectName, transactionalTimerObjectName, nonTransactionalTimerObjectName, null, ejbConfigBuilder, null, webConfigBuilder, null, appClientConfigBuilder, null); - File carFile = File.createTempFile("EARTest", ".car"); + File tempDir = null; try { + tempDir = DeploymentUtil.createTempDir(); Object plan = configBuilder.getDeploymentPlan(null, earFile); - configBuilder.buildConfiguration(carFile, null, plan, earFile); + configBuilder.buildConfiguration(plan, earFile, tempDir); fail("Should have thrown a DeploymentException"); } catch (DeploymentException e) { // expected } finally { - carFile.delete(); + DeploymentUtil.recursiveDelete(tempDir); } } + private static void close(Module module) { + if (module != null) { + module.close(); + } + } } Modified: geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java ============================================================================== --- geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java (original) +++ geronimo/trunk/modules/j2ee/src/test/org/apache/geronimo/j2ee/deployment/EJBRefContextTest.java Mon Oct 4 15:54:53 2004 @@ -16,7 +16,6 @@ */ package org.apache.geronimo.j2ee.deployment; -import java.io.File; import java.net.URI; import javax.naming.Reference; @@ -44,7 +43,6 @@ private final String car_gt_local = "car_gt_local"; private final String car_enzo = "car_enzo"; private final String car_enzo_local = "car_enzo_local"; - private File carFile; private EJBRefContext ejbRefContext; public void testSimpleRefs() throws Exception { @@ -153,7 +151,6 @@ } protected void setUp() throws Exception { - carFile = File.createTempFile("EARTest", ".car"); ejbRefContext = new EJBRefContext(new EJBReferenceBuilder() { public Reference createEJBLocalReference(String objectName, boolean isSession, String localHome, String local) { return new FakeReference(objectName); @@ -178,10 +175,6 @@ ejbRefContext.addEJBLocalId(car, "gt", car_gt_local, true, "GTLocalHome", "GTLocalRemote"); ejbRefContext.addEJBRemoteId(car, "enzo", car_enzo, true, "EnzoHome", "EnzoRemote"); ejbRefContext.addEJBLocalId(car, "enzo", car_enzo_local, true, "LocalHome", "Local"); - } - - protected void tearDown() throws Exception { - carFile.delete(); } private void assertReferenceEqual(String expected, Reference reference) { 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 Mon Oct 4 15:54:53 2004 @@ -17,10 +17,8 @@ package org.apache.geronimo.jetty.deployment; -import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; -import java.io.InputStream; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; @@ -40,8 +38,7 @@ import org.apache.geronimo.deployment.DeploymentException; import org.apache.geronimo.deployment.service.GBeanHelper; -import org.apache.geronimo.deployment.util.IOUtil; -import org.apache.geronimo.deployment.util.JarUtil; +import org.apache.geronimo.deployment.util.DeploymentUtil; import org.apache.geronimo.gbean.GBeanInfo; import org.apache.geronimo.gbean.GBeanInfoFactory; import org.apache.geronimo.gbean.jmx.GBeanMBean; @@ -103,12 +100,12 @@ WebAppType webApp; try { if (specDDUrl == null) { - specDDUrl = JarUtil.createJarURL(moduleFile, "WEB-INF/web.xml"); + specDDUrl = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/web.xml"); } // read in the entire specDD as a string, we need this for getDeploymentDescriptor // on the J2ee management object - specDD = IOUtil.readAll(specDDUrl); + specDD = DeploymentUtil.readAll(specDDUrl); // parse it WebAppDocument webAppDoc = SchemaConversionUtils.convertToServletSchema(SchemaConversionUtils.parse(specDD)); @@ -158,7 +155,7 @@ if (plan != null) { jettyWebAppdoc = JettyWebAppDocument.Factory.parse((File)plan); } else { - URL path = JarUtil.createJarURL(moduleFile, "WEB-INF/geronimo-jetty.xml"); + URL path = DeploymentUtil.createJarURL(moduleFile, "WEB-INF/geronimo-jetty.xml"); jettyWebAppdoc = JettyWebAppDocument.Factory.parse(path); } if (jettyWebAppdoc != null) { @@ -215,24 +212,19 @@ public void installModule(JarFile earFile, EARContext earContext, Module module) throws DeploymentException { try { - URI targetURI = URI.create(module.getTargetPath() + "/"); + URI baseDir = URI.create(module.getTargetPath() + "/"); // add the warfile's content to the configuration JarFile warFile = module.getModuleFile(); Enumeration entries = warFile.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); - URI target = targetURI.resolve(entry.getName()); + URI targetPath = baseDir.resolve(entry.getName()); if (entry.getName().equals("WEB-INF/web.xml")) { // TODO gets rid of these tests when Jetty will use the serialized Geronimo DD. - earContext.addFile(target, new ByteArrayInputStream(module.getOriginalSpecDD().getBytes())); + earContext.addFile(targetPath, module.getOriginalSpecDD()); } else { - InputStream in = warFile.getInputStream(entry); - try { - earContext.addFile(target, in); - } finally { - IOUtil.close(in); - } + earContext.addFile(targetPath, warFile, entry); } } Modified: geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java ============================================================================== --- geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java (original) +++ geronimo/trunk/modules/kernel/src/java/org/apache/geronimo/kernel/config/ConfigurationStore.java Mon Oct 4 15:54:53 2004 @@ -18,6 +18,7 @@ package org.apache.geronimo.kernel.config; import java.io.IOException; +import java.io.File; import java.net.URI; import java.net.URL; import java.util.List; @@ -38,6 +39,15 @@ * @throws InvalidConfigException if there is a configuration problem with the CAR */ URI install(URL source) throws IOException, InvalidConfigException; + + /** + * Move the unpacked configuration directory into this store + * + * @param source the directory which contains a contiguration + * @throws IOException if the direcotyr could not be moved into the store + * @throws InvalidConfigException if there is a configuration problem within the source direcotry + */ + URI install(File source) throws IOException, InvalidConfigException; void uninstall(URI configID) throws NoSuchConfigException, IOException; Modified: geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/config/RunTest.java ============================================================================== --- geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/config/RunTest.java (original) +++ geronimo/trunk/modules/kernel/src/test/org/apache/geronimo/kernel/config/RunTest.java Mon Oct 4 15:54:53 2004 @@ -49,36 +49,49 @@ protected void setUp() throws Exception { super.setUp(); - Map gbeans = new HashMap(); - ObjectName objectName = new ObjectName("test:name=MyGBean"); - gbeans.put(objectName, new GBeanMBean(MyGBean.GBEAN_INFO)); - GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO); - config.setAttribute("ID", URI.create("org/apache/geronimo/run-test")); - config.setReferencePatterns("Parent", null); - config.setAttribute("classPath", Collections.EMPTY_LIST); - config.setAttribute("gBeanState", Configuration.storeGBeans(gbeans)); + try { + Map gbeans = new HashMap(); + ObjectName objectName = new ObjectName("test:name=MyGBean"); + gbeans.put(objectName, new GBeanMBean(MyGBean.GBEAN_INFO)); + GBeanMBean config = new GBeanMBean(Configuration.GBEAN_INFO); + config.setAttribute("ID", URI.create("org/apache/geronimo/run-test")); + config.setReferencePatterns("Parent", null); + config.setAttribute("classPath", Collections.EMPTY_LIST); + config.setAttribute("gBeanState", Configuration.storeGBeans(gbeans)); - carFile = File.createTempFile("run", ".car"); - Manifest manifest = new Manifest(); - Attributes attrs = manifest.getMainAttributes(); - attrs.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); - attrs.putValue("Geronimo-GBean", objectName.toString()); - attrs.putValue(Attributes.Name.MAIN_CLASS.toString(), Run.class.getName()); - attrs.putValue(Attributes.Name.CLASS_PATH.toString(), "geronimo-kernel-DEV.jar commons-logging-1.0.3.jar cglib-full-2.0-RC2.jar"); - JarOutputStream jos = new JarOutputStream(new FileOutputStream(carFile), manifest); - jos.putNextEntry(new ZipEntry("META-INF/config.ser")); - ObjectOutputStream oos = new ObjectOutputStream(jos); - Configuration.storeGMBeanState(config, oos); - oos.flush(); - jos.closeEntry(); - jos.putNextEntry(new ZipEntry("org/apache/geronimo/kernel/config/MyGBean.class")); - byte[] buffer = new byte[4096]; - InputStream is = MyGBean.class.getClassLoader().getResourceAsStream("org/apache/geronimo/kernel/config/MyGBean.class"); - int count; - while ((count = is.read(buffer)) > 0) { - jos.write(buffer, 0, count); + carFile = File.createTempFile("run", ".car"); + Manifest manifest = new Manifest(); + Attributes attrs = manifest.getMainAttributes(); + attrs.putValue(Attributes.Name.MANIFEST_VERSION.toString(), "1.0"); + attrs.putValue("Geronimo-GBean", objectName.toString()); + attrs.putValue(Attributes.Name.MAIN_CLASS.toString(), Run.class.getName()); + attrs.putValue(Attributes.Name.CLASS_PATH.toString(), "geronimo-kernel-DEV.jar commons-logging-1.0.3.jar cglib-full-2.0-RC2.jar"); + JarOutputStream jos = new JarOutputStream(new FileOutputStream(carFile), manifest); + jos.putNextEntry(new ZipEntry("META-INF/config.ser")); + ObjectOutputStream oos = new ObjectOutputStream(jos); + Configuration.storeGMBeanState(config, oos); + oos.flush(); + jos.closeEntry(); + jos.putNextEntry(new ZipEntry("org/apache/geronimo/kernel/config/MyGBean.class")); + byte[] buffer = new byte[4096]; + InputStream is = MyGBean.class.getClassLoader().getResourceAsStream("org/apache/geronimo/kernel/config/MyGBean.class"); + int count; + while ((count = is.read(buffer)) > 0) { + jos.write(buffer, 0, count); + } + jos.closeEntry(); + jos.close(); + } catch (Exception e) { + if (carFile != null) { + carFile.delete(); + } + throw e; + } + } + + protected void tearDown() throws Exception { + if (carFile != null) { + carFile.delete(); } - jos.closeEntry(); - jos.close(); } } Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java ============================================================================== --- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java (original) +++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java Mon Oct 4 15:54:53 2004 @@ -136,32 +136,81 @@ } } + private File createConfigurationDir() { + // loop until we find a directory that doesn't alredy exist + // this can happen when a deployment fails (leaving an bad directory) + // and the server reboots without saving out the index.propreties file + // the is rare but we should check for it + File configurationDir; + do { + String newId; + synchronized (this) { + newId = Integer.toString(++maxId); + } + configurationDir = new File(rootDir, newId); + } while (configurationDir.exists()); + configurationDir.mkdir(); + return configurationDir; + } + public URI install(URL source) throws IOException, InvalidConfigException { - String newId; - synchronized (this) { - newId = Integer.toString(++maxId); - } - File bundleRoot = new File(rootDir, newId); - bundleRoot.mkdir(); + File configurationDir = createConfigurationDir(); + InputStream is = source.openStream(); try { - unpack(bundleRoot, is); + unpack(configurationDir, is); + } catch (IOException e) { + delete(configurationDir); + throw e; } finally { is.close(); } + + URI configId; + try { + GBeanMBean config = loadConfig(configurationDir); + configId = (URI) config.getAttribute("ID"); + index.setProperty(configId.toString(), configurationDir.getName()); + } catch (Exception e) { + delete(configurationDir); + throw new InvalidConfigException("Unable to get ID from downloaded configuration", e); + } + + synchronized (this) { + saveIndex(); + } + + log.info("Installed configuration " + configId + " in location " + configurationDir.getName()); + return configId; + } + + public URI install(File source) throws IOException, InvalidConfigException { + if (!source.isDirectory()) { + throw new InvalidConfigException("Source must be a directory"); + } + + File configurationDir = createConfigurationDir(); + if (!source.renameTo(configurationDir)) { + throw new IOException("Could not move source directory into config store:" + + " source=" + source.getAbsolutePath() + ", destination=" + configurationDir.getAbsolutePath()); + } + URI configId; try { - GBeanMBean config = loadConfig(bundleRoot); + GBeanMBean config = loadConfig(configurationDir); configId = (URI) config.getAttribute("ID"); - index.setProperty(configId.toString(), newId); + index.setProperty(configId.toString(), configurationDir.getName()); } catch (Exception e) { - delete(bundleRoot); + // try to put the file back + configurationDir.renameTo(source); throw new InvalidConfigException("Unable to get ID from downloaded configuration", e); } + synchronized (this) { saveIndex(); } - log.info("Installed configuration " + configId + " in location " + newId); + + log.info("Installed configuration " + configId + " in location " + configurationDir.getName()); return configId; } Modified: geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java ============================================================================== --- geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java (original) +++ geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java Mon Oct 4 15:54:53 2004 @@ -26,12 +26,10 @@ import java.util.jar.JarOutputStream; import java.util.zip.ZipEntry; +import junit.framework.TestCase; import org.apache.geronimo.gbean.jmx.GBeanMBean; -import org.apache.geronimo.system.configuration.LocalConfigStore; import org.apache.geronimo.kernel.config.Configuration; -import junit.framework.TestCase; - /** * * @@ -53,28 +51,37 @@ } protected void setUp() throws Exception { - root = new File(System.getProperty("java.io.tmpdir") + "/config-store"); - root.mkdir(); - - store = new LocalConfigStore(root); - store.doStart(); - - GBeanMBean gbean = new GBeanMBean(Configuration.GBEAN_INFO); - uri = new URI("test"); - gbean.setAttribute("ID", uri); - sourceFile = File.createTempFile("test", ".car"); - source = sourceFile.toURL(); - JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(sourceFile))); - jos.putNextEntry(new ZipEntry("META-INF/config.ser")); - ObjectOutputStream oos = new ObjectOutputStream(jos); - Configuration.storeGMBeanState(gbean, oos); - oos.flush(); - jos.closeEntry(); - jos.close(); + try { + root = new File(System.getProperty("java.io.tmpdir") + "/config-store"); + root.mkdir(); + + store = new LocalConfigStore(root); + store.doStart(); + + GBeanMBean gbean = new GBeanMBean(Configuration.GBEAN_INFO); + uri = new URI("test"); + gbean.setAttribute("ID", uri); + sourceFile = File.createTempFile("test", ".car"); + source = sourceFile.toURL(); + JarOutputStream jos = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(sourceFile))); + jos.putNextEntry(new ZipEntry("META-INF/config.ser")); + ObjectOutputStream oos = new ObjectOutputStream(jos); + Configuration.storeGMBeanState(gbean, oos); + oos.flush(); + jos.closeEntry(); + jos.close(); + } catch (Exception e) { + if (sourceFile != null) { + sourceFile.delete(); + } + throw e; + } } protected void tearDown() throws Exception { - sourceFile.delete(); + if (sourceFile != null) { + sourceFile.delete(); + } store.doStop(); store = null; recursiveDelete(root); Modified: geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/url/file/FileProtocolTest.java ============================================================================== --- geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/url/file/FileProtocolTest.java (original) +++ geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/url/file/FileProtocolTest.java Mon Oct 4 15:54:53 2004 @@ -48,12 +48,21 @@ private URL fileURL; protected void setUp() throws Exception { - file = File.createTempFile("FileProtocolTest", ".tmp"); - fileURL = file.toURI().toURL(); + try { + file = File.createTempFile("FileProtocolTest", ".tmp"); + fileURL = file.toURI().toURL(); + } catch (Exception e) { + if (file != null) { + file.delete(); + } + throw e; + } } protected void tearDown() throws Exception { - file.delete(); + if (file != null) { + file.delete(); + } } public void testCreateURL() throws Exception { @@ -61,10 +70,17 @@ } public void testURLConnectionType() throws Exception { - File tempFile = File.createTempFile("foo", "bar"); - URL url = new URL(tempFile.toURL().toExternalForm()); - URLConnection c = url.openConnection(); - assertEquals(FileURLConnection.class, c.getClass()); + File tempFile = null; + try { + tempFile = File.createTempFile("foo", "bar"); + URL url = new URL(tempFile.toURL().toExternalForm()); + URLConnection c = url.openConnection(); + assertEquals(FileURLConnection.class, c.getClass()); + } finally { + if (tempFile != null) { + tempFile.delete(); + } + } } public void testFileToURL() throws Exception { @@ -128,12 +144,15 @@ } public void testGetContentType() throws Exception { - File file = File.createTempFile("FileProtocolTest", ".xml"); + File file = null; try { + file = File.createTempFile("FileProtocolTest", ".xml"); URLConnection c = file.toURI().toURL().openConnection(); assertEquals("application/xml", c.getContentType()); } finally { - file.delete(); + if (file != null) { + file.delete(); + } } } @@ -159,16 +178,25 @@ } public void testSyncFDUpdatesFileLength() throws Exception { - File foo = File.createTempFile("TestFileLength", ".tmp"); - FileOutputStream fos = new FileOutputStream(foo); - OutputStream out = new BufferedOutputStream(fos); + File foo = null; + OutputStream out = null; try { + foo = File.createTempFile("TestFileLength", ".tmp"); + FileOutputStream fos = new FileOutputStream(foo); + out = new BufferedOutputStream(fos); + out.write(new byte[10]); out.flush(); // out.close(); fos.getFD().sync(); // this is required on Windows for foo.length to be updated assertEquals(10, foo.length()); } finally { + if (out != null) { + try { + out.close(); + } catch (IOException ignored) { + } + } foo.delete(); } }