#218: add possibility to start a command in a new window with the process builder - #2239
Conversation
…the process builder
…nd-in-a-new-window-with-the-process-builder
Coverage Report for CI Build 30622595516Coverage decreased (-0.1%) to 72.527%Details
Uncovered ChangesNo uncovered changes found. Coverage Regressions72 previously-covered lines in 2 files lost coverage.
Coverage Stats💛 - Coveralls |
Ali-Shariati-Najafabadi
left a comment
There was a problem hiding this comment.
Nice approach overall, but I ran this locally and found a few things.
cli/src/test/resources/process-context/write-marker.sh
Root cause of the above, needs chmod +x before committing.
cli/src/test/java/com/devonfw/tools/ide/process/BackgroundNewWindowTest.java:218, :267, :319
The three "actually execute" E2E tests only skip in CI, not on a normal local run, so anyone running mvn clean test on Windows/Mac gets a CMD or Terminal window popping up. You called this out yourself in the PR description as a TODO, just don't want it to slip through review. Might be worth gating them behind a system property; the structural/mocked tests already cover the command shape fine on their own.
| * https://github.com/devonfw/IDEasy/issues/1917[#1917]: Allow the creation of a desktop shortcut for the GUI | ||
| * https://github.com/devonfw/IDEasy/issues/2134[#2134]: Add auto-completion for icd command | ||
| * https://github.com/devonfw/IDEasy/issues/2145[#2145]: Improve documentation on symlink regarding ide ln | ||
| * https://github.com/devonfw/IDEasy/issues/2145[#218]: Added possibility to start a command in a new window using the process builder |
There was a problem hiding this comment.
CHANGELOG.adoc:17
Wrong issue link (points to #2145 instead of #218):
| * https://github.com/devonfw/IDEasy/issues/2145[#218]: Added possibility to start a command in a new window using the process builder | |
| * https://github.com/devonfw/IDEasy/issues/218[#218]: Added possibility to start a command in a new window using the process builder |
| s -> assertThat(s).contains("Terminal")); | ||
| // Should NOT fall back to plain disown anymore | ||
| assertThat(bashCommand).as("Bash command should NOT contain disown on macOS (has terminal support)") | ||
| .doesNotContain("disown"); |
There was a problem hiding this comment.
This asserts the mac command shouldn't contain disown, but it does. ProcessContextImpl always appends ; disown for new-window mode regardless of OS (see ProcessContextImpl.java:454), so the test's just wrong about what the code actually does. Ran it locally, fails every time.
|
|
||
| # Writes a marker to stdout — used to verify background processes actually execute. | ||
| # The caller should provide $1 as the marker file path. | ||
| echo "background-process-ran" > "$1" No newline at end of file |
There was a problem hiding this comment.
cli/src/test/resources/process-context/write-marker.sh
Root cause of the above needs chmod +x before committing.
| } | ||
|
|
||
| // Quote unconditionally and escape cmd.exe metacharacters | ||
| String escaped = value.replace("^", "^^").replace("%", "%%").replace("\"", "\\\""); |
There was a problem hiding this comment.
cli/src/main/java/com/devonfw/tools/ide/process/ProcessContextImpl.java:580
windowsQuote() escapes ^, %, " but not &, |, <, >, which cmd.exe treats as operators even inside quotes sometimes. Worth a test with & or | in an argument. Also doubling % to %% only works inside .bat files, not on a plain cmd /c line.
| assert processMode.isBackground() : "Cannot handle non background process mode!"; | ||
| String commandToRunInBackground = buildCommand(args); | ||
|
|
||
| if (this.context.getSystemInfo().isWindows()) { |
There was a problem hiding this comment.
This routes all background modes through cmd.exe /c start on Windows now, not just the new one. Before this PR, BACKGROUND/BACKGROUND_SILENT on Windows went through git-bash. That's a real behavior change for existing callers (Eclipse, Gui, IdeToolCommandlet, Tomcat, the IdeasyCommandlet self-update cleanup that runs sleep 10 && rm -rf ...) with no tests for the new Windows path. Intentional? If yes, worth a test; if not, maybe keep those on the old bash path.
| void backgroundNewWindowShouldActuallyExecuteViaOsascriptOnMac() throws Exception { | ||
| // arrange | ||
| if (isCiEnvironment()) { | ||
| return; // Skip — opening a terminal window would leak in CI | ||
| } | ||
| IdeTestContext context = newContext(PROJECT_BASIC, null, false); | ||
| if (context.findBash() == null) { | ||
| return; // Skip when no bash is available | ||
| } | ||
|
|
||
| // Verify osascript is available (required for Terminal.app / iTerm2 AppleScript) | ||
| if (!isOsascriptAvailable()) { | ||
| // Skip - no GUI session or osascript not available (e.g. headless CI) | ||
| return; | ||
| } | ||
|
|
||
| Path markerFile = Files.createTempFile("bg-marker-mac-", ".txt"); | ||
| Files.delete(markerFile); // Remove so polling can detect when the script creates it | ||
| Path scriptPath = TEST_RESOURCES.resolve("process-context").resolve("write-marker.sh"); | ||
|
|
||
| ProcessContextImpl processContext = new ProcessContextImpl(context); | ||
| // act | ||
| ProcessResult result = processContext.executable(scriptPath).addArg(markerFile.toString()) | ||
| .run(ProcessMode.BACKGROUND_NEW_WINDOW); |
There was a problem hiding this comment.
Blows up with End of answers reached! at line 342. write-marker.sh got committed without the executable bit, so IDEasy prompts to chmod it and this test never answers that prompt,unlike the Linux test at BackgroundNewWindowTest.java:276, which does context.setAnswers("1"). Missing that here.
This PR fixes #218
Implemented changes:
ProcessMode#BACKGROUND_NEW_WINDOWmode that starts a command in a new terminal window while detaching it from the parent process.ProcessContextImpl:gnome-terminal,konsole,xfce4-terminal,tilix,alacritty,xterm,x-terminal-emulator) and uses the correct flag syntax for each, with adisownfallback when no terminal emulator is available.osascriptto launch a new Terminal.app or iTerm2 window via AppleScript.cmd.exe /c startto open a new CMD window.launchesNewWindow()method toProcessModeto check whether the mode should launch a process in a new window.isBackground()to include the newBACKGROUND_NEW_WINDOWmode.BackgroundNewWindowTest.java:disownfallback.Testing instructions
mvn clean test— all tests should pass, including the 10 new tests inBackgroundNewWindowTest.java.backgroundNewWindowShouldActuallyExecuteViaStartOnWindows— observe a new CMD window opening.backgroundNewWindowShouldActuallyExecuteViaOsascriptOnMac— observe a new Terminal.app (or iTerm2) window opening.backgroundNewWindowShouldActuallyExecuteOnLinux— observe a new terminal window opening (if a desktop environment is available), or the test passing via thedisownfallback in headless environments.Checklist for this PR
Make sure everything is checked before merging this PR. For further info please also see
our DoD.
mvn clean testlocally all tests pass and build is successful#«issue-id»:«brief summary»(e.g.#921: fixed setup.bat). If no issue ID exists, title only.In Progressand assigned to you or there is no issue (might happen for very small PRs)with
internal