Revision: 6577
          http://sourceforge.net/p/jump-pilot/code/6577
Author:   edso
Date:     2020-10-04 20:41:46 +0000 (Sun, 04 Oct 2020)
Log Message:
-----------
add multiple extension dir support
cleanup/enforce pluginclassloader usage

Modified Paths:
--------------
    core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java

Modified: 
core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java  
2020-10-04 20:33:09 UTC (rev 6576)
+++ core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java  
2020-10-04 20:41:46 UTC (rev 6577)
@@ -70,7 +70,7 @@
     private Collection configurations = new ArrayList();
 
     private File plugInDirectory;
-    private ClassLoader classLoader;
+    private PlugInClassLoader classLoader;
 
     /**
      * @param plugInDirectory
@@ -81,11 +81,6 @@
         this.monitor = monitor;
         Assert.isTrue((plugInDirectory == null)
                 || plugInDirectory.isDirectory());
-        // add plugin folder and recursively all jar/zip files in it to 
classpath
-        if ( plugInDirectory instanceof File ) {
-          ArrayList<File> files = new ArrayList();
-          files.add( plugInDirectory );
-          files.addAll( findFilesRecursively( plugInDirectory,true) );
 
 //          class ExtendedURLClassLoader extends URLClassLoader{
 //
@@ -137,37 +132,32 @@
           
 //          
System.out.println("A:"+ClassLoader.getSystemClassLoader().getClass().getClassLoader());
 //          System.out.println("B:"+PlugInClassLoader.class.getClassLoader());;
-            PlugInClassLoader mycl = null;
-            try {
-              mycl = (PlugInClassLoader) ClassLoader.getSystemClassLoader();
-            } catch (ClassCastException e) {
-              Exception je = new JUMPException(
-                  "Wrong classloader. Make sure to run JRE with property 
-Djava.system.class.loader=com.vividsolutions.jump.workbench.plugin.PlugInClassLoader
 set!",e);
-              throw je;
-            }
 
-//          
-//          // add system classpath (eg. org.deegree overrides classes in 
deegree.jar)
-//          System.out.println(Arrays.toString(((URLClassLoader) 
mycl.getParent()).getURLs()));
-//          System.out.println(mycl);
-//          System.out.println(mycl.getParent());
-//          if (getClass().getClassLoader() instanceof URLClassLoader)
-//            mycl.addUrls(((URLClassLoader) mycl.getParent()).getURLs());
-          // add jars in lib/ext and subfolders
-          mycl.addUrls(toURLs(files));
-          classLoader = mycl;
-          
-          // debugging output of all urls in our classloader
-          Logger.debug(Arrays.toString(mycl.getURLs()));
-        } else {
-          classLoader = getClass().getClassLoader();
+        try {
+          classLoader = (PlugInClassLoader) ClassLoader.getSystemClassLoader();
+        } catch (ClassCastException e) {
+          Exception je = new JUMPException(
+              "Wrong classloader. Make sure to run JRE with property 
-Djava.system.class.loader=com.vividsolutions.jump.workbench.plugin.PlugInClassLoader
 set!",e);
+          throw je;
         }
 
+        // add plugin folder and recursively all jar/zip files in it to 
classpath
+        if ( plugInDirectory instanceof File ) {
+          addExtensionDir(plugInDirectory);
+          this.plugInDirectory = plugInDirectory;
+        }
+
         I18N.setClassLoader(classLoader);
         this.context = context;
-        this.plugInDirectory = plugInDirectory;
     }
 
+    public void addExtensionDir(File dir) {
+      ArrayList<File> files = new ArrayList();
+      files.add( dir );
+      files.addAll( findFilesRecursively( dir,true) );
+      classLoader.addUrls(toURLs(files));
+    }
+
     // pretty much the main method, finds and loads extensions from
     // plugin dir
     // and
@@ -368,7 +358,7 @@
       return configurations;
     }
 
-    FileFilter jarfilter = new FileFilter(){
+    static FileFilter jarfilter = new FileFilter(){
       public boolean accept(File f) {
         return f.getName().matches(".*\\.(?i:jar|zip)$") || f.isDirectory();
       }
@@ -518,7 +508,7 @@
      * To access extension classes, use this ClassLoader rather than the 
default
      * ClassLoader. Extension classes will not be present in the latter.
      */
-    public ClassLoader getClassLoader() {
+    public PlugInClassLoader getClassLoader() {
         return classLoader;
     }
     /**



_______________________________________________
Jump-pilot-devel mailing list
Jump-pilot-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel

Reply via email to