Skip to content

Commit

Permalink
Check if gem available in default plugin location
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Jul 16, 2024
1 parent 53b6e89 commit dd1ce86
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@

public enum StringPreferences implements Preference<String> {

GEM_PATH("GemPath", "Solargraph executable:", CommandHelper.findPath(isWindows() ? "solargraph.bat" : "solargraph")),
GEM_PATH("GemPath", "Solargraph executable:", CommandHelper.findPath(isWindows() ? "solargraph.bat" : "solargraph", true)),
RUBY_DIR("RubyDir", "Override Ruby bin directory:", CommandHelper.findDirectory("ruby")),
READAPT_PATH("ReadaptPath", "Readapt executable:", CommandHelper.findPath(isWindows() ? "readapt.bat" : "readapt"));
READAPT_PATH("ReadaptPath", "Readapt executable:", CommandHelper.findPath(isWindows() ? "readapt.bat" : "readapt", true));

private final String key;
private final String desc;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class CommandHelper {
private static final AtomicReference<String> DEFAULT_SHELL_MACOS = new AtomicReference<>();

public static String findDirectory(String executable) {
String executablePath = findPath(executable);
String executablePath = findPath(executable, false);
if (!executablePath.isEmpty()) {
File executableDirectory = new File(executablePath).getParentFile();
if (executableDirectory != null && executableDirectory.isDirectory()) {
Expand All @@ -40,7 +40,13 @@ public static String findDirectory(String executable) {
return "";
}

public static String findPath(String executable) {
public static String findPath(String executable, boolean searchInDefaultPluginLocation) {
if (searchInDefaultPluginLocation) {
String defaultPluginLocation = GemHelper.getPluginStateLocation() + File.separator + executable;
if (new File(defaultPluginLocation).exists()) {
return defaultPluginLocation;
}
}
String locationCommand = (isWindows() ? "where " : "which ") + executable;
try {
Process process = new ProcessBuilder(getPlatformCommand(locationCommand)).redirectErrorStream(true).start();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void scheduleUpdate(String gem, long delay, StringPreferences path
new CommandJob(gem, plarformCommand, "Update in progress").schedule(delay);
}

private static String getPluginStateLocation() {
static String getPluginStateLocation() {
return Platform.getStateLocation(FrameworkUtil.getBundle(GemHelper.class)).toOSString();
}

Expand Down

0 comments on commit dd1ce86

Please sign in to comment.