org.openstreetmap.josm.plugins
Class PluginInformation

java.lang.Object
  extended by 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.


Field Summary
 java.util.Map<java.lang.String,java.lang.String> attr
           
 java.lang.String author
           
 java.lang.String className
           
 java.lang.String description
           
 java.lang.String downloadlink
           
 boolean early
           
private static javax.swing.ImageIcon emptyIcon
           
 java.io.File file
           
 javax.swing.ImageIcon icon
           
 java.lang.String iconPath
           
 java.util.List<java.net.URL> libraries
           
 java.lang.String link
           
 int localmainversion
           
 java.lang.String localversion
           
 int mainversion
           
 java.lang.String name
           
 boolean oldmode
           
 java.lang.String requires
           
 int stage
           
 java.lang.String version
           
 
Constructor Summary
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 name name.
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 stream manifestStream.
 
Method Summary
static java.net.URL fileToURL(java.io.File f)
           
static PluginInformation findPlugin(java.lang.String pluginName)
          Try to find a plugin after some criterias.
 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.lang.String getName()
          Replies the name of the plugin
static java.util.Collection<java.lang.String> getPluginLocations()
           
 javax.swing.ImageIcon getScaledIcon()
           
 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)
          Load and instantiate the plugin
 java.lang.Class<?> loadClass(java.lang.ClassLoader classLoader)
          Load 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.Manifest manifest, boolean oldcheck)
           
 void setName(java.lang.String name)
          Sets the name
 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

file

public java.io.File file

name

public java.lang.String name

mainversion

public int mainversion

localmainversion

public int localmainversion

className

public java.lang.String className

oldmode

public boolean oldmode

requires

public java.lang.String requires

link

public java.lang.String link

description

public java.lang.String description

early

public boolean early

author

public java.lang.String author

stage

public int stage

version

public java.lang.String version

localversion

public java.lang.String localversion

downloadlink

public java.lang.String downloadlink

iconPath

public java.lang.String iconPath

icon

public javax.swing.ImageIcon icon

libraries

public java.util.List<java.net.URL> libraries

attr

public final java.util.Map<java.lang.String,java.lang.String> attr

emptyIcon

private static final javax.swing.ImageIcon emptyIcon
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 name name. Information about the plugin is extracted from the maifest file in the plugin jar file.

Parameters:
file - the plugin jar
name - the plugin name
Throws:
PluginException - thrown 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 stream manifestStream.

Parameters:
manifestStream - the stream to read the manifest from
name - the plugin name
url - the download URL for the plugin
Throws:
PluginException - thrown 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

scanManifest

private void scanManifest(java.util.jar.Manifest manifest,
                          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

load

public PluginProxy load(java.lang.Class<?> klass)
                 throws PluginException
Load and instantiate the plugin

Parameters:
the - plugin class
Returns:
the instantiated and initialized plugin
Throws:
PluginException

loadClass

public java.lang.Class<?> loadClass(java.lang.ClassLoader classLoader)
                             throws PluginException
Load the class of the plugin

Parameters:
classLoader - the class loader to use
Returns:
the loaded class
Throws:
PluginException

fileToURL

public static java.net.URL fileToURL(java.io.File f)

findPlugin

public static PluginInformation findPlugin(java.lang.String pluginName)
                                    throws PluginException
Try to find a plugin after some criterias. 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. (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/.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//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/ If a plugin class or jar file is found earlier in the list but seem not to be working, an PluginException is thrown rather than continuing the search. This is so JOSM can detect broken user-provided plugins and do not go silently ignore them. The plugin is not initialized. If the plugin is a .jar file, it is not loaded (only the manifest is extracted). In the classloader-case, the class is bootstraped (e.g. static {} - declarations will run. However, nothing else is done.

      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()

    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


    setName

    public void setName(java.lang.String name)
    Sets the name

    Parameters:
    name -

    getScaledIcon

    public javax.swing.ImageIcon getScaledIcon()


    JOSM