You are viewing a plain text version of this content. The canonical link for it is here.
Posted to scm@geronimo.apache.org by jb...@apache.org on 2004/02/10 23:34:04 UTC

cvs commit: incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel ConfigTest.java

jboynes     2004/02/10 14:34:04

  Modified:    modules/deployment/src/java/org/apache/geronimo/deployment
                        ModuleDeployer.java
               modules/deployment/src/test/org/apache/geronimo/deployment/service
                        ParentDeployerTest.java
               modules/kernel/src/java/org/apache/geronimo/kernel/config
                        Configuration.java
               modules/kernel/src/test/org/apache/geronimo/kernel
                        ConfigTest.java
  Added:       modules/kernel/src/java/org/apache/geronimo/kernel/repository
                        LocalRepository.java
                        MissingDependencyException.java Repository.java
  Log:
  Add basic repository to kernel to allow component references from Configurations
  
  Revision  Changes    Path
  1.4       +11 -1     incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ModuleDeployer.java
  
  Index: ModuleDeployer.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/java/org/apache/geronimo/deployment/ModuleDeployer.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- ModuleDeployer.java	24 Jan 2004 19:50:04 -0000	1.3
  +++ ModuleDeployer.java	10 Feb 2004 22:34:04 -0000	1.4
  @@ -73,9 +73,14 @@
   import java.util.LinkedList;
   import java.util.List;
   import java.util.Map;
  +import java.util.Collections;
   import java.util.jar.JarOutputStream;
   import java.util.zip.ZipEntry;
   import javax.management.ObjectName;
  +import javax.management.AttributeNotFoundException;
  +import javax.management.InvalidAttributeValueException;
  +import javax.management.MBeanException;
  +import javax.management.ReflectionException;
   
   import org.apache.geronimo.gbean.InvalidConfigurationException;
   import org.apache.geronimo.gbean.jmx.GBeanMBean;
  @@ -177,6 +182,11 @@
                   config.setAttribute("GBeanState", Configuration.storeGBeans(gbeans));
               } catch (Exception e) {
                   throw new DeploymentException("Unable to save state to configuration", e);
  +            }
  +            try {
  +                config.setAttribute("Dependencies", Collections.EMPTY_LIST);
  +            } catch (Exception e) {
  +                throw new DeploymentException("Unable to intialize Dependencies", e);
               }
           } finally {
               // tell each module we are done with it
  
  
  
  1.6       +2 -1      incubator-geronimo/modules/deployment/src/test/org/apache/geronimo/deployment/service/ParentDeployerTest.java
  
  Index: ParentDeployerTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/deployment/src/test/org/apache/geronimo/deployment/service/ParentDeployerTest.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- ParentDeployerTest.java	4 Feb 2004 05:43:31 -0000	1.5
  +++ ParentDeployerTest.java	10 Feb 2004 22:34:04 -0000	1.6
  @@ -98,6 +98,7 @@
           parentPath.add(new URI(cl.getResource("services/").toString()));
           parentGBean.setAttribute("ClassPath", parentPath);
           parentGBean.setAttribute("GBeanState", state);
  +        parentGBean.setAttribute("Dependencies", Collections.EMPTY_LIST);
           kernel.load(parentGBean, null, parentName);
           kernel.getMBeanServer().invoke(parentName, "start", null, null);
   
  
  
  
  1.9       +54 -37    incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java
  
  Index: Configuration.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/config/Configuration.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- Configuration.java	6 Feb 2004 08:27:49 -0000	1.8
  +++ Configuration.java	10 Feb 2004 22:34:04 -0000	1.9
  @@ -66,33 +66,33 @@
   import java.net.URI;
   import java.net.URL;
   import java.net.URLClassLoader;
  -import java.util.ArrayList;
  -import java.util.Collections;
  +import java.util.Collection;
   import java.util.HashMap;
  -import java.util.HashSet;
   import java.util.Iterator;
   import java.util.List;
   import java.util.Map;
   import java.util.Set;
  -
  -import javax.management.MBeanServer;
  -import javax.management.ObjectName;
   import javax.management.AttributeNotFoundException;
   import javax.management.InvalidAttributeValueException;
   import javax.management.MBeanException;
  +import javax.management.MBeanServer;
  +import javax.management.ObjectName;
   import javax.management.ReflectionException;
   
   import org.apache.commons.logging.Log;
   import org.apache.commons.logging.LogFactory;
   import org.apache.geronimo.gbean.GAttributeInfo;
  +import org.apache.geronimo.gbean.GBean;
  +import org.apache.geronimo.gbean.GBeanContext;
   import org.apache.geronimo.gbean.GBeanInfo;
  +import org.apache.geronimo.gbean.GBeanInfoFactory;
   import org.apache.geronimo.gbean.GConstructorInfo;
   import org.apache.geronimo.gbean.GReferenceInfo;
   import org.apache.geronimo.gbean.jmx.GBeanMBean;
   import org.apache.geronimo.gbean.jmx.GBeanMBeanContext;
  -import org.apache.geronimo.gbean.GBean;
  -import org.apache.geronimo.gbean.GBeanContext;
   import org.apache.geronimo.kernel.Kernel;
  +import org.apache.geronimo.kernel.repository.Repository;
  +import org.apache.geronimo.kernel.repository.MissingDependencyException;
   
   /**
    * A Configuration represents a collection of runnable services that can be
  @@ -129,7 +129,9 @@
       private final URI id;
       private final ConfigurationParent parent;
       private final List classPath;
  +    private final List dependencies;
       private final byte[] gbeanState;
  +    private final Collection repositories;
   
       private GBeanMBeanContext context;
       private URL baseURL;
  @@ -145,12 +147,16 @@
        * @param parent the parent Configuration; may be null
        * @param classPath a List<URI> of locations that define the codebase for this Configuration
        * @param gbeanState a byte array contain the Java Serialized form of the GBeans in this Configuration
  +     * @param repositories a Collection<Repository> of repositories used to resolve dependencies
  +     * @param dependencies a List<URI> of dependencies
        */
  -    public Configuration(URI id, ConfigurationParent parent, List classPath, byte[] gbeanState) {
  +    public Configuration(URI id, ConfigurationParent parent, List classPath, byte[] gbeanState, Collection repositories, List dependencies) {
           this.id = id;
           this.parent = parent;
           this.gbeanState = gbeanState;
           this.classPath = classPath;
  +        this.dependencies = dependencies;
  +        this.repositories = repositories;
       }
   
       public void setGBeanContext(GBeanContext context) {
  @@ -159,11 +165,29 @@
   
       public void doStart() throws Exception {
           // build classpath
  -        URL[] urls = new URL[classPath.size()];
  -        for (int i = 0; i < urls.length; i++) {
  -            URI path = (URI) classPath.get(i);
  -            urls[i] = new URL(baseURL, path.toString());
  +        URL[] urls = new URL[dependencies.size() + classPath.size()];
  +        int idx = 0;
  +        for (Iterator i = dependencies.iterator(); i.hasNext();) {
  +            URI uri = (URI) i.next();
  +            URL url = null;
  +            for (Iterator j = repositories.iterator(); j.hasNext();) {
  +                Repository repository = (Repository) j.next();
  +                if (repository.hasURI(uri)) {
  +                    url = repository.getURL(uri);
  +                    break;
  +                }
  +            }
  +            if (url == null) {
  +                throw new MissingDependencyException("Unable to resolve dependency " + uri);
  +            }
  +            urls[idx++] = url;
  +        }
  +        for (Iterator i = classPath.iterator(); i.hasNext();) {
  +            URI uri = (URI) i.next();
  +            urls[idx++] = new URL(baseURL, uri.toString());
           }
  +        assert idx == urls.length;
  +
           if (parent == null) {
               classLoader = new URLClassLoader(urls);
           } else {
  @@ -355,29 +379,22 @@
       public static final GBeanInfo GBEAN_INFO;
   
       static {
  -        Set attributes = new HashSet();
  -        attributes.add(new GAttributeInfo("ID", true));
  -        attributes.add(new GAttributeInfo("ClassPath", true));
  -        attributes.add(new GAttributeInfo("GBeanState", true));
  -        attributes.add(new GAttributeInfo("BaseURL"));
  -        attributes.add(new GAttributeInfo("ObjectName"));
  -        attributes.add(new GAttributeInfo("ClassLoader"));
  -        attributes.add(new GAttributeInfo("SavedState"));
  -        List constructorNames = new ArrayList();
  -        constructorNames.add("ID");
  -        constructorNames.add("Parent");
  -        constructorNames.add("ClassPath");
  -        constructorNames.add("GBeanState");
  -        List constructorTypes = new ArrayList();
  -        constructorTypes.add(URI.class);
  -        constructorTypes.add(ConfigurationParent.class);
  -        constructorTypes.add(List.class);
  -        constructorTypes.add(byte[].class);
  -        GConstructorInfo constructor = new GConstructorInfo(constructorNames, constructorTypes);
  -        Set endpoints = new HashSet();
  -        endpoints.add(new GReferenceInfo("Parent", ConfigurationParent.class.getName()));
  -        Set operations = Collections.EMPTY_SET;
  -        GBEAN_INFO = new GBeanInfo(Configuration.class.getName(), attributes, constructor, operations, endpoints, Collections.EMPTY_SET);
  +        GBeanInfoFactory infoFactory = new GBeanInfoFactory(Configuration.class);
  +        infoFactory.addAttribute(new GAttributeInfo("ID", true));
  +        infoFactory.addAttribute(new GAttributeInfo("ClassPath", true));
  +        infoFactory.addAttribute(new GAttributeInfo("Dependencies", true));
  +        infoFactory.addAttribute(new GAttributeInfo("GBeanState", true));
  +        infoFactory.addAttribute(new GAttributeInfo("BaseURL"));
  +        infoFactory.addAttribute(new GAttributeInfo("ObjectName"));
  +        infoFactory.addAttribute(new GAttributeInfo("ClassLoader"));
  +        infoFactory.addAttribute(new GAttributeInfo("SavedState")); // @todo is this used?
  +        infoFactory.addReference(new GReferenceInfo("Parent", ConfigurationParent.class));
  +        infoFactory.addReference(new GReferenceInfo("Repositories", Repository.class));
  +        infoFactory.setConstructor(new GConstructorInfo(
  +                new String[]{"ID", "Parent", "ClassPath", "GBeanState", "Repositories", "Dependencies"},
  +                new Class[]{URI.class, ConfigurationParent.class, List.class, byte[].class, Collection.class, List.class}
  +        ));
  +        GBEAN_INFO = infoFactory.getBeanInfo();
       }
   
       public static GBeanInfo getGBeanInfo() {
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/repository/LocalRepository.java
  
  Index: LocalRepository.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 apache@apache.org.
   *
   * 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.kernel.repository;
  
  import java.io.File;
  import java.net.MalformedURLException;
  import java.net.URI;
  import java.net.URL;
  
  import org.apache.geronimo.gbean.GAttributeInfo;
  import org.apache.geronimo.gbean.GBeanInfo;
  import org.apache.geronimo.gbean.GBeanInfoFactory;
  import org.apache.geronimo.gbean.GConstructorInfo;
  
  /**
   *
   *
   * @version $Revision: 1.1 $ $Date: 2004/02/10 22:34:04 $
   */
  public class LocalRepository implements Repository {
      private final URI root;
  
      public LocalRepository(File root) {
          this.root = root.toURI();
      }
  
      public boolean hasURI(URI uri) {
          File f = new File(root.resolve(uri));
          return f.exists() && f.canRead();
      }
  
      public URL getURL(URI uri) throws MalformedURLException {
          return root.resolve(uri).toURL();
      }
  
      public static final GBeanInfo GBEAN_INFO;
  
      static {
          GBeanInfoFactory infoFactory = new GBeanInfoFactory(LocalRepository.class);
          infoFactory.addAttribute(new GAttributeInfo("Root", true));
          infoFactory.addInterface(Repository.class);
          infoFactory.setConstructor(new GConstructorInfo(
                  new String[] {"Root"},
                  new Class[] {File.class}
          ));
          GBEAN_INFO = infoFactory.getBeanInfo();
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/repository/MissingDependencyException.java
  
  Index: MissingDependencyException.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 apache@apache.org.
   *
   * 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.kernel.repository;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2004/02/10 22:34:04 $
   */
  public class MissingDependencyException extends Exception {
      public MissingDependencyException() {
      }
  
      public MissingDependencyException(Throwable cause) {
          super(cause);
      }
  
      public MissingDependencyException(String message) {
          super(message);
      }
  
      public MissingDependencyException(String message, Throwable cause) {
          super(message, cause);
      }
  }
  
  
  
  1.1                  incubator-geronimo/modules/kernel/src/java/org/apache/geronimo/kernel/repository/Repository.java
  
  Index: Repository.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 apache@apache.org.
   *
   * 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.kernel.repository;
  
  import java.net.URL;
  import java.net.URI;
  import java.net.MalformedURLException;
  
  /**
   * 
   * 
   * @version $Revision: 1.1 $ $Date: 2004/02/10 22:34:04 $
   */
  public interface Repository {
      boolean hasURI(URI uri);
      
      URL getURL(URI uri) throws MalformedURLException;
  }
  
  
  
  1.11      +2 -1      incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java
  
  Index: ConfigTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/modules/kernel/src/test/org/apache/geronimo/kernel/ConfigTest.java,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- ConfigTest.java	4 Feb 2004 05:42:57 -0000	1.10
  +++ ConfigTest.java	10 Feb 2004 22:34:04 -0000	1.11
  @@ -101,6 +101,7 @@
           config.setReferencePatterns("Parent", null);
           config.setAttribute("ClassPath", Collections.EMPTY_LIST);
           config.setAttribute("GBeanState", state);
  +        config.setAttribute("Dependencies", Collections.EMPTY_LIST);
           ObjectName configName = (ObjectName) mbServer.invoke(Kernel.KERNEL, "load", new Object[]{config, null}, new String[]{GBeanMBean.class.getName(), URL.class.getName()});
           mbServer.invoke(configName, "startRecursive", null, null);