From e6fe0ecea7d160e7b2938f39e014b8c18a510448 Mon Sep 17 00:00:00 2001 From: Sajal-Kulshreshtha Date: Tue, 9 Sep 2025 02:39:19 +0530 Subject: [PATCH 1/2] Fix CLI to respect sketch.properties main file --- app/src/processing/app/Sketch.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index 8bb50352b0..6a8a34d27e 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -1320,10 +1320,13 @@ static protected File findMain(File folder, List modeList) { String main = props.get("main"); if (main != null) { File mainFile = new File(folder, main); - if (!mainFile.exists()) { + if (mainFile.exists()) { + return mainFile; + } + else { System.err.println(main + " does not exist inside " + folder); // Fall through to the code below in case we can recover. - // Not removing the bad entry since this is a find() method. + } } } catch (IOException e) { From 5b5720a3f4e63b4357db1ea72fc5732c61c3c717 Mon Sep 17 00:00:00 2001 From: Sajal-Kulshreshtha Date: Tue, 9 Sep 2025 19:43:21 +0530 Subject: [PATCH 2/2] fixed the editor and added cli test --- app/src/processing/app/ui/Editor.java | 24 +++++++++++++++--------- app/test/processing/app/CLITest.kt | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 10 deletions(-) diff --git a/app/src/processing/app/ui/Editor.java b/app/src/processing/app/ui/Editor.java index d710890a95..6d749b4b69 100644 --- a/app/src/processing/app/ui/Editor.java +++ b/app/src/processing/app/ui/Editor.java @@ -2256,20 +2256,26 @@ public boolean checkModified() { * shouldn't rely on any of its variables being initialized already. */ protected void handleOpenInternal(String path) throws EditorException { - // Prior to 4.0 beta 6, a lot of logic happened here that was - // instead moved into Base. Probably was here so that other Modes - // could override the behavior, but that was too messy. [fry 220206] + try { + File sketchFolder = new File(path); - try { - sketch = new Sketch(path, this); - } catch (IOException e) { - throw new EditorException("Could not create the sketch.", e); + // Try to locate main file using sketch.properties or fallback + File mainFile = Sketch.findMain(sketchFolder, Base.getModeList()); + if (mainFile == null) { + throw new EditorException("No valid main .pde file found in " + sketchFolder); } - header.rebuild(); - updateTitle(); + // Use the parent folder of the main file + sketch = new Sketch(mainFile.getParentFile(), this); + + } catch (IOException e) { + throw new EditorException("Could not create the sketch.", e); } + header.rebuild(); + updateTitle(); +} + /** * Set the title of the PDE window based on the current sketch, i.e. diff --git a/app/test/processing/app/CLITest.kt b/app/test/processing/app/CLITest.kt index 2bd8cc81e7..da62f61f5a 100644 --- a/app/test/processing/app/CLITest.kt +++ b/app/test/processing/app/CLITest.kt @@ -47,4 +47,20 @@ class CLITest { println("Done running CLI with arguments: $args (Result: $result)") } -} \ No newline at end of file + fun runCLIAndCapture(vararg args: String): String { + val argLine = args.joinToString(" ") + println("Running CLI with arguments: $argLine") + + val process = ProcessBuilder("./gradlew", "run", "--args=$argLine", "--quiet") + .directory(File(System.getProperty("user.dir")).resolve("../../../")) + .redirectErrorStream(true) + .start() + + val output = process.inputStream.bufferedReader().readText() + val exitCode = process.waitFor() + + println("Done running CLI with arguments: $argLine (Exit code: $exitCode)") + return output + } + +}