org.freehep.application.studio
Class PluginMap

java.lang.Object
  extended by org.freehep.application.studio.PluginMap

public final class PluginMap
extends Object

Contains information on installed plugins and libraries, and supports operations on them.

Author:
onoprien

Nested Class Summary
static class PluginMap.Orphan
          Enumeration of unclaimed libraries treatment options.
 
Constructor Summary
PluginMap(Studio application)
          Constructs PluginMap by scanning application extension directories.
 
Method Summary
 PluginMap add(Collection<PluginInfo> plugins)
          Creates a PluginMap that can be used to download and install the specified plugins.
 void commit(List<LibInfo> libraries)
          Installs specified libraries..
 Map<String,LibInfo> getActiveLibraries()
          Returns a map of IDs to descriptors for all currently active libraries.
 Map<String,LibInfo> getActiveLibraries(PluginInfo plugin)
          Returns a map of IDs to descriptors for currently active libraries claimed by the specified plugin.
 LibInfo getActiveLibrary(LibInfo library)
          Returns active library that corresponds to the specified library.
 Map<String,PluginInfo> getActivePlugins()
          Returns a map of names to descriptors for all currently active plugins.
 Set<PluginInfo> getDependentPlugins(PluginInfo plugin)
          Returns a set of dependents (direct and transient) of the specified plugin.
 List<LibInfo> getDownloads(Collection<LibInfo> libraries, boolean checkInstalled)
          Returns a list of libraries that need to be downloaded to install specified libraries.
 List<LibInfo> getDownloads(Collection<PluginInfo> plugins)
          Returns a list of libraries that need to be downloaded to install specified plugins.
 List<LibInfo> getDownloads(Collection<PluginInfo> plugins, Map<String,PluginInfo> available)
          Returns a list of libraries that need to be downloaded to install specified plugins.
 URL[] getExtensionClasspath()
          Returns URLs for all active libraries.
 List<LibInfo> getLibraries()
          Returns a list of all non-duplicate libraries in this map.
 Collection<LibInfo> getLibraries(PluginDir dir)
          Returns a collection of all non-duplicate libraries in the specified directory.
 LibInfo getLibrary(LibInfo library)
          Returns installed library that corresponds to the specified library.
 LibInfo getLibrary(String id, PluginDir dir)
          Returns library descriptor for the specified ID and directory.
 Map<String,PluginInfo> getLoadablePlugins()
          Returns a map of names to descriptors for all currently active non-broken load-at-start plugins and their dependencies.
 List<LibInfo> getMissingLibraries()
          Returns a list of libraries missed by active plugins.
 PluginInfo getPlugin(String name)
          Returns active plugin descriptor with the specified name.
 PluginInfo getPlugin(String name, PluginDir dir)
          Returns a plugin descriptor for the specified plugin name and directory.
 List<PluginInfo> getPlugins()
          Returns a list of all plugin descriptors in this map.
 Map<String,PluginInfo> getPlugins(PluginDir dir)
          Returns a map of plugin names to descriptors in the specified directory.
 EnumMap<PluginDir,ArrayList<LibInfo>> getUnclaimedLibraries()
          Returns mapping of extension directories to lists of unclaimed libraries found in those directories.
 void insertPlugins(Collection<PluginInfo> plugins)
          Insert specified plugins into this map without downloading or replacing libraries.
 void invalidate()
          Clears all secondary data structures.
 void processUnclaimedLibraries(PluginMap.Orphan action)
          Creates plugins for unclaimed libraries if necessary, and sets their properties to ensure that purge() method will take appropriate action.
 void purge()
          Purges unused libraries.
 boolean remove(Collection<PluginInfo> plugins)
          Removes the specified plugins from this map and deletes (or marks for deletion) the files that are no longer needed.
 void scan()
          Scans all extension directories and constructs primary data structures in this map.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PluginMap

public PluginMap(Studio application)
Constructs PluginMap by scanning application extension directories. Attempts to delete empty files while scanning.

Method Detail

scan

public void scan()
Scans all extension directories and constructs primary data structures in this map. Any information previously contained in this map is lost, except for in-memory plugins (currently, those are used to keep track of unclaimed libraries present at the application startup.


insertPlugins

public void insertPlugins(Collection<PluginInfo> plugins)
Insert specified plugins into this map without downloading or replacing libraries. This can be useful when one needs to add plugins found on the classpath and not in the extensions directories, for example. Plugins in the collection should have their target directories set before this method is called. If the target directory is BUILTIN, libraries referenced by added plugins will be added to the list of available libraries.


processUnclaimedLibraries

public void processUnclaimedLibraries(PluginMap.Orphan action)
Creates plugins for unclaimed libraries if necessary, and sets their properties to ensure that purge() method will take appropriate action.


add

public PluginMap add(Collection<PluginInfo> plugins)
Creates a PluginMap that can be used to download and install the specified plugins. This method should be called on the application master map, which is not modified as a result of the call. The returned map can be used to get a collection of required downloads through a call to #getDownloads(). Once the files are downloaded, it can be passed to the master map's #commit() method to install or update the plugins.

Implementation notes:

Parameters:
plugins - Collection of plugins to be installed. Must contain all required dependencies.
Returns:
PluginMap that contains only plugins that have to be installed. For each library, getFile() will return the path where the file needs to be downloaded, or null if the same or newer version of this library is already installed.

commit

public void commit(List<LibInfo> libraries)
Installs specified libraries..

Parameters:
update -

remove

public boolean remove(Collection<PluginInfo> plugins)
Removes the specified plugins from this map and deletes (or marks for deletion) the files that are no longer needed.

Parameters:
plugins - Collection of plugins to be removed. Should not contain dependencies of other plugins - no checking is done by this method.
Returns:
True if restart is required before the changes can take effect.

purge

public void purge()
Purges unused libraries.


invalidate

public void invalidate()
Clears all secondary data structures.


getActivePlugins

public Map<String,PluginInfo> getActivePlugins()
Returns a map of names to descriptors for all currently active plugins. A plugin is active if it would be loaded if the application was starting now. A plugin may be present in this map but inactive if and only if an identically named plugin exists in one of the extensions directories that appear earlier in the directories search order (builtin - user - group - system).


getLoadablePlugins

public Map<String,PluginInfo> getLoadablePlugins()
Returns a map of names to descriptors for all currently active non-broken load-at-start plugins and their dependencies.


getActiveLibraries

public Map<String,LibInfo> getActiveLibraries()
Returns a map of IDs to descriptors for all currently active libraries. A library is active if it would be added to the classpath if the application was starting now. The algorithm for choosing an active library for a given ID: if there is a built-in library with this ID, choose it; otherwise, among all libraries with this ID located in extensions directories where there are installed plugins referencing it, choose the latest version. If there are identical versions, choose the library in the directory that appears earlier in the search order (user - group - system). Unknown version is treated as latest.


getMissingLibraries

public List<LibInfo> getMissingLibraries()
Returns a list of libraries missed by active plugins.


getActiveLibraries

public Map<String,LibInfo> getActiveLibraries(PluginInfo plugin)
Returns a map of IDs to descriptors for currently active libraries claimed by the specified plugin.

Throws:
IllegalArgumentException - if there is no active library to satisfy the plugin's requirements.

getActiveLibrary

public LibInfo getActiveLibrary(LibInfo library)
Returns active library that corresponds to the specified library.

Parameters:
library - Library descriptor, typically part of a plugin descriptor.
Returns:
Descriptor of the corresponding active library (null if none found).

getExtensionClasspath

public URL[] getExtensionClasspath()
Returns URLs for all active libraries.


getPlugins

public List<PluginInfo> getPlugins()
Returns a list of all plugin descriptors in this map.


getPlugins

public Map<String,PluginInfo> getPlugins(PluginDir dir)
Returns a map of plugin names to descriptors in the specified directory.


getPlugin

public PluginInfo getPlugin(String name)
Returns active plugin descriptor with the specified name. Returns null if there is no such plugin in this map.


getPlugin

public PluginInfo getPlugin(String name,
                            PluginDir dir)
Returns a plugin descriptor for the specified plugin name and directory. Returns null if there is no such plugin in this map.


getLibraries

public List<LibInfo> getLibraries()
Returns a list of all non-duplicate libraries in this map.


getLibraries

public Collection<LibInfo> getLibraries(PluginDir dir)
Returns a collection of all non-duplicate libraries in the specified directory.


getLibrary

public LibInfo getLibrary(String id,
                          PluginDir dir)
Returns library descriptor for the specified ID and directory. Returns null if there is no such library in this map.


getLibrary

public LibInfo getLibrary(LibInfo library)
Returns installed library that corresponds to the specified library.

Parameters:
library - Library descriptor, typically part of a plugin descriptor.
Returns:
Descriptor of the corresponding installed library (null if none found).

getDependentPlugins

public Set<PluginInfo> getDependentPlugins(PluginInfo plugin)
Returns a set of dependents (direct and transient) of the specified plugin. Only looks for dependents installed in the same directory. No version checking is done.


getUnclaimedLibraries

public EnumMap<PluginDir,ArrayList<LibInfo>> getUnclaimedLibraries()
Returns mapping of extension directories to lists of unclaimed libraries found in those directories. A directory that does not contain unclaimed libraries will not be in the map.


getDownloads

public List<LibInfo> getDownloads(Collection<PluginInfo> plugins,
                                  Map<String,PluginInfo> available)
Returns a list of libraries that need to be downloaded to install specified plugins. Libraries that have a satisfactory version already installed are not included. If a plugin from the specified collection has a dependency that is neither present in the collection nor already installed, that dependency is added from the collection of available plugins if possible.

This method should be called on the application master map, which is not modified as a result of the call.

Parameters:
plugins - Collection of plugins to be installed.
available - Collection of plugins available for download.
Returns:
List of newly created LibInfo objects with their File properties set to appropriate download location.

getDownloads

public List<LibInfo> getDownloads(Collection<PluginInfo> plugins)
Returns a list of libraries that need to be downloaded to install specified plugins. The latest version is chosen between installed and multiple requests for the same library. No plugin dependency checking.

This method should be called on the application master map, which is not modified as a result of the call.

Parameters:
plugins - Collection of plugins to be installed.
Returns:
List of newly created LibInfo objects with their File properties set to appropriate download location.

getDownloads

public List<LibInfo> getDownloads(Collection<LibInfo> libraries,
                                  boolean checkInstalled)
Returns a list of libraries that need to be downloaded to install specified libraries.

Parameters:
libraries - List of libraries to download. Objects from this list will not be modified.
checkInstalled - If true, only libraries that do not have same of newer version already installed will be included.
Returns:
List of newly created LibInfo objects with their File properties set to appropriate download location.


Copyright © 2000-2014 FreeHEP. All Rights Reserved.