jdk/src/java.base/share/classes/sun/misc/ExtensionDependency.java
changeset 30655 d83f50188ca9
parent 27565 729f9700483a
equal deleted inserted replaced
30654:3c2e826aa5ea 30655:d83f50188ca9
    43 import java.net.URL;
    43 import java.net.URL;
    44 import java.net.MalformedURLException;
    44 import java.net.MalformedURLException;
    45 import sun.net.www.ParseUtil;
    45 import sun.net.www.ParseUtil;
    46 
    46 
    47 /**
    47 /**
    48  * <p>
       
    49  * This class checks dependent extensions a particular jar file may have
    48  * This class checks dependent extensions a particular jar file may have
    50  * declared through its manifest attributes.
    49  * declared through its manifest attributes.
    51  * </p>
    50  * <p>
    52  * Jar file declared dependent extensions through the extension-list
    51  * Jar file declared dependent extensions through the extension-list
    53  * attribute. The extension-list contains a list of keys used to
    52  * attribute. The extension-list contains a list of keys used to
    54  * fetch the other attributes describing the required extension.
    53  * fetch the other attributes describing the required extension.
    55  * If key is the extension key declared in the extension-list
    54  * If key is the extension key declared in the extension-list
    56  * attribute, the following describing attribute can be found in
    55  * attribute, the following describing attribute can be found in
    57  * the manifest :
    56  * the manifest:
    58  * key-Extension-Name:  (Specification package name)
    57  * <ul>
    59  * key-Specification-Version: (Specification-Version)
    58  * <li>key-Extension-Name:  (Specification package name)</li>
    60  * key-Implementation-Version: (Implementation-Version)
    59  * <li>key-Specification-Version: (Specification-Version)</li>
    61  * key-Implementation-Vendor-Id: (Imlementation-Vendor-Id)
    60  * <li>key-Implementation-Version: (Implementation-Version)</li>
    62  * key-Implementation-Version: (Implementation version)
    61  * <li>key-Implementation-Vendor-Id: (Imlementation-Vendor-Id)</li>
    63  * key-Implementation-URL: (URL to download the requested extension)
    62  * <li>key-Implementation-Version: (Implementation version)</li>
       
    63  * <li>key-Implementation-URL: (URL to download the requested extension)</li>
       
    64  * </ul>
    64  * <p>
    65  * <p>
    65  * This class also maintain versioning consistency of installed
    66  * This class also maintain versioning consistency of installed
    66  * extensions dependencies declared in jar file manifest.
    67  * extensions dependencies declared in jar file manifest.
    67  * </p>
       
    68  *
    68  *
    69  * @deprecated this class will be removed in a future release.
    69  * @deprecated this class will be removed in a future release.
    70  * @author  Jerome Dochez
    70  * @author  Jerome Dochez
    71  */
    71  */
    72 @Deprecated
    72 @Deprecated
    74 
    74 
    75     /* Callbak interfaces to delegate installation of missing extensions */
    75     /* Callbak interfaces to delegate installation of missing extensions */
    76     private static Vector<ExtensionInstallationProvider> providers;
    76     private static Vector<ExtensionInstallationProvider> providers;
    77 
    77 
    78     /**
    78     /**
    79      * <p>
       
    80      * Register an ExtensionInstallationProvider. The provider is responsible
    79      * Register an ExtensionInstallationProvider. The provider is responsible
    81      * for handling the installation (upgrade) of any missing extensions.
    80      * for handling the installation (upgrade) of any missing extensions.
    82      * </p>
    81      *
    83      * @param eip ExtensionInstallationProvider implementation
    82      * @param eip ExtensionInstallationProvider implementation
    84      */
    83      */
    85     public synchronized static void addExtensionInstallationProvider
    84     public synchronized static void addExtensionInstallationProvider
    86         (ExtensionInstallationProvider eip)
    85         (ExtensionInstallationProvider eip)
    87     {
    86     {
    90         }
    89         }
    91         providers.add(eip);
    90         providers.add(eip);
    92     }
    91     }
    93 
    92 
    94     /**
    93     /**
    95      * <p>
       
    96      * Unregister a previously installed installation provider
    94      * Unregister a previously installed installation provider
    97      * </p>
       
    98      */
    95      */
    99     public synchronized static void removeExtensionInstallationProvider
    96     public synchronized static void removeExtensionInstallationProvider
   100         (ExtensionInstallationProvider eip)
    97         (ExtensionInstallationProvider eip)
   101     {
    98     {
   102         providers.remove(eip);
    99         providers.remove(eip);
   103     }
   100     }
   104 
   101 
   105     /**
   102     /**
   106      * <p>
       
   107      * Checks the dependencies of the jar file on installed extension.
   103      * Checks the dependencies of the jar file on installed extension.
   108      * </p>
   104      *
   109      * @param jarFile containing the attriutes declaring the dependencies
   105      * @param jar containing the attributes declaring the dependencies
   110      */
   106      */
   111     public static boolean checkExtensionsDependencies(JarFile jar)
   107     public static boolean checkExtensionsDependencies(JarFile jar)
   112     {
   108     {
   113         if (providers == null) {
   109         if (providers == null) {
   114             // no need to bother, nobody is registered to install missing
   110             // no need to bother, nobody is registered to install missing
   180         return result;
   176         return result;
   181     }
   177     }
   182 
   178 
   183 
   179 
   184     /*
   180     /*
   185      * <p>
       
   186      * Check that a particular dependency on an extension is satisfied.
   181      * Check that a particular dependency on an extension is satisfied.
   187      * </p>
   182      *
   188      * @param extensionName is the key used for the attributes in the manifest
   183      * @param extensionName is the key used for the attributes in the manifest
   189      * @param attr is the attributes of the manifest file
   184      * @param attr is the attributes of the manifest file
   190      *
   185      *
   191      * @return true if the dependency is satisfied by the installed extensions
   186      * @return true if the dependency is satisfied by the installed extensions
   192      */
   187      */
   202         ExtensionInfo reqInfo = new ExtensionInfo(extensionName, attr);
   197         ExtensionInfo reqInfo = new ExtensionInfo(extensionName, attr);
   203         return installExtension(reqInfo, null);
   198         return installExtension(reqInfo, null);
   204     }
   199     }
   205 
   200 
   206     /*
   201     /*
   207      * <p>
       
   208      * Check if a particular extension is part of the currently installed
   202      * Check if a particular extension is part of the currently installed
   209      * extensions.
   203      * extensions.
   210      * </p>
   204      *
   211      * @param extensionName is the key for the attributes in the manifest
   205      * @param extensionName is the key for the attributes in the manifest
   212      * @param attr is the attributes of the manifest
   206      * @param attr is the attributes of the manifest
   213      *
   207      *
   214      * @return true if the requested extension is already installed
   208      * @return true if the requested extension is already installed
   215      */
   209      */
   260         }
   254         }
   261         return false;
   255         return false;
   262     }
   256     }
   263 
   257 
   264     /*
   258     /*
   265      * <p>
       
   266      * Check if the requested extension described by the attributes
   259      * Check if the requested extension described by the attributes
   267      * in the manifest under the key extensionName is compatible with
   260      * in the manifest under the key extensionName is compatible with
   268      * the jar file.
   261      * the jar file.
   269      * </p>
       
   270      *
   262      *
   271      * @param extensionName key in the attribute list
   263      * @param extensionName key in the attribute list
   272      * @param attr manifest file attributes
   264      * @param attr manifest file attributes
   273      * @param file installed extension jar file to compare the requested
   265      * @param file installed extension jar file to compare the requested
   274      * extension against.
   266      * extension against.
   335         }
   327         }
   336         return false;
   328         return false;
   337     }
   329     }
   338 
   330 
   339     /*
   331     /*
   340      * <p>
       
   341      * An required extension is missing, if an ExtensionInstallationProvider is
   332      * An required extension is missing, if an ExtensionInstallationProvider is
   342      * registered, delegate the installation of that particular extension to it.
   333      * registered, delegate the installation of that particular extension to it.
   343      * </p>
       
   344      *
   334      *
   345      * @param reqInfo Missing extension information
   335      * @param reqInfo Missing extension information
   346      * @param instInfo Older installed version information
   336      * @param instInfo Older installed version information
   347      *
   337      *
   348      * @return true if the installation is successful
   338      * @return true if the installation is successful
   378         debug(reqInfo.name + " installation failed");
   368         debug(reqInfo.name + " installation failed");
   379         return false;
   369         return false;
   380     }
   370     }
   381 
   371 
   382     /**
   372     /**
   383      * <p>
       
   384      * Checks if the extension, that is specified in the extension-list in
   373      * Checks if the extension, that is specified in the extension-list in
   385      * the applet jar manifest, is already installed (i.e. exists in the
   374      * the applet jar manifest, is already installed (i.e. exists in the
   386      * extension directory).
   375      * extension directory).
   387      * </p>
       
   388      *
   376      *
   389      * @param extensionName extension name in the extension-list
   377      * @param extensionName extension name in the extension-list
   390      *
   378      *
   391      * @return the extension if it exists in the extension directory
   379      * @return the extension if it exists in the extension directory
   392      */
   380      */
   426                 }
   414                 }
   427             });
   415             });
   428     }
   416     }
   429 
   417 
   430     /**
   418     /**
   431      * <p>
       
   432      * @return the java.ext.dirs property as a list of directory
   419      * @return the java.ext.dirs property as a list of directory
   433      * </p>
       
   434      */
   420      */
   435     private static File[] getExtDirs() {
   421     private static File[] getExtDirs() {
   436         String s = java.security.AccessController.doPrivileged(
   422         String s = java.security.AccessController.doPrivileged(
   437                 new sun.security.action.GetPropertyAction("java.ext.dirs"));
   423                 new sun.security.action.GetPropertyAction("java.ext.dirs"));
   438 
   424 
   454         debug("getExtDirs dirs.length " + dirs.length);
   440         debug("getExtDirs dirs.length " + dirs.length);
   455         return dirs;
   441         return dirs;
   456     }
   442     }
   457 
   443 
   458     /*
   444     /*
   459      * <p>
       
   460      * Scan the directories and return all files installed in those
   445      * Scan the directories and return all files installed in those
   461      * </p>
   446      *
   462      * @param dirs list of directories to scan
   447      * @param dirs list of directories to scan
   463      *
   448      *
   464      * @return the list of files installed in all the directories
   449      * @return the list of files installed in all the directories
   465      */
   450      */
   466     private static File[] getExtFiles(File[] dirs) throws IOException {
   451     private static File[] getExtFiles(File[] dirs) throws IOException {
   481         debug("getExtFiles ua.length " + ua.length);
   466         debug("getExtFiles ua.length " + ua.length);
   482         return ua;
   467         return ua;
   483     }
   468     }
   484 
   469 
   485     /*
   470     /*
   486      * <p>
       
   487      * @return the list of installed extensions jar files
   471      * @return the list of installed extensions jar files
   488      * </p>
       
   489      */
   472      */
   490     private File[] getInstalledExtensions() throws IOException {
   473     private File[] getInstalledExtensions() throws IOException {
   491         return AccessController.doPrivileged(
   474         return AccessController.doPrivileged(
   492             new PrivilegedAction<File[]>() {
   475             new PrivilegedAction<File[]>() {
   493                 public File[] run() {
   476                 public File[] run() {
   501                  }
   484                  }
   502             });
   485             });
   503     }
   486     }
   504 
   487 
   505     /*
   488     /*
   506      * <p>
       
   507      * Add the newly installed jar file to the extension class loader.
   489      * Add the newly installed jar file to the extension class loader.
   508      * </p>
       
   509      *
   490      *
   510      * @param cl the current installed extension class loader
   491      * @param cl the current installed extension class loader
   511      *
   492      *
   512      * @return true if successful
   493      * @return true if successful
   513      */
   494      */