Ignore:
Timestamp:
2013-09-23T16:47:50+02:00 (12 years ago)
Author:
Don-vip
Message:

Rework console output:

  • new log level "error"
  • Replace nearly all calls to system.out and system.err to Main.(error|warn|info|debug)
  • Remove some unnecessary debug output
  • Some messages are modified (removal of "Info", "Warning", "Error" from the message itself -> notable i18n impact but limited to console error messages not seen by the majority of users, so that's ok)
Location:
trunk/src/org/openstreetmap/josm/plugins
Files:
5 edited

Legend:

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

    r6073 r6248  
    114114        try {
    115115            if (pi.downloadlink == null) {
    116                 String msg = tr("Warning: Cannot download plugin ''{0}''. Its download link is not known. Skipping download.", pi.name);
    117                 System.err.println(msg);
     116                String msg = tr("Cannot download plugin ''{0}''. Its download link is not known. Skipping download.", pi.name);
     117                Main.warn(msg);
    118118                throw new PluginDownloadException(msg);
    119119            }
     
    128128                out.write(buffer, 0, read);
    129129            }
    130         } catch(MalformedURLException e) {
    131             String msg = tr("Warning: Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", pi.name, pi.downloadlink);
    132             System.err.println(msg);
     130        } catch (MalformedURLException e) {
     131            String msg = tr("Cannot download plugin ''{0}''. Its download link ''{1}'' is not a valid URL. Skipping download.", pi.name, pi.downloadlink);
     132            Main.warn(msg);
    133133            throw new PluginDownloadException(msg);
    134134        } catch (IOException e) {
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r6090 r6248  
    6666 * PluginHandler is basically a collection of static utility functions used to bootstrap
    6767 * and manage the loaded plugins.
    68  *
     68 * @since 1326
    6969 */
    7070public class PluginHandler {
    7171
    7272    /**
    73      * deprecated plugins that are removed on start
     73     * Deprecated plugins that are removed on start
    7474     */
    7575    public final static Collection<DeprecatedPlugin> DEPRECATED_PLUGINS;
     
    117117    }
    118118
     119    /**
     120     * Description of a deprecated plugin
     121     */
    119122    public static class DeprecatedPlugin implements Comparable<DeprecatedPlugin> {
    120         public String name;
    121         // short explanation, can be null
    122         public String reason;
    123         // migration, can be null
    124         private Runnable migration;
    125 
     123        /** Plugin name */
     124        public final String name;
     125        /** Short explanation about deprecation, can be {@code null} */
     126        public final String reason;
     127        /** Code to run to perform migration, can be {@code null} */
     128        private final Runnable migration;
     129
     130        /**
     131         * Constructs a new {@code DeprecatedPlugin}.
     132         * @param name The plugin name
     133         */
    126134        public DeprecatedPlugin(String name) {
    127             this.name = name;
    128         }
    129 
     135            this(name, null, null);
     136        }
     137
     138        /**
     139         * Constructs a new {@code DeprecatedPlugin} with a given reason.
     140         * @param name The plugin name
     141         * @param reason The reason about deprecation
     142         */
    130143        public DeprecatedPlugin(String name, String reason) {
    131             this.name = name;
    132             this.reason = reason;
    133         }
    134 
     144            this(name, reason, null);
     145        }
     146
     147        /**
     148         * Constructs a new {@code DeprecatedPlugin}.
     149         * @param name The plugin name
     150         * @param reason The reason about deprecation
     151         * @param migration The code to run to perform migration
     152         */
    135153        public DeprecatedPlugin(String name, String reason, Runnable migration) {
    136154            this.name = name;
     
    139157        }
    140158
     159        /**
     160         * Performs migration.
     161         */
    141162        public void migrate() {
    142163            if (migration != null) {
     
    151172    }
    152173
     174    /**
     175     * List of unmaintained plugins. Not really up-to-date as the vast majority of plugins are not really maintained after a few months, sadly...
     176     */
    153177    final public static String [] UNMAINTAINED_PLUGINS = new String[] {"gpsbabelgui", "Intersect_way"};
    154178
     
    319343        if (policy.equals("never")) {
    320344            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    321                 System.out.println(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
     345                Main.info(tr("Skipping plugin update after JOSM upgrade. Automatic update at startup is disabled."));
    322346            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    323                 System.out.println(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
     347                Main.info(tr("Skipping plugin update after elapsed update interval. Automatic update at startup is disabled."));
    324348            }
    325349            return false;
     
    328352        if (policy.equals("always")) {
    329353            if ("pluginmanager.version-based-update.policy".equals(togglePreferenceKey)) {
    330                 System.out.println(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
     354                Main.info(tr("Running plugin update after JOSM upgrade. Automatic update at startup is enabled."));
    331355            } else if ("pluginmanager.time-based-update.policy".equals(togglePreferenceKey)) {
    332                 System.out.println(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
     356                Main.info(tr("Running plugin update after elapsed update interval. Automatic update at startup is disabled."));
    333357            }
    334358            return true;
     
    336360
    337361        if (!policy.equals("ask")) {
    338             System.err.println(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
     362            Main.warn(tr("Unexpected value ''{0}'' for preference ''{1}''. Assuming value ''ask''.", policy, togglePreferenceKey));
    339363        }
    340364        int ret = HelpAwareOptionPane.showOptionDialog(
     
    513537     * the class loader <code>pluginClassLoader</code>.
    514538     *
     539     * @param parent The parent component to be used for the displayed dialog
    515540     * @param plugin the plugin
    516541     * @param pluginClassLoader the plugin class loader
     
    521546            Class<?> klass = plugin.loadClass(pluginClassLoader);
    522547            if (klass != null) {
    523                 System.out.println(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion));
     548                Main.info(tr("loading plugin ''{0}'' (version {1})", plugin.name, plugin.localversion));
    524549                PluginProxy pluginProxy = plugin.load(klass);
    525550                pluginList.add(pluginProxy);
     
    528553            msg = null;
    529554        } catch (PluginException e) {
    530             System.err.println(e.getMessage());
     555            Main.error(e.getMessage());
    531556            Throwable cause = e.getCause();
    532557            if (cause != null) {
    533558                msg = cause.getLocalizedMessage();
    534559                if (msg != null) {
    535                     System.err.println("Cause: " + cause.getClass().getName()+": " + msg);
     560                    Main.error("Cause: " + cause.getClass().getName()+": " + msg);
    536561                } else {
    537562                    cause.printStackTrace();
     
    545570            e.printStackTrace();
    546571        }
    547         if(msg != null && confirmDisablePlugin(parent, msg, plugin.name)) {
     572        if (msg != null && confirmDisablePlugin(parent, msg, plugin.name)) {
    548573            Main.pref.removeFromCollection("plugins", plugin.name);
    549574        }
     
    554579     * memory.
    555580     *
     581     * @param parent The parent component to be used for the displayed dialog
    556582     * @param plugins the list of plugins
    557583     * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
     
    621647     * set to false.
    622648     *
     649     * @param parent The parent component to be used for the displayed dialog
    623650     * @param plugins the collection of plugins
    624651     * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
     
    698725     * messages.
    699726     *
     727     * @param parent The parent component to be used for the displayed dialog
    700728     * @param monitor the progress monitor. Defaults to {@link NullProgressMonitor#INSTANCE} if null.
    701729     * @return the set of plugins to load (as set of plugin names)
     
    785813                    }
    786814                } catch (PluginException e) {
    787                     System.out.println(tr("Warning: failed to find plugin {0}", name));
     815                    Main.warn(tr("Failed to find plugin {0}", name));
    788816                    e.printStackTrace();
    789817                }
     
    801829     * @throws IllegalArgumentException thrown if plugins is null
    802830     */
    803     public static List<PluginInformation>  updatePlugins(Component parent,
     831    public static List<PluginInformation> updatePlugins(Component parent,
    804832            List<PluginInformation> plugins, ProgressMonitor monitor)
    805833            throws IllegalArgumentException{
     
    825853                allPlugins = task1.getAvailablePlugins();
    826854                plugins = buildListOfPluginsToLoad(parent,monitor.createSubTaskMonitor(1, false));
    827             } catch(ExecutionException e) {
    828                 System.out.println(tr("Warning: failed to download plugin information list"));
     855            } catch (ExecutionException e) {
     856                Main.warn(tr("Failed to download plugin information list"));
    829857                e.printStackTrace();
    830858                // don't abort in case of error, continue with downloading plugins below
    831             } catch(InterruptedException e) {
    832                 System.out.println(tr("Warning: failed to download plugin information list"));
     859            } catch (InterruptedException e) {
     860                Main.warn(tr("Failed to download plugin information list"));
    833861                e.printStackTrace();
    834862                // don't abort in case of error, continue with downloading plugins below
     
    838866            //
    839867            Collection<PluginInformation> pluginsToUpdate = new ArrayList<PluginInformation>();
    840             for(PluginInformation pi: plugins) {
     868            for (PluginInformation pi: plugins) {
    841869                if (pi.isUpdateRequired()) {
    842870                    pluginsToUpdate.add(pi);
     
    907935    /**
    908936     * Ask the user for confirmation that a plugin shall be disabled.
    909      *
     937     *
     938     * @param parent The parent component to be used for the displayed dialog
    910939     * @param reason the reason for disabling the plugin
    911940     * @param name the plugin name
     
    940969    }
    941970
     971    /**
     972     * Returns the plugin of the specified name.
     973     * @param name The plugin name
     974     * @return The plugin of the specified name, if installed and loaded, or {@code null} otherwise.
     975     */
    942976    public static Object getPlugin(String name) {
    943977        for (PluginProxy plugin : pluginList)
    944             if(plugin.getPluginInformation().name.equals(name))
     978            if (plugin.getPluginInformation().name.equals(name))
    945979                return plugin.plugin;
    946980        return null;
     
    9861020            if (plugin.exists()) {
    9871021                if (!plugin.delete() && dowarn) {
    988                     System.err.println(tr("Warning: failed to delete outdated plugin ''{0}''.", plugin.toString()));
    989                     System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
     1022                    Main.warn(tr("Failed to delete outdated plugin ''{0}''.", plugin.toString()));
     1023                    Main.warn(tr("Failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
    9901024                    continue;
    9911025                }
     
    9961030            } catch (Exception e) {
    9971031                if (dowarn) {
    998                     System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}", plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()));
     1032                    Main.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. {2}", plugin.toString(), updatedPlugin.toString(), e.getLocalizedMessage()));
    9991033                }
    10001034                continue;
     
    10021036            // Install plugin
    10031037            if (!updatedPlugin.renameTo(plugin) && dowarn) {
    1004                 System.err.println(tr("Warning: failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString()));
    1005                 System.err.println(tr("Warning: failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
     1038                Main.warn(tr("Failed to install plugin ''{0}'' from temporary download file ''{1}''. Renaming failed.", plugin.toString(), updatedPlugin.toString()));
     1039                Main.warn(tr("Failed to install already downloaded plugin ''{0}''. Skipping installation. JOSM is still going to load the old plugin version.", pluginName));
    10061040            }
    10071041        }
     
    11771211    }
    11781212
     1213    /**
     1214     * Returns the list of loaded plugins as a {@code String} to be displayed in status report. Useful for bug reports.
     1215     * @return The list of loaded plugins (one plugin per line)
     1216     */
    11791217    public static String getBugReportText() {
    1180         String text = "";
     1218        StringBuilder text = new StringBuilder();
    11811219        LinkedList <String> pl = new LinkedList<String>(Main.pref.getCollection("plugins", new LinkedList<String>()));
    11821220        for (final PluginProxy pp : pluginList) {
     
    11881226        Collections.sort(pl);
    11891227        for (String s : pl) {
    1190             text += "Plugin: " + s + "\n";
    1191         }
    1192         return text;
    1193     }
    1194 
     1228            text.append("Plugin: ").append(s).append("\n");
     1229        }
     1230        return text.toString();
     1231    }
     1232
     1233    /**
     1234     * Returns the list of loaded plugins as a {@code JPanel} to be displayed in About dialog.
     1235     * @return The list of loaded plugins (one "line" of Swing components per plugin)
     1236     */
    11951237    public static JPanel getInfoPanel() {
    11961238        JPanel pluginTab = new JPanel(new GridBagLayout());
  • trunk/src/org/openstreetmap/josm/plugins/PluginInformation.java

    r6232 r6248  
    2323import java.util.jar.JarInputStream;
    2424import java.util.jar.Manifest;
     25
    2526import javax.swing.ImageIcon;
    2627
     
    186187                new URL(s);
    187188            } catch (MalformedURLException e) {
    188                 System.out.println(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
     189                Main.info(tr("Invalid URL ''{0}'' in plugin {1}", s, name));
    189190                s = null;
    190191            }
     
    200201                    s = tr(s);
    201202                } catch (IllegalArgumentException e) {
    202                     System.out.println(tr("Invalid plugin description ''{0}'' in plugin {1}", s, name));
     203                    Main.info(tr("Invalid plugin description ''{0}'' in plugin {1}", s, name));
    203204                }
    204205            }
  • trunk/src/org/openstreetmap/josm/plugins/ReadLocalPluginInformationTask.java

    r6084 r6248  
    1414import java.util.Map;
    1515
     16import org.openstreetmap.josm.Main;
    1617import org.openstreetmap.josm.gui.PleaseWaitRunnable;
    1718import org.openstreetmap.josm.gui.progress.ProgressMonitor;
     
    9091                processLocalPluginInformationFile(f);
    9192            } catch(PluginListParseException e) {
    92                 System.err.println(tr("Warning: Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
     93                Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    9394                e.printStackTrace();
    9495            }
     
    151152                }
    152153            } catch (PluginException e){
    153                 System.err.println(e.getMessage());
    154                 System.err.println(tr("Warning: Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
     154                Main.warn("PluginException: "+e.getMessage());
     155                Main.warn(tr("Failed to scan file ''{0}'' for plugin information. Skipping.", fname));
    155156            }
    156157            monitor.worked(1);
  • trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java

    r6084 r6248  
    259259            if (!pluginDir.exists()) {
    260260                if (! pluginDir.mkdirs()) {
    261                     System.err.println(tr("Warning: failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.", pluginDir.toString(), site));
     261                    Main.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.", pluginDir.toString(), site));
    262262                }
    263263            }
     
    311311            List<PluginInformation> pis = new PluginListParser().parse(in);
    312312            availablePlugins.addAll(filterDeprecatedPlugins(pis));
    313         } catch(UnsupportedEncodingException e) {
    314             System.err.println(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
    315             e.printStackTrace();
    316         } catch(PluginListParseException e) {
    317             System.err.println(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
     313        } catch (UnsupportedEncodingException e) {
     314            Main.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
     315            e.printStackTrace();
     316        } catch (PluginListParseException e) {
     317            Main.error(tr("Failed to parse plugin list document from site ''{0}''. Skipping site. Exception was: {1}", site, e.toString()));
    318318            e.printStackTrace();
    319319        }
Note: See TracChangeset for help on using the changeset viewer.