33/*
44Part of the Processing project - http://processing.org
55
6- Copyright (c) 2012-16 The Processing Foundation
6+ Copyright (c) 2012-19 The Processing Foundation
77Copyright (c) 2004-12 Ben Fry and Casey Reas
88Copyright (c) 2001-04 Massachusetts Institute of Technology
99
5858import processing .mode .java .preproc .PreprocessorResult ;
5959import processing .mode .java .preproc .SurfaceInfo ;
6060
61- // Would you believe there's a java.lang.Compiler class? I wouldn't.
62-
6361
6462public class JavaBuild {
6563 public static final String PACKAGE_REGEX =
@@ -224,10 +222,11 @@ public String preprocess(File srcFolder,
224222
225223 // Remove the entries being moved to settings(). They will be re-inserted
226224 // by writeFooter() when it emits the settings() method.
227- if (sizeInfo != null && sizeInfo .hasSettings ()) {
228- // String sizeStatement = sizeInfo.getStatement();
225+ // If the user already has a settings() method, don't mess with anything.
226+ // https://github.com/processing/processing/issues/4703
227+ if (!PdePreprocessor .hasSettingsMethod (bigCode .toString ()) &&
228+ sizeInfo != null && sizeInfo .hasSettings ()) {
229229 for (String stmt : sizeInfo .getStatements ()) {
230- //System.out.format("size stmt is '%s'%n", sizeStatement);
231230 // Don't remove newlines (and while you're at it, just keep spaces)
232231 // https://github.com/processing/processing/issues/3654
233232 stmt = stmt .trim ();
@@ -267,19 +266,10 @@ public String preprocess(File srcFolder,
267266 // then search through for anyone else whose preprocName is null,
268267 // since they've also been combined into the main pde.
269268 int errorFile = findErrorFile (errorLine );
270- // System.out.println("error line is " + errorLine + ", file is " + errorFile);
271269 errorLine -= sketch .getCode (errorFile ).getPreprocOffset ();
272- // System.out.println(" preproc offset for that file: " + sketch.getCode(errorFile).getPreprocOffset());
273-
274- // System.out.println("i found this guy snooping around..");
275- // System.out.println("whatcha want me to do with 'im boss?");
276- // System.out.println(errorLine + " " + errorFile + " " + code[errorFile].getPreprocOffset());
277270
278271 String msg = re .getMessage ();
279272
280- //System.out.println(java.getAbsolutePath());
281- // System.out.println(bigCode);
282-
283273 if (msg .contains ("expecting RCURLY" ) || msg .contains ("expecting LCURLY" )) {
284274 for (int i = 0 ; i < sketch .getCodeCount (); i ++) {
285275 SketchCode sc = sketch .getCode (i );
@@ -294,8 +284,8 @@ public String preprocess(File srcFolder,
294284 // the result of PApplet.match(msg, "found ('.*')") on missing
295285 // LCURLY.
296286 throw new SketchException (braceTest [0 ] > 0
297- ? "Found one too many { characters without a } to match it."
298- : "Found one too many } characters without a { to match it." ,
287+ ? "Found an extra { character without a } to match it."
288+ : "Found an extra } character without a { to match it." ,
299289 i , braceTest [1 ], braceTest [2 ], false );
300290 }
301291 }
@@ -413,26 +403,19 @@ public String preprocess(File srcFolder,
413403 javaLibraryPath += File .pathSeparator + core .getNativePath ();
414404 }
415405
416- // System.out.println("extra imports: " + result.extraImports);
417406 for (String item : result .extraImports ) {
418- // System.out.println("item = '" + item + "'");
419407 // remove things up to the last dot
420408 int dot = item .lastIndexOf ('.' );
421409 // http://dev.processing.org/bugs/show_bug.cgi?id=1145
422410 String entry = (dot == -1 ) ? item : item .substring (0 , dot );
423- // System.out.print(entry + " => ");
424411
425412 if (item .startsWith ("static " )) {
426413 // import static - https://github.com/processing/processing/issues/8
427- // Remove more stuff.
428414 int dot2 = item .lastIndexOf ('.' );
429415 entry = entry .substring (7 , (dot2 == -1 ) ? entry .length () : dot2 );
430- // System.out.println(entry);
431416 }
432417
433- // System.out.println("library searching for " + entry);
434418 Library library = mode .getLibrary (entry );
435- // System.out.println(" found " + library);
436419
437420 if (library != null ) {
438421 if (!importedLibraries .contains (library )) {
@@ -461,7 +444,6 @@ public String preprocess(File srcFolder,
461444 }
462445 }
463446 }
464- // PApplet.println(PApplet.split(libraryPath, File.pathSeparatorChar));
465447
466448 // Finally, add the regular Java CLASSPATH. This contains everything
467449 // imported by the PDE itself (core.jar, pde.jar, quaqua.jar) which may
@@ -533,6 +515,7 @@ public String preprocess(File srcFolder,
533515 return result .className ;
534516 }
535517
518+
536519 /**
537520 * Returns true if this package isn't part of a library (it's a system import
538521 * or something like that). Don't bother complaining about java.* or javax.*
0 commit comments