Ignore:
Timestamp:
2017-08-22T22:26:32+02:00 (7 years ago)
Author:
Don-vip
Message:

see #15182 - deprecate all Main logging methods and introduce suitable replacements in Logging for most of them

Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
7 edited

Legend:

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

    r12279 r12620  
    2323import org.openstreetmap.josm.tools.CheckParameterUtil;
    2424import org.openstreetmap.josm.tools.HttpClient;
     25import org.openstreetmap.josm.tools.Logging;
    2526import org.xml.sax.SAXException;
    2627
     
    117118            if (pi.downloadlink == null) {
    118119                String msg = tr("Cannot download plugin ''{0}''. Its download link is not known. Skipping download.", pi.name);
    119                 Main.warn(msg);
     120                Logging.warn(msg);
    120121                throw new PluginDownloadException(msg);
    121122            }
     
    131132            String msg = tr("Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.",
    132133                    pi.name, pi.downloadlink);
    133             Main.warn(msg);
     134            Logging.warn(msg);
    134135            throw new PluginDownloadException(msg, e);
    135136        } catch (IOException e) {
     
    150151            String message = tr("Failed to create plugin directory ''{0}''", pluginDir.toString());
    151152            lastException = new PluginDownloadException(message);
    152             Main.error(message);
     153            Logging.error(message);
    153154            failed.addAll(toUpdate);
    154155            return;
     
    159160                return;
    160161            String message = tr("Downloading Plugin {0}...", d.name);
    161             Main.info(message);
     162            Logging.info(message);
    162163            progressMonitor.subTask(message);
    163164            progressMonitor.worked(1);
     
    167168            } catch (PluginDownloadException e) {
    168169                lastException = e;
    169                 Main.error(e);
     170                Logging.error(e);
    170171                failed.add(d);
    171172                continue;
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r12599 r12620  
    6969import org.openstreetmap.josm.tools.I18n;
    7070import org.openstreetmap.josm.tools.ImageProvider;
     71import org.openstreetmap.josm.tools.Logging;
    7172import org.openstreetmap.josm.tools.SubclassFilteredCollection;
    7273import org.openstreetmap.josm.tools.Utils;
     
    304305            sources.add(org.openstreetmap.josm.gui.MainApplication.class.getClassLoader());
    305306        } catch (SecurityException ex) {
    306             Main.debug(ex);
     307            Logging.debug(ex);
    307308            sources.add(ImageProvider.class.getClassLoader());
    308309        }
     
    414415    public static boolean checkAndConfirmPluginUpdate(Component parent) {
    415416        if (!checkOfflineAccess()) {
    416             Main.info(tr("{0} not available (offline mode)", tr("Plugin update")));
     417            Logging.info(tr("{0} not available (offline mode)", tr("Plugin update")));
    417418            return false;
    418419        }
     
    456457        case "never":
    457458            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    458                 Main.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
     459                Logging.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
    459460            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    460                 Main.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
     461                Logging.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
    461462            }
    462463            return false;
     
    464465        case "always":
    465466            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    466                 Main.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
     467                Logging.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
    467468            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    468                 Main.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
     469                Logging.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
    469470            }
    470471            return true;
     
    474475
    475476        default:
    476             Main.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
     477            Logging.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
    477478        }
    478479
     
    529530                    OnlineResource.JOSM_WEBSITE.checkOfflineAccess(updateSite, Main.getJOSMWebsite());
    530531                } catch (OfflineAccessException e) {
    531                     Main.trace(e);
     532                    Logging.trace(e);
    532533                    return false;
    533534                }
     
    614615                            RestartAction.restartJOSM();
    615616                        } catch (IOException e) {
    616                             Main.error(e);
     617                            Logging.error(e);
    617618                        }
    618619                    } else {
    619                         Main.warn("No plugin downloaded, restart canceled");
     620                        Logging.warn("No plugin downloaded, restart canceled");
    620621                    }
    621622                });
    622623            } else {
    623                 Main.warn("No plugin to download, operation canceled");
     624                Logging.warn("No plugin to download, operation canceled");
    624625            }
    625626        });
     
    776777            Class<?> klass = plugin.loadClass(pluginClassLoader);
    777778            if (klass != null) {
    778                 Main.info(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion));
     779                Logging.info(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion));
    779780                PluginProxy pluginProxy = plugin.load(klass, pluginClassLoader);
    780781                pluginList.add(pluginProxy);
     
    784785        } catch (PluginException e) {
    785786            pluginLoadingExceptions.put(plugin.name, e);
    786             Main.error(e);
     787            Logging.error(e);
    787788            if (e.getCause() instanceof ClassNotFoundException) {
    788789                msg = tr("<html>Could not load plugin {0} because the plugin<br>main class ''{1}'' was not found.<br>"
     
    791792        } catch (RuntimeException e) { // NOPMD
    792793            pluginLoadingExceptions.put(plugin.name, e);
    793             Main.error(e);
     794            Logging.error(e);
    794795        }
    795796        if (msg != null && confirmDisablePlugin(parent, msg, plugin.name)) {
     
    919920                task.run();
    920921            } catch (RuntimeException e) { // NOPMD
    921                 Main.error(e);
     922                Logging.error(e);
    922923                return null;
    923924            }
     
    968969            monitor.beginTask(tr("Determining plugins to load..."));
    969970            Set<String> plugins = new HashSet<>(Main.pref.getCollection("plugins", new LinkedList<String>()));
    970             if (Main.isDebugEnabled()) {
    971                 Main.debug("Plugins list initialized to " + plugins);
    972             }
     971            Logging.debug("Plugins list initialized to {0}", plugins);
    973972            String systemProp = System.getProperty("josm.plugins");
    974973            if (systemProp != null) {
    975974                plugins.addAll(Arrays.asList(systemProp.split(",")));
    976                 if (Main.isDebugEnabled()) {
    977                     Main.debug("josm.plugins system property set to '" + systemProp+"'. Plugins list is now " + plugins);
    978                 }
     975                Logging.debug("josm.plugins system property set to '{0}'. Plugins list is now {1}", systemProp, plugins);
    979976            }
    980977            monitor.subTask(tr("Removing deprecated plugins..."));
     
    982979            monitor.subTask(tr("Removing unmaintained plugins..."));
    983980            filterUnmaintainedPlugins(parent, plugins);
    984             if (Main.isDebugEnabled()) {
    985                 Main.debug("Plugins list is finally set to " + plugins);
    986             }
     981            Logging.debug("Plugins list is finally set to {0}", plugins);
    987982            Map<String, PluginInformation> infos = loadLocallyAvailablePluginInformation(monitor.createSubTaskMonitor(1, false));
    988983            List<PluginInformation> ret = new LinkedList<>();
     
    10531048                    }
    10541049                } catch (PluginException e) {
    1055                     Main.warn(tr("Failed to find plugin {0}", name));
    1056                     Main.error(e);
     1050                    Logging.warn(tr("Failed to find plugin {0}", name));
     1051                    Logging.error(e);
    10571052                }
    10581053            }
     
    10971092                }
    10981093            } catch (RuntimeException e) { // NOPMD
    1099                 Main.warn(tr("Failed to download plugin information list"));
    1100                 Main.error(e);
     1094                Logging.warn(tr("Failed to download plugin information list"));
     1095                Logging.error(e);
    11011096                // don't abort in case of error, continue with downloading plugins below
    11021097            }
     
    11421137                    pluginDownloadTask.run();
    11431138                } catch (RuntimeException e) { // NOPMD
    1144                     Main.error(e);
     1139                    Logging.error(e);
    11451140                    alertFailedPluginUpdate(parent, pluginsToUpdate);
    11461141                    return plugins;
     
    12681263            String pluginName = updatedPlugin.getName().substring(0, updatedPlugin.getName().length() - 8);
    12691264            if (plugin.exists() && !plugin.delete() && dowarn) {
    1270                 Main.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
    1271                 Main.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
     1265                Logging.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
     1266                Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
    12721267                        "Skipping installation. JOSM is still going to load the old plugin version.",
    12731268                        pluginName));
     
    12791274            } catch (IOException e) {
    12801275                if (dowarn) {
    1281                     Main.warn(e, tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",
    1282                             plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()));
     1276                    Logging.log(Logging.LEVEL_WARN, tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}",
     1277                            plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()), e);
    12831278                }
    12841279                continue;
     
    12861281            // Install plugin
    12871282            if (!updatedPlugin.renameTo(plugin) && dowarn) {
    1288                 Main.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.",
     1283                Logging.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.",
    12891284                        plugin.toString(), updatedPlugin.toString()));
    1290                 Main.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
     1285                Logging.warn(tr("Failed to install already downloaded plugin ''{0}''. " +
    12911286                        "Skipping installation. JOSM is still going to load the old plugin version.",
    12921287                        pluginName));
     
    13061301                new JarFile(jar).close();
    13071302            } catch (IOException e) {
    1308                 Main.warn(e);
     1303                Logging.warn(e);
    13091304                return false;
    13101305            }
    13111306            return true;
    13121307        } else if (jar != null) {
    1313             Main.warn("Invalid jar file ''"+jar+"'' (exists: "+jar.exists()+", canRead: "+jar.canRead()+')');
     1308            Logging.warn("Invalid jar file ''"+jar+"'' (exists: "+jar.exists()+", canRead: "+jar.canRead()+')');
    13141309        }
    13151310        return false;
     
    13511346                pi.updateFromJar(new PluginInformation(downloadedPluginFile, pi.name));
    13521347            } catch (PluginException e) {
    1353                 Main.error(e);
     1348                Logging.error(e);
    13541349            }
    13551350        }
     
    14051400            return task.get();
    14061401        } catch (InterruptedException | ExecutionException e) {
    1407             Main.warn(e);
     1402            Logging.warn(e);
    14081403        }
    14091404        return -1;
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r12322 r12620  
    2929import org.openstreetmap.josm.tools.ImageProvider;
    3030import org.openstreetmap.josm.tools.LanguageInfo;
     31import org.openstreetmap.josm.tools.Logging;
    3132import org.openstreetmap.josm.tools.Utils;
    3233
     
    201202        String s = Optional.ofNullable(attr.getValue(lang+"Plugin-Link")).orElseGet(() -> attr.getValue("Plugin-Link"));
    202203        if (s != null && !Utils.isValidUrl(s)) {
    203             Main.info(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
     204            Logging.info(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
    204205            s = null;
    205206        }
     
    213214                    s = tr(s);
    214215                } catch (IllegalArgumentException e) {
    215                     Main.debug(e);
    216                     Main.info(tr("Invalid plugin description ''{0}'' in plugin {1}", s, name));
     216                    Logging.debug(e);
     217                    Logging.info(tr("Invalid plugin description ''{0}'' in plugin {1}", s, name));
    217218                }
    218219            }
     
    230231                mainversion = Integer.parseInt(s);
    231232            } catch (NumberFormatException e) {
    232                 Main.warn(tr("Invalid plugin main version ''{0}'' in plugin {1}", s, name));
     233                Logging.warn(tr("Invalid plugin main version ''{0}'' in plugin {1}", s, name));
    233234            }
    234235        } else {
    235             Main.warn(tr("Missing plugin main version in plugin {0}", name));
     236            Logging.warn(tr("Missing plugin main version in plugin {0}", name));
    236237        }
    237238        author = attr.getValue("Author");
     
    265266                    }
    266267                } catch (NumberFormatException e) {
    267                     Main.error(e);
     268                    Logging.error(e);
    268269                }
    269270            }
     
    391392            }
    392393        } catch (IOException e) {
    393             Main.warn(e);
     394            Logging.warn(e);
    394395        }
    395396
  • trunk/src/org/openstreetmap/josm/plugins/PluginListParser.java

    r11381 r12620  
    1313import java.util.List;
    1414
    15 import org.openstreetmap.josm.Main;
     15import org.openstreetmap.josm.tools.Logging;
    1616
    1717/**
     
    103103            }
    104104        } catch (PluginListParseException ex) {
    105             Main.error(ex);
     105            Logging.error(ex);
    106106        }
    107107    }
  • trunk/src/org/openstreetmap/josm/plugins/PluginProxy.java

    r12599 r12620  
    44import java.util.List;
    55
    6 import org.openstreetmap.josm.Main;
    76import org.openstreetmap.josm.gui.MapFrame;
    87import org.openstreetmap.josm.gui.download.DownloadSelection;
    98import org.openstreetmap.josm.gui.preferences.PreferenceSetting;
     9import org.openstreetmap.josm.tools.Logging;
    1010import org.openstreetmap.josm.tools.bugreport.BugReportExceptionHandler;
    1111
     
    6666            plugin.getClass().getMethod("mapFrameInitialized", MapFrame.class, MapFrame.class).invoke(plugin, oldFrame, newFrame);
    6767        } catch (NoSuchMethodException e) {
    68             Main.trace(e);
    69             Main.debug("Plugin "+plugin+" does not define mapFrameInitialized");
     68            Logging.trace(e);
     69            Logging.debug("Plugin "+plugin+" does not define mapFrameInitialized");
    7070        } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
    7171            handlePluginException(e);
     
    7878            return (PreferenceSetting) plugin.getClass().getMethod("getPreferenceSetting").invoke(plugin);
    7979        } catch (NoSuchMethodException e) {
    80             Main.trace(e);
    81             Main.debug("Plugin "+plugin+" does not define getPreferenceSetting");
     80            Logging.trace(e);
     81            Logging.debug("Plugin "+plugin+" does not define getPreferenceSetting");
    8282            return null;
    8383        } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
     
    9292            plugin.getClass().getMethod("addDownloadSelection", List.class).invoke(plugin, list);
    9393        } catch (NoSuchMethodException e) {
    94             Main.trace(e);
    95             Main.debug("Plugin "+plugin+" does not define addDownloadSelection");
     94            Logging.trace(e);
     95            Logging.debug("Plugin "+plugin+" does not define addDownloadSelection");
    9696        } catch (ReflectiveOperationException | IllegalArgumentException | NoClassDefFoundError e) {
    9797            handlePluginException(e);
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r10965 r12620  
    1414import java.util.Map;
    1515
    16 import org.openstreetmap.josm.Main;
    1716import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1817import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1918import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    2019import org.openstreetmap.josm.io.OsmTransferException;
     20import org.openstreetmap.josm.tools.Logging;
    2121import org.xml.sax.SAXException;
    2222
     
    9696                processLocalPluginInformationFile(f);
    9797            } catch (PluginListParseException e) {
    98                 Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    99                 Main.error(e);
     98                Logging.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
     99                Logging.error(e);
    100100            }
    101101            monitor.worked(1);
     
    123123                }
    124124            } catch (PluginException e) {
    125                 Main.warn(e, "PluginException: ");
    126                 Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
     125                Logging.log(Logging.LEVEL_WARN, "PluginException: ", e);
     126                Logging.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    127127            }
    128128            monitor.worked(1);
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r11553 r12620  
    3939import org.openstreetmap.josm.tools.GBC;
    4040import org.openstreetmap.josm.tools.HttpClient;
     41import org.openstreetmap.josm.tools.Logging;
    4142import org.openstreetmap.josm.tools.Utils;
    4243import org.xml.sax.SAXException;
     
    164165        } catch (MalformedURLException e) {
    165166            if (canceled) return null;
    166             Main.error(e);
     167            Logging.error(e);
    167168            return null;
    168169        } catch (IOException e) {
     
    184185        final String msg = e.getMessage();
    185186        if (details == null || details.isEmpty()) {
    186             Main.error(e.getClass().getSimpleName()+": " + msg);
     187            Logging.error(e.getClass().getSimpleName()+": " + msg);
    187188        } else {
    188             Main.error(msg + " - Details:\n" + details);
     189            Logging.error(msg + " - Details:\n" + details);
    189190        }
    190191
     
    227228        File pluginDir = Main.pref.getPluginsDirectory();
    228229        if (!pluginDir.exists() && !pluginDir.mkdirs()) {
    229             Main.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.",
     230            Logging.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.",
    230231                    pluginDir.toString(), site));
    231232        }
     
    237238        } catch (IOException e) {
    238239            // just failed to write the cache file. No big deal, but log the exception anyway
    239             Main.error(e);
     240            Logging.error(e);
    240241        }
    241242    }
     
    276277            availablePlugins.addAll(filterDeprecatedPlugins(pis));
    277278        } catch (PluginListParseException e) {
    278             Main.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
    279             Main.error(e);
     279            Logging.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
     280            Logging.error(e);
    280281        }
    281282    }
Note: See TracChangeset for help on using the changeset viewer.