Skip to content

Commit 99751b4

Browse files
committed
scrubbing the class paths for #3812
1 parent 44ab414 commit 99751b4

File tree

3 files changed

+34
-24
lines changed

3 files changed

+34
-24
lines changed

java/src/processing/mode/java/JavaMode.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,13 +266,14 @@ public boolean handleExportApplication(Sketch sketch) throws SketchException, IO
266266

267267

268268
/**
269-
* Any modes that extend JavaMode can override this method to add additional jars to be
270-
* included in the classpath for code completion and error checking
269+
* Any modes that extend JavaMode can override this method to add additional
270+
* JARs to be included in the classpath for code completion and error checking
271271
* @return searchPath: file-paths separated by File.pathSeparatorChar
272272
*/
273273
public String getSearchPath() {
274274
// Java Mode doesn't need any default external jars at the moment.
275-
return "";
275+
// This is here for Android Mode so that it can add its android.jar file.
276+
return null;
276277
}
277278

278279

java/src/processing/mode/java/pdex/ASTGenerator.java

Lines changed: 21 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
import processing.app.Util;
112112
import processing.app.syntax.JEditTextArea;
113113
import processing.app.ui.Toolkit;
114+
import processing.data.StringList;
114115
import processing.mode.java.JavaEditor;
115116
import processing.mode.java.JavaMode;
116117
import processing.mode.java.preproc.PdePreprocessor;
@@ -295,36 +296,43 @@ protected void done() {
295296
*/
296297
protected ClassPath classPath;
297298

298-
//protected JFrame frmJavaDoc;
299-
300-
protected String getJavaSearchPath() {
301-
return System.getProperty("java.class.path") +
302-
File.pathSeparatorChar + System.getProperty("java.home") +
303-
File.separator + "lib" + File.separator + "rt.jar";
304-
}
305299

306300
/**
307301
* Loads up .jar files and classes defined in it for completion lookup
308302
*/
309303
protected void loadJars() {
310304
factory = new ClassPathFactory();
311305

312-
StringBuilder path = new StringBuilder();
313-
String modeClassPath = getJavaSearchPath() + File.pathSeparatorChar + ((JavaMode) editor.getMode()).getSearchPath();
306+
StringList entries = new StringList();
307+
entries.append(System.getProperty("java.class.path"));
308+
entries.append(System.getProperty("java.home") +
309+
File.separator + "lib" + File.separator + "rt.jar");
310+
311+
String modeClassPath = ((JavaMode) editor.getMode()).getSearchPath();
314312
if (modeClassPath != null) {
315-
path.append(modeClassPath);
313+
entries.append(modeClassPath);
316314
}
317315

318316
if (errorCheckerService.classpathJars != null) {
319317
synchronized (errorCheckerService.classpathJars) {
320318
for (URL jarPath : errorCheckerService.classpathJars) {
321-
//log(jarPath.getPath());
322-
path.append(jarPath.getPath() + File.pathSeparatorChar);
319+
entries.append(jarPath.getPath());
323320
}
324321
}
325322
}
326323

327-
classPath = factory.createFromPath(path.toString());
324+
// // Just in case, make sure we don't run off into oblivion
325+
// String workingDirectory = System.getProperty("user.dir");
326+
// if (entries.removeValue(workingDirectory) != -1) {
327+
// System.err.println("user.dir found in classpath");
328+
// }
329+
330+
// // hm, these weren't problematic either
331+
// entries.append(System.getProperty("user.dir"));
332+
// entries.append("");
333+
// entries.print();
334+
335+
classPath = factory.createFromPath(entries.join(File.pathSeparator));
328336
log("Classpath created " + (classPath != null));
329337
log("Sketch classpath jars loaded.");
330338
if (Platform.isMacOS()) {

java/src/processing/mode/java/pdex/ErrorCheckerService.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -887,17 +887,18 @@ protected void prepareCompilerClasspath() {
887887
e2.printStackTrace();
888888
}
889889
}
890-
891-
892890
}
893891

894892
// Also add jars specified in mode's search path
895-
String modeJars[] = ((JavaMode) getEditor().getMode()).getSearchPath().split(File.pathSeparatorChar + "");
896-
for (String mj : modeJars) {
897-
try {
898-
classpathJars.add(new File(mj).toURI().toURL());
899-
} catch (MalformedURLException e) {
900-
e.printStackTrace();
893+
String searchPath = ((JavaMode) getEditor().getMode()).getSearchPath();
894+
if (searchPath != null) {
895+
String[] modeJars = PApplet.split(searchPath, File.pathSeparatorChar);
896+
for (String mj : modeJars) {
897+
try {
898+
classpathJars.add(new File(mj).toURI().toURL());
899+
} catch (MalformedURLException e) {
900+
e.printStackTrace();
901+
}
901902
}
902903
}
903904
}

0 commit comments

Comments
 (0)