From 065702c02824c18235e542878dafe1d142824236 Mon Sep 17 00:00:00 2001 From: benfry Date: Tue, 23 Oct 2012 16:53:02 +0000 Subject: [PATCH] change search location for lib folder, fix ClassNotFoundException for processing-java (issue #1334) --- app/src/processing/app/Base.java | 41 +++++++++++-------- app/src/processing/app/Mode.java | 5 ++- .../app/contrib/InstalledContribution.java | 1 + .../app/contrib/ModeContribution.java | 4 +- app/src/processing/mode/java/Commander.java | 25 +++++------ todo.txt | 4 +- 6 files changed, 45 insertions(+), 35 deletions(-) diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 6f90f1544..bde733554 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -278,9 +278,9 @@ public class Base { "processing.mode.javascript.JavaScriptMode").getMode(); coreModes = new Mode[] { javaMode, androidMode, javaScriptMode }; - for (Mode mode : coreModes) { - mode.setupGUI(); - } +// for (Mode mode : coreModes) { // already called by load() above +// mode.setupGUI(); +// } } @@ -2338,21 +2338,28 @@ public class Base { } */ + /** + * Adjacent the executable on Windows and Linux, + * or inside Contents/Resources/Java on Mac OS X. + */ + static protected File processingRoot; + static public File getContentFile(String name) { - // Get the path to the .jar file that contains Base.class - String path = Base.class.getProtectionDomain().getCodeSource().getLocation().getPath(); - // Path may have URL encoding, so remove it - String decodedPath = PApplet.urlDecode(path); - // The .jar file will be in the lib folder - File libFolder = new File(decodedPath).getParentFile(); - File processingRoot = null; - if (libFolder.getName().equals("lib")) { - // The main Processing installation directory - processingRoot = libFolder.getParentFile(); - } else { - Base.log("Could not find lib in " + - libFolder.getAbsolutePath() + ", switching to user.dir"); - processingRoot = new File(System.getProperty("user.dir")); + if (processingRoot == null) { + // Get the path to the .jar file that contains Base.class + String path = Base.class.getProtectionDomain().getCodeSource().getLocation().getPath(); + // Path may have URL encoding, so remove it + String decodedPath = PApplet.urlDecode(path); + // The .jar file will be in the lib folder + File libFolder = new File(decodedPath).getParentFile(); + if (libFolder.getName().equals("lib")) { + // The main Processing installation directory + processingRoot = libFolder.getParentFile(); + } else { + Base.log("Could not find lib in " + + libFolder.getAbsolutePath() + ", switching to user.dir"); + processingRoot = new File(System.getProperty("user.dir")); + } } /* String path = System.getProperty("user.dir"); diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index bdc4fc36e..539d72d73 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -90,8 +90,9 @@ public abstract class Mode { /** - * Setup additional elements that are only required when running - * with a GUI, rather than from the command-line. + * Setup additional elements that are only required when running with a GUI, + * rather than from the command-line. Note that this will not be called when + * the Mode is used from the command line (because Base will be null). */ public void setupGUI() { try { diff --git a/app/src/processing/app/contrib/InstalledContribution.java b/app/src/processing/app/contrib/InstalledContribution.java index 26e0430ae..b10ae77bf 100644 --- a/app/src/processing/app/contrib/InstalledContribution.java +++ b/app/src/processing/app/contrib/InstalledContribution.java @@ -89,6 +89,7 @@ public abstract class InstalledContribution implements Contribution { public String initLoader(String className) throws Exception { File modeDirectory = new File(folder, getTypeName()); if (modeDirectory.exists()) { + Base.log("checking mode folder regarding " + className); // If no class name specified, search the main .jar for the // full name package and mode name. if (className == null) { diff --git a/app/src/processing/app/contrib/ModeContribution.java b/app/src/processing/app/contrib/ModeContribution.java index f5693e64c..488ec86e2 100644 --- a/app/src/processing/app/contrib/ModeContribution.java +++ b/app/src/processing/app/contrib/ModeContribution.java @@ -97,7 +97,9 @@ public class ModeContribution extends InstalledContribution { Constructor con = modeClass.getConstructor(Base.class, File.class); mode = (Mode) con.newInstance(base, folder); mode.setClassLoader(loader); - mode.setupGUI(); + if (base != null) { + mode.setupGUI(); + } } // // Class name already found above, go ahead and instantiate diff --git a/app/src/processing/mode/java/Commander.java b/app/src/processing/mode/java/Commander.java index f73f00b3e..cdd4fee1a 100644 --- a/app/src/processing/mode/java/Commander.java +++ b/app/src/processing/mode/java/Commander.java @@ -26,12 +26,8 @@ import java.io.File; import java.io.IOException; import java.io.PrintStream; -import processing.app.Base; -import processing.app.Library; -import processing.app.Preferences; -import processing.app.SketchException; -import processing.app.RunnerListener; -import processing.app.Sketch; +import processing.app.*; +import processing.app.contrib.ModeContribution; import processing.core.PApplet; import processing.mode.java.runner.*; @@ -71,26 +67,28 @@ public class Commander implements RunnerListener { if (args == null || args.length == 0) { // System.out.println(System.getProperty("user.dir")); args = new String[] { -// "--export", + "--export", // "--build", - "--run", +// "--run", // "--present", -// "--force", + "--force", // "--platform=windows", "--platform=macosx", "--bits=64", "--sketch=/Users/fry/coconut/processing/java/examples/Basics/Lights/Directional", +// "--sketch=/Users/fry/coconut/sketchbook/sketchbook_libraries_test", "--output=/Users/fry/Desktop/test-build" }; } */ - + // Do this early so that error messages go to the console Base.setCommandLine(); // init the platform so that prefs and other native code is ready to go Base.initPlatform(); // make sure a full JDK is installed Base.initRequirements(); + // launch command line handler new Commander(args); } @@ -228,8 +226,11 @@ public class Commander implements RunnerListener { } else { boolean success = false; - JavaMode javaMode = - new JavaMode(null, Base.getContentFile("modes/java")); +// JavaMode javaMode = +// new JavaMode(null, Base.getContentFile("modes/java")); + JavaMode javaMode = (JavaMode) + ModeContribution.load(null, Base.getContentFile("modes/java"), + "processing.mode.java.JavaMode").getMode(); try { sketch = new Sketch(pdePath, javaMode); if (task == BUILD || task == RUN || task == PRESENT) { diff --git a/todo.txt b/todo.txt index 2edeeb675..84202c541 100644 --- a/todo.txt +++ b/todo.txt @@ -9,13 +9,11 @@ X Import statements are executed within multiline comments X http://code.google.com/p/processing/issues/detail?id=911 X write preferences file sorted X Major change to how lib folder is found, hopefully handles cmd line better - o caretBlinks always true.. just remove the pref? o blockCaret always false.. remove it? X report from someone about blinking caret X http://code.google.com/p/processing/issues/detail?id=1136 - -_ see if commander is still headless +X see if commander is still headless _ don't use --request on OS X, not available