Skip to content

Commit

Permalink
Use lists instead of arrays where possible
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Jul 16, 2024
1 parent 328570a commit d0736a6
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void launch(ILaunchConfiguration configuration, String mode, ILaunch laun
}

DSPLaunchDelegateLaunchBuilder builder = new DSPLaunchDelegateLaunchBuilder(configuration, mode, launch, monitor);
List<String> readaptCommand = List.of(CommandHelper.getPlatformCommand("\"" + readaptPath + "\" stdio"));
List<String> readaptCommand = CommandHelper.getPlatformCommand("\"" + readaptPath + "\" stdio");
builder.setLaunchDebugAdapter(readaptCommand.get(0), readaptCommand.subList(1, readaptCommand.size()));
builder.setMonitorDebugAdapter(DEBUG_READAPT.getValue());
builder.setDspParameters(Map.of(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void start() throws IOException {
private static List<String> getSolargraphCommand() {
String gemPath = GEM_PATH.getValue();
if (gemPath != null && new File(gemPath).exists()) {
return List.of(CommandHelper.getPlatformCommand("\"" + gemPath + "\" stdio"));
return CommandHelper.getPlatformCommand("\"" + gemPath + "\" stdio");
}
return List.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.core.runtime.Platform;
Expand Down Expand Up @@ -62,7 +63,7 @@ public static String findPath(String executable, boolean searchInDefaultPluginLo
return "";
}

public static String[] getAbsolutePlatformCommand(String command) {
public static List<String> getAbsolutePlatformCommand(String command) {
if (!SYSTEM_RUBY.getValue()) {
String rubyDir = RUBY_DIR.getValue();
if (rubyDir != null && !rubyDir.isEmpty()) {
Expand All @@ -72,18 +73,18 @@ public static String[] getAbsolutePlatformCommand(String command) {
return CommandHelper.getPlatformCommand(command);
}

public static String[] getPlatformCommand(String command) {
public static List<String> getPlatformCommand(String command) {
if (isWindows()) {
return new String[] { "cmd.exe", "/c", command };
return List.of("cmd.exe", "/c", command);
} else if (isMacOS()) {
String defaultShellMacOS = DEFAULT_SHELL_MACOS.get();
if (defaultShellMacOS == null) {
defaultShellMacOS = findDefaultShellMacOS();
DEFAULT_SHELL_MACOS.set(defaultShellMacOS);
}
return new String[] { defaultShellMacOS, "-c", "-li", command };
return List.of(defaultShellMacOS, "-c", "-li", command);
}
return new String[] { "bash", "-c", "-l", command };
return List.of("bash", "-c", "-l", command);
}

public static boolean isWindows() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import java.util.stream.Collectors;
Expand All @@ -26,11 +27,11 @@

public class CommandJob extends Job {

private final String[] command;
private final List<String> command;
private final String description;
private volatile Process process;

public CommandJob(String gemName, String[] command, String description) {
public CommandJob(String gemName, List<String> command, String description) {
super(gemName);
this.command = command;
this.description = description;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
package io.github.pyvesb.eclipse_solargraph.utils;

import java.io.File;
import java.util.List;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
Expand All @@ -34,7 +35,7 @@ public class GemHelper {
public static void install(String gem, StringPreferences pathPreference) {
String lowerCaseGem = gem.toLowerCase();
String command = String.format("gem install -V -n \"%s\" %s", getPluginStateLocation(), lowerCaseGem);
String[] platformCommand = CommandHelper.getPlatformCommand(command);
List<String> platformCommand = CommandHelper.getPlatformCommand(command);
CommandJob installCommandJob = new CommandJob(gem, platformCommand, "Installation in progress");

installCommandJob.addJobChangeListener(new JobChangeAdapter() {
Expand All @@ -57,7 +58,7 @@ public static void scheduleUpdate(String gem, long delay, StringPreferences path
String path = pathPreference.getValue();
String lowerCaseGem = gem.toLowerCase();
String command = String.format("gem update -V -n \"%s\" %s", path.substring(0, path.lastIndexOf(File.separator)), lowerCaseGem);
String[] plarformCommand = CommandHelper.getPlatformCommand(command);
List<String> plarformCommand = CommandHelper.getPlatformCommand(command);
new CommandJob(gem, plarformCommand, "Update in progress").schedule(delay);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.github.pyvesb.eclipse_solargraph.utils;

import java.io.File;
import java.util.List;
import java.util.concurrent.CompletableFuture;

import org.eclipse.core.runtime.CoreException;
Expand All @@ -16,10 +17,10 @@ public static Job createJob(ILaunch launch, String command, String workingDirect
}

public static Job createJob(ILaunch launch, String command, File workingDirectory) {
String[] absolutePlatformCommand = CommandHelper.getAbsolutePlatformCommand(command);
List<String> absolutePlatformCommand = CommandHelper.getAbsolutePlatformCommand(command);
return Job.create("Running '" + command + "'", r -> {
try {
Process process = DebugPlugin.exec(absolutePlatformCommand, workingDirectory);
Process process = DebugPlugin.exec(absolutePlatformCommand.toArray(new String[0]), workingDirectory);
if (process == null) {
LogHelper.cancelled("Command cancelled: " + command);
return;
Expand Down

0 comments on commit d0736a6

Please sign in to comment.