Package org.openstreetmap.josm.plugins
Class PluginHandler
- java.lang.Object
-
- org.openstreetmap.josm.plugins.PluginHandler
-
public final class PluginHandler extends Object
PluginHandler is basically a collection of static utility functions used to bootstrap and manage the loaded plugins.- Since:
- 1326
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
PluginHandler.DeprecatedPlugin
Description of a deprecated plugin(package private) static class
PluginHandler.PluginInformationAction
private static class
PluginHandler.UpdatePluginsMessagePanel
-
Field Summary
Fields Modifier and Type Field Description private static Map<String,PluginClassLoader>
classLoaders
Plugin class loaders.static int
DEFAULT_TIME_BASED_UPDATE_INTERVAL
Default time-based update interval, in days (pluginmanager.time-based-update.interval)(package private) static List<PluginHandler.DeprecatedPlugin>
DEPRECATED_PLUGINS
Deprecated plugins that are removed on startprivate static DynamicURLClassLoader
joinedPluginResourceCL
Class loader to locate resources from plugins.private static PluginDownloadTask
pluginDownloadTask
(package private) static Collection<PluginProxy>
pluginList
All installed and loaded plugins (resp.(package private) static Collection<PluginInformation>
pluginListNotLoaded
All installed but not loaded plugins(package private) static Map<String,Throwable>
pluginLoadingExceptions
All exceptions that occurred during plugin loadingprivate static List<ClassLoader>
sources
Add here all ClassLoader whose resource should be searched.(package private) static List<String>
UNMAINTAINED_PLUGINS
List of unmaintained plugins.
-
Constructor Summary
Constructors Modifier Constructor Description private
PluginHandler()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
addDownloadSelection(List<DownloadSelection> downloadSelections)
Called in the download dialog to give the plugins a chance to modify the list of bounding box selectors.private static void
alertFailedPluginUpdate(Component parent, Collection<PluginInformation> plugins)
private static void
alertJOSMUpdateRequired(Component parent, String plugin, int requiredVersion)
private static void
alertMissingPluginInformation(Component parent, Collection<String> plugins)
private static void
alertMissingRequiredPlugin(Component parent, String plugin, Set<String> missingRequiredPlugin)
Alerts the user if a plugin required by another plugin is missing, and offer to download them & restart JOSMprivate static int
askUpdateDisableKeepPluginAfterException(PluginProxy plugin)
static List<PluginInformation>
buildListOfPluginsToLoad(Component parent, ProgressMonitor monitor)
Builds the set of plugins to load.static boolean
checkAndConfirmPluginUpdate(Component parent)
Checks whether the locally available plugins should be updated and asks the user if running an update is OK.static boolean
checkLoadPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin)
Checks whether all preconditions for loading the pluginplugin
are met.static boolean
checkRequiredPluginsPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin, boolean local)
Checks if required plugins preconditions for loading the pluginplugin
are met.static boolean
confirmDisablePlugin(Component parent, String reason, String name)
Ask the user for confirmation that a plugin shall be disabled.private static void
downloadRequiredPluginsAndRestart(Component parent, Set<String> missingRequiredPlugin)
private static void
extendJoinedPluginResourceCL(Collection<PluginInformation> plugins)
Add more plugins to the joined plugin resource class loader.(package private) static void
filterDeprecatedPlugins(Component parent, Collection<String> plugins)
Removes deprecated plugins from a collection of plugins.(package private) static void
filterUnmaintainedPlugins(Component parent, Collection<String> plugins)
Removes unmaintained plugins from a collection of plugins.private static Set<PluginInformation>
findRequiredPluginsToDownload(Collection<PluginInformation> pluginsToUpdate, List<PluginInformation> allPlugins, Set<PluginInformation> pluginsToDownload)
static File
findUpdatedJar(String name)
Replies the updated jar file for the given plugin name.static Collection<String>
getBugReportInformation()
Returns the list of loaded plugins as aString
to be displayed in status report.static Set<String>
getDeprecatedAndUnmaintainedPlugins()
Returns the set of deprecated and unmaintained plugins.static JPanel
getInfoPanel()
Returns the list of loaded plugins as aJPanel
to be displayed in About dialog.private static DynamicURLClassLoader
getJoinedPluginResourceCL()
Get class loader to locate resources from plugins.static Object
getPlugin(String name)
Returns the plugin of the specified name.private static PluginProxy
getPluginCausingException(Throwable ex)
Replies the plugin which most likely threw the exceptionex
.static PluginClassLoader
getPluginClassLoader(String name)
Returns the plugin class loader for the plugin of the specified name.static Collection<PluginClassLoader>
getPluginClassLoaders()
Returns all plugin classloaders.static List<PluginInformation>
getPlugins()
Returns the list of currently installed and loaded plugins, sorted by name.static Collection<PreferenceSettingFactory>
getPreferenceSetting()
Returns the list of plugin preference settings.(package private) static String
getRemovedPluginsMessage(Collection<PluginHandler.DeprecatedPlugin> removedPlugins)
static Collection<ClassLoader>
getResourceClassLoaders()
Returns all ClassLoaders whose resource should be searched.(package private) static String
getUnmaintainedPluginMessage(String unmaintained)
static void
installDownloadedPlugins(Collection<PluginInformation> pluginsToLoad, boolean dowarn)
Installs downloaded plugins.private static boolean
isDependency(PluginInformation pi, String depName)
static boolean
isValidJar(File jar)
Determines if the specified file is a valid and accessible JAR file.static void
loadEarlyPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads plugins fromplugins
which have the flagPluginInformation.early
set to true and a non-negativePluginInformation.stage
value.static void
loadLatePlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads plugins fromplugins
which have the flagPluginInformation.early
set to false.private static Map<String,PluginInformation>
loadLocallyAvailablePluginInformation(ProgressMonitor monitor)
Loads locally available plugin information from local plugin jars and from cached plugin lists.private static void
loadPlugin(Component parent, PluginInformation plugin, PluginClassLoader pluginClassLoader)
Loads and instantiates the plugin described byplugin
using the class loaderpluginClassLoader
.static void
loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads the plugin inplugins
from locally available jar files into memory.static void
loadVeryEarlyPlugins()
Loads plugins fromplugins
which have the flagPluginInformation.early
set to true and a negativePluginInformation.stage
value.private static void
logJavaUpdateRequired(String plugin, int requiredVersion)
private static void
logWrongPlatform(String plugin, String pluginPlatform)
static void
refreshLocalUpdatedPluginInfo(Collection<PluginInformation> updatedPlugins)
Refreshes the given PluginInformation objects with new contents read from their corresponding jar file.static boolean
removePlugins(List<PluginInformation> deactivatedPlugins)
Remove deactivated plugins, returning true if JOSM should restartstatic PluginDownloadTask
updateOrdisablePluginAfterException(Throwable e)
Checks whether the exceptione
was thrown by a plugin.static Collection<PluginInformation>
updatePlugins(Component parent, Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor, boolean displayErrMsg)
Updates the plugins inplugins
.
-
-
-
Field Detail
-
DEPRECATED_PLUGINS
static final List<PluginHandler.DeprecatedPlugin> DEPRECATED_PLUGINS
Deprecated plugins that are removed on start
-
UNMAINTAINED_PLUGINS
static final List<String> UNMAINTAINED_PLUGINS
List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not maintained after a few months, sadly...
-
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
static final Collection<PluginProxy> pluginList
All installed and loaded plugins (resp. their main classes)
-
pluginListNotLoaded
static final Collection<PluginInformation> pluginListNotLoaded
All installed but not loaded plugins
-
pluginLoadingExceptions
static final Map<String,Throwable> pluginLoadingExceptions
All exceptions that occurred during plugin loading
-
joinedPluginResourceCL
private static DynamicURLClassLoader joinedPluginResourceCL
Class loader to locate resources from plugins.- See Also:
getJoinedPluginResourceCL()
-
sources
private static final List<ClassLoader> sources
Add here all ClassLoader whose resource should be searched.
-
classLoaders
private static final Map<String,PluginClassLoader> classLoaders
Plugin class loaders.
-
pluginDownloadTask
private static PluginDownloadTask pluginDownloadTask
-
-
Constructor Detail
-
PluginHandler
private PluginHandler()
-
-
Method Detail
-
getPlugins
public static List<PluginInformation> getPlugins()
Returns the list of currently installed and loaded plugins, sorted by name.- Returns:
- the list of currently installed and loaded plugins, sorted by name
- Since:
- 10982
-
getResourceClassLoaders
public static Collection<ClassLoader> getResourceClassLoaders()
Returns all ClassLoaders whose resource should be searched.- Returns:
- all ClassLoaders whose resource should be searched
-
getPluginClassLoaders
public static Collection<PluginClassLoader> getPluginClassLoaders()
Returns all plugin classloaders.- Returns:
- all plugin classloaders
- Since:
- 14978
-
filterDeprecatedPlugins
static void filterDeprecatedPlugins(Component parent, Collection<String> plugins)
Removes deprecated plugins from a collection of plugins. Modifies the collectionplugins
. Also notifies the user about removed deprecated plugins- Parameters:
parent
- The parent Component used to display warning popupplugins
- the collection of plugins
-
getRemovedPluginsMessage
static String getRemovedPluginsMessage(Collection<PluginHandler.DeprecatedPlugin> removedPlugins)
-
filterUnmaintainedPlugins
static void filterUnmaintainedPlugins(Component parent, Collection<String> plugins)
Removes unmaintained plugins from a collection of plugins. Modifies the collectionplugins
. 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:
parent
- The parent Component used to display warning popupplugins
- the collection of plugins
-
getUnmaintainedPluginMessage
static String getUnmaintainedPluginMessage(String unmaintained)
-
checkAndConfirmPluginUpdate
public static boolean checkAndConfirmPluginUpdate(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(Component parent, String plugin, Set<String> missingRequiredPlugin)
Alerts the user if a plugin required by another plugin is missing, and offer to download them & restart JOSM- Parameters:
parent
- The parent Component used to display error popupplugin
- the pluginmissingRequiredPlugin
- the missing required plugin
-
downloadRequiredPluginsAndRestart
private static void downloadRequiredPluginsAndRestart(Component parent, Set<String> missingRequiredPlugin)
-
logWrongPlatform
private static void logWrongPlatform(String plugin, String pluginPlatform)
-
logJavaUpdateRequired
private static void logJavaUpdateRequired(String plugin, int requiredVersion)
-
alertJOSMUpdateRequired
private static void alertJOSMUpdateRequired(Component parent, String plugin, int requiredVersion)
-
checkLoadPreconditions
public static boolean checkLoadPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin)
Checks whether all preconditions for loading the pluginplugin
are met. The current Java and JOSM versions 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 popupplugins
- the collection of all loaded pluginsplugin
- the plugin for which preconditions are checked- Returns:
- true, if the preconditions are met; false otherwise
-
checkRequiredPluginsPreconditions
public static boolean checkRequiredPluginsPreconditions(Component parent, Collection<PluginInformation> plugins, PluginInformation plugin, boolean local)
Checks if required plugins preconditions for loading the pluginplugin
are met. No other plugins this plugin depends on should be missing.- Parameters:
parent
- The parent Component used to display error popup. If parent is null, the error popup is suppressedplugins
- the collection of all processed pluginsplugin
- the plugin for which preconditions are checkedlocal
- Determines if the local or up-to-date plugin dependencies are to be checked.- Returns:
- true, if the preconditions are met; false otherwise
- Since:
- 5601
-
getJoinedPluginResourceCL
private static DynamicURLClassLoader getJoinedPluginResourceCL()
Get class loader to locate resources from plugins. It joins URLs of all plugins, to find images, etc. (Not for loading Java classes - each plugin has a separatePluginClassLoader
for that purpose.)- Returns:
- class loader to locate resources from plugins
-
extendJoinedPluginResourceCL
private static void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins)
Add more plugins to the joined plugin resource class loader.- Parameters:
plugins
- the plugins to add
-
loadPlugin
private static void loadPlugin(Component parent, PluginInformation plugin, PluginClassLoader pluginClassLoader)
Loads and instantiates the plugin described byplugin
using the class loaderpluginClassLoader
.- Parameters:
parent
- The parent component to be used for the displayed dialogplugin
- the pluginpluginClassLoader
- the plugin class loader
-
loadPlugins
public static void loadPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads the plugin inplugins
from locally available jar files into memory.- Parameters:
parent
- The parent component to be used for the displayed dialogplugins
- the list of pluginsmonitor
- the progress monitor. Defaults toNullProgressMonitor.INSTANCE
if null.
-
isDependency
private static boolean isDependency(PluginInformation pi, String depName)
-
loadVeryEarlyPlugins
public static void loadVeryEarlyPlugins()
Loads plugins fromplugins
which have the flagPluginInformation.early
set to true and a negativePluginInformation.stage
value. This is meant for plugins that provide additionalLookAndFeel
.
-
loadEarlyPlugins
public static void loadEarlyPlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads plugins fromplugins
which have the flagPluginInformation.early
set to true and a non-negativePluginInformation.stage
value.- Parameters:
parent
- The parent component to be used for the displayed dialogplugins
- the collection of pluginsmonitor
- the progress monitor. Defaults toNullProgressMonitor.INSTANCE
if null.
-
loadLatePlugins
public static void loadLatePlugins(Component parent, Collection<PluginInformation> plugins, ProgressMonitor monitor)
Loads plugins fromplugins
which have the flagPluginInformation.early
set to false.- Parameters:
parent
- The parent component to be used for the displayed dialogplugins
- the collection of pluginsmonitor
- the progress monitor. Defaults toNullProgressMonitor.INSTANCE
if null.
-
loadLocallyAvailablePluginInformation
private static Map<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 toNullProgressMonitor.INSTANCE
if null.- Returns:
- the list of locally available plugin information, null in case of errors
-
alertMissingPluginInformation
private static void alertMissingPluginInformation(Component parent, Collection<String> plugins)
-
buildListOfPluginsToLoad
public static List<PluginInformation> buildListOfPluginsToLoad(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:
parent
- The parent component to be used for the displayed dialogmonitor
- the progress monitor. Defaults toNullProgressMonitor.INSTANCE
if null.- Returns:
- the set of plugins to load (as set of plugin names)
-
alertFailedPluginUpdate
private static void alertFailedPluginUpdate(Component parent, Collection<PluginInformation> plugins)
-
findRequiredPluginsToDownload
private static Set<PluginInformation> findRequiredPluginsToDownload(Collection<PluginInformation> pluginsToUpdate, List<PluginInformation> allPlugins, Set<PluginInformation> pluginsToDownload)
-
updatePlugins
public static Collection<PluginInformation> updatePlugins(Component parent, Collection<PluginInformation> pluginsWanted, ProgressMonitor monitor, boolean displayErrMsg)
Updates the plugins inplugins
.- Parameters:
parent
- the parent component for message boxespluginsWanted
- the collection of plugins to update. Updates all plugins ifnull
monitor
- the progress monitor. Defaults toNullProgressMonitor.INSTANCE
if null.displayErrMsg
- iftrue
, a blocking error message is displayed in case of I/O exception.- Returns:
- the list of plugins to load
- Throws:
IllegalArgumentException
- if plugins is null
-
confirmDisablePlugin
public static boolean confirmDisablePlugin(Component parent, String reason, String name)
Ask the user for confirmation that a plugin shall be disabled.- Parameters:
parent
- The parent component to be used for the displayed dialogreason
- the reason for disabling the pluginname
- the plugin name- Returns:
- true, if the plugin shall be disabled; false, otherwise
-
getPlugin
public static Object getPlugin(String name)
Returns the plugin of the specified name.- Parameters:
name
- The plugin name- Returns:
- The plugin of the specified name, if installed and loaded, or
null
otherwise.
-
getPluginClassLoader
public static PluginClassLoader getPluginClassLoader(String name)
Returns the plugin class loader for the plugin of the specified name.- Parameters:
name
- The plugin name- Returns:
- The plugin class loader for the plugin of the specified name, if
installed and loaded, or
null
otherwise. - Since:
- 12323
-
addDownloadSelection
public static void addDownloadSelection(List<DownloadSelection> downloadSelections)
Called in the download dialog to give the plugins a chance to modify the list of bounding box selectors.- Parameters:
downloadSelections
- list of bounding box selectors
-
getPreferenceSetting
public static Collection<PreferenceSettingFactory> getPreferenceSetting()
Returns the list of plugin preference settings.- Returns:
- the list of plugin preference settings
-
installDownloadedPlugins
public static void installDownloadedPlugins(Collection<PluginInformation> pluginsToLoad, boolean dowarn)
Installs downloaded plugins. Moves files with the suffix ".jar.new" to the corresponding ".jar" files. Ifdowarn
is true, this methods emits warning messages on the console if a downloaded but not yet installed plugin .jar can't be be installed. Ifdowarn
is false, the installation of the respective plugin is silently skipped.- Parameters:
pluginsToLoad
- list of plugin informations to updatedowarn
- if true, warning messages are displayed; false otherwise- Since:
- 13294
-
isValidJar
public static boolean isValidJar(File jar)
Determines if the specified file is a valid and accessible JAR file.- Parameters:
jar
- The file to check- Returns:
- true if file can be opened as a JAR file.
- Since:
- 5723
-
findUpdatedJar
public static File findUpdatedJar(String name)
Replies the updated jar file for the given plugin name.- Parameters:
name
- The plugin name to find.- Returns:
- the updated jar file for the given plugin name. null if not found or not readable.
- Since:
- 5601
-
refreshLocalUpdatedPluginInfo
public static void refreshLocalUpdatedPluginInfo(Collection<PluginInformation> updatedPlugins)
Refreshes the given PluginInformation objects with new contents read from their corresponding jar file.- Parameters:
updatedPlugins
- The PluginInformation objects to update.- Since:
- 5601
-
askUpdateDisableKeepPluginAfterException
private static int askUpdateDisableKeepPluginAfterException(PluginProxy plugin)
-
getPluginCausingException
private static PluginProxy getPluginCausingException(Throwable ex)
Replies the plugin which most likely threw the exceptionex
.- Parameters:
ex
- the exception- Returns:
- the plugin; null, if the exception probably wasn't thrown from a plugin
-
updateOrdisablePluginAfterException
public static PluginDownloadTask updateOrdisablePluginAfterException(Throwable e)
Checks whether the exceptione
was thrown by a plugin. If so, conditionally updates or deactivates the plugin, but asks the user first.- Parameters:
e
- the exception- Returns:
- plugin download task if the plugin has been updated to a newer version,
null
if it has been disabled or kept as it
-
getBugReportInformation
public static Collection<String> getBugReportInformation()
Returns the list of loaded plugins as aString
to be displayed in status report. Useful for bug reports.- Returns:
- The list of loaded plugins
-
getInfoPanel
public static JPanel getInfoPanel()
Returns the list of loaded plugins as aJPanel
to be displayed in About dialog.- Returns:
- The list of loaded plugins (one "line" of Swing components per plugin)
-
getDeprecatedAndUnmaintainedPlugins
public static Set<String> getDeprecatedAndUnmaintainedPlugins()
Returns the set of deprecated and unmaintained plugins.- Returns:
- set of deprecated and unmaintained plugins names.
- Since:
- 8938
-
removePlugins
public static boolean removePlugins(List<PluginInformation> deactivatedPlugins)
Remove deactivated plugins, returning true if JOSM should restart- Parameters:
deactivatedPlugins
- The plugins to deactivate- Returns:
- true if there was a plugin that requires a restart
- Since:
- 15508
-
-