jboynes 2004/01/15 19:48:43
Added: modules/deployment project.xml
modules/deployment/src/java/org/apache/geronimo/deployment
BatchDeployer.java ConfigurationCallback.java
DeploymentModule.java ModuleFactory.java
NoDeployerException.java
modules/deployment/src/java/org/apache/geronimo/deployment/service
GBeanDefault.java ServiceDeployer.java
ServiceModule.java
modules/deployment/src/java/org/apache/geronimo/deployment/tools
DeployCommand.java
modules/deployment/src/test/org/apache/geronimo/deployment
MockEndpoint.java MockGBean.java
modules/deployment/src/test/org/apache/geronimo/deployment/service
ServiceDeployerTest.java
modules/deployment/src/test-resources/services service1.xml
service2.jar
modules/deployment/src/test-resources/services/service3/META-INF
MANIFEST.MF geronimo-service.xml
modules/deployment/src/test-resources/services/service3/classes
test-resource.dat
Log:
Initial checkin of service deployment code
Revision Changes Path
1.1 incubator-geronimo/modules/deployment/project.xml
Index: project.xml
===================================================================
<?xml version="1.0" encoding="ISO-8859-1"?>
<!-- $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $ -->
<project>
<pomVersion>3</pomVersion>
<extend>${basedir}/../../etc/project.xml</extend>
<!-- ===================== -->
<!-- Module Identification -->
<!-- ===================== -->
<name>Geronimo :: Deployment</name>
<id>geronimo-deployment</id>
<shortDescription>Geronimo Deployment</shortDescription>
<description>Geronimo Deployment</description>
<url>http://incubator.apache.org/projects/geronimo/deployment/</url>
<siteDirectory>/www/incubator.apache.org/projects/geronimo/deployment</siteDirectory>
<distributionDirectory>/www/incubator.apache.org/projects/geronimo/builds/deployment</distributionDirectory>
<currentVersion>DEV</currentVersion>
<!-- ============ -->
<!-- Dependencies -->
<!-- ============ -->
<dependencies>
<dependency>
<groupId>geronimo</groupId>
<artifactId>geronimo-kernel</artifactId>
<version>DEV</version>
<properties>
<module>true</module>
</properties>
</dependency>
<dependency>
<id>cglib</id>
<version>HEAD-20031111</version>
<url>http://cglib.sf.net/</url>
<properties>
<runtime>true</runtime>
<destinations>bootlib</destinations>
</properties>
</dependency>
<dependency>
<id>mx4j</id>
<version>SNAPSHOT</version>
<properties>
<runtime>true</runtime>
<destinations>bootlib</destinations>
</properties>
</dependency>
<dependency>
<id>commons-logging</id>
<version>1.0.3</version>
<url>http://jakarta.apache.org/commons/logging/</url>
<properties>
<runtime>true</runtime>
<destinations>bootlib</destinations>
</properties>
</dependency>
</dependencies>
<!-- =================== -->
<!-- Build Specification -->
<!-- =================== -->
<build>
<unitTest>
<includes>
<include>**/*Test.java</include>
</includes>
<excludes>
<exclude>**/Abstract*.java</exclude>
</excludes>
<resources>
<resource>
<directory>${basedir}/src/schema</directory>
<includes>
<include>*.xsd</include>
</includes>
</resource>
<resource>
<directory>${basedir}/src/test-resources</directory>
</resource>
</resources>
</unitTest>
</build>
</project>
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/BatchDeployer.java
Index: BatchDeployer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
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.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
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.zip.ZipEntry;
import javax.management.ObjectName;
import org.apache.geronimo.kernel.config.Configuration;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class BatchDeployer implements ConfigurationCallback {
private final URI configRoot;
private final List deployers;
private final Set moduleIDs = new HashSet();
private final List modules = new ArrayList();
private final LinkedHashSet classPath = new LinkedHashSet();
private final GBeanMBean config;
private final Map gbeans = new HashMap();
private final byte[] buffer = new byte[4096];
public BatchDeployer(URI configID, List deployers, File workingDir) {
if (!workingDir.isDirectory()) {
throw new IllegalArgumentException("workingDir is not a
directory");
}
this.configRoot = workingDir.toURI();
this.deployers = deployers;
try {
config = new GBeanMBean(Configuration.GBEAN_INFO);
} catch (InvalidConfigurationException e) {
throw (AssertionError) new AssertionError("Unable to initialize
Configuration GMBean").initCause(e);
}
try {
config.setAttribute("ID", configID);
} catch (Exception e) {
throw (AssertionError) new AssertionError("Unable to initialize
ID attribute").initCause(e);
}
}
public void addSource(URLInfo source) throws NoDeployerException,
DeploymentException {
String path = source.getUrl().getPath();
while (path.endsWith("/")) {
path = path.substring(0, path.length()-1);
}
int end = path.lastIndexOf('/');
if (end != -1) {
path = path.substring(end+1);
}
if (path.length() == 0) {
path = "module";
}
URI moduleID = null;
try {
moduleID = new URI(path);
int i=0;
while (moduleIDs.contains(moduleID)) {
moduleID = new URI(++i + path);
}
} catch (URISyntaxException e) {
throw new DeploymentException("Unable to construct moduleID for
URL: "+source.getUrl(), e);
}
for (Iterator i = deployers.iterator(); i.hasNext();) {
ModuleFactory deployer = (ModuleFactory) i.next();
DeploymentModule module = deployer.getModule(source, moduleID);
if (module != null) {
modules.add(module);
return;
}
}
throw new NoDeployerException("No deployer could handle source " +
source.getUrl());
}
public void deploy() throws DeploymentException {
classPath.clear();
gbeans.clear();
try {
// tell each module we are starting deployment
for (Iterator i = modules.iterator(); i.hasNext();) {
DeploymentModule module = (DeploymentModule) i.next();
module.init();
}
// get all the classpath URLs the modules define
for (Iterator i = modules.iterator(); i.hasNext();) {
DeploymentModule module = (DeploymentModule) i.next();
module.generateClassPath(this);
}
ArrayList path = new ArrayList(classPath);
try {
config.setAttribute("ClassPath", path);
} catch (Exception e) {
throw new DeploymentException("Unable to save state to
configuration", e);
}
// build the ClassLoader for those URLs
URL[] urls = new URL[path.size()];
int idx = 0;
for (Iterator i = path.iterator(); i.hasNext();) {
URI uri = (URI) i.next();
uri = configRoot.resolve(uri);
try {
urls[idx] = uri.toURL();
} catch (MalformedURLException e) {
throw new DeploymentException("Unable to convert
classPath URI to absolute URL: " + uri, e);
}
}
ClassLoader cl = new URLClassLoader(urls);
// get the GBeans from each module
for (Iterator i = modules.iterator(); i.hasNext();) {
DeploymentModule module = (DeploymentModule) i.next();
module.defineGBeans(this, cl);
}
// initialize the Configuration state
try {
config.setAttribute("GBeanState",
Configuration.storeGBeans(gbeans));
} catch (Exception e) {
throw new DeploymentException("Unable to save state to
configuration", e);
}
} finally {
// tell each module we are done with it
for (Iterator i = modules.iterator(); i.hasNext();) {
DeploymentModule module = (DeploymentModule) i.next();
module.complete();
}
}
}
public void addFile(URI path, InputStream is) throws IOException {
if (path.isAbsolute()) {
throw new IllegalArgumentException("path must be a relative URI");
}
File to = new File(configRoot.resolve(path));
to.getParentFile().mkdirs();
OutputStream os = new FileOutputStream(to);
try {
for (int count; (count = is.read(buffer)) > 0;) {
os.write(buffer, 0, count);
}
} catch (IOException e) {
try {
os.close();
to.delete();
} catch (IOException e1) {
// ignore
}
throw e;
}
}
public void addToClasspath(URI uri) {
classPath.add(uri);
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
gbeans.put(name, gbean);
}
public void saveConfiguration(JarOutputStream jos) throws IOException {
// add the configuration data
jos.putNextEntry(new ZipEntry("META-INF/config.ser"));
ObjectOutputStream oos = new ObjectOutputStream(jos);
for (Iterator i =
config.getGBeanInfo().getPersistentAttributes().iterator(); i.hasNext();) {
GAttributeInfo attributeInfo = (GAttributeInfo) i.next();
try {
oos.writeObject(config.getAttribute(attributeInfo.getName()));
} catch (IOException e) {
throw e;
} catch (Exception e) {
throw (IllegalStateException) new
IllegalStateException("Unable to save attribute " +
attributeInfo.getName()).initCause(e);
}
}
oos.flush();
jos.closeEntry();
// add the files from the modules
LinkedList dirs = new LinkedList();
dirs.add(new File(configRoot));
while (!dirs.isEmpty()) {
File dir = (File) dirs.removeFirst();
assert dir.isDirectory() : "Added a file to the directory list" +
dir;
File[] files = dir.listFiles();
for (int i = 0; i < files.length; i++) {
File file = files[i];
if (file.isDirectory()) {
dirs.addFirst(file);
} else {
URI name = configRoot.relativize(file.toURI());
assert (!name.isAbsolute()) : "Could not construct
relative path for file " + file;
jos.putNextEntry(new ZipEntry(name.toString()));
InputStream is = new FileInputStream(file);
try {
for (int count; (count = is.read(buffer)) > 0;) {
jos.write(buffer, 0, count);
}
} finally {
is.close();
}
jos.closeEntry();
}
}
}
}
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ConfigurationCallback.java
Index: ConfigurationCallback.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import javax.management.ObjectName;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
/**
* Callback supplied by a deployer to allow DeploymentModules to build the
* output Configuration.
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public interface ConfigurationCallback {
/**
* Add a file to the output Configuration
* @param path the path, relative to the root of the Configuration, to
use for the file;
* to avoid conflicts between modules this path should typically
include the
* module id supplied to the factory
* @param source a stream that can be read to provide the file's content
* @throws IOException if there was a problem adding the file to the
configuration
*/
void addFile(URI path, InputStream source) throws IOException;
/**
* Add a location to the Configuration's classpath.
* This would typically be a relative URI for resolution against the
* Configuration root and include the module id; absolute references to
* external resources are allowed.
* @param uri the location to add to the classpath
*/
void addToClasspath(URI uri);
/**
* Add a GMBean to the Configuration
* @param name the JMX name to use for the bean
* @param gbean the GBean
*/
void addGBean(ObjectName name, GBeanMBean gbean);
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/DeploymentModule.java
Index: DeploymentModule.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
import java.util.List;
import java.util.Map;
import org.apache.geronimo.kernel.deployment.DeploymentException;
/**
* A module representing a resource being deployed. The deployer will call
each
* method once in the sequence:
* <li>init</li>
* <li>generateClassPath</li>
* <li>defineGBeans</li>
* <li>complete</li>
*
* Once deployment starts, complete() method must always be called even if
* problems in the deployment process prevent the other methods being called.
* complete() may be called without a prior call to init().
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public interface DeploymentModule {
/**
* Indication to this module that the deployment process is starting.
*/
void init() throws DeploymentException;
/**
* Perform any callbacks needed to define the classpath this module needs
* the resulting Configuration to contain. This would typically involve
* callbacks to add files to the Configuration or to add URLs for external
* resources
* @param callback the callback to use to interact with the deployer
* @throws DeploymentException if there was a problem generating the
classpath
*/
void generateClassPath(ConfigurationCallback callback) throws
DeploymentException;
/**
* Perform callbacks needed to define GBeans in the resulting
Configuration.
* @param callback the callback to use to interact with the deployer
* @param cl a ClassLoader created by the deployer which is guaranteed to
* contain all the classpath entries this module added in the
prior
* call to generateClassPath
* @throws DeploymentException
*/
void defineGBeans(ConfigurationCallback callback, ClassLoader cl) throws
DeploymentException;
/**
* Indication from the deployer that its use of this module is complete.
*/
void complete();
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ModuleFactory.java
Index: ModuleFactory.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
import java.net.URI;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
/**
* A factory for a specific module type capable of returning a module from
* an external resource.
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public interface ModuleFactory {
/**
* Examine the resource at the supplied URL and, if it is recognized,
* return a DeploymentModule representing the resource.
* @param urlInfo the URL to examine
* @param moduleID a unique id to assign to this module
* @return a DeploymentModule representing the resource that can be used
* for the remainder of the deployment process; null if this
* factory does not recognize the resource or does not wish to
* handle it
* @throws DeploymentException if this factory was trying to return a
module
* but was unable to construct it
*/
DeploymentModule getModule(URLInfo urlInfo, URI moduleID) throws
DeploymentException;
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/NoDeployerException.java
Index: NoDeployerException.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
/**
* Exception indicating no ModuleFactory could be found for the supplied
* resource.
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class NoDeployerException extends Exception {
public NoDeployerException() {
}
public NoDeployerException(Throwable cause) {
super(cause);
}
public NoDeployerException(String message) {
super(message);
}
public NoDeployerException(String message, Throwable cause) {
super(message, cause);
}
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/GBeanDefault.java
Index: GBeanDefault.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment.service;
import java.util.Map;
import org.apache.geronimo.gbean.GBeanInfo;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class GBeanDefault {
private final String className;
private final GBeanInfo info;
private final String objectName;
private final Map values;
public GBeanDefault(GBeanInfo info, String objectName, Map values) {
this.info = info;
this.objectName = objectName;
this.values = values;
this.className = null;
}
public GBeanDefault(String className, String objectName, Map values) {
this.className = className;
this.objectName = objectName;
this.values = values;
this.info = null;
}
public GBeanInfo getGBeanInfo() {
return info;
}
public String getObjectName() {
return objectName;
}
public Map getValues() {
return values;
}
public String getClassName() {
return className;
}
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceDeployer.java
Index: ServiceDeployer.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment.service;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import javax.xml.parsers.DocumentBuilder;
import org.apache.geronimo.deployment.ModuleFactory;
import org.apache.geronimo.deployment.DeploymentModule;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
import org.apache.geronimo.kernel.deployment.scanner.URLType;
import org.apache.geronimo.kernel.deployment.service.XMLUtil;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class ServiceDeployer implements ModuleFactory {
private final DocumentBuilder parser;
public ServiceDeployer(DocumentBuilder parser) {
this.parser = parser;
}
public DeploymentModule getModule(URLInfo urlInfo, URI moduleID) throws
DeploymentException {
URL baseURL = urlInfo.getUrl();
URL metaDataURL;
try {
if (urlInfo.getType() == URLType.RESOURCE) {
metaDataURL = baseURL;
} else if (urlInfo.getType() == URLType.PACKED_ARCHIVE) {
baseURL = new URL("jar:" + baseURL.toString() + "!/");
metaDataURL = new URL(baseURL,
"META-INF/geronimo-service.xml");
} else if (urlInfo.getType() == URLType.UNPACKED_ARCHIVE) {
metaDataURL = new URL(baseURL,
"META-INF/geronimo-service.xml");
} else {
return null;
}
} catch (MalformedURLException e) {
return null;
}
Document doc = null;
try {
doc = parser.parse(metaDataURL.openStream());
} catch (Exception e) {
// this is not an XML file we can parse - let someone else try
return null;
}
Element documentElement = doc.getDocumentElement();
if ("gbeans".equals(documentElement.getNodeName()) == false) {
// document does not have correct root element - ignore
return null;
}
LinkedHashSet path = new LinkedHashSet();
List gbeans = new ArrayList();
NodeList nl = documentElement.getChildNodes();
for (int i = 0; i < nl.getLength(); i++) {
Node node = nl.item(i);
if (node.getNodeType() != Node.ELEMENT_NODE) {
continue;
}
Element element = (Element) node;
if ("path".equals(element.getNodeName())) {
String uri = (String) XMLUtil.getContent(element);
try {
path.add(new URI(uri));
} catch (URISyntaxException e) {
throw new DeploymentException("Invalid path URI: "+uri,
e);
}
} else if ("gbean".equals(element.getNodeName())) {
gbeans.add(loadDefault(element));
}
}
return new ServiceModule(moduleID, urlInfo, new ArrayList(path),
gbeans);
}
private GBeanDefault loadDefault(Element gbeanElement) {
String className = gbeanElement.getAttribute("class");
String objectName = gbeanElement.getAttribute("objectName");
NodeList nl = gbeanElement.getElementsByTagName("default");
Map values = new HashMap(nl.getLength());
for (int i = 0; i < nl.getLength(); i++) {
Element defaultElement = (Element) nl.item(i);
String attr = defaultElement.getAttribute("attribute");
String value = (String) XMLUtil.getContent(defaultElement);
values.put(attr, value);
}
return new GBeanDefault(className, objectName, values);
}
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/service/ServiceModule.java
Index: ServiceModule.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment.service;
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.LinkedList;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;
import javax.management.MalformedObjectNameException;
import javax.management.ObjectName;
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.DeploymentModule;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
import org.apache.geronimo.kernel.deployment.scanner.URLType;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.InvalidConfigurationException;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class ServiceModule implements DeploymentModule {
private final URI moduleID;
private final URLInfo urlInfo;
private final List pathURIs;
private final List gbeanDefaults;
public ServiceModule(URI moduleID, URLInfo urlInfo, List urls, List
gbeanDefaults) {
this.moduleID = moduleID;
this.urlInfo = urlInfo;
this.pathURIs = urls;
this.gbeanDefaults = gbeanDefaults;
}
public void init() throws DeploymentException {
}
public void generateClassPath(ConfigurationCallback callback) throws
DeploymentException {
URI moduleBase = URI.create(moduleID.toString()+"/");
if (urlInfo.getType() == URLType.PACKED_ARCHIVE) {
try {
InputStream is = urlInfo.getUrl().openStream();
try {
ZipInputStream zis = new ZipInputStream(new
BufferedInputStream(is));
for (ZipEntry entry; (entry = zis.getNextEntry()) !=
null; zis.closeEntry()) {
String name = entry.getName();
if (name.endsWith("/")) {
continue;
}
for (Iterator i = pathURIs.iterator(); i.hasNext();) {
URI path = (URI) i.next();
if (!path.isAbsolute() &&
name.startsWith(path.getPath())) {
callback.addFile(moduleBase.resolve(name),
zis);
break;
}
}
}
} finally {
is.close();
}
} catch (IOException e) {
throw new DeploymentException("Error adding content from
archive " + urlInfo.getUrl().toString(), e);
}
} else if (urlInfo.getType() == URLType.UNPACKED_ARCHIVE) {
//@todo support proper recursive file scanning (with WebDAV and
filters)
URL url = urlInfo.getUrl();
if (!"file".equals(url.getProtocol())) {
throw new DeploymentException("Unpacked archives not
supported for URL "+url.toString());
}
URI root = URI.create(url.toString());
for (Iterator i = pathURIs.iterator(); i.hasNext();) {
URI pathRoot = (URI) i.next();
if (pathRoot.isAbsolute()) {
continue;
}
pathRoot = root.resolve(pathRoot);
LinkedList dirs = new LinkedList();
dirs.add(pathRoot);
while (!dirs.isEmpty()) {
URI uri = (URI) dirs.removeFirst();
File dir = new File(uri);
if (!dir.exists()) {
continue;
}
assert (dir.isDirectory()) : "Found file in directory
list";
File[] files = dir.listFiles();
for (int j = 0; j < files.length; j++) {
File file = files[j];
if (file.isDirectory()) {
if (!"CVS".equals(file.getName())) {
dirs.addFirst(file.toURI());
}
} else {
try {
FileInputStream is = new
FileInputStream(file);
try {
URI path = root.relativize(file.toURI());
callback.addFile(moduleBase.resolve(path), is);
} finally {
is.close();
}
} catch (IOException e) {
throw new DeploymentException("Unable to add
file:"+file, e);
}
}
}
}
}
}
for (Iterator i = pathURIs.iterator(); i.hasNext();) {
URI uri = (URI) i.next();
callback.addToClasspath(moduleBase.resolve(uri));
}
}
public void defineGBeans(ConfigurationCallback callback, ClassLoader cl)
throws DeploymentException {
for (Iterator i = gbeanDefaults.iterator(); i.hasNext();) {
GBeanDefault defs = (GBeanDefault) i.next();
ObjectName name;
try {
name = new ObjectName(defs.getObjectName());
} catch (MalformedObjectNameException e) {
throw new DeploymentException("Invalid JMX ObjectName: " +
defs.getObjectName(), e);
}
GBeanInfo gbeanInfo = defs.getGBeanInfo();
if (gbeanInfo == null) {
String className = defs.getClassName();
try {
gbeanInfo = GBeanInfo.getGBeanInfo(className, cl);
} catch (InvalidConfigurationException e) {
throw new DeploymentException("Unable to get GBeanInfo
from class " + className, e);
}
}
GBeanMBean gbean;
try {
gbean = new GBeanMBean(gbeanInfo);
} catch (InvalidConfigurationException e) {
throw new DeploymentException("Unable to create GMBean", e);
}
for (Iterator j = defs.getValues().entrySet().iterator();
j.hasNext();) {
Map.Entry entry = (Map.Entry) j.next();
try {
gbean.setAttribute((String) entry.getKey(),
entry.getValue());
} catch (Exception e) {
throw new DeploymentException("Unable to set GMBean
attribute " + entry.getKey(), e);
}
}
callback.addGBean(name, gbean);
}
}
public void complete() {
}
}
1.1
incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/tools/DeployCommand.java
Index: DeployCommand.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment.tools;
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.util.ArrayList;
import java.util.List;
import java.util.jar.JarOutputStream;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;
import org.apache.geronimo.deployment.BatchDeployer;
import org.apache.geronimo.deployment.NoDeployerException;
import org.apache.geronimo.deployment.service.ServiceDeployer;
import org.apache.geronimo.kernel.deployment.DeploymentException;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
import org.apache.geronimo.kernel.deployment.scanner.URLType;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class DeployCommand {
private final File configFile;
private final BatchDeployer batcher;
public DeployCommand(File configFile, URI configID, File workDir, List
deployers) {
this.configFile = configFile;
batcher = new BatchDeployer(configID, deployers, workDir);
}
public void add(URL url) throws IOException, DeploymentException,
NoDeployerException {
URLType type = URLType.getType(url);
batcher.addSource(new URLInfo(url, type));
}
public void deploy() throws IOException, DeploymentException {
batcher.deploy();
JarOutputStream jos = new JarOutputStream(new
BufferedOutputStream(new FileOutputStream(configFile)));
batcher.saveConfiguration(jos);
jos.close();
}
public static void main(String[] args) {
if (args.length < 3) {
System.err.println("usage: "+DeployCommand.class.getName()+"
<configID> <outfile> <url>+");
System.exit(1);
throw new AssertionError();
}
URI configID = null;
try {
configID = new URI(args[0]);
} catch (URISyntaxException e) {
e.printStackTrace();
System.exit(1);
throw new AssertionError();
}
File configFile = new File(args[1]);
File workDir;
try {
workDir = File.createTempFile("deployer", "");
workDir.delete();
workDir.mkdir();
} catch (IOException e) {
System.err.println("Unable to create working directory");
System.exit(2);
throw new AssertionError();
}
List deployers = getDeployers();
DeployCommand deployer = new DeployCommand(configFile, configID,
workDir, deployers);
int status = 0;
try {
for (int i=2; i < args.length; i++) {
File source = new File(args[i]);
deployer.add(source.toURL());
}
deployer.deploy();
} catch (Exception e) {
e.printStackTrace();
status = 2;
} finally {
try {
recursiveDelete(workDir);
} catch (IOException e) {
// ignore
}
}
System.exit(status);
}
private static List getDeployers() {
try {
List deployers = new ArrayList();
DocumentBuilder parser =
DocumentBuilderFactory.newInstance().newDocumentBuilder();
deployers.add(new ServiceDeployer(parser));
return deployers;
} catch (ParserConfigurationException e) {
throw new AssertionError("Unable to instanciate XML Parser");
}
}
private static void recursiveDelete(File root) throws IOException {
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();
}
}
1.1
incubator-geronimo/modules/deployment/src/test/org/apache/geronimo/deployment/MockEndpoint.java
Index: MockEndpoint.java
===================================================================
package org.apache.geronimo.deployment;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*
* */
public interface MockEndpoint {
String doSomething(String name);
}
1.1
incubator-geronimo/modules/deployment/src/test/org/apache/geronimo/deployment/MockGBean.java
Index: MockGBean.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment;
import java.util.Collections;
import org.apache.geronimo.gbean.GAttributeInfo;
import org.apache.geronimo.gbean.GBeanInfo;
import org.apache.geronimo.gbean.GBeanInfoFactory;
import org.apache.geronimo.gbean.GConstructorInfo;
import org.apache.geronimo.gbean.GEndpointInfo;
import org.apache.geronimo.gbean.GOperationInfo;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:42 $
*/
public class MockGBean implements MockEndpoint {
private static final GBeanInfo GBEAN_INFO;
private final String name;
private String value;
private MockEndpoint endpoint;
public static GBeanInfo getGBeanInfo() {
return GBEAN_INFO;
}
static {
GBeanInfoFactory infoFactory = new GBeanInfoFactory("MockGBean",
"test description", MockGBean.class.getName());
infoFactory.addAttribute(new GAttributeInfo("Name", true));
infoFactory.addAttribute(new GAttributeInfo("Value", true));
infoFactory.addOperation(new GOperationInfo("checkResource", new
String[]{"name"}, new String[]{"java.lang.String"}));
infoFactory.addOperation(new GOperationInfo("checkEndpoint"));
infoFactory.addOperation(new GOperationInfo("doSomething", new
String[]{"name"}, new String[]{"java.lang.String"}));
infoFactory.addEndpoint(new GEndpointInfo("MockEndpoint",
MockEndpoint.class.getName()));
infoFactory.setConstructor(new
GConstructorInfo(Collections.singletonList("Name"),
Collections.singletonList(String.class)));
GBEAN_INFO = infoFactory.getBeanInfo();
}
public MockGBean(String name) {
this.name = name;
}
public String getName() {
return name;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public MockEndpoint getMockEndpoint() {
return endpoint;
}
public void setMockEndpoint(MockEndpoint endpoint) {
this.endpoint = endpoint;
}
public boolean checkResource(String name) {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
return cl.getResource(name) != null;
}
public String doSomething(String name) {
return name;
}
public String checkEndpoint() {
if (endpoint == null) {
return "no endpoint";
}
return endpoint.doSomething("endpointCheck");
}
}
1.1
incubator-geronimo/modules/deployment/src/test/org/apache/geronimo/deployment/service/ServiceDeployerTest.java
Index: ServiceDeployerTest.java
===================================================================
/* ====================================================================
* The Apache Software License, Version 1.1
*
* Copyright (c) 2003 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "Apache" and "Apache Software Foundation" and
* "Apache Geronimo" must not be used to endorse or promote products
* derived from this software without prior written permission. For
* written permission, please contact [EMAIL PROTECTED]
*
* 5. Products derived from this software may not be called "Apache",
* "Apache Geronimo", nor may "Apache" appear in their name, without
* prior written permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*
* ====================================================================
*/
package org.apache.geronimo.deployment.service;
import java.io.IOException;
import java.io.InputStream;
import java.io.File;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.net.URI;
import java.net.URL;
import java.util.HashSet;
import java.util.Set;
import java.util.Collections;
import java.util.Enumeration;
import java.util.zip.ZipEntry;
import java.util.jar.JarOutputStream;
import java.util.jar.JarFile;
import javax.management.ObjectName;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.geronimo.deployment.ConfigurationCallback;
import org.apache.geronimo.deployment.BatchDeployer;
import org.apache.geronimo.kernel.deployment.scanner.URLInfo;
import org.apache.geronimo.kernel.deployment.scanner.URLType;
import org.apache.geronimo.gbean.jmx.GBeanMBean;
import junit.framework.TestCase;
/**
*
*
* @version $Revision: 1.1 $ $Date: 2004/01/16 03:48:43 $
*/
public class ServiceDeployerTest extends TestCase {
private static final URI MODULE_ID = URI.create("service");
private static final Set serviceURIs = new HashSet();
static {
serviceURIs.add(URI.create("service/classes/test-resource.dat"));
}
private DocumentBuilder parser;
private ServiceDeployer deployer;
private File workDir;
private BatchDeployer batcher;
private File configFile;
public void testResource() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL resource = cl.getResource("services/service1.xml");
URLInfo urlInfo = new URLInfo(resource, URLType.RESOURCE);
ServiceModule module = (ServiceModule) deployer.getModule(urlInfo,
MODULE_ID);
module.generateClassPath(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
fail();
}
public void addToClasspath(URI uri) {
fail();
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
fail();
}
});
module.defineGBeans(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
fail();
}
public void addToClasspath(URI uri) {
fail();
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
try {
assertEquals(new
ObjectName("geronimo.test:name=MyMockGMBean"), name);
assertEquals("1234", gbean.getAttribute("Value"));
} catch (Exception e) {
fail();
}
}
}, ClassLoader.getSystemClassLoader());
}
public void testPacked() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL resource = cl.getResource("services/service2.jar");
URLInfo urlInfo = new URLInfo(resource, URLType.PACKED_ARCHIVE);
ServiceModule module = (ServiceModule) deployer.getModule(urlInfo,
MODULE_ID);
final Set paths = new HashSet();
module.generateClassPath(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
paths.add(path);
}
public void addToClasspath(URI uri) {
assertEquals(URI.create("service/classes/"), uri);
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
fail();
}
});
assertEquals(serviceURIs, paths);
module.defineGBeans(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
fail();
}
public void addToClasspath(URI uri) {
fail();
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
try {
assertEquals(new
ObjectName("geronimo.test:name=MyMockGMBean"), name);
assertEquals("1234", gbean.getAttribute("Value"));
} catch (Exception e) {
fail();
}
}
}, ClassLoader.getSystemClassLoader());
}
public void testUnpacked() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL resource = cl.getResource("services/service3/");
URLInfo urlInfo = new URLInfo(resource, URLType.UNPACKED_ARCHIVE);
ServiceModule module = (ServiceModule) deployer.getModule(urlInfo,
MODULE_ID);
final Set paths = new HashSet();
module.generateClassPath(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
paths.add(path);
}
public void addToClasspath(URI uri) {
assertEquals(URI.create("service/classes/"), uri);
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
fail();
}
});
assertEquals(serviceURIs, paths);
module.defineGBeans(new ConfigurationCallback() {
public void addFile(URI path, InputStream is) throws IOException {
fail();
}
public void addToClasspath(URI uri) {
fail();
}
public void addGBean(ObjectName name, GBeanMBean gbean) {
try {
assertEquals(new
ObjectName("geronimo.test:name=MyMockGMBean"), name);
assertEquals("1234", gbean.getAttribute("Value"));
} catch (Exception e) {
fail();
}
}
}, ClassLoader.getSystemClassLoader());
}
public void testBatchResource() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
URL resource = cl.getResource("services/service1.xml");
URLInfo urlInfo = new URLInfo(resource, URLType.RESOURCE);
batcher.addSource(urlInfo);
batcher.deploy();
JarOutputStream jos = new JarOutputStream(new
BufferedOutputStream(new FileOutputStream(configFile)));
batcher.saveConfiguration(jos);
jos.close();
JarFile jar = new JarFile(configFile);
Set jarEntries = new HashSet();
for (Enumeration e = jar.entries(); e.hasMoreElements();) {
ZipEntry entry = (ZipEntry) e.nextElement();
jarEntries.add(entry.getName());
}
Set result = new HashSet();
result.add("META-INF/config.ser");
assertEquals(result, jarEntries);
}
public void testBatchPacked() throws Exception {
ClassLoader cl = Thread.currentThread().getContextClassLoader();
final URL resource = cl.getResource("services/service2.jar");
URLInfo urlInfo = new URLInfo(resource, URLType.PACKED_ARCHIVE);
batcher.addSource(urlInfo);
batcher.deploy();
JarOutputStream jos = new JarOutputStream(new
BufferedOutputStream(new FileOutputStream(configFile)));
batcher.saveConfiguration(jos);
jos.close();
JarFile jar = new JarFile(configFile);
Set jarEntries = new HashSet();
for (Enumeration e = jar.entries(); e.hasMoreElements();) {
ZipEntry entry = (ZipEntry) e.nextElement();
jarEntries.add(entry.getName());
}
Set result = new HashSet();
result.add("META-INF/config.ser");
result.add("service2.jar/classes/test-resource.dat");
assertEquals(result, jarEntries);
}
protected void setUp() throws Exception {
parser = DocumentBuilderFactory.newInstance().newDocumentBuilder();
deployer = new ServiceDeployer(parser);
File tmpDir = new File(System.getProperty("java.io.tmpdir"));
workDir = new File(tmpDir, "test.car.work");
workDir.mkdir();
configFile = new File(tmpDir, "test.car");
batcher = new BatchDeployer(URI.create("test"),
Collections.singletonList(deployer), workDir);
}
protected void tearDown() throws Exception {
recursiveDelete(workDir);
configFile.delete();
}
private static void recursiveDelete(File root) throws Exception {
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();
}
}
1.1
incubator-geronimo/modules/deployment/src/test-resources/services/service1.xml
Index: service1.xml
===================================================================
<gbeans>
<gbean class="org.apache.geronimo.deployment.MockGBean"
objectName="geronimo.test:name=MyMockGMBean">
<default attribute="Value">1234</default>
</gbean>
</gbeans>
1.1
incubator-geronimo/modules/deployment/src/test-resources/services/service2.jar
<<Binary file>>
1.1
incubator-geronimo/modules/deployment/src/test-resources/services/service3/META-INF/MANIFEST.MF
Index: MANIFEST.MF
===================================================================
Manifest-Version: 1.0
Created-By: 1.4.2 (Sun Microsystems Inc.)
1.1
incubator-geronimo/modules/deployment/src/test-resources/services/service3/META-INF/geronimo-service.xml
Index: geronimo-service.xml
===================================================================
<gbeans>
<path>classes/</path>
<gbean class="org.apache.geronimo.deployment.MockGBean"
objectName="geronimo.test:name=MyMockGMBean">
<default attribute="Value">1234</default>
</gbean>
</gbeans>
1.1
incubator-geronimo/modules/deployment/src/test-resources/services/service3/classes/test-resource.dat
Index: test-resource.dat
===================================================================
Hello