jdk/src/share/classes/sun/misc/Launcher.java
author herrick
Fri, 12 Jun 2009 14:56:32 -0400
changeset 3111 fefdeafb7ab9
parent 2448 1e8128f3ff61
child 3958 b8acd5ee4f4f
permissions -rw-r--r--
6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7 6845973: Update JDK7 with deployment changes in 6u13, 6u14 4802695: Support 64-bit Java Plug-in and Java webstart on Windows/Linux on AMD64 6825019: DownloadManager should not be loaded and referenced for full JRE 6738770: REGRESSION:JSException throws when use LiveConnect javascript facility 6772884: plugin2 : java.lang.OutOfMemoryError or crash 6707535: Crossing domain hole affecting multiple sites/domains using plug-in 6728071: Non-verification of Update files may allow unintended updates 6704154: Code loaded from local filesystem should not get access to localhost 6727081: Web Start security restrictions bypass using special extension jnlp 6727079: Java Web Start Socket() restriction bypass 6727071: Cache location/user name information disclosure in SingleInstanceImpl. 6716217: AppletClassLoader adds permissions based on codebase regardless of CS 6694892: Java Webstart inclusion via system properties override [CVE-2008-2086] 6704074: localhost socket access due to cache location exposed 6703909: Java webstart arbitrary file creation using nativelib 6665315: browser crashes when deployment.properties has more slashes ( / ) 6660121: Encoding values in JNLP files can cause buffer overflow 6606110: URLConnection.setProxiedHost for resources that are loaded via proxy 6581221: SSV(VISTA): Redirection FAILS to work if user does a downgrade install 6609756: Buffer Overflow in Java ActiveX component 6608712: Bypassing the same origin policy in Java with crafted names 6534630: "gnumake clobber" doesn't 6849953: JDK7 - replacement of bufferoverflowU.lib on amd64 breaks build 6849029: Need some JDK7 merge clean-up after comments on the webrev 6847582: Build problem on JDK7 with isSecureProperty in merge 6827935: JDK 7 deployment merging - problem in Compiler-msvm.gmk 6823215: latest merge fixes from 6u12 -> JDK7 6816153: further mergers for JDK7 deployment integration 6807074: Fix Java Kernel and JQS in initial JDK7 builds Summary: Initial changeset for implementing 6uX Deployment Features into JDK7 Reviewed-by: dgu, billyh
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
     2
 * Copyright 1998-2009 Sun Microsystems, Inc.  All Rights Reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package sun.misc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.io.File;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.FilePermission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.net.URLClassLoader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.net.URLStreamHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.net.URLStreamHandlerFactory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.HashSet;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.Set;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.AccessController;
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
    41
import java.security.AllPermission;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.security.AccessControlContext;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import java.security.PermissionCollection;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
import java.security.Permissions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
import java.security.Permission;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
import java.security.ProtectionDomain;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
import java.security.CodeSource;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
import sun.security.action.GetPropertyAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
import sun.security.util.SecurityConstants;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
import sun.net.www.ParseUtil;
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
    53
import sun.jkernel.Bundle;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
    54
import sun.jkernel.DownloadManager;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * This class is used by the system to launch the main application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
Launcher */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
public class Launcher {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
    private static URLStreamHandlerFactory factory = new Factory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    private static Launcher launcher = new Launcher();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
    public static Launcher getLauncher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
        return launcher;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    private ClassLoader loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
    public Launcher() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
        // Create the extension class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
        ClassLoader extcl;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
            extcl = ExtClassLoader.getExtClassLoader();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
            throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                "Could not create extension class loader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
        // Now create the class loader to use to launch the application
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
            loader = AppClassLoader.getAppClassLoader(extcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
            throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
                "Could not create application class loader");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        // Also set the context class loader for the primordial thread.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
        Thread.currentThread().setContextClassLoader(loader);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        // Finally, install a security manager if requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
        String s = System.getProperty("java.security.manager");
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
            SecurityManager sm = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
            if ("".equals(s) || "default".equals(s)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
                sm = new java.lang.SecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
                    sm = (SecurityManager)loader.loadClass(s).newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
                } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
                } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
                } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
                } catch (ClassCastException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
            if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
                System.setSecurityManager(sm);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
                throw new InternalError(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
                    "Could not create SecurityManager: " + s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
     * Returns the class loader used to launch the main application.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
    public ClassLoader getClassLoader() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        return loader;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   121
    public static void addURLToAppClassLoader(URL u) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   122
        AccessController.checkPermission(new AllPermission());
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   123
        ClassLoader loader = Launcher.getLauncher().getClassLoader();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   124
        ((Launcher.AppClassLoader) loader).addAppURL(u);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   125
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   126
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   127
    public static void addURLToExtClassLoader(URL u) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   128
        AccessController.checkPermission(new AllPermission());
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   129
        ClassLoader loader = Launcher.getLauncher().getClassLoader();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   130
        ((Launcher.ExtClassLoader) loader.getParent()).addExtURL(u);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   131
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   132
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * The class loader used for loading installed extensions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
    static class ExtClassLoader extends URLClassLoader {
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   137
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   138
        static {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   139
            ClassLoader.registerAsParallelCapable();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   140
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
         * create an ExtClassLoader. The ExtClassLoader is created
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
         * within a context that limits which files it can read
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        public static ExtClassLoader getExtClassLoader() throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            final File[] dirs = getExtDirs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                // Prior implementations of this doPrivileged() block supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                // aa synthesized ACC via a call to the private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                // ExtClassLoader.getContext().
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   155
                return AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   156
                    new PrivilegedExceptionAction<ExtClassLoader>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   157
                        public ExtClassLoader run() throws IOException {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                            int len = dirs.length;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                            for (int i = 0; i < len; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                                MetaIndex.registerDirectory(dirs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                            return new ExtClassLoader(dirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
            } catch (java.security.PrivilegedActionException e) {
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   166
                throw (IOException) e.getException();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
        void addExtURL(URL url) {
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   171
            super.addURL(url);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
         * Creates a new ExtClassLoader for the specified directories.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        public ExtClassLoader(File[] dirs) throws IOException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
            super(getExtURLs(dirs), null, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
        private static File[] getExtDirs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
            String s = System.getProperty("java.ext.dirs");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
            File[] dirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
            if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
                StringTokenizer st =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
                    new StringTokenizer(s, File.pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
                int count = st.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
                dirs = new File[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
                    dirs[i] = new File(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
                dirs = new File[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
            return dirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        private static URL[] getExtURLs(File[] dirs) throws IOException {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   199
            Vector<URL> urls = new Vector<URL>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
            for (int i = 0; i < dirs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
                String[] files = dirs[i].list();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
                if (files != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
                    for (int j = 0; j < files.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
                        if (!files[j].equals("meta-index")) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
                            File f = new File(dirs[i], files[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
                            urls.add(getFileURL(f));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
            URL[] ua = new URL[urls.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
            urls.copyInto(ua);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
            return ua;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
         * Searches the installed extension directories for the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
         * library name. For each extension directory, we first look for
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
         * the native library in the subdirectory whose name is the value
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
         * of the system property <code>os.arch</code>. Failing that, we
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
         * look in the extension directory itself.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
        public String findLibrary(String name) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
            name = System.mapLibraryName(name);
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   225
            URL[] urls = super.getURLs();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   226
            File prevDir = null;
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   227
            for (int i = 0; i < urls.length; i++) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   228
                // Get the ext directory from the URL
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   229
                File dir = new File(urls[i].getPath()).getParentFile();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   230
                if (dir != null && !dir.equals(prevDir)) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   231
                    // Look in architecture-specific subdirectory first
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   232
                    String arch = System.getProperty("os.arch");
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   233
                    if (arch != null) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   234
                        File file = new File(new File(dir, arch), name);
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   235
                        if (file.exists()) {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   236
                            return file.getAbsolutePath();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   237
                        }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   238
                    }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   239
                    // Then check the extension directory
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   240
                    File file = new File(dir, name);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
                    if (file.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
                        return file.getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                }
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   245
                prevDir = dir;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
            return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   250
        protected Class findClass(String name) throws ClassNotFoundException {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   251
            if (VM.isBootedKernelVM()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   252
                // Check for download before we look for it.  If
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   253
                // DownloadManager ends up downloading it, it will add it to
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   254
                // our search path before we proceed to the findClass().
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   255
                DownloadManager.getBootClassPathEntryForClass(name);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   256
            }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   257
            return super.findClass(name);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   258
        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   259
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
        private static AccessControlContext getContext(File[] dirs)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
            PathPermissions perms =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
                new PathPermissions(dirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
            ProtectionDomain domain = new ProtectionDomain(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
                new CodeSource(perms.getCodeBase(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                perms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
            AccessControlContext acc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
                new AccessControlContext(new ProtectionDomain[] { domain });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
            return acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
     * The class loader used for loading from java.class.path.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * runs in a restricted security context.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
    static class AppClassLoader extends URLClassLoader {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   284
        static {
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   285
            ClassLoader.registerAsParallelCapable();
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   286
        }
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   287
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        public static ClassLoader getAppClassLoader(final ClassLoader extcl)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            throws IOException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
            final String s = System.getProperty("java.class.path");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            final File[] path = (s == null) ? new File[0] : getClassPath(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
            // Note: on bugid 4256530
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            // Prior implementations of this doPrivileged() block supplied
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
            // a rather restrictive ACC via a call to the private method
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
            // AppClassLoader.getContext(). This proved overly restrictive
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            // when loading  classes. Specifically it prevent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
            // accessClassInPackage.sun.* grants from being honored.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
            //
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   301
            return AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   302
                new PrivilegedAction<AppClassLoader>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   303
                    public AppClassLoader run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
                    URL[] urls =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
                        (s == null) ? new URL[0] : pathToURLs(path);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
                    return new AppClassLoader(urls, extcl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
         * Creates a new AppClassLoader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        AppClassLoader(URL[] urls, ClassLoader parent) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
            super(urls, parent, factory);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
         * Override loadClass so we can checkPackageAccess.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
         */
2448
1e8128f3ff61 4735126: (cl) ClassLoader.loadClass locks all instances in chain when delegating
valeriep
parents: 715
diff changeset
   321
        public Class loadClass(String name, boolean resolve)
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            throws ClassNotFoundException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        {
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   324
            if (VM.isBootedKernelVM()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   325
                DownloadManager.getBootClassPathEntryForClass(name);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   326
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
            int i = name.lastIndexOf('.');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
            if (i != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
                SecurityManager sm = System.getSecurityManager();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
                if (sm != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
                    sm.checkPackageAccess(name.substring(0, i));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
            return (super.loadClass(name, resolve));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
         * allow any classes loaded from classpath to exit the VM.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
        protected PermissionCollection getPermissions(CodeSource codesource)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
            PermissionCollection perms = super.getPermissions(codesource);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
            perms.add(new RuntimePermission("exitVM"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   344
            return perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   346
90ce3da70b43 Initial load
duke
parents:
diff changeset
   347
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   348
         * This class loader supports dynamic additions to the class path
90ce3da70b43 Initial load
duke
parents:
diff changeset
   349
         * at runtime.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
         *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   351
         * @see java.lang.instrument.Instrumentation#appendToSystemClassPathSearch
90ce3da70b43 Initial load
duke
parents:
diff changeset
   352
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   353
        private void appendToClassPathForInstrumentation(String path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
            assert(Thread.holdsLock(this));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
            // addURL is a no-op if path already contains the URL
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
            super.addURL( getFileURL(new File(path)) );
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
        /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
         * create a context that can read any directories (recursively)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
         * mentioned in the class path. In the case of a jar, it has to
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
         * be the directory containing the jar, not just the jar, as jar
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
         * files might refer to other jar files.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
         */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        private static AccessControlContext getContext(File[] cp)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
            throws java.net.MalformedURLException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
            PathPermissions perms =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
                new PathPermissions(cp);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
            ProtectionDomain domain =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
                new ProtectionDomain(new CodeSource(perms.getCodeBase(),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
                    (java.security.cert.Certificate[]) null),
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
                perms);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
            AccessControlContext acc =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
                new AccessControlContext(new ProtectionDomain[] { domain });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
            return acc;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   383
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   384
        void addAppURL(URL url) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   385
            super.addURL(url);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   386
        }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   387
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   388
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   389
    private static URLClassPath bootstrapClassPath;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   390
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   391
    public static synchronized URLClassPath getBootstrapClassPath() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   392
        if (bootstrapClassPath == null) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   393
            String prop = AccessController.doPrivileged(
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   394
                new GetPropertyAction("sun.boot.class.path"));
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   395
            URL[] urls;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   396
            if (prop != null) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   397
                final String path = prop;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   398
                urls = AccessController.doPrivileged(
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   399
                    new PrivilegedAction<URL[]>() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   400
                        public URL[] run() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   401
                            File[] classPath = getClassPath(path);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   402
                            int len = classPath.length;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   403
                            Set<File> seenDirs = new HashSet<File>();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   404
                            for (int i = 0; i < len; i++) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   405
                                File curEntry = classPath[i];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   406
                                // Negative test used to properly handle
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   407
                                // nonexistent jars on boot class path
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   408
                                if (!curEntry.isDirectory()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   409
                                    curEntry = curEntry.getParentFile();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   410
                                }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   411
                                if (curEntry != null && seenDirs.add(curEntry)) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   412
                                    MetaIndex.registerDirectory(curEntry);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   413
                                }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                            }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   415
                            return pathToURLs(classPath);
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
                    }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   418
                );
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   419
            } else {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   420
                urls = new URL[0];
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   421
            }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   422
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   423
            bootstrapClassPath = new URLClassPath(urls, factory);
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   424
            if (VM.isBootedKernelVM()) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   425
                final File[] additionalBootStrapPaths =
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   426
                    DownloadManager.getAdditionalBootStrapPaths();
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   427
                AccessController.doPrivileged(new PrivilegedAction() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   428
                    public Object run() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   429
                        for (int i=0; i<additionalBootStrapPaths.length; i++) {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   430
                            bootstrapClassPath.addURL(
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   431
                                getFileURL(additionalBootStrapPaths[i]));
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   432
                        }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   433
                        return null;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   434
                    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   435
                });
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   436
            }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
        }
3111
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   438
        return bootstrapClassPath;
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   439
    }
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   440
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   441
    public static synchronized void flushBootstrapClassPath() {
fefdeafb7ab9 6797688: Umbrella: Merge all JDK 6u4 - 6u12 deployment code into JDK7
herrick
parents: 2448
diff changeset
   442
        bootstrapClassPath = null;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
    private static URL[] pathToURLs(File[] path) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   446
        URL[] urls = new URL[path.length];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
        for (int i = 0; i < path.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
            urls[i] = getFileURL(path[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
        // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
        //for (int i = 0; i < urls.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   452
        //  System.out.println("urls[" + i + "] = " + '"' + urls[i] + '"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
        return urls;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
    private static File[] getClassPath(String cp) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
        File[] path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
        if (cp != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
            int count = 0, maxCount = 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
            int pos = 0, lastPos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            // Count the number of separators first
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
            while ((pos = cp.indexOf(File.pathSeparator, lastPos)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
                maxCount++;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
                lastPos = pos + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
            path = new File[maxCount];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
            lastPos = pos = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
            // Now scan for each path component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
            while ((pos = cp.indexOf(File.pathSeparator, lastPos)) != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
                if (pos - lastPos > 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
                    path[count++] = new File(cp.substring(lastPos, pos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   474
                    // empty path component translates to "."
90ce3da70b43 Initial load
duke
parents:
diff changeset
   475
                    path[count++] = new File(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   476
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                lastPos = pos + 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
            // Make sure we include the last path component
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
            if (lastPos < cp.length()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                path[count++] = new File(cp.substring(lastPos));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   482
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                path[count++] = new File(".");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            // Trim array to correct size
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
            if (count != maxCount) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
                File[] tmp = new File[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
                System.arraycopy(path, 0, tmp, 0, count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
                path = tmp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
            path = new File[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
        // DEBUG
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
        //for (int i = 0; i < path.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        //  System.out.println("path[" + i + "] = " + '"' + path[i] + '"');
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
        //}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
        return path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
    private static URLStreamHandler fileHandler;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
    static URL getFileURL(File file) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
            file = file.getCanonicalFile();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
        } catch (IOException e) {}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
            return ParseUtil.fileToEncodedURL(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
            // Should never happen since we specify the protocol...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
            throw new InternalError();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
     * The stream handler factory for loading system protocol handlers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
    private static class Factory implements URLStreamHandlerFactory {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
        private static String PREFIX = "sun.net.www.protocol";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
        public URLStreamHandler createURLStreamHandler(String protocol) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
            String name = PREFIX + "." + protocol + ".Handler";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                Class c = Class.forName(name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                return (URLStreamHandler)c.newInstance();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
            } catch (ClassNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            } catch (InstantiationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            } catch (IllegalAccessException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
                e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            throw new InternalError("could not load " + protocol +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
                                    "system protocol handler");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
class PathPermissions extends PermissionCollection {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
    // use serialVersionUID from JDK 1.2.2 for interoperability
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private static final long serialVersionUID = 8133287259134945693L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
    private File path[];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
    private Permissions perms;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
    URL codeBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
    PathPermissions(File path[])
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        this.path = path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
        this.perms = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
        this.codeBase = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   555
90ce3da70b43 Initial load
duke
parents:
diff changeset
   556
    URL getCodeBase()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   557
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   558
        return codeBase;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   559
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   560
90ce3da70b43 Initial load
duke
parents:
diff changeset
   561
    public void add(java.security.Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   562
        throw new SecurityException("attempt to add a permission");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   563
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   564
90ce3da70b43 Initial load
duke
parents:
diff changeset
   565
    private synchronized void init()
90ce3da70b43 Initial load
duke
parents:
diff changeset
   566
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   567
        if (perms != null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   568
            return;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   569
90ce3da70b43 Initial load
duke
parents:
diff changeset
   570
        perms = new Permissions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   571
90ce3da70b43 Initial load
duke
parents:
diff changeset
   572
        // this is needed to be able to create the classloader itself!
90ce3da70b43 Initial load
duke
parents:
diff changeset
   573
        perms.add(SecurityConstants.CREATE_CLASSLOADER_PERMISSION);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   574
90ce3da70b43 Initial load
duke
parents:
diff changeset
   575
        // add permission to read any "java.*" property
90ce3da70b43 Initial load
duke
parents:
diff changeset
   576
        perms.add(new java.util.PropertyPermission("java.*",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   577
            SecurityConstants.PROPERTY_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   578
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   579
        AccessController.doPrivileged(new PrivilegedAction<Void>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   580
            public Void run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   581
                for (int i=0; i < path.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   582
                    File f = path[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   583
                    String path;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   584
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   585
                        path = f.getCanonicalPath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   586
                    } catch (IOException ioe) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   587
                        path = f.getAbsolutePath();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   588
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   589
                    if (i == 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   590
                        codeBase = Launcher.getFileURL(new File(path));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   591
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   592
                    if (f.isDirectory()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   593
                        if (path.endsWith(File.separator)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   594
                            perms.add(new FilePermission(path+"-",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   595
                                SecurityConstants.FILE_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   596
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   597
                            perms.add(new FilePermission(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   598
                                path + File.separator+"-",
90ce3da70b43 Initial load
duke
parents:
diff changeset
   599
                                SecurityConstants.FILE_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   600
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   601
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   602
                        int endIndex = path.lastIndexOf(File.separatorChar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   603
                        if (endIndex != -1) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   604
                            path = path.substring(0, endIndex+1) + "-";
90ce3da70b43 Initial load
duke
parents:
diff changeset
   605
                            perms.add(new FilePermission(path,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   606
                                SecurityConstants.FILE_READ_ACTION));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   607
                        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   608
                            // XXX?
90ce3da70b43 Initial load
duke
parents:
diff changeset
   609
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   610
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   611
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   612
                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   613
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   614
        });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   615
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   616
90ce3da70b43 Initial load
duke
parents:
diff changeset
   617
    public boolean implies(java.security.Permission permission) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   618
        if (perms == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   619
            init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   620
        return perms.implies(permission);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   621
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   622
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   623
    public java.util.Enumeration<Permission> elements() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   624
        if (perms == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   625
            init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   626
        synchronized (perms) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   627
            return perms.elements();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   628
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   629
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   630
90ce3da70b43 Initial load
duke
parents:
diff changeset
   631
    public String toString() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   632
        if (perms == null)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   633
            init();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   634
        return perms.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   635
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   636
}