-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for opening the IDE from DevUI even if the default ide sc…
…ript doesn't exist Currently support for this is only added for IntelliJ. Code is opened client side (via the URL handler it installs) so this support isn't needed, Netbeans already used something similar and Eclipse seems to be sort of problematic because we don't have a command which we can test that would not launch the IDE. Fixes: #15721
- Loading branch information
Showing
3 changed files
with
93 additions
and
24 deletions.
There are no files selected for viewing
74 changes: 63 additions & 11 deletions
74
core/deployment/src/main/java/io/quarkus/deployment/ide/Ide.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,75 @@ | ||
package io.quarkus.deployment.ide; | ||
|
||
import java.io.File; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.concurrent.TimeUnit; | ||
|
||
import org.apache.commons.lang3.SystemUtils; | ||
|
||
public enum Ide { | ||
|
||
IDEA("idea"), | ||
ECLIPSE("eclipse"), | ||
VSCODE("code"), | ||
NETBEANS("netbeans"); | ||
IDEA("idea", "--help"), | ||
ECLIPSE("eclipse", (String[]) null), | ||
VSCODE("code", "--version"), | ||
NETBEANS(null); | ||
|
||
private String executable; | ||
private final String defaultCommand; | ||
private final List<String> markerArgs; | ||
private String machineSpecificCommand; | ||
|
||
private Ide(String executable) { | ||
this.executable = executable; | ||
private String effectiveCommand; | ||
|
||
Ide(String defaultCommand, String... markerArgs) { | ||
this.defaultCommand = defaultCommand; | ||
this.markerArgs = markerArgs != null ? Arrays.asList(markerArgs) : Collections.emptyList(); | ||
} | ||
|
||
public String getExecutable() { | ||
return executable; | ||
/** | ||
* Attempts to launch the default IDE script. If it succeeds, then that command is used (as the command is on the $PATH), | ||
* otherwise the full path of the command (determined earlier in the process by looking at the running processes) | ||
* is used. | ||
*/ | ||
public String getEffectiveCommand() { | ||
if (effectiveCommand != null) { | ||
return effectiveCommand; | ||
} | ||
effectiveCommand = doGetEffectiveCommand(); | ||
return effectiveCommand; | ||
} | ||
|
||
public void setExecutable(String executable) { | ||
this.executable = executable; | ||
private String doGetEffectiveCommand() { | ||
if (defaultCommand != null) { | ||
if (markerArgs == null) { | ||
// in this case there is nothing much we can do but hope that the default command will work | ||
return defaultCommand; | ||
} else { | ||
try { | ||
List<String> command = new ArrayList<>(1 + markerArgs.size()); | ||
command.add(defaultCommand); | ||
command.addAll(markerArgs); | ||
new ProcessBuilder(command).redirectError(NULL_FILE).redirectOutput(NULL_FILE).start().waitFor(10, | ||
TimeUnit.SECONDS); | ||
return defaultCommand; | ||
} catch (Exception e) { | ||
return machineSpecificCommand; | ||
} | ||
} | ||
} else { | ||
// in this case the IDE does not provide a default command so we need to rely on what was found | ||
// from inspecting the running processes | ||
return machineSpecificCommand; | ||
} | ||
} | ||
|
||
public void setMachineSpecificCommand(String machineSpecificCommand) { | ||
this.machineSpecificCommand = machineSpecificCommand; | ||
} | ||
|
||
// copied from Java 9 | ||
// TODO remove when we move to Java 11 | ||
|
||
private static final File NULL_FILE = new File(SystemUtils.IS_OS_WINDOWS ? "NUL" : "/dev/null"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters