tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From r...@apache.org
Subject cvs commit: jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup catalina.properties CatalinaProperties.java Bootstrap.java ClassLoaderFactory.java
Date Thu, 24 Oct 2002 13:53:23 GMT
remm        2002/10/24 06:53:22

  Modified:    catalina/src/share/org/apache/catalina/startup
                        Bootstrap.java ClassLoaderFactory.java
  Added:       catalina/src/share/org/apache/catalina/startup
                        catalina.properties CatalinaProperties.java
  Log:
  - Since it didn't get vetoed, I'm going forward with the CL configurability feature.
  - Adds new catalina.properties file which allows to configure the three Catalina
    classloaders. This should allow to embed Tomcat in a more flexible way
    without using the Embedded class.
  - The functionality is far from being done. For example, it would be desirable to
    be able to specify the configuration source (currently hardcoded to
    conf/server.xml) in the properties file.
  
  Revision  Changes    Path
  1.5       +57 -4     jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/Bootstrap.java
  
  Index: Bootstrap.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/Bootstrap.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- Bootstrap.java	22 Oct 2002 20:25:29 -0000	1.4
  +++ Bootstrap.java	24 Oct 2002 13:53:22 -0000	1.5
  @@ -71,6 +71,7 @@
   import java.net.MalformedURLException;
   import java.net.URL;
   import java.util.ArrayList;
  +import java.util.StringTokenizer;
   import org.apache.catalina.loader.StandardClassLoader;
   import org.apache.catalina.security.SecurityClassLoad;
   
  @@ -101,6 +102,7 @@
       protected ClassLoader catalinaLoader = null;
       protected ClassLoader sharedLoader = null;
   
  +    protected static final String CATALINA_TOKEN = "${catalina.home}";
       
       public void setDebug( int debug ) {
           this.debug=debug;
  @@ -109,10 +111,15 @@
       public void setArgs(String args[] ) {
           this.args=args;
       }
  +
  +
       // ----------------------------------------------------------- Main Program
   
  +
       public void initClassLoaders() {
           try {
  +
  +            /*
               File unpacked[] = new File[1];
               File packed[] = new File[1];
               File packed2[] = new File[2];
  @@ -142,6 +149,13 @@
               sharedLoader =
                   ClassLoaderFactory.createClassLoader(unpacked, packed,
                                                        commonLoader);
  +            */
  +
  +            ClassLoaderFactory.setDebug(debug);
  +            commonLoader = createClassLoader("common", null);
  +            catalinaLoader = createClassLoader("server", commonLoader);
  +            sharedLoader = createClassLoader("shared", commonLoader);
  +
           } catch (Throwable t) {
   
               log("Class loader creation threw exception", t);
  @@ -149,6 +163,45 @@
   
           }
       }
  +
  +
  +    private ClassLoader createClassLoader(String name, ClassLoader parent)
  +        throws Exception {
  +
  +        String value = CatalinaProperties.getProperty(name + ".loader");
  +        if ((value == null) || (value.equals("")))
  +            return parent;
  +
  +        ArrayList unpackedList = new ArrayList();
  +        ArrayList packedList = new ArrayList();
  +
  +        StringTokenizer tokenizer = new StringTokenizer(value, ",");
  +        while (tokenizer.hasMoreElements()) {
  +            String repository = tokenizer.nextToken();
  +            boolean packed = false;
  +            if (repository.startsWith(CATALINA_TOKEN)) {
  +                repository = getCatalinaHome() 
  +                    + repository.substring(CATALINA_TOKEN.length());
  +            }
  +            if (repository.endsWith("*.jar")) {
  +                packed = true;
  +                repository = repository.substring
  +                    (0, repository.length() - "*.jar".length());
  +            }
  +            if (packed) {
  +                packedList.add(new File(repository));
  +            } else {
  +                unpackedList.add(new File(repository));
  +            }
  +        }
  +
  +        File[] unpacked = (File[]) unpackedList.toArray(new File[0]);
  +        File[] packed = (File[]) packedList.toArray(new File[0]);
  +
  +        return ClassLoaderFactory.createClassLoader(unpacked, packed, parent);
  +
  +    }
  +
   
       // ----------------------------------------------------------- Main Program
   
  
  
  
  1.2       +7 -6      jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ClassLoaderFactory.java
  
  Index: ClassLoaderFactory.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/ClassLoaderFactory.java,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- ClassLoaderFactory.java	18 Jul 2002 16:47:48 -0000	1.1
  +++ ClassLoaderFactory.java	24 Oct 2002 13:53:22 -0000	1.2
  @@ -163,10 +163,11 @@
           if (unpacked != null) {
               for (int i = 0; i < unpacked.length; i++)  {
                   File file = unpacked[i];
  -                if (!file.isDirectory() || !file.exists() || !file.canRead())
  +                if (!file.exists() || !file.canRead())
                       continue;
                   if (debug >= 1)
  -                    log("  Including directory " + file.getAbsolutePath());
  +                    log("  Including directory or JAR " 
  +                        + file.getAbsolutePath());
                   URL url = new URL("file", null,
                                     file.getCanonicalPath() + File.separator);
                   list.add(url.toString());
  
  
  
  1.1                  jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/catalina.properties
  
  Index: catalina.properties
  ===================================================================
  #
  # List of comma-separated packages that start with or equal this string
  # will cause a security exception to be thrown when
  # passed to checkPackageAccess unless the
  # corresponding RuntimePermission ("accessClassInPackage."+package) has
  # been granted.
  package.access=sun.
  
  #
  # List of comma-separated packages that start with or equal this string
  # will cause a security exception to be thrown when
  # passed to checkPackageDefinition unless the
  # corresponding RuntimePermission ("defineClassInPackage."+package) has
  # been granted.
  #
  # by default, no packages are restricted for definition, and none of
  # the class loaders supplied with the JDK call checkPackageDefinition.
  #
  #package.definition=
  
  #
  # List of comma-separated paths defining the contents of the "common" 
  # classloader. Prefixes should be used to define what is the repository type.
  # Path may be relative to the CATALINA_HOME path or absolute. If left as blank,
  # the JVM system loader will be used as Catalina's "common" loader.
  # Examples:
  #     "foo": Add this folder as a class repository
  #     "foo/*.jar": Add all the JARs of the specified folder as class 
  #                  repositories
  #     "foo/bar.jar": Add bar.jar as a class repository
  common.loader=${catalina.home}/common/classes,${catalina.home}/common/endorsed/*.jar,${catalina.home}/common/lib/*.jar
  
  #
  # List of comma-separated paths defining the contents of the "server" 
  # classloader. Prefixes should be used to define what is the repository type.
  # Path may be relative to the CATALINA_HOME path or absolute. If left as blank,
  # the "common" loader will be used as Catalina's "server" loader.
  # Examples:
  #     "foo": Add this folder as a class repository
  #     "foo/*.jar": Add all the JARs of the specified folder as class 
  #                  repositories
  #     "foo/bar.jar": Add bar.jar as a class repository
  server.loader=${catalina.home}/server/classes,${catalina.home}/server/lib/*.jar
  
  #
  # List of comma-separated paths defining the contents of the "shared" 
  # classloader. Prefixes should be used to define what is the repository type.
  # Path may be relative to the CATALINA_BASE path or absolute. If left as blank,
  # the "common" loader will be used as Catalina's "shared" loader.
  # Examples:
  #     "foo": Add this folder as a class repository
  #     "foo/*.jar": Add all the JARs of the specified folder as class 
  #                  repositories
  #     "foo/bar.jar": Add bar.jar as a class repository 
  shared.loader=${catalina.home}/shared/classes,${catalina.home}/shared/lib/*.jar
  
  
  
  1.1                  jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/CatalinaProperties.java
  
  Index: CatalinaProperties.java
  ===================================================================
  /*
   * $Header: /home/cvs/jakarta-tomcat-catalina/catalina/src/share/org/apache/catalina/startup/CatalinaProperties.java,v
1.1 2002/10/24 13:53:22 remm Exp $
   * $Revision: 1.1 $
   * $Date: 2002/10/24 13:53:22 $
   *
   * ====================================================================
   *
   * The Apache Software License, Version 1.1
   *
   * Copyright (c) 1999 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 acknowlegement:
   *       "This product includes software developed by the
   *        Apache Software Foundation (http://www.apache.org/)."
   *    Alternately, this acknowlegement may appear in the software itself,
   *    if and wherever such third-party acknowlegements normally appear.
   *
   * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
   *    Foundation" 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"
   *    nor may "Apache" appear in their names without prior written
   *    permission of the Apache Group.
   *
   * 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/>.
   *
   * [Additional notices, if required by prior licensing conditions]
   *
   */
  
  
  package org.apache.catalina.startup;
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.InputStream;
  import java.net.URL;
  import java.util.Properties;
  
  
  /**
   * Utility class to read the bootstrap Catalina configuration.
   *
   * @author Remy Maucherat
   * @version $Revision: 1.1 $ $Date: 2002/10/24 13:53:22 $
   */
  
  public class CatalinaProperties {
  
  
      // ------------------------------------------------------- Static Variables
  
  
      private static Properties properties = null;
  
  
      static {
  
          loadProperties();
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Return specified property value.
       */
      public static String getProperty(String name) {
  
          return properties.getProperty(name);
  
      }
  
  
      /**
       * Return specified property value.
       */
      public static String getProperty(String name, String defaultValue) {
  
          return properties.getProperty(name, defaultValue);
  
      }
  
  
      // --------------------------------------------------------- Public Methods
  
  
      /**
       * Load properties.
       */
      private static void loadProperties() {
  
          InputStream is = null;
          Throwable error = null;
  
          try {
              String configUrl = getConfigUrl();
              if (configUrl != null) {
                  is = (new URL(configUrl)).openStream();
              }
          } catch (Throwable t) {
              // Ignore
          }
  
          if (is == null) {
              try {
                  File home = new File(getCatalinaHome());
                  File conf = new File(home, "conf");
                  File properties = new File(conf, "catalina.properties");
                  is = new FileInputStream(properties);
              } catch (Throwable t) {
                  // Ignore
              }
          }
  
          if (is == null) {
              try {
                  is = CatalinaProperties.class.getResourceAsStream
                      ("/org/apache/catalina/startup/catalina.properties");
              } catch (Throwable t) {
                  // Ignore
              }
          }
  
          if (is != null) {
              try {
                  properties = new Properties();
                  properties.load(is);
                  is.close();
              } catch (Throwable t) {
                  error = t;
              }
          }
  
          if ((is == null) || (error != null)) {
              // Do something
              System.out.println("Error");
          }
  
      }
  
  
      /**
       * Get the value of the catalina.home environment variable.
       */
      private static String getCatalinaHome() {
          return System.getProperty("catalina.home",
                                    System.getProperty("user.dir"));
      }
  
  
      /**
       * Get the value of the configuration URL.
       */
      private static String getConfigUrl() {
          return System.getProperty("catalina.config");
      }
  
  
  }
  
  
  

--
To unsubscribe, e-mail:   <mailto:tomcat-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-dev-help@jakarta.apache.org>


Mime
View raw message