Skip to content

Commit

Permalink
Keep install jobs when finished and add job icon
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Jul 17, 2024
1 parent e1ba285 commit 8af4847
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.osgi.framework.FrameworkUtil;

public class CommandJob extends Job {

Expand All @@ -41,14 +42,15 @@ public CommandJob(String gemName, List<String> command, String description) {
protected IStatus run(IProgressMonitor monitor) {
String commandString = "'" + String.join(" ", command) + "'";
LogHelper.info("Running command " + commandString);
monitor.beginTask(description, IProgressMonitor.UNKNOWN);
monitor.beginTask(description + " in progress", IProgressMonitor.UNKNOWN);
try {
process = new ProcessBuilder(command).start();
monitorOutput(monitor, commandString);
CompletableFuture<String> error = consumeError();
int exitValue = process.waitFor();
if (exitValue == 0) {
return Status.OK_STATUS;
String pluginId = FrameworkUtil.getBundle(LogHelper.class).getSymbolicName();
return new Status(IStatus.OK, pluginId, IStatus.OK, description + " completed successfully", null);
} else {
LogHelper.error("Unexpected exit value " + exitValue + " from command " + commandString
+ System.lineSeparator() + "Error details:" + System.lineSeparator() + error.get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,22 @@
package io.github.pyvesb.eclipse_solargraph.utils;

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

import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.preference.PreferenceDialog;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.swt.widgets.Display;
import org.eclipse.ui.PartInitException;
import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.dialogs.PreferencesUtil;
import org.eclipse.ui.progress.IProgressConstants;
import org.osgi.framework.FrameworkUtil;

import io.github.pyvesb.eclipse_solargraph.preferences.PreferencePage;
Expand All @@ -36,13 +40,16 @@ public static void install(String gem, StringPreferences pathPreference) {
String lowerCaseGem = gem.toLowerCase();
String command = String.format("gem install -V -n \"%s\" %s", getPluginStateLocation(), lowerCaseGem);
List<String> platformCommand = CommandHelper.getPlatformCommand(command);
CommandJob installCommandJob = new CommandJob(gem, platformCommand, "Installation in progress");

CommandJob installCommandJob = new CommandJob(gem, platformCommand, "Gem installation");
installCommandJob.setProperty(IProgressConstants.KEEP_PROPERTY, Boolean.TRUE);
URL url = FileLocator.find(FrameworkUtil.getBundle(GemHelper.class), new Path("/icon/ruby-launch.png"));
ImageDescriptor rubyImageDescriptor = ImageDescriptor.createFromURL(url);
installCommandJob.setProperty(IProgressConstants.ICON_PROPERTY, rubyImageDescriptor);
installCommandJob.addJobChangeListener(new JobChangeAdapter() {

@Override
public void done(IJobChangeEvent event) {
if (event.getResult() == Status.OK_STATUS) {
if (event.getResult().isOK()) {
String extension = CommandHelper.isWindows() ? ".bat" : "";
String gemPath = getPluginStateLocation() + File.separator + lowerCaseGem + extension;
pathPreference.setValue(gemPath);
Expand All @@ -59,7 +66,11 @@ public static void scheduleUpdate(String gem, long delay, StringPreferences path
String lowerCaseGem = gem.toLowerCase();
String command = String.format("gem update -V -n \"%s\" %s", path.substring(0, path.lastIndexOf(File.separator)), lowerCaseGem);
List<String> plarformCommand = CommandHelper.getPlatformCommand(command);
new CommandJob(gem, plarformCommand, "Update in progress").schedule(delay);
CommandJob commandJob = new CommandJob(gem, plarformCommand, "Gem update");
URL url = FileLocator.find(FrameworkUtil.getBundle(GemHelper.class), new Path("/icon/ruby-launch.png"));
ImageDescriptor rubyImageDescriptor = ImageDescriptor.createFromURL(url);
commandJob.setProperty(IProgressConstants.ICON_PROPERTY, rubyImageDescriptor);
commandJob.schedule(delay);
}

static String getPluginStateLocation() {
Expand Down

0 comments on commit 8af4847

Please sign in to comment.