Revision: 6579
http://sourceforge.net/p/jump-pilot/code/6579
Author: edso
Date: 2020-10-05 19:43:52 +0000 (Mon, 05 Oct 2020)
Log Message:
-----------
add multiple extension dirs support, needed eg. in eclipse where lib/ext/ and
lib/plus/ are separate folders. might be usable in the future to place each
extension in their own folder.
use by giving multiple -plug-in-directory params eg. -plug-in-directory
"lib\plus" -plug-in-directory "lib\ext"
Modified Paths:
--------------
core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java
core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java
Modified: core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java
2020-10-04 21:18:10 UTC (rev 6578)
+++ core/trunk/src/com/vividsolutions/jump/workbench/JUMPWorkbench.java
2020-10-05 19:43:52 UTC (rev 6579)
@@ -267,27 +267,44 @@
properties = new WorkbenchPropertiesFile(files, frame);
// -- end new
- File extensionsDirectory;
+
+ File extensionsDirectory = null;
+ List<File> moreDirs = new ArrayList<File>();
if (commandLine.hasOption(PLUG_IN_DIRECTORY_OPTION)) {
- extensionsDirectory = new File(commandLine.getOption(
- PLUG_IN_DIRECTORY_OPTION).getArg(0));
- if (!extensionsDirectory.exists()) {
- Logger.warn("Extensions directory does not exist: "
- + extensionsDirectory);
- extensionsDirectory = null;
+ // we support multiple -plug-in-directory definitions, where the first
is set default
+ // and all others and contained jar/zip files get added to classpath
below
+ // this mainly helps when run during development where lib/plus/ &
lib/ext/ are different folders
+ Iterator<String> paths =
commandLine.getAllArguments(PLUG_IN_DIRECTORY_OPTION);
+ while (paths.hasNext()) {
+ String path = paths.next();
+ if (extensionsDirectory == null) {
+ // first entry get's default
+ extensionsDirectory = new File(path);
+ Logger.debug("Set plugin-dir -> "+path);
+ continue;
+ }
+ // rest get's added to classloader
+ File dir = new File(path);
+ if (!dir.exists()) {
+ Logger.error("given parameter "+PLUG_IN_DIRECTORY_OPTION+"
'"+path+"' does not exist.");
+ continue;
+ }
+ Logger.debug("Add plugin-dir -> "+path);
+ moreDirs.add(dir);
}
} else {
extensionsDirectory = new File("lib/ext");
- if (!extensionsDirectory.exists()) {
- // Added further information so that debug user will know where
- // it is actually looking for as the extension directory. [Ed Deen]
- Logger.warn("Extensions directory does not exist: "
- + extensionsDirectory + " where homedir = ["
- + System.getProperty("user.dir") + "]");
- extensionsDirectory = null;
- }
}
+ if (!extensionsDirectory.exists()) {
+ // Added further information so that debug user will know where
+ // it is actually looking for as the extension directory. [Ed Deen]
+ Logger.error("Extensions directory does not exist: "
+ + extensionsDirectory + " where homedir = ["
+ + System.getProperty("user.dir") + "]");
+ extensionsDirectory = null;
+ }
+
// [ede 12.2012] deprecated -project option
if (commandLine.hasOption(INITIAL_PROJECT_FILE)) {
String task = commandLine.getOption(INITIAL_PROJECT_FILE).getArg(0);
@@ -308,7 +325,14 @@
}
}
+ // create plugin manager
plugInManager = new PlugInManager(context, extensionsDirectory, monitor);
+ // add secondary extension folders (mainly for dev where we have lib/ext/
& lib/plus/)
+ for (File dir : moreDirs) {
+ plugInManager.addExtensionDir(dir);
+ }
+ // debugging output of all urls in our classloader
+ Logger.debug("Classpath ->
"+Arrays.toString(plugInManager.getClassLoader().getURLs()));
// Load drivers before initializing the frame because part of the frame
// initialization is the initialization of the driver dialogs. [Jon
Modified:
core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java
===================================================================
--- core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java
2020-10-04 21:18:10 UTC (rev 6578)
+++ core/trunk/src/com/vividsolutions/jump/workbench/plugin/PlugInManager.java
2020-10-05 19:43:52 UTC (rev 6579)
@@ -30,7 +30,6 @@
import java.io.FileFilter;
import java.net.MalformedURLException;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@@ -67,9 +66,9 @@
private TaskMonitor monitor;
private WorkbenchContext context;
- private Collection configurations = new ArrayList();
+ private Collection<Configuration> configurations = new ArrayList();
- private File plugInDirectory;
+ private List<File> extensionDirs = new ArrayList<File>();
private PlugInClassLoader classLoader;
/**
@@ -79,8 +78,6 @@
public PlugInManager(WorkbenchContext context, File plugInDirectory,
TaskMonitor monitor) throws Exception {
this.monitor = monitor;
- Assert.isTrue((plugInDirectory == null)
- || plugInDirectory.isDirectory());
// class ExtendedURLClassLoader extends URLClassLoader{
//
@@ -144,7 +141,6 @@
// 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);
@@ -152,10 +148,17 @@
}
public void addExtensionDir(File dir) {
+ // already added? we don't want duplicates
+ if (extensionDirs.contains(dir))
+ return;
+
+ // add contained jars/zips and base folder to classloader
ArrayList<File> files = new ArrayList();
files.add( dir );
files.addAll( findFilesRecursively( dir,true) );
classLoader.addUrls(toURLs(files));
+ // add to internal list
+ extensionDirs.add(dir);
}
// pretty much the main method, finds and loads extensions from
@@ -170,9 +173,11 @@
// Find the configurations right away so they get reported to the splash
// screen ASAP. [Jon Aquino]
- if (plugInDirectory != null) {
+ if (!extensionDirs.isEmpty()) {
start = Timer.milliSecondsSince(0);
- configurations.addAll(findConfigurations(plugInDirectory));
+ for (File dir : extensionDirs) {
+ configurations.addAll(findConfigurations(dir));
+ }
Logger.info("Finding all OJ extensions took "
+ Timer.secondsSinceString(start) + "s");
}
@@ -511,10 +516,21 @@
public PlugInClassLoader getClassLoader() {
return classLoader;
}
+
/**
+ * fetch a list of folders holding extension jars that were added during
start
+ */
+ public List<File> getExtensionDirs(){
+ return Collections.unmodifiableList(extensionDirs);
+ }
+
+ /**
+ * get extension folder, cloned to prevent modification
+ * @deprecated use {@link #getExtensionDirs()}
* @return possibly null
*/
+ @Deprecated
public File getPlugInDirectory() {
- return plugInDirectory;
+ return extensionDirs.isEmpty() ? null : new
File(extensionDirs.get(0).toURI());
}
}
\ No newline at end of file
_______________________________________________
Jump-pilot-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jump-pilot-devel