Changeset 250 in josm for src/org/openstreetmap/josm/plugins


Ignore:
Timestamp:
2007-05-31T00:29:59+02:00 (18 years ago)
Author:
framm
Message:
  • patch by Christof Dallermassl that will use a common classloader for plugins in order to allow them to reference each other.
File:
1 edited

Legend:

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

    r243 r250  
    3333        public final String author;
    3434        public final int stage;
    35         public final List<URL> libraries = new ArrayList<URL>();
     35        protected final List<URL> libraries = new ArrayList<URL>();
     36        protected ClassLoader classLoader;
    3637
    3738        public final Map<String, String> attr = new TreeMap<String, String>();
     
    6869                        if (file != null)
    6970                                libraries.add(new URL(getURLString(file.getAbsolutePath())));
    70                         String classPath = attr.getValue("Class-Path");
     71                        String classPath = attr.getValue(Attributes.Name.CLASS_PATH);
    7172                        if (classPath != null) {
    7273                                String[] cp = classPath.split(" ");
     
    112113        public Class<?> loadClass() {
    113114                try {
    114                         URL[] urls = new URL[libraries.size()];
    115                         urls = libraries.toArray(urls);
    116                         ClassLoader loader = URLClassLoader.newInstance(urls, getClass().getClassLoader());
    117                         Class<?> realClass = Class.forName(className, true, loader);
     115                        Class<?> realClass = Class.forName(className, true, getClassLoader());
    118116                        return realClass;
    119117                } catch (Exception e) {
     
    127125                return "file://"+fileName;
    128126        }
     127
     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    }
    129156       
    130157        /**
     
    190217    }
    191218}
     219
Note: See TracChangeset for help on using the changeset viewer.