Skip to content

Commit

Permalink
Clean up LaunchHelper class
Browse files Browse the repository at this point in the history
  • Loading branch information
PyvesB committed Apr 8, 2024
1 parent 18bc8d7 commit bc04d13
Showing 1 changed file with 15 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@
import java.util.concurrent.CompletableFuture;

import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.debug.core.DebugPlugin;
import org.eclipse.debug.core.ILaunch;

public class LaunchHelper {


public static Job createJob(ILaunch launch, String command, String workingDirectory) {
return createJob(launch, command, new File(workingDirectory));
}
Expand All @@ -27,32 +26,28 @@ public static Job createJob(ILaunch launch, String command, File workingDirector
}
CompletableFuture<Process> future = process.onExit();
// initialize a process completion future to log any non-zero process exit
future.defaultExecutor().execute(new Runnable() {
@Override
public void run() {
try {
if (process.isAlive()) {
process.waitFor();
}
} catch (InterruptedException e) {
LogHelper.cancelled("Process monitor interrupted: " + command);
return;
}
int exc = process.exitValue();
if (exc != 0) {
String msg = String.format("Process exited non-zero (%d): %s ", exc, command);
LogHelper.error(msg);
future.defaultExecutor().execute(() -> {
try {
if (process.isAlive()) {
process.waitFor();
}
} catch (InterruptedException e) {
LogHelper.cancelled("Process monitor interrupted: " + command);
return;
}
int exc = process.exitValue();
if (exc != 0) {
String msg = String.format("Process exited non-zero (%d): %s ", exc, command);
LogHelper.error(msg);
}

});
DebugPlugin.newProcess(launch, process, command);
} catch (CoreException e) {
// CoreException from exec
LogHelper.log(Status.ERROR, "Exception when launching process: " + command, e);
LogHelper.log(IStatus.ERROR, "Exception when launching process: " + command, e);
return;
}
});
}

};;
}

0 comments on commit bc04d13

Please sign in to comment.