jdk/src/java.base/share/classes/sun/misc/ExtensionDependency.java
author avstepan
Tue, 19 May 2015 16:04:14 +0400
changeset 30655 d83f50188ca9
parent 27565 729f9700483a
permissions -rw-r--r--
8080422: some docs cleanup for core libs Summary: some docs cleanup Reviewed-by: rriggs, lancea
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
23010
6dadb192ad81 8029235: Update copyright year to match last edit in jdk8 jdk repository for 2013
lana
parents: 21591
diff changeset
     2
 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. 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
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
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
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 715
diff changeset
    23
 * questions.
2
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.FilenameFilter;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
import java.io.IOException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
import java.io.FileNotFoundException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
import java.util.StringTokenizer;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
import java.util.Vector;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
import java.util.Enumeration;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
import java.util.jar.JarFile;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
import java.util.jar.Manifest;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
import java.util.jar.Attributes;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
import java.util.jar.Attributes.Name;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
import java.security.AccessController;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
import java.security.PrivilegedAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
import java.security.PrivilegedExceptionAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
import java.security.PrivilegedActionException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
import java.net.URL;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
import java.net.MalformedURLException;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
import sun.net.www.ParseUtil;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * This class checks dependent extensions a particular jar file may have
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * declared through its manifest attributes.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    50
 * <p>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 * Jar file declared dependent extensions through the extension-list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 * attribute. The extension-list contains a list of keys used to
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * fetch the other attributes describing the required extension.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * If key is the extension key declared in the extension-list
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * attribute, the following describing attribute can be found in
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    56
 * the manifest:
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    57
 * <ul>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    58
 * <li>key-Extension-Name:  (Specification package name)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    59
 * <li>key-Specification-Version: (Specification-Version)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    60
 * <li>key-Implementation-Version: (Implementation-Version)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    61
 * <li>key-Implementation-Vendor-Id: (Imlementation-Vendor-Id)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    62
 * <li>key-Implementation-Version: (Implementation version)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    63
 * <li>key-Implementation-URL: (URL to download the requested extension)</li>
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    64
 * </ul>
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * This class also maintain versioning consistency of installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 * extensions dependencies declared in jar file manifest.
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    68
 *
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    69
 * @deprecated this class will be removed in a future release.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 * @author  Jerome Dochez
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
 */
27565
729f9700483a 8049367: Modular Run-Time Images
chegar
parents: 25859
diff changeset
    72
@Deprecated
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
public class ExtensionDependency {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
    /* Callbak interfaces to delegate installation of missing extensions */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
    76
    private static Vector<ExtensionInstallationProvider> providers;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * Register an ExtensionInstallationProvider. The provider is responsible
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * for handling the installation (upgrade) of any missing extensions.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
    81
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * @param eip ExtensionInstallationProvider implementation
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
    public synchronized static void addExtensionInstallationProvider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
        (ExtensionInstallationProvider eip)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
        if (providers == null) {
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
    88
            providers = new Vector<>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
        providers.add(eip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     * Unregister a previously installed installation provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     */
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
    96
    public synchronized static void removeExtensionInstallationProvider
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
        (ExtensionInstallationProvider eip)
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
        providers.remove(eip);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     * Checks the dependencies of the jar file on installed extension.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   104
     *
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   105
     * @param jar containing the attributes declaring the dependencies
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
    public static boolean checkExtensionsDependencies(JarFile jar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
        if (providers == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
            // no need to bother, nobody is registered to install missing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
            // extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
            ExtensionDependency extDep = new ExtensionDependency();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
            return extDep.checkExtensions(jar);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        } catch (ExtensionInstallationException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
            debug(e.getMessage());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
     * Check for all declared required extensions in the jar file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
     * manifest.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    protected boolean checkExtensions(JarFile jar)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
        throws ExtensionInstallationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
        Manifest man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
            man = jar.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
        if (man == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
            // The applet does not define a manifest file, so
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
            // we just assume all dependencies are satisfied.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
        boolean result = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
        Attributes attr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
        if (attr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
            // Let's get the list of declared dependencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
            String value = attr.getValue(Name.EXTENSION_LIST);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
            if (value != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
                StringTokenizer st = new StringTokenizer(value);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
                // Iterate over all declared dependencies
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
                while (st.hasMoreTokens()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
                    String extensionName = st.nextToken();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
                    debug("The file " + jar.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
                          " appears to depend on " + extensionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
                    // Sanity Check
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
                    String extName = extensionName + "-" +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
                        Name.EXTENSION_NAME.toString();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
                    if (attr.getValue(extName) == null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
                        debug("The jar file " + jar.getName() +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
                              " appers to depend on "
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
                              + extensionName + " but does not define the " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                              extName + " attribute in its manifest ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
                    } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
                        if (!checkExtension(extensionName, attr)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
                            debug("Failed installing " + extensionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
                            result = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
                debug("No dependencies for " + jar.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
        return result;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * Check that a particular dependency on an extension is satisfied.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   182
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @param extensionName is the key used for the attributes in the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     * @param attr is the attributes of the manifest file
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
     * @return true if the dependency is satisfied by the installed extensions
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
    protected synchronized boolean checkExtension(final String extensionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
                                     final Attributes attr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
        throws ExtensionInstallationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
        debug("Checking extension " + extensionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
        if (checkExtensionAgainstInstalled(extensionName, attr))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
            return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
        debug("Extension not currently installed ");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
        ExtensionInfo reqInfo = new ExtensionInfo(extensionName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
        return installExtension(reqInfo, null);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     * Check if a particular extension is part of the currently installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * extensions.
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   204
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
     * @param extensionName is the key for the attributes in the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
     * @param attr is the attributes of the manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
     * @return true if the requested extension is already installed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    boolean checkExtensionAgainstInstalled(String extensionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
                                           Attributes attr)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
        throws ExtensionInstallationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
        File fExtension = checkExtensionExists(extensionName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
        if (fExtension != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
        // Extension already installed, just check against this one
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
                if (checkExtensionAgainst(extensionName, attr, fExtension))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
            } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
                debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
            } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
                debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
            return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
        // Not sure if extension is already installed, so check all the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
        // installed extension jar files to see if we get a match
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
            File[] installedExts;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
            // Get the list of installed extension jar files so we can
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
            // compare the installed versus the requested extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
                installedExts = getInstalledExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
            } catch(IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
                debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
                return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
            for (int i=0;i<installedExts.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
                try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
                    if (checkExtensionAgainst(extensionName, attr, installedExts[i]))
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
                        return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
                } catch (FileNotFoundException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
                    debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
                } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
                    debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
                    // let's continue with the next installed extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     * Check if the requested extension described by the attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * in the manifest under the key extensionName is compatible with
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     * the jar file.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
     *
21591
35320b590d9b 8026491: Typos in string literals
malenkov
parents: 14342
diff changeset
   263
     * @param extensionName key in the attribute list
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
     * @param attr manifest file attributes
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * @param file installed extension jar file to compare the requested
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * extension against.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
    protected boolean checkExtensionAgainst(String extensionName,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
                                            Attributes attr,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
                                            final File file)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
        throws IOException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
               FileNotFoundException,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
               ExtensionInstallationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
    {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
        debug("Checking extension " + extensionName +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
              " against " + file.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
        // Load the jar file ...
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
        Manifest man;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
        try {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   282
            man = AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   283
                new PrivilegedExceptionAction<Manifest>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   284
                    public Manifest run()
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
                            throws IOException, FileNotFoundException {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
                         if (!file.exists())
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
                             throw new FileNotFoundException(file.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
                         JarFile jarFile =  new JarFile(file);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
                         return jarFile.getManifest();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
                 });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
        } catch(PrivilegedActionException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
            if (e.getException() instanceof FileNotFoundException)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
                throw (FileNotFoundException) e.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            throw (IOException) e.getException();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
        // Construct the extension information object
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        ExtensionInfo reqInfo = new ExtensionInfo(extensionName, attr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        debug("Requested Extension : " + reqInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        int isCompatible = ExtensionInfo.INCOMPATIBLE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
        ExtensionInfo instInfo = null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
        if (man != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
            Attributes instAttr = man.getMainAttributes();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
            if (instAttr != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
                instInfo = new ExtensionInfo(null, instAttr);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
                debug("Extension Installed " + instInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
                isCompatible = instInfo.isCompatibleWith(reqInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
                switch(isCompatible) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
                case ExtensionInfo.COMPATIBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
                    debug("Extensions are compatible");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
                case ExtensionInfo.INCOMPATIBLE:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
                    debug("Extensions are incompatible");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
                    return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
                default:
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
                    // everything else
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
                    debug("Extensions require an upgrade or vendor switch");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
                    return installExtension(reqInfo, instInfo);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   329
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   330
90ce3da70b43 Initial load
duke
parents:
diff changeset
   331
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   332
     * An required extension is missing, if an ExtensionInstallationProvider is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   333
     * registered, delegate the installation of that particular extension to it.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   334
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   335
     * @param reqInfo Missing extension information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   336
     * @param instInfo Older installed version information
90ce3da70b43 Initial load
duke
parents:
diff changeset
   337
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   338
     * @return true if the installation is successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   339
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   340
    protected boolean installExtension(ExtensionInfo reqInfo,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   341
                                       ExtensionInfo instInfo)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   342
        throws ExtensionInstallationException
90ce3da70b43 Initial load
duke
parents:
diff changeset
   343
    {
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   344
        Vector<ExtensionInstallationProvider> currentProviders;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   345
        synchronized(providers) {
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   346
            @SuppressWarnings("unchecked")
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   347
            Vector<ExtensionInstallationProvider> tmp =
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   348
                (Vector<ExtensionInstallationProvider>) providers.clone();
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   349
            currentProviders = tmp;
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   350
        }
11119
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   351
        for (Enumeration<ExtensionInstallationProvider> e = currentProviders.elements();
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   352
                e.hasMoreElements();) {
6ff03c1202ce 7116722: Miscellaneous warnings sun.misc ( and related classes )
chegar
parents: 5506
diff changeset
   353
            ExtensionInstallationProvider eip = e.nextElement();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   354
90ce3da70b43 Initial load
duke
parents:
diff changeset
   355
            if (eip!=null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   356
                // delegate the installation to the provider
90ce3da70b43 Initial load
duke
parents:
diff changeset
   357
                if (eip.installExtension(reqInfo, instInfo)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   358
                    debug(reqInfo.name + " installation successful");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   359
                    Launcher.ExtClassLoader cl = (Launcher.ExtClassLoader)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   360
                        Launcher.getLauncher().getClassLoader().getParent();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   361
                    addNewExtensionsToClassLoader(cl);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   362
                    return true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   363
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   364
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   365
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   366
        // We have tried all of our providers, noone could install this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   367
        // extension, we just return failure at this point
90ce3da70b43 Initial load
duke
parents:
diff changeset
   368
        debug(reqInfo.name + " installation failed");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   369
        return false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   370
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   371
90ce3da70b43 Initial load
duke
parents:
diff changeset
   372
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   373
     * Checks if the extension, that is specified in the extension-list in
90ce3da70b43 Initial load
duke
parents:
diff changeset
   374
     * the applet jar manifest, is already installed (i.e. exists in the
90ce3da70b43 Initial load
duke
parents:
diff changeset
   375
     * extension directory).
90ce3da70b43 Initial load
duke
parents:
diff changeset
   376
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   377
     * @param extensionName extension name in the extension-list
90ce3da70b43 Initial load
duke
parents:
diff changeset
   378
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   379
     * @return the extension if it exists in the extension directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   380
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   381
    private File checkExtensionExists(String extensionName) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   382
        // Function added to fix bug 4504166
90ce3da70b43 Initial load
duke
parents:
diff changeset
   383
        final String extName = extensionName;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   384
        final String[] fileExt = {".jar", ".zip"};
90ce3da70b43 Initial load
duke
parents:
diff changeset
   385
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   386
        return AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   387
            new PrivilegedAction<File>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   388
                public File run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   389
                    try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   390
                        File fExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   391
                        File[] dirs = getExtDirs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   392
90ce3da70b43 Initial load
duke
parents:
diff changeset
   393
                        // Search the extension directories for the extension that is specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   394
                        // in the attribute extension-list in the applet jar manifest
90ce3da70b43 Initial load
duke
parents:
diff changeset
   395
                        for (int i=0;i<dirs.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   396
                            for (int j=0;j<fileExt.length;j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   397
                                if (extName.toLowerCase().endsWith(fileExt[j])) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   398
                                    fExtension = new File(dirs[i], extName);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   399
                                } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   400
                                    fExtension = new File(dirs[i], extName+fileExt[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   401
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   402
                                debug("checkExtensionExists:fileName " + fExtension.getName());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   403
                                if (fExtension.exists()) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   404
                                    return fExtension;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   405
                                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   406
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   407
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   408
                        return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   409
90ce3da70b43 Initial load
duke
parents:
diff changeset
   410
                    } catch(Exception e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   411
                         debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   412
                         return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   413
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   414
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   415
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   416
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   417
90ce3da70b43 Initial load
duke
parents:
diff changeset
   418
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   419
     * @return the java.ext.dirs property as a list of directory
90ce3da70b43 Initial load
duke
parents:
diff changeset
   420
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   421
    private static File[] getExtDirs() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   422
        String s = java.security.AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   423
                new sun.security.action.GetPropertyAction("java.ext.dirs"));
90ce3da70b43 Initial load
duke
parents:
diff changeset
   424
90ce3da70b43 Initial load
duke
parents:
diff changeset
   425
        File[] dirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   426
        if (s != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   427
            StringTokenizer st =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   428
                new StringTokenizer(s, File.pathSeparator);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   429
            int count = st.countTokens();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   430
            debug("getExtDirs count " + count);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   431
            dirs = new File[count];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   432
            for (int i = 0; i < count; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   433
                dirs[i] = new File(st.nextToken());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   434
                debug("getExtDirs dirs["+i+"] "+ dirs[i]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   435
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   436
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   437
            dirs = new File[0];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   438
            debug("getExtDirs dirs " + dirs);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   439
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   440
        debug("getExtDirs dirs.length " + dirs.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   441
        return dirs;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   442
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   443
90ce3da70b43 Initial load
duke
parents:
diff changeset
   444
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   445
     * Scan the directories and return all files installed in those
30655
d83f50188ca9 8080422: some docs cleanup for core libs
avstepan
parents: 27565
diff changeset
   446
     *
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   447
     * @param dirs list of directories to scan
90ce3da70b43 Initial load
duke
parents:
diff changeset
   448
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   449
     * @return the list of files installed in all the directories
90ce3da70b43 Initial load
duke
parents:
diff changeset
   450
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   451
    private static File[] getExtFiles(File[] dirs) throws IOException {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   452
        Vector<File> urls = new Vector<File>();
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   453
        for (int i = 0; i < dirs.length; i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   454
            String[] files = dirs[i].list(new JarFilter());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   455
            if (files != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   456
                debug("getExtFiles files.length " + files.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   457
                for (int j = 0; j < files.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   458
                    File f = new File(dirs[i], files[j]);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   459
                    urls.add(f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   460
                    debug("getExtFiles f["+j+"] "+ f);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   461
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   462
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   463
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   464
        File[] ua = new File[urls.size()];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   465
        urls.copyInto(ua);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   466
        debug("getExtFiles ua.length " + ua.length);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   467
        return ua;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   468
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   469
90ce3da70b43 Initial load
duke
parents:
diff changeset
   470
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   471
     * @return the list of installed extensions jar files
90ce3da70b43 Initial load
duke
parents:
diff changeset
   472
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   473
    private File[] getInstalledExtensions() throws IOException {
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   474
        return AccessController.doPrivileged(
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   475
            new PrivilegedAction<File[]>() {
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   476
                public File[] run() {
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   477
                     try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   478
                         return getExtFiles(getExtDirs());
90ce3da70b43 Initial load
duke
parents:
diff changeset
   479
                     } catch(IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   480
                         debug("Cannot get list of installed extensions");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   481
                         debugException(e);
51
6fe31bc95bbc 6600143: Remove another 450 unnecessary casts
martin
parents: 2
diff changeset
   482
                        return new File[0];
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
   483
                     }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   484
                 }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   485
            });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   486
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   487
90ce3da70b43 Initial load
duke
parents:
diff changeset
   488
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   489
     * Add the newly installed jar file to the extension class loader.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   490
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   491
     * @param cl the current installed extension class loader
90ce3da70b43 Initial load
duke
parents:
diff changeset
   492
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   493
     * @return true if successful
90ce3da70b43 Initial load
duke
parents:
diff changeset
   494
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   495
    private Boolean addNewExtensionsToClassLoader(Launcher.ExtClassLoader cl) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   496
        try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   497
            File[] installedExts = getInstalledExtensions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   498
            for (int i=0;i<installedExts.length;i++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   499
                final File instFile = installedExts[i];
90ce3da70b43 Initial load
duke
parents:
diff changeset
   500
                URL instURL = AccessController.doPrivileged(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   501
                    new PrivilegedAction<URL>() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   502
                        public URL run() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   503
                            try {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   504
                                return ParseUtil.fileToEncodedURL(instFile);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   505
                            } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   506
                                debugException(e);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   507
                                return null;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   508
                            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   509
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   510
                    });
90ce3da70b43 Initial load
duke
parents:
diff changeset
   511
                if (instURL != null) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   512
                    URL[] urls = cl.getURLs();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   513
                    boolean found=false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   514
                    for (int j = 0; j<urls.length; j++) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   515
                        debug("URL["+j+"] is " + urls[j] + " looking for "+
90ce3da70b43 Initial load
duke
parents:
diff changeset
   516
                                           instURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   517
                        if (urls[j].toString().compareToIgnoreCase(
90ce3da70b43 Initial load
duke
parents:
diff changeset
   518
                                    instURL.toString())==0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   519
                            found=true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   520
                            debug("Found !");
90ce3da70b43 Initial load
duke
parents:
diff changeset
   521
                        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   522
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   523
                    if (!found) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   524
                        debug("Not Found ! adding to the classloader " +
90ce3da70b43 Initial load
duke
parents:
diff changeset
   525
                              instURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   526
                        cl.addExtURL(instURL);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   527
                    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   528
                }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   529
            }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   530
        } catch (MalformedURLException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   531
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   532
        } catch (IOException e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   533
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   534
            // let's continue with the next installed extension
90ce3da70b43 Initial load
duke
parents:
diff changeset
   535
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   536
        return Boolean.TRUE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   537
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   538
90ce3da70b43 Initial load
duke
parents:
diff changeset
   539
    // True to display all debug and trace messages
90ce3da70b43 Initial load
duke
parents:
diff changeset
   540
    static final boolean DEBUG = false;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   541
90ce3da70b43 Initial load
duke
parents:
diff changeset
   542
    private static void debug(String s) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   543
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   544
            System.err.println(s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   545
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   546
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   547
90ce3da70b43 Initial load
duke
parents:
diff changeset
   548
    private void debugException(Throwable e) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   549
        if (DEBUG) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   550
            e.printStackTrace();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   551
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   552
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   553
90ce3da70b43 Initial load
duke
parents:
diff changeset
   554
}