org.openstreetmap.josm.plugins
Class PluginHandler

java.lang.Object
  extended by org.openstreetmap.josm.plugins.PluginHandler

public class PluginHandler
extends java.lang.Object

PluginHandler is basically a collection of static utility functions used to bootstrap and manage the loaded plugins.


Nested Class Summary
static class PluginHandler.DeprecatedPlugin
           
private static class PluginHandler.UpdatePluginsMessagePanel
           
 
Field Summary
static int DEFAULT_TIME_BASED_UPDATE_INTERVAL
          Default time-based update interval, in days (pluginmanager.time-based-update.interval)
static java.util.Collection<PluginHandler.DeprecatedPlugin> DEPRECATED_PLUGINS
           
static java.util.Collection<PluginProxy> pluginList
          All installed and loaded plugins (resp.
private static java.util.List<java.lang.ClassLoader> sources
          Add here all ClassLoader whose resource should be searched.
static java.lang.String[] UNMAINTAINED_PLUGINS
           
 
Constructor Summary
PluginHandler()
           
 
Method Summary
static void addDownloadSelection(java.util.List<DownloadSelection> downloadSelections)
           
private static void alertFailedPluginUpdate(java.awt.Component parent, java.util.Collection<PluginInformation> plugins)
           
private static void alertJOSMUpdateRequired(java.awt.Component parent, java.lang.String plugin, int requiredVersion)
           
private static void alertMissingPluginInformation(java.awt.Component parent, java.util.Collection<java.lang.String> plugins)
           
private static void alertMissingRequiredPlugin(java.awt.Component parent, java.lang.String plugin, java.util.Set<java.lang.String> missingRequiredPlugin)
          Alerts the user if a plugin required by another plugin is missing
static java.util.List<PluginInformation> buildListOfPluginsToLoad(java.awt.Component parent, ProgressMonitor monitor)
          Builds the set of plugins to load.
static boolean checkAndConfirmPluginUpdate(java.awt.Component parent)
          Checks whether the locally available plugins should be updated and asks the user if running an update is OK.
static boolean checkLoadPreconditions(java.awt.Component parent, java.util.Collection<PluginInformation> plugins, PluginInformation plugin)
          Checks whether all preconditions for loading the plugin plugin are met.
static boolean checkRequiredPluginsPreconditions(java.awt.Component parent, java.util.Collection<PluginInformation> plugins, PluginInformation plugin)
          Checks if required plugins preconditions for loading the plugin plugin are met.
private static boolean confirmDeactivatingPluginAfterException(PluginProxy plugin)
           
static boolean confirmDisablePlugin(java.awt.Component parent, java.lang.String reason, java.lang.String name)
          Ask the user for confirmation that a plugin shall be disabled.
static java.lang.ClassLoader createClassLoader(java.util.Collection<PluginInformation> plugins)
          Creates a class loader for loading plugin code.
static void disablePluginAfterException(java.lang.Throwable e)
          Checks whether the exception e was thrown by a plugin.
private static void filterDeprecatedPlugins(java.awt.Component parent, java.util.Collection<java.lang.String> plugins)
          Removes deprecated plugins from a collection of plugins.
private static void filterUnmaintainedPlugins(java.awt.Component parent, java.util.Collection<java.lang.String> plugins)
          Removes unmaintained plugins from a collection of plugins.
static java.lang.String getBugReportText()
           
static javax.swing.JPanel getInfoPanel()
           
static java.lang.Object getPlugin(java.lang.String name)
           
private static PluginProxy getPluginCausingException(java.lang.Throwable ex)
          Replies the plugin which most likely threw the exception ex.
static void getPreferenceSetting(java.util.Collection<PreferenceSettingFactory> settings)
           
static java.util.Collection<java.lang.ClassLoader> getResourceClassLoaders()
           
static void installDownloadedPlugins(boolean dowarn)
          Installs downloaded plugins.
static void loadEarlyPlugins(java.awt.Component parent, java.util.Collection<PluginInformation> plugins, ProgressMonitor monitor)
          Loads plugins from plugins which have the flag PluginInformation.early set to true.
static void loadLatePlugins(java.awt.Component parent, java.util.Collection<PluginInformation> plugins, ProgressMonitor monitor)
          Loads plugins from plugins which have the flag PluginInformation.early set to false.
private static java.util.Map<java.lang.String,PluginInformation> loadLocallyAvailablePluginInformation(ProgressMonitor monitor)
          Loads locally available plugin information from local plugin jars and from cached plugin lists.
static void loadPlugin(java.awt.Component parent, PluginInformation plugin, java.lang.ClassLoader pluginClassLoader)
          Loads and instantiates the plugin described by plugin using the class loader pluginClassLoader.
static void loadPlugins(java.awt.Component parent, java.util.Collection<PluginInformation> plugins, ProgressMonitor monitor)
          Loads the plugin in plugins from locally available jar files into memory.
static void notifyMapFrameChanged(MapFrame old, MapFrame map)
          Notified loaded plugins about a new map frame
static java.util.List<PluginInformation> updatePlugins(java.awt.Component parent, java.util.List<PluginInformation> plugins, ProgressMonitor monitor)
          Updates the plugins in plugins.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEPRECATED_PLUGINS

public static final java.util.Collection<PluginHandler.DeprecatedPlugin> DEPRECATED_PLUGINS

UNMAINTAINED_PLUGINS

public static final java.lang.String[] UNMAINTAINED_PLUGINS

DEFAULT_TIME_BASED_UPDATE_INTERVAL

public static final int DEFAULT_TIME_BASED_UPDATE_INTERVAL
Default time-based update interval, in days (pluginmanager.time-based-update.interval)

See Also:
Constant Field Values

pluginList

public static final java.util.Collection<PluginProxy> pluginList
All installed and loaded plugins (resp. their main classes)


sources

private static final java.util.List<java.lang.ClassLoader> sources
Add here all ClassLoader whose resource should be searched.

Constructor Detail

PluginHandler

public PluginHandler()
Method Detail

getResourceClassLoaders

public static java.util.Collection<java.lang.ClassLoader> getResourceClassLoaders()

filterDeprecatedPlugins

private static void filterDeprecatedPlugins(java.awt.Component parent,
                                            java.util.Collection<java.lang.String> plugins)
Removes deprecated plugins from a collection of plugins. Modifies the collection plugins. Also notifies the user about removed deprecated plugins

Parameters:
parent - The parent Component used to display warning popup
plugins - the collection of plugins

filterUnmaintainedPlugins

private static void filterUnmaintainedPlugins(java.awt.Component parent,
                                              java.util.Collection<java.lang.String> plugins)
Removes unmaintained plugins from a collection of plugins. Modifies the collection plugins. Also removes the plugin from the list of plugins in the preferences, if necessary. Asks the user for every unmaintained plugin whether it should be removed.

Parameters:
plugins - the collection of plugins

checkAndConfirmPluginUpdate

public static boolean checkAndConfirmPluginUpdate(java.awt.Component parent)
Checks whether the locally available plugins should be updated and asks the user if running an update is OK. An update is advised if JOSM was updated to a new version since the last plugin updates or if the plugins were last updated a long time ago.

Parameters:
parent - the parent component relative to which the confirmation dialog is to be displayed
Returns:
true if a plugin update should be run; false, otherwise

alertMissingRequiredPlugin

private static void alertMissingRequiredPlugin(java.awt.Component parent,
                                               java.lang.String plugin,
                                               java.util.Set<java.lang.String> missingRequiredPlugin)
Alerts the user if a plugin required by another plugin is missing

Parameters:
parent - The parent Component used to display error popup
plugin - the plugin
missingRequiredPlugin - the missing required plugin

alertJOSMUpdateRequired

private static void alertJOSMUpdateRequired(java.awt.Component parent,
                                            java.lang.String plugin,
                                            int requiredVersion)

checkLoadPreconditions

public static boolean checkLoadPreconditions(java.awt.Component parent,
                                             java.util.Collection<PluginInformation> plugins,
                                             PluginInformation plugin)
Checks whether all preconditions for loading the plugin plugin are met. The current JOSM version must be compatible with the plugin and no other plugins this plugin depends on should be missing.

Parameters:
parent - The parent Component used to display error popup
plugins - the collection of all loaded plugins
plugin - the plugin for which preconditions are checked
Returns:
true, if the preconditions are met; false otherwise

checkRequiredPluginsPreconditions

public static boolean checkRequiredPluginsPreconditions(java.awt.Component parent,
                                                        java.util.Collection<PluginInformation> plugins,
                                                        PluginInformation plugin)
Checks if required plugins preconditions for loading the plugin plugin are met. No other plugins this plugin depends on should be missing.

Parameters:
parent - The parent Component used to display error popup
plugins - the collection of all loaded plugins
plugin - the plugin for which preconditions are checked
Returns:
true, if the preconditions are met; false otherwise

createClassLoader

public static java.lang.ClassLoader createClassLoader(java.util.Collection<PluginInformation> plugins)
Creates a class loader for loading plugin code.

Parameters:
plugins - the collection of plugins which are going to be loaded with this class loader
Returns:
the class loader

loadPlugin

public static void loadPlugin(java.awt.Component parent,
                              PluginInformation plugin,
                              java.lang.ClassLoader pluginClassLoader)
Loads and instantiates the plugin described by plugin using the class loader pluginClassLoader.

Parameters:
plugin - the plugin
pluginClassLoader - the plugin class loader

loadPlugins

public static void loadPlugins(java.awt.Component parent,
                               java.util.Collection<PluginInformation> plugins,
                               ProgressMonitor monitor)
Loads the plugin in plugins from locally available jar files into memory.

Parameters:
plugins - the list of plugins
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.

loadEarlyPlugins

public static void loadEarlyPlugins(java.awt.Component parent,
                                    java.util.Collection<PluginInformation> plugins,
                                    ProgressMonitor monitor)
Loads plugins from plugins which have the flag PluginInformation.early set to true.

Parameters:
plugins - the collection of plugins
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.

loadLatePlugins

public static void loadLatePlugins(java.awt.Component parent,
                                   java.util.Collection<PluginInformation> plugins,
                                   ProgressMonitor monitor)
Loads plugins from plugins which have the flag PluginInformation.early set to false.

Parameters:
plugins - the collection of plugins
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.

loadLocallyAvailablePluginInformation

private static java.util.Map<java.lang.String,PluginInformation> loadLocallyAvailablePluginInformation(ProgressMonitor monitor)
Loads locally available plugin information from local plugin jars and from cached plugin lists.

Parameters:
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.
Returns:
the list of locally available plugin information

alertMissingPluginInformation

private static void alertMissingPluginInformation(java.awt.Component parent,
                                                  java.util.Collection<java.lang.String> plugins)

buildListOfPluginsToLoad

public static java.util.List<PluginInformation> buildListOfPluginsToLoad(java.awt.Component parent,
                                                                         ProgressMonitor monitor)
Builds the set of plugins to load. Deprecated and unmaintained plugins are filtered out. This involves user interaction. This method displays alert and confirmation messages.

Parameters:
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.
Returns:
the set of plugins to load (as set of plugin names)

alertFailedPluginUpdate

private static void alertFailedPluginUpdate(java.awt.Component parent,
                                            java.util.Collection<PluginInformation> plugins)

updatePlugins

public static java.util.List<PluginInformation> updatePlugins(java.awt.Component parent,
                                                              java.util.List<PluginInformation> plugins,
                                                              ProgressMonitor monitor)
                                                       throws java.lang.IllegalArgumentException
Updates the plugins in plugins.

Parameters:
parent - the parent component for message boxes
plugins - the collection of plugins to update. Must not be null.
monitor - the progress monitor. Defaults to NullProgressMonitor.INSTANCE if null.
Throws:
java.lang.IllegalArgumentException - thrown if plugins is null

confirmDisablePlugin

public static boolean confirmDisablePlugin(java.awt.Component parent,
                                           java.lang.String reason,
                                           java.lang.String name)
Ask the user for confirmation that a plugin shall be disabled.

Parameters:
reason - the reason for disabling the plugin
name - the plugin name
Returns:
true, if the plugin shall be disabled; false, otherwise

notifyMapFrameChanged

public static void notifyMapFrameChanged(MapFrame old,
                                         MapFrame map)
Notified loaded plugins about a new map frame

Parameters:
old - the old map frame
map - the new map frame

getPlugin

public static java.lang.Object getPlugin(java.lang.String name)

addDownloadSelection

public static void addDownloadSelection(java.util.List<DownloadSelection> downloadSelections)

getPreferenceSetting

public static void getPreferenceSetting(java.util.Collection<PreferenceSettingFactory> settings)

installDownloadedPlugins

public static void installDownloadedPlugins(boolean dowarn)
Installs downloaded plugins. Moves files with the suffix ".jar.new" to the corresponding ".jar" files. If dowarn is true, this methods emits warning messages on the console if a downloaded but not yet installed plugin .jar can't be be installed. If dowarn is false, the installation of the respective plugin is sillently skipped.

Parameters:
dowarn - if true, warning messages are displayed; false otherwise

confirmDeactivatingPluginAfterException

private static boolean confirmDeactivatingPluginAfterException(PluginProxy plugin)

getPluginCausingException

private static PluginProxy getPluginCausingException(java.lang.Throwable ex)
Replies the plugin which most likely threw the exception ex.

Parameters:
ex - the exception
Returns:
the plugin; null, if the exception probably wasn't thrown from a plugin

disablePluginAfterException

public static void disablePluginAfterException(java.lang.Throwable e)
Checks whether the exception e was thrown by a plugin. If so, conditionally deactivates the plugin, but asks the user first.

Parameters:
e - the exception

getBugReportText

public static java.lang.String getBugReportText()

getInfoPanel

public static javax.swing.JPanel getInfoPanel()


JOSM