Skip to content

Commit

Permalink
Ensure gem updates work even when installed in non-default locations
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Jul 16, 2024
1 parent cef8133 commit 53b6e89
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
}

if (UPDATE_GEM.getValue() && !HAS_UPDATED_READAPT.getAndSet(true)) {
GemHelper.scheduleUpdate("Readapt", READAPT_UPDATE_DELAY);
GemHelper.scheduleUpdate("Readapt", READAPT_UPDATE_DELAY, READAPT_PATH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void start() throws IOException {
}
super.start();
if (UPDATE_GEM.getValue() && !HAS_UPDATED_SOLARGRAPH.getAndSet(true)) {
GemHelper.scheduleUpdate("Solargraph", 30000L);
GemHelper.scheduleUpdate("Solargraph", 30000L, GEM_PATH);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,11 @@

public class GemHelper {

private static String buildGemCmd(String cmd, String lowerCaseGem) {
return String.format(
"gem %s -V -n \"%s\" %s",
cmd, getPluginStateLocation(), lowerCaseGem);
}

public static void install(String gem, StringPreferences pathPreference) {
String lowerCaseGem = gem.toLowerCase();
String[] command = CommandHelper.getPlatformCommand(buildGemCmd("install", lowerCaseGem));
CommandJob installCommandJob = new CommandJob(gem, command, "Installation in progress");
String command = String.format("gem install -V -n \"%s\" %s", getPluginStateLocation(), lowerCaseGem);
String[] platformCommand = CommandHelper.getPlatformCommand(command);
CommandJob installCommandJob = new CommandJob(gem, platformCommand, "Installation in progress");

installCommandJob.addJobChangeListener(new JobChangeAdapter() {

Expand All @@ -58,9 +53,11 @@ public void done(IJobChangeEvent event) {
installCommandJob.schedule();
}

public static void scheduleUpdate(String gem, long delay) {
String[] command = CommandHelper.getPlatformCommand(buildGemCmd("update", gem));
new CommandJob(gem, command, "Update in progress").schedule(delay);
public static void scheduleUpdate(String gem, long delay, StringPreferences pathPreference) {
String path = pathPreference.getValue();
String command = String.format("gem update -V -n \"%s\" %s", path.substring(0, path.lastIndexOf(File.separator)), gem);
String[] plarformCommand = CommandHelper.getPlatformCommand(command);
new CommandJob(gem, plarformCommand, "Update in progress").schedule(delay);
}

private static String getPluginStateLocation() {
Expand Down

0 comments on commit 53b6e89

Please sign in to comment.