classpath
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: vm shortname patch


From: Jeroen Frijters
Subject: RE: vm shortname patch
Date: Thu, 19 Dec 2002 09:36:12 +0100

I love the idea of using URLs to load these config files, but I'm not quite
sure I like the fact that they all use the same base URL. Would it be
possible (and make sense) to use URLs for the individual properties? In the
current solution there is no way for an end user to override just the
location of the .security file (for example).

A possible solution would be to construct the URLs in the static initializer
of System. For example:

if(defaultProperties.get("gnu.classpath.vm.security.url") == null)
  defaultProperties.put("gnu.classpath.vm.security.url",
    defaultProperties.getProperty("gnu.classpath.home.url") + "/security/"
    + System.getProperty("gnu.classpath.vm.shortname") + ".security");

And do the same for "gnu.classpath.security.url", "gnu.classpath.jndi.url",
etc.

Regards,
Jeroen

> -----Original Message-----
> From: address@hidden 
> [mailto:address@hidden On 
> Behalf Of Tom Tromey
> Sent: Wednesday, December 18, 2002 23:57
> To: Classpath Discussion Mailing List
> Subject: RFC: vm shortname patch
> 
> 
> I'm posting this patch for comments on the general approach.  I
> haven't tested it yet (though if you see an obvious bug I'd welcome
> the information).
> 
> The idea here is that Classpath should look up its auxiliary
> properties files using a URL rather than a simple path.  This lets us
> support configurations where there is no filesystem (for instance, an
> embedded libgcj using core: URLs), among other things.
> 
> This also adds a new `vm shortname' property.  This is a "short" name
> for the current VM, suitable for use as a file name.  If it isn't
> provided by the VM, it is initialized to a reasonable value.
> 
> Comments?  Questions?  Criticisms?
> 
> Will this patch adversely affect the Classpath startup process?
> 
> Tom
> 
> Index: ChangeLog
> from  Tom Tromey  <address@hidden>
> 
>       * javax/naming/InitialContext.java (init): Use
>       gnu.classpath.home.url.
>       * java/util/logging/LogManager.java (readConfiguration): Use
>       gnu.classpath.home.url.
>       * java/security/Security.java: Use new properties.
>       (loadProviders): Accept base url; use it.
>       * java/lang/System.java: Document 
> gnu.classpath.vm.shortname, and
>       gnu.classpath.home.url.
>       (gnu.classpath.home.url): Define.
>       (gnu.classpath.vm.shortname): Likewise.
> 
> Index: java/lang/System.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/lang/System.java,v
> retrieving revision 1.26
> diff -u -r1.26 System.java
> --- java/lang/System.java 18 Dec 2002 14:09:45 -0000 1.26
> +++ java/lang/System.java 18 Dec 2002 22:54:57 -0000
> @@ -84,6 +84,21 @@
>      defaultProperties.put("gnu.classpath.version",
>                   Configuration.CLASSPATH_VERSION);
>  
> +    // Set base URL if not already set.
> +    if (defaultProperties.get("gnu.classpath.home.url") == null)
> +      defaultProperties.put("gnu.classpath.home.url",
> +                         "file://" + 
> Configuration.CLASSPATH_HOME + "/lib");
> +
> +    // Set short name if not already set.
> +    if (defaultProperties.get("gnu.classpath.vm.shortname") == null)
> +      {
> +     String value = defaultProperties.getProperty("java.vm.name");
> +     int index = value.lastIndexOf(' ');
> +     if (index != -1)
> +       value = value.substring(index + 1);
> +     defaultProperties.put("gnu.classpath.vm.shortname", value);
> +      }
> +
>      defaultProperties.put("gnu.cpu.endian",
>                            VMSystem.isWordsBigEndian() ? 
> "big" : "little");
>  
> @@ -435,6 +450,10 @@
>     * <dl>
>     * <dl> gnu.classpath.home <dd> Path to the classpath libraries.
>     * <dl> gnu.classpath.version <dd> Version of the 
> classpath libraries.
> +   * <dl> gnu.classpath.vm.shortname <dd> Succinct version 
> of the VM name;
> +   *      used for finding property files in file system
> +   * <dl> gnu.classpath.home.url <dd> Base URL; used for finding
> +   *      property files in file system
>     * <dt> gnu.cpu.endian      <dd>big or little
>     * <dt> gnu.java.io.encoding_scheme_alias.ISO-8859-?   <dd>8859_?
>     * <dt> gnu.java.io.encoding_scheme_alias.iso-8859-?   <dd>8859_?
> Index: java/security/Security.java
> ===================================================================
> RCS file: /cvsroot/classpath/classpath/java/security/Security.java,v
> retrieving revision 1.12
> diff -u -r1.12 Security.java
> --- java/security/Security.java 13 Dec 2002 11:17:51 -0000 1.12
> +++ java/security/Security.java 18 Dec 2002 22:54:57 -0000
> @@ -37,9 +37,10 @@
>  
>  package java.security;
>  import java.io.File;
> -import java.io.FileInputStream;
> +import java.io.InputStream;
>  import java.io.IOException;
>  import java.io.FileNotFoundException;
> +import java.net.URL;
>  import java.security.Provider;
>  import java.util.Vector;
>  import java.util.Enumeration;
> @@ -59,9 +60,9 @@
>  
>    static
>    {
> -    loadProviders(System.getProperty("java.home"),
> -               System.getProperty("java.vm.name"));
> -    loadProviders(System.getProperty("gnu.classpath.home"), 
> "classpath");
> +    String base = System.getProperty("gnu.classpath.home.url");
> +    loadProviders(base, 
> System.getProperty("gnu.classpath.vm.shortname"));
> +    loadProviders(base, "classpath");
>    }
>  
>    // This class can't be instantiated.
> @@ -69,20 +70,16 @@
>    {
>    }
>  
> -  private static void loadProviders(String dir, String vendor)
> +  private static void loadProviders(String baseUrl, String vendor)
>    {
> -    if (dir == null || vendor == null)
> +    if (baseUrl == null || vendor == null)
>        return;
>  
> -    String separator = System.getProperty("file.separator");
> -    String secfilestr = (dir +
> -                      separator + "lib" +
> -                      separator + "security" +
> -                      separator + vendor + ".security");
> +    String secfilestr = baseUrl + "/security/" + vendor + 
> ".security";
>  
>      try
>        {
> -     FileInputStream fin = new FileInputStream(secfilestr);
> +     InputStream fin = new URL(secfilestr).openStream();
>       secprops = new Properties();
>       secprops.load(fin);
>  
> Index: java/util/logging/LogManager.java
> ===================================================================
> RCS file: 
> /cvsroot/classpath/classpath/java/util/logging/LogManager.java,v
> retrieving revision 1.4
> diff -u -r1.4 LogManager.java
> --- java/util/logging/LogManager.java 17 Dec 2002 10:16:44 -0000 1.4
> +++ java/util/logging/LogManager.java 18 Dec 2002 22:54:57 -0000
> @@ -46,6 +46,7 @@
>  import java.beans.PropertyChangeSupport;
>  import java.io.IOException;
>  import java.io.InputStream;
> +import java.net.URL;
>  import java.util.Collections;
>  import java.util.Properties;
>  import java.util.Enumeration;
> @@ -91,11 +92,11 @@
>   *     property <code>java.util.logging.config.file</code>.</li>
>   *
>   * <li>If the system property 
> <code>java.util.logging.config.file</code>
> - *     is not set, however, the contents of the file
> - *     "{java.home}/lib/logging.properties" are passed to
> + *     is not set, however, the contents of the URL
> + *     "{gnu.classpath.home.url}/lib/logging.properties" are 
> passed to
>   *     address@hidden #readConfiguration(java.io.InputStream)}.
> - *     Here, "{java.home}" stands for the value of
> - *     the system property <code>java.home</code>.</li>
> + *     Here, "{gnu.classpath.home.url}" stands for the value of
> + *     the system property <code>gnu.classpath.home.url</code>.</li>
>   * </ol>
>   *
>   * @author Sascha Brawer (address@hidden)
> @@ -467,9 +468,10 @@
>     * Configures the logging framework by reading a 
> configuration file.
>     * The name and location of this file are specified by the system
>     * property <code>java.util.logging.config.file</code>.  If this
> -   * property is not set, the file 
> "{java.home}/lib/logging.properties"
> -   * is taken, where "{java.home}" stands for the value of the system
> -   * property <code>java.home</code>.
> +   * property is not set, the URL
> +   * "{gnu.classpath.home.url}/lib/logging.properties" is 
> taken, where
> +   * "{gnu.classpath.home.url}" stands for the value of the system
> +   * property <code>gnu.classpath.home.url</code>.
>     *
>     * <p>The task of configuring the framework is then delegated to
>     * address@hidden #readConfiguration(java.io.InputStream)}, which will
> @@ -488,19 +490,19 @@
>      throws IOException, SecurityException
>    {
>      String       path;
> -    String       pathSep;
>      InputStream  inputStream;
>  
>      path = System.getProperty("java.util.logging.config.file");
>      if ((path == null) || (path.length() == 0))
>      {
> -      pathSep = System.getProperty("file.separator");
> -      path = System.getProperty("java.home")
> -             + pathSep + "lib"
> -          + pathSep + "logging.properties";
> +      String url = (System.getProperty("gnu.classpath.home.url")
> +                 + "/lib/logging.properties");
> +      inputStream = new URL(url).openStream();
> +    }
> +    else
> +    {
> +      inputStream = new java.io.FileInputStream(path);
>      }
> -
> -    inputStream = new java.io.FileInputStream(path);
>  
>      try
>      {
> Index: javax/naming/InitialContext.java
> ===================================================================
> RCS file: 
> /cvsroot/classpath/classpath/javax/naming/InitialContext.java,v
> retrieving revision 1.1
> diff -u -r1.1 InitialContext.java
> --- javax/naming/InitialContext.java 23 Nov 2002 21:44:28 -0000 1.1
> +++ javax/naming/InitialContext.java 18 Dec 2002 22:54:57 -0000
> @@ -1,5 +1,5 @@
>  /* InitialContext.java --
> -   Copyright (C) 2000 Free Software Foundation, Inc.
> +   Copyright (C) 2000, 2002 Free Software Foundation, Inc.
>  
>  This file is part of GNU Classpath.
>  
> @@ -126,18 +126,22 @@
>       }
>        catch (IOException e) {}
>  
> -      String home = System.getProperty("java.home");
> +      String home = System.getProperty("gnu.classpath.home.url");
>        if (home != null)
>       {
> -       String fileName = home + File.separator
> -         + "lib" + File.separator + "jndi.properties";
> +       String url = home + "/lib/jndi.properties";
>         Properties p = new Properties ();
>       
> -       try {
> -         InputStream is = new FileInputStream (fileName);
> -         p.load (is);
> -         is.close ();
> -       } catch (IOException e) {}
> +       try
> +         {
> +           InputStream is = new URL(url).openStream();
> +           p.load (is);
> +           is.close ();
> +         }
> +       catch (IOException e)
> +         {
> +           // Ignore.
> +         }
>  
>         merge (myProps, p);
>       }
> 
> 
> _______________________________________________
> Classpath mailing list
> address@hidden
> http://mail.gnu.org/mailman/listinfo/classpath
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]