Changeset 8938 in josm for trunk


Ignore:
Timestamp:
2015-10-24T14:58:06+02:00 (9 years ago)
Author:
Don-vip
Message:

add new unit test to check that all available plugins can be loaded

Location:
trunk
Files:
2 edited
1 moved

Legend:

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

    r8855 r8938  
    162162        for (PluginInformation d : toUpdate) {
    163163            if (canceled) return;
    164             progressMonitor.subTask(tr("Downloading Plugin {0}...", d.name));
     164            String message = tr("Downloading Plugin {0}...", d.name);
     165            Main.info(message);
     166            progressMonitor.subTask(message);
    165167            progressMonitor.worked(1);
    166168            File pluginFile = new File(pluginDir, d.name + ".jar.new");
  • trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java

    r8928 r8938  
    232232
    233233    /**
     234     * All exceptions that occured during plugin loading
     235     * @since 8938
     236     */
     237    public static final Map<String, Exception> pluginLoadingExceptions = new HashMap<>();
     238
     239    /**
    234240     * Global plugin ClassLoader.
    235241     */
     
    279285        // notify user about removed deprecated plugins
    280286        //
    281         StringBuilder sb = new StringBuilder();
     287        StringBuilder sb = new StringBuilder(32);
    282288        sb.append("<html>")
    283289          .append(trn(
     
    308314     *
    309315     * Asks the user for every unmaintained plugin whether it should be removed.
     316     * @param parent The parent Component used to display warning popup
    310317     *
    311318     * @param plugins the collection of plugins
     
    316323                continue;
    317324            }
    318             String msg =  tr("<html>Loading of the plugin \"{0}\" was requested."
     325            String msg = tr("<html>Loading of the plugin \"{0}\" was requested."
    319326                    + "<br>This plugin is no longer developed and very likely will produce errors."
    320327                    +"<br>It should be disabled.<br>Delete from preferences?</html>", unmaintained);
     
    702709            msg = null;
    703710        } catch (PluginException e) {
     711            pluginLoadingExceptions.put(plugin.name, e);
    704712            Main.error(e);
    705713            if (e.getCause() instanceof ClassNotFoundException) {
     
    708716            }
    709717        }  catch (Exception e) {
     718            pluginLoadingExceptions.put(plugin.name, e);
    710719            Main.error(e);
    711720        }
     
    14491458    }
    14501459
     1460    /**
     1461     * Returns the set of deprecated and unmaintained plugins.
     1462     * @return set of deprecated and unmaintained plugins names.
     1463     * @since 8938
     1464     */
     1465    public static Set<String> getDeprecatedAndUnmaintainedPlugins() {
     1466        Set<String> result = new HashSet<>(DEPRECATED_PLUGINS.size() + UNMAINTAINED_PLUGINS.length);
     1467        for (DeprecatedPlugin dp : DEPRECATED_PLUGINS) {
     1468            result.add(dp.name);
     1469        }
     1470        result.addAll(Arrays.asList(UNMAINTAINED_PLUGINS));
     1471        return result;
     1472    }
     1473
    14511474    private static class UpdatePluginsMessagePanel extends JPanel {
    14521475        private JMultilineLabel lblMessage;
  • trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTest.java

    r8937 r8938  
    22package org.openstreetmap.josm.plugins;
    33
     4import static org.junit.Assert.assertEquals;
    45import static org.junit.Assert.assertFalse;
     6import static org.junit.Assert.assertTrue;
    57
     8import java.util.Iterator;
    69import java.util.List;
     10import java.util.Set;
    711
    812import org.junit.BeforeClass;
     
    1014import org.openstreetmap.josm.JOSMFixture;
    1115import org.openstreetmap.josm.Main;
     16import org.openstreetmap.josm.gui.progress.NullProgressMonitor;
    1217
    1318/**
    14  * Unit tests of {@link ReadRemotePluginInformationTask} class.
     19 * Unit tests of {@link PluginHandler} class.
    1520 */
    16 public class ReadRemotePluginInformationTaskTest {
     21public class PluginHandlerTest {
    1722
    1823    /**
     
    2126    @BeforeClass
    2227    public static void setUp() {
    23         JOSMFixture.createUnitTestFixture().init();
     28        JOSMFixture.createUnitTestFixture().init(true);
    2429    }
    2530
    2631    /**
    27      * Test of plugin list download.
     32     * Test that available plugins rules can be loaded.
    2833     */
    2934    @Test
    30     public void testDownloadPluginList() {
     35    public void testValidityOfAvailablePlugins() {
     36        // Download complete list of plugins
    3137        ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask(
    3238                Main.pref.getOnlinePluginSites());
    3339        pluginInfoDownloadTask.run();
    34         List<PluginInformation> list = pluginInfoDownloadTask.getAvailablePlugins();
    35         assertFalse(list.isEmpty());
    36         PluginInformation info = list.get(0);
     40        List<PluginInformation> plugins = pluginInfoDownloadTask.getAvailablePlugins();
     41        System.out.println("Original plugin list contains " + plugins.size() + " plugins");
     42        assertFalse(plugins.isEmpty());
     43        PluginInformation info = plugins.get(0);
    3744        assertFalse(info.getName().isEmpty());
    3845        assertFalse(info.getClass().getName().isEmpty());
     46
     47        // Filter deprecated and unmaintained ones
     48        Set<String> deprecatedPlugins = PluginHandler.getDeprecatedAndUnmaintainedPlugins();
     49        for (Iterator<PluginInformation> it = plugins.iterator(); it.hasNext();) {
     50            PluginInformation pi = it.next();
     51            if (deprecatedPlugins.contains(pi.name)) {
     52                it.remove();
     53            }
     54        }
     55        System.out.println("Filtered plugin list contains " + plugins.size() + " plugins");
     56
     57        // Update the locally installed plugins
     58        PluginDownloadTask pluginDownloadTask = new PluginDownloadTask(NullProgressMonitor.INSTANCE, plugins, null);
     59        pluginDownloadTask.run();
     60        assertTrue(pluginDownloadTask.getFailedPlugins().toString(), pluginDownloadTask.getFailedPlugins().isEmpty());
     61        assertEquals(plugins.size(), pluginDownloadTask.getDownloadedPlugins().size());
     62
     63        // Update Plugin info for downloaded plugins
     64        PluginHandler.refreshLocalUpdatedPluginInfo(pluginDownloadTask.getDownloadedPlugins());
     65
     66        // Load early plugins
     67        PluginHandler.loadEarlyPlugins(null, plugins, null);
     68
     69        // Load late plugins
     70        PluginHandler.loadLatePlugins(null, plugins, null);
     71
     72        assertTrue(PluginHandler.pluginLoadingExceptions.toString(), PluginHandler.pluginLoadingExceptions.isEmpty());
    3973    }
    4074}
Note: See TracChangeset for help on using the changeset viewer.