Package org.openstreetmap.josm.plugins
Class PluginInformation
- java.lang.Object
-
- org.openstreetmap.josm.plugins.PluginInformation
-
public class PluginInformation extends java.lang.Object
Encapsulate general information about a plugin. This information is available without the need of loading any class from the plugin jar file.- Since:
- 153
-
-
Field Summary
Fields Modifier and Type Field Description java.util.jar.Attributes
attr
All manifest attributes.java.lang.String
author
The plugin author.boolean
canloadatruntime
Plugin can be loaded at any time and not just at start.java.lang.String
className
The plugin class name.java.lang.String
description
The plugin description.java.lang.String
downloadlink
The plugin download link.boolean
early
Determines if the plugin must be loaded early or not.private static javax.swing.ImageIcon
emptyIcon
Empty icon for these plugins which have nonejava.io.File
file
The plugin jar file.private ImageProvider
icon
The plugin icon.java.lang.String
iconPath
The plugin icon path inside jar.(package private) java.util.List<java.lang.String>
invalidManifestEntries
Invalid manifest entriesjava.util.List<java.net.URL>
libraries
The libraries referenced in Class-Path manifest attribute.java.lang.String
link
The plugin link (for documentation).int
localmainversion
The lowest JOSM version required by this plugin (from locally available jar).int
localminjavaversion
The lowest Java version required by this plugin (from locally available jar).java.lang.String
localrequires
The list of required plugins, separated by ';' (from locally available jar).java.lang.String
localversion
The plugin version (from locally available jar).int
mainversion
The lowest JOSM version required by this plugin (from plugin list).int
minjavaversion
The lowest Java version required by this plugin (from plugin list).java.lang.String
name
The plugin name.boolean
oldmode
Determines if the plugin is an old version loaded for incompatibility with latest JOSM (from plugin list)java.lang.String
platform
The plugin platform on which it is meant to run (windows, osx, unixoid).java.lang.String
provides
The virtual plugin provided by this plugin, if native for a given platform.java.lang.String
requires
The list of required plugins, separated by ';' (from plugin list).int
stage
The plugin stage, determining the loading sequence order of plugins.java.lang.String
version
The plugin version (from plugin list).
-
Constructor Summary
Constructors Constructor Description PluginInformation(java.io.File file)
Creates a plugin information object by reading the plugin information from the manifest in the plugin jar.PluginInformation(java.io.File file, java.lang.String name)
Creates a plugin information object for the plugin with namename
.PluginInformation(java.io.InputStream manifestStream, java.lang.String name, java.lang.String url)
Creates a plugin information object by reading plugin information in Manifest format from the input streammanifestStream
.PluginInformation(java.util.jar.Attributes attr, java.lang.String name, java.lang.String url)
Creates a plugin information object by reading plugin information in Manifest format from the input streammanifestStream
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static PluginInformation
findPlugin(java.lang.String pluginName)
Try to find a plugin after some criteria.java.lang.String
getDescriptionAsHtml()
Replies the description as HTML document, including a link to a web page with more information, provided such a link is available.java.util.List<java.lang.String>
getLocalRequiredPlugins()
Replies the list of plugins required by the local instance of this plugin.java.lang.String
getName()
Replies the name of the plugin.static java.util.Collection<java.lang.String>
getPluginLocations()
Returns all possible plugin locations.java.util.List<java.lang.String>
getRequiredPlugins()
Replies the list of plugins required by the up-to-date version of this plugin.private static java.util.List<java.lang.String>
getRequiredPlugins(java.lang.String pluginList)
javax.swing.ImageIcon
getScaledIcon()
Replies the plugin icon, scaled to LARGE_ICON size.boolean
isExternal()
Determines if this plugin comes from an external, non-official source.boolean
isForCurrentPlatform()
Determines if this plugin can be run on the current platform.boolean
isUpdateRequired()
Replies true if this this plugin should be updated/downloaded because either it is not available locally (its local version is null) or its local version is older than the available version on the server.boolean
isUpdateRequired(java.lang.String referenceVersion)
Replies true if the plugin with the given information is most likely outdated with respect to the referenceVersion.PluginProxy
load(java.lang.Class<?> klass, PluginClassLoader classLoader)
Loads and instantiates the plugin.java.lang.Class<?>
loadClass(java.lang.ClassLoader classLoader)
Loads the class of the plugin.boolean
matches(java.lang.String filter)
Replies true if either the name, the description, or the version match (case insensitive) one of the words in filter.protected boolean
matches(java.lang.String filter, java.lang.String value)
private void
scanManifest(java.util.jar.Attributes attr, boolean oldcheck)
void
setName(java.lang.String name)
Sets the namejava.lang.String
toString()
void
updateFromJar(PluginInformation other)
Updates the plugin information of this plugin information object with the plugin information in a plugin information object retrieved from a plugin jar.void
updateFromPluginSite(PluginInformation other)
Updates the plugin information of this plugin information object with the plugin information in a plugin information object retrieved from a plugin update site.void
updateLocalInfo(PluginInformation info)
Updates the local fields (localversion
,localmainversion
,localminjavaversion
,localrequires
) to values contained in the up-to-date fields (version
,mainversion
,minjavaversion
,requires
) of the given PluginInformation.
-
-
-
Field Detail
-
file
public java.io.File file
The plugin jar file.
-
name
public java.lang.String name
The plugin name.
-
mainversion
public int mainversion
The lowest JOSM version required by this plugin (from plugin list).
-
localmainversion
public int localmainversion
The lowest JOSM version required by this plugin (from locally available jar).
-
minjavaversion
public int minjavaversion
The lowest Java version required by this plugin (from plugin list).
-
localminjavaversion
public int localminjavaversion
The lowest Java version required by this plugin (from locally available jar).
-
className
public java.lang.String className
The plugin class name.
-
oldmode
public boolean oldmode
Determines if the plugin is an old version loaded for incompatibility with latest JOSM (from plugin list)
-
requires
public java.lang.String requires
The list of required plugins, separated by ';' (from plugin list).
-
localrequires
public java.lang.String localrequires
The list of required plugins, separated by ';' (from locally available jar).
-
platform
public java.lang.String platform
The plugin platform on which it is meant to run (windows, osx, unixoid).
-
provides
public java.lang.String provides
The virtual plugin provided by this plugin, if native for a given platform.
-
link
public java.lang.String link
The plugin link (for documentation).
-
description
public java.lang.String description
The plugin description.
-
early
public boolean early
Determines if the plugin must be loaded early or not.
-
author
public java.lang.String author
The plugin author.
-
stage
public int stage
The plugin stage, determining the loading sequence order of plugins.
-
version
public java.lang.String version
The plugin version (from plugin list).
-
localversion
public java.lang.String localversion
The plugin version (from locally available jar).
-
downloadlink
public java.lang.String downloadlink
The plugin download link.
-
iconPath
public java.lang.String iconPath
The plugin icon path inside jar.
-
icon
private ImageProvider icon
The plugin icon.
-
canloadatruntime
public boolean canloadatruntime
Plugin can be loaded at any time and not just at start.
-
libraries
public java.util.List<java.net.URL> libraries
The libraries referenced in Class-Path manifest attribute.
-
attr
public java.util.jar.Attributes attr
All manifest attributes.
-
invalidManifestEntries
final java.util.List<java.lang.String> invalidManifestEntries
Invalid manifest entries
-
emptyIcon
private static final javax.swing.ImageIcon emptyIcon
Empty icon for these plugins which have none
-
-
Constructor Detail
-
PluginInformation
public PluginInformation(java.io.File file) throws PluginException
Creates a plugin information object by reading the plugin information from the manifest in the plugin jar. The plugin name is derived from the file name.- Parameters:
file
- the plugin jar file- Throws:
PluginException
- if reading the manifest fails
-
PluginInformation
public PluginInformation(java.io.File file, java.lang.String name) throws PluginException
Creates a plugin information object for the plugin with namename
. Information about the plugin is extracted from the manifest file in the plugin jarfile
.- Parameters:
file
- the plugin jarname
- the plugin name- Throws:
PluginException
- if reading the manifest file fails
-
PluginInformation
public PluginInformation(java.io.InputStream manifestStream, java.lang.String name, java.lang.String url) throws PluginException
Creates a plugin information object by reading plugin information in Manifest format from the input streammanifestStream
.- Parameters:
manifestStream
- the stream to read the manifest fromname
- the plugin nameurl
- the download URL for the plugin- Throws:
PluginException
- if the plugin information can't be read from the input stream
-
PluginInformation
public PluginInformation(java.util.jar.Attributes attr, java.lang.String name, java.lang.String url) throws PluginException
Creates a plugin information object by reading plugin information in Manifest format from the input streammanifestStream
.- Parameters:
attr
- the manifest attributesname
- the plugin nameurl
- the download URL for the plugin- Throws:
PluginException
- if the plugin information can't be read from the input stream
-
-
Method Detail
-
updateFromPluginSite
public void updateFromPluginSite(PluginInformation other)
Updates the plugin information of this plugin information object with the plugin information in a plugin information object retrieved from a plugin update site.- Parameters:
other
- the plugin information object retrieved from the update site
-
updateFromJar
public void updateFromJar(PluginInformation other)
Updates the plugin information of this plugin information object with the plugin information in a plugin information object retrieved from a plugin jar.- Parameters:
other
- the plugin information object retrieved from the jar file- Since:
- 5601
-
scanManifest
private void scanManifest(java.util.jar.Attributes attr, boolean oldcheck)
-
getDescriptionAsHtml
public java.lang.String getDescriptionAsHtml()
Replies the description as HTML document, including a link to a web page with more information, provided such a link is available.- Returns:
- the description as HTML document
-
isExternal
public boolean isExternal()
Determines if this plugin comes from an external, non-official source.- Returns:
true
if this plugin comes from an external, non-official source.- Since:
- 18267
-
load
public PluginProxy load(java.lang.Class<?> klass, PluginClassLoader classLoader) throws PluginException
Loads and instantiates the plugin.- Parameters:
klass
- the plugin classclassLoader
- the class loader for the plugin- Returns:
- the instantiated and initialized plugin
- Throws:
PluginException
- if the plugin cannot be loaded or instanciated- Since:
- 12322
-
loadClass
public java.lang.Class<?> loadClass(java.lang.ClassLoader classLoader) throws PluginException
Loads the class of the plugin.- Parameters:
classLoader
- the class loader to use- Returns:
- the loaded class
- Throws:
PluginException
- if the class cannot be loaded
-
findPlugin
public static PluginInformation findPlugin(java.lang.String pluginName) throws PluginException
Try to find a plugin after some criteria. Extract the plugin-information from the plugin and return it. The plugin is searched in the following way:- first look after an MANIFEST.MF in the package org.openstreetmap.josm.plugins.<plugin name> (After removing all fancy characters from the plugin name). If found, the plugin is loaded using the bootstrap classloader.
- If not found, look for a jar file in the user specific plugin directory (~/.josm/plugins/<plugin name>.jar)
- If not found and the environment variable JOSM_RESOURCES + "/plugins/" exist, look there.
- Try for the java property josm.resources + "/plugins/" (set via java -Djosm.plugins.path=...)
- If the environment variable ALLUSERSPROFILE and APPDATA exist, look in ALLUSERSPROFILE/<the last stuff from APPDATA>/JOSM/plugins. (*sic* There is no easy way under Windows to get the All User's application directory)
- Finally, look in some typical unix paths:
- /usr/local/share/josm/plugins/
- /usr/local/lib/josm/plugins/
- /usr/share/josm/plugins/
- /usr/lib/josm/plugins/
- Parameters:
pluginName
- The name of the plugin (in all lowercase). E.g. "lang-de"- Returns:
- Information about the plugin or
null
, if the plugin was nowhere to be found. - Throws:
PluginException
- In case of broken plugins.
-
getPluginLocations
public static java.util.Collection<java.lang.String> getPluginLocations()
Returns all possible plugin locations.- Returns:
- all possible plugin locations.
-
isUpdateRequired
public boolean isUpdateRequired(java.lang.String referenceVersion)
Replies true if the plugin with the given information is most likely outdated with respect to the referenceVersion.- Parameters:
referenceVersion
- the reference version. Can be null if we don't know a reference version- Returns:
- true, if the plugin needs to be updated; false, otherweise
-
isUpdateRequired
public boolean isUpdateRequired()
Replies true if this this plugin should be updated/downloaded because either it is not available locally (its local version is null) or its local version is older than the available version on the server.- Returns:
- true if the plugin should be updated
-
matches
protected boolean matches(java.lang.String filter, java.lang.String value)
-
matches
public boolean matches(java.lang.String filter)
Replies true if either the name, the description, or the version match (case insensitive) one of the words in filter. Replies true if filter is null.- Parameters:
filter
- the filter expression- Returns:
- true if this plugin info matches with the filter
-
getName
public java.lang.String getName()
Replies the name of the plugin.- Returns:
- The plugin name
-
setName
public void setName(java.lang.String name)
Sets the name- Parameters:
name
- Plugin name
-
getScaledIcon
public javax.swing.ImageIcon getScaledIcon()
Replies the plugin icon, scaled to LARGE_ICON size.- Returns:
- the plugin icon, scaled to LARGE_ICON size.
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
getRequiredPlugins
private static java.util.List<java.lang.String> getRequiredPlugins(java.lang.String pluginList)
-
getRequiredPlugins
public java.util.List<java.lang.String> getRequiredPlugins()
Replies the list of plugins required by the up-to-date version of this plugin.- Returns:
- List of plugins required. Empty if no plugin is required.
- Since:
- 5601
-
getLocalRequiredPlugins
public java.util.List<java.lang.String> getLocalRequiredPlugins()
Replies the list of plugins required by the local instance of this plugin.- Returns:
- List of plugins required. Empty if no plugin is required.
- Since:
- 5601
-
updateLocalInfo
public void updateLocalInfo(PluginInformation info)
Updates the local fields (localversion
,localmainversion
,localminjavaversion
,localrequires
) to values contained in the up-to-date fields (version
,mainversion
,minjavaversion
,requires
) of the given PluginInformation.- Parameters:
info
- The plugin information to get the data from.- Since:
- 5601
-
isForCurrentPlatform
public boolean isForCurrentPlatform()
Determines if this plugin can be run on the current platform.- Returns:
true
if this plugin can be run on the current platform- Since:
- 14384
-
-