Changeset 267 in josm for src/org/openstreetmap/josm


Ignore:
Timestamp:
2007-06-30T22:01:02+02:00 (17 years ago)
Author:
imi
Message:
  • added and fixed some tests
Location:
src/org/openstreetmap/josm
Files:
1 added
7 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/Main.java

    r266 r267  
    234234                // iterate all plugins and collect all libraries of all plugins:
    235235                List<URL> allPluginLibraries = new ArrayList<URL>();
    236                 for (Collection<PluginInformation> c : p.values()) {
    237                         for (PluginInformation info : c) {
    238                                 allPluginLibraries.addAll(info.getLibraries());
    239                         }
    240                 }
     236                for (Collection<PluginInformation> c : p.values())
     237                        for (PluginInformation info : c)
     238                                allPluginLibraries.addAll(info.libraries);
    241239                // create a classloader for all plugins:
    242240                URL[] jarUrls = new URL[allPluginLibraries.size()];
    243241                jarUrls = allPluginLibraries.toArray(jarUrls);
    244242                URLClassLoader pluginClassLoader = new URLClassLoader(jarUrls, Main.class.getClassLoader());
    245                
    246                
     243
    247244                for (Collection<PluginInformation> c : p.values()) {
    248245                        for (PluginInformation info : c) {
    249246                                try {
    250                                         info.setClassLoader(pluginClassLoader); // set the common classloader
    251                                         Class<?> klass = info.loadClass();
     247                                        Class<?> klass = info.loadClass(pluginClassLoader);
    252248                                        ImageProvider.sources.add(0, klass);
    253249                                        System.out.println("loading "+info.name);
  • src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java

    r203 r267  
    7272                }
    7373        };
     74
    7475        /**
    7576         * Main table. 3 columns:
     
    8081
    8182        private Map<OsmPrimitive, List<HistoryItem>> cache = new HashMap<OsmPrimitive, List<HistoryItem>>();
    82         private JLabel notLoaded = new JLabel("<html><i><p align=\"center\">"+tr("Click Reload to refresh list")+"</p></i></html>");
     83        private JLabel notLoaded = new JLabel("<html><i>"+tr("Click Reload to refresh list")+"</i></html>");
    8384        private JButton reloadButton = new JButton(tr("Reload"), ImageProvider.get("dialogs/refresh"));
    8485        private JButton revertButton = new JButton(tr("Revert"), ImageProvider.get("dialogs/revert"));
     
    8889                historyPane.setVisible(false);
    8990                notLoaded.setVisible(true);
     91                notLoaded.setHorizontalAlignment(JLabel.CENTER);
    9092
    9193                history.setDefaultRenderer(Object.class, new DefaultTableCellRenderer(){
     
    131133                reloadButton.setToolTipText(tr("Reload all currently selected objects and refresh the list."));
    132134                reloadButton.putClientProperty("help", "Dialog/History/Reload");
     135               
    133136                revertButton.addActionListener(new ActionListener(){
    134137                        public void actionPerformed(ActionEvent e) {
  • src/org/openstreetmap/josm/plugins/Plugin.java

    r237 r267  
    4040public abstract class Plugin {
    4141
    42         private String name;
     42        String name;
    4343
    4444        public Plugin() {
    45                 URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs();
    46                 name = urls[urls.length-1].toString();
    47                 if (name.toLowerCase().endsWith(".jar")) {
    48                         int lastSlash = name.lastIndexOf('/');
    49                         name = name.substring(lastSlash+1, name.length()-4);
    50                 }
     45                try {
     46                URL[] urls = ((URLClassLoader)getClass().getClassLoader()).getURLs();
     47                name = urls[urls.length-1].toString();
     48                if (name.toLowerCase().endsWith(".jar")) {
     49                        int lastSlash = name.lastIndexOf('/');
     50                        name = name.substring(lastSlash+1, name.length()-4);
     51                }
     52        } catch (RuntimeException e) {
     53                name = "unknown";
     54        }
    5155    }
    5256
    5357        /**
    5458         * @return The name of this plugin. This is the name of the .jar file.
     59         * @deprecated Plugins have to know their name by themself.
    5560         */
    56         public final String getName() {
     61        @Deprecated public final String getName() {
    5762                return name;
    5863        }
    5964        /**
    6065         * @return The directory for the plugin to store all kind of stuff.
     66         * @deprecated Use <code>Main.pref.getPreferencesDir()+"plugins/"+name+"/";</code> instead.
    6167         */
    62         public final String getPluginDir() {
     68        @Deprecated public final String getPluginDir() {
    6369                return Main.pref.getPreferencesDir()+"plugins/"+name+"/";
    6470        }
  • src/org/openstreetmap/josm/plugins/PluginException.java

    r149 r267  
    1111 */
    1212public class PluginException extends RuntimeException {
    13         private final PluginProxy plugin;
    14         private final String name;
     13        public final PluginProxy plugin;
     14        public final String name;
    1515
    1616        public PluginException(PluginProxy plugin, String name, Throwable cause) {
     
    1919                this.name = name;
    2020    }
    21        
    22         public PluginProxy getPlugin() {
    23                 return plugin;
    24         }
    25         public String getName() {
    26                 return name;
    27         }
    2821}
  • src/org/openstreetmap/josm/plugins/PluginInformation.java

    r250 r267  
    66import java.io.InputStream;
    77import java.net.URL;
    8 import java.net.URLClassLoader;
    98import java.util.ArrayList;
    109import java.util.Collection;
     
    3332        public final String author;
    3433        public final int stage;
    35         protected final List<URL> libraries = new ArrayList<URL>();
    36         protected ClassLoader classLoader;
     34        public final List<URL> libraries = new ArrayList<URL>();
    3735
    3836        public final Map<String, String> attr = new TreeMap<String, String>();
     
    8280                                        s = entry.toString();
    8381                                        entry = new StringBuilder();
    84                                         if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:"))
     82                                        if (!s.startsWith("/") && !s.startsWith("\\") && !s.matches("^.\\:") && file != null)
    8583                                                s = file.getParent() + File.separator + s;
    8684                                        libraries.add(new URL(getURLString(s)));
     
    111109         * Load the class of the plugin
    112110         */
    113         public Class<?> loadClass() {
     111        public Class<?> loadClass(ClassLoader classLoader) {
    114112                try {
    115                         Class<?> realClass = Class.forName(className, true, getClassLoader());
     113                        Class<?> realClass = Class.forName(className, true, classLoader);
    116114                        return realClass;
    117115                } catch (Exception e) {
     
    126124        }
    127125
    128         /**
    129          * Returns all libraries the plugin needs (the plugin's jar file itself and all jars declared
    130          * in the manifest's Class-Path section).
    131          * @return the libraries a list of URLs to the libraries.
    132          */
    133         public List<URL> getLibraries() {
    134                 return libraries;
    135         }
    136 
    137         /**
    138      * @return the classLoader
    139      */
    140     public ClassLoader getClassLoader() {
    141                 // if I have no classloader set, create one for me and my libraries:
    142                 if(classLoader == null) {
    143                         URL[] urls = new URL[libraries.size()];
    144                         urls = libraries.toArray(urls);
    145                         classLoader = URLClassLoader.newInstance(urls, getClass().getClassLoader());
    146                 }
    147         return classLoader;
    148     }
    149 
    150         /**
    151      * @param classLoader the classLoader to set
    152      */
    153     public void setClassLoader(ClassLoader classLoader) {
    154         this.classLoader = classLoader;
    155     }
    156        
    157126        /**
    158127         * Try to find a plugin after some criterias. Extract the plugin-information
  • src/org/openstreetmap/josm/plugins/PluginProxy.java

    r238 r267  
    2424                this.plugin = plugin;
    2525                this.info = info;
     26
     27                // setting name of the plugin by reflection
     28                if (plugin instanceof Plugin) {
     29                        try {
     30                        Plugin.class.getDeclaredField("name").set(plugin, info.name);
     31                } catch (Exception e) {
     32                        if (e instanceof RuntimeException)
     33                                throw (RuntimeException)e;
     34                        throw new RuntimeException(e);
     35                }
     36                }
    2637    }
    2738
  • src/org/openstreetmap/josm/tools/BugReportExceptionHandler.java

    r243 r267  
    4343                        // Check for an explicit problem when calling a plugin function
    4444                        if (e instanceof PluginException) {
    45                                 PluginProxy plugin = ((PluginException)e).getPlugin();
     45                                PluginProxy plugin = ((PluginException)e).plugin;
    4646                                if (plugin != null && !plugin.misbehaving) {
    4747                                        JOptionPane.showMessageDialog(Main.parent, tr("The plugin {0} throwed an exception: {1}\nIt may be outdated. Please contact the plugin's autor.\nThis message will not shown again until JOSM is restarted.", plugin.info.name, e.getMessage()));
Note: See TracChangeset for help on using the changeset viewer.