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