Changeset 6843 in josm


Ignore:
Timestamp:
2014-02-12T11:10:01+01:00 (11 years ago)
Author:
Don-vip
Message:

fix #9711 - Nicer report of invalid plugins + javadoc

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r6830 r6843  
    4040 */
    4141public class PluginInformation {
     42
     43    /** The plugin jar file. */
    4244    public File file = null;
     45    /** The plugin name. */
    4346    public String name = null;
     47    /** The lowest JOSM version required by this plugin (from plugin list). **/
    4448    public int mainversion = 0;
     49    /** The lowest JOSM version required by this plugin (from locally available jar). **/
    4550    public int localmainversion = 0;
     51    /** The plugin class name. */
    4652    public String className = null;
    4753    public boolean oldmode = false;
     54    /** The list of required plugins, separated by ';' (from plugin list). */
    4855    public String requires = null;
     56    /** The list of required plugins, separated by ';' (from locally available jar). */
    4957    public String localrequires = null;
     58    /** The plugin link (for documentation). */
    5059    public String link = null;
     60    /** The plugin description. */
    5161    public String description = null;
     62    /** Determines if the plugin must be loaded early or not. */
    5263    public boolean early = false;
     64    /** The plugin author. */
    5365    public String author = null;
     66    /** The plugin stage, determining the loading sequence order of plugins. */
    5467    public int stage = 50;
     68    /** The plugin version (from plugin list). **/
    5569    public String version = null;
     70    /** The plugin version (from locally available jar). **/
    5671    public String localversion = null;
     72    /** The plugin download link. */
    5773    public String downloadlink = null;
    5874    public String iconPath;
     75    /** The plugin icon. */
    5976    public ImageIcon icon;
    6077    public List<URL> libraries = new LinkedList<URL>();
     
    136153     * update site.
    137154     *
    138      * @param other the plugin information object retrieved from the update
    139      * site
     155     * @param other the plugin information object retrieved from the update site
    140156     */
    141157    public void updateFromPluginSite(PluginInformation other) {
     
    176192    }
    177193
    178     private void scanManifest(Manifest manifest, boolean oldcheck){
     194    private void scanManifest(Manifest manifest, boolean oldcheck) {
    179195        String lang = LanguageInfo.getLanguageCodeManifest();
    180196        Attributes attr = manifest.getMainAttributes();
    181197        className = attr.getValue("Plugin-Class");
    182198        String s = attr.getValue(lang+"Plugin-Link");
    183         if(s == null) {
     199        if (s == null) {
    184200            s = attr.getValue("Plugin-Link");
    185201        }
    186         if(s != null) {
     202        if (s != null) {
    187203            try {
    188204                new URL(s);
     
    195211        requires = attr.getValue("Plugin-Requires");
    196212        s = attr.getValue(lang+"Plugin-Description");
    197         if(s == null)
    198         {
     213        if (s == null) {
    199214            s = attr.getValue("Plugin-Description");
    200             if(s != null) {
     215            if (s != null) {
    201216                try {
    202217                    s = tr(s);
     
    213228        stage = stageStr == null ? 50 : Integer.parseInt(stageStr);
    214229        version = attr.getValue("Plugin-Version");
    215         try {
    216             mainversion = Integer.parseInt(attr.getValue("Plugin-Mainversion"));
    217         } catch(NumberFormatException e) {
    218             Main.warn(e);
     230        s = attr.getValue("Plugin-Mainversion");
     231        if (s != null) {
     232            try {
     233                mainversion = Integer.parseInt(s);
     234            } catch(NumberFormatException e) {
     235                Main.warn(tr("Invalid plugin main version ''{0}'' in plugin {1}", s, name));
     236            }
     237        } else {
     238            Main.warn(tr("Missing plugin main version in plugin {0}", name));
    219239        }
    220240        author = attr.getValue("Author");
     
    224244            icon = new ImageProvider(iconPath).setArchive(file).setMaxWidth(24).setMaxHeight(24).setOptional(true).get();
    225245        }
    226         if(oldcheck && mainversion > Version.getInstance().getVersion())
    227         {
     246        if (oldcheck && mainversion > Version.getInstance().getVersion()) {
    228247            int myv = Version.getInstance().getVersion();
    229             for(Map.Entry<Object, Object> entry : attr.entrySet())
    230             {
     248            for (Map.Entry<Object, Object> entry : attr.entrySet()) {
    231249                try {
    232250                    String key = ((Attributes.Name)entry.getKey()).toString();
    233                     if(key.endsWith("_Plugin-Url"))
    234                     {
     251                    if (key.endsWith("_Plugin-Url")) {
    235252                        int mv = Integer.parseInt(key.substring(0,key.length()-11));
    236                         if(mv <= myv && (mv > mainversion || mainversion > myv))
    237                         {
     253                        if (mv <= myv && (mv > mainversion || mainversion > myv)) {
    238254                            String v = (String)entry.getValue();
    239255                            int i = v.indexOf(';');
    240                             if(i > 0)
    241                             {
     256                            if (i > 0) {
    242257                                downloadlink = v.substring(i+1);
    243258                                mainversion = mv;
     
    248263                    }
    249264                }
    250                 catch(Exception e) { Main.error(e); }
     265                catch(Exception e) {
     266                    Main.error(e);
     267                }
    251268            }
    252269        }
     
    292309
    293310    /**
    294      * Load and instantiate the plugin
     311     * Loads and instantiates the plugin.
    295312     *
    296313     * @param klass the plugin class
    297314     * @return the instantiated and initialized plugin
    298      */
    299     public PluginProxy load(Class<?> klass) throws PluginException{
     315     * @throws PluginException if the plugin cannot be loaded or instanciated
     316     */
     317    public PluginProxy load(Class<?> klass) throws PluginException {
    300318        try {
    301319            Constructor<?> c = klass.getConstructor(PluginInformation.class);
     
    314332
    315333    /**
    316      * Load the class of the plugin
     334     * Loads the class of the plugin.
    317335     *
    318336     * @param classLoader the class loader to use
    319337     * @return the loaded class
     338     * @throws PluginException if the class cannot be loaded
    320339     */
    321340    public Class<?> loadClass(ClassLoader classLoader) throws PluginException {
Note: See TracChangeset for help on using the changeset viewer.