Changeset 10986 in josm for trunk/test/unit
- Timestamp:
- 2016-09-10T04:18:26+02:00 (8 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/test/unit/org/openstreetmap/josm/plugins/PluginHandlerTestIT.java
r10560 r10986 8 8 import java.util.Arrays; 9 9 import java.util.Collection; 10 import java.util.HashMap; 10 11 import java.util.Iterator; 11 12 import java.util.List; 13 import java.util.Map; 12 14 import java.util.Set; 15 import java.util.stream.Collectors; 13 16 17 import org.apache.commons.collections.MapUtils; 18 import org.apache.commons.lang.exception.ExceptionUtils; 14 19 import org.junit.BeforeClass; 15 20 import org.junit.Rule; … … 18 23 import org.openstreetmap.josm.JOSMFixture; 19 24 import org.openstreetmap.josm.Main; 25 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 20 27 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 28 import org.openstreetmap.josm.plugins.PluginHandler.DynamicURLClassLoader; 21 29 22 30 import edu.umd.cs.findbugs.annotations.SuppressFBWarnings; … … 79 87 PluginHandler.loadLatePlugins(null, plugins, null); 80 88 81 assertTrue(PluginHandler.pluginLoadingExceptions.toString(), PluginHandler.pluginLoadingExceptions.isEmpty()); 89 Map<String, Throwable> loadingExceptions = PluginHandler.pluginLoadingExceptions.entrySet().stream() 90 .collect(Collectors.toMap(e -> e.getKey(), e -> ExceptionUtils.getRootCause(e.getValue()))); 91 92 // Add/remove a data layer twice to test basic plugin good behaviour 93 Map<String, Throwable> layerExceptions = new HashMap<>(); 94 List<PluginInformation> loadedPlugins = PluginHandler.getPlugins(); 95 for (int i = 0; i < 2; i++) { 96 OsmDataLayer layer = new OsmDataLayer(new DataSet(), "Layer "+i, null); 97 try { 98 Main.getLayerManager().addLayer(layer); 99 } catch (Exception | LinkageError t) { 100 Throwable root = ExceptionUtils.getRootCause(t); 101 layerExceptions.put(findFaultyPlugin(loadedPlugins, root), root); 102 } 103 try { 104 Main.getLayerManager().removeLayer(layer); 105 } catch (Exception | LinkageError t) { 106 Throwable root = ExceptionUtils.getRootCause(t); 107 layerExceptions.put(findFaultyPlugin(loadedPlugins, root), root); 108 } 109 } 110 111 MapUtils.debugPrint(System.out, null, loadingExceptions); 112 MapUtils.debugPrint(System.out, null, layerExceptions); 113 String msg = Arrays.toString(loadingExceptions.entrySet().toArray()) + '\n' + 114 Arrays.toString(layerExceptions.entrySet().toArray()); 115 assertTrue(msg, loadingExceptions.isEmpty() && layerExceptions.isEmpty()); 116 } 117 118 private static String findFaultyPlugin(Collection<PluginInformation> plugins, Throwable root) { 119 DynamicURLClassLoader cl = PluginHandler.getPluginClassLoader(); 120 for (PluginInformation p : plugins) { 121 try { 122 String pluginPackage = cl.loadClass(p.className).getPackage().getName(); 123 for (StackTraceElement e : root.getStackTrace()) { 124 try { 125 String stackPackage = cl.loadClass(e.getClassName()).getPackage().getName(); 126 if (stackPackage.startsWith(pluginPackage)) { 127 return p.name; 128 } 129 } catch (ClassNotFoundException ex) { 130 System.err.println(ex.getMessage()); 131 continue; 132 } 133 } 134 } catch (ClassNotFoundException ex) { 135 System.err.println(ex.getMessage()); 136 continue; 137 } 138 } 139 return "<unknown>"; 82 140 } 83 141
Note:
See TracChangeset
for help on using the changeset viewer.