Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
Signed-off-by: Scott Kurz <[email protected]>
  • Loading branch information
scottkurz committed Jul 5, 2023
1 parent bea7eb7 commit 14fbf4f
Showing 1 changed file with 21 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ public class DevModeOperations {
public static final String BROWSER_MVN_UT_REPORT_NAME_SUFFIX = "surefire report";
public static final String BROWSER_GRADLE_TEST_REPORT_NAME_SUFFIX = "test report";

private static final int STOP_TIMEOUT_SECONDS = 40;
protected static final QualifiedName STOP_JOB_COMPLETION_TIMEOUT = new QualifiedName("io.openliberty.tools.eclipse.ui",
"stopJobCompletionTimeout");
protected static final QualifiedName STOP_JOB_COMPLETION_EXIT_CODE = new QualifiedName("io.openliberty.tools.eclipse.ui",
"stopJobCompletionExitCode");
protected static final QualifiedName STOP_JOB_COMPLETION_OUTPUT = new QualifiedName("io.openliberty.tools.eclipse.ui",
"stopJobCompletionOutput");
private Map<Job, Boolean> runningJobs = new ConcurrentHashMap<Job, Boolean>();

/**
* Project terminal tab controller instance.
*/
Expand Down Expand Up @@ -779,27 +788,21 @@ public void startDevMode(String cmd, String projectName, String projectPath, Str
*/
private void handleStopActionError(String projectName, String baseMsg) {
String msg = baseMsg
+ "\n\nWould you like to issue the Liberty plugin stop command for this project to stop a Liberty server that may still be running the project outside of the Liberty Tools session?";
+ "\n\nWould you like to issue the Liberty Maven or Gradle stop command for this project to stop a Liberty server that may still be running the project outside of the Liberty Tools session?";
Integer response = ErrorHandler.processWarningMessage(msg, true, new String[] { "Yes", "No" }, 0);
if (response != null && response == 0) {
issueLPStopCommand(projectName);
}
}

final int STOP_TIMEOUT_SECONDS = 45;
final QualifiedName STOP_JOB_COMPLETION_TIMEOUT = new QualifiedName("io.openliberty.tools.eclipse.ui", "stopJobCompletionTimeout");
final QualifiedName STOP_JOB_COMPLETION_EXIT_CODE = new QualifiedName("io.openliberty.tools.eclipse.ui", "stopJobCompletionExitCode");
final QualifiedName STOP_JOB_COMPLETION_OUTPUT = new QualifiedName("io.openliberty.tools.eclipse.ui", "stopJobCompletionOutput");
private Map<Job, Boolean> runningJobs = new ConcurrentHashMap<Job, Boolean>();

/**
* Issues the Liberty plugin stop command to stop the Liberty server associated with the specified project.
*
* @param projectName The name of the project for which the the Liberty plugin stop command is issued.
*/
private void issueLPStopCommand(String projectName) {
if (Trace.isEnabled()) {
Trace.getTracer().traceExit(Trace.TRACE_TOOLS, projectName);
Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, projectName);
}

try {
Expand Down Expand Up @@ -841,10 +844,8 @@ private void issueLPStopCommand(String projectName) {
pb.environment().put("JAVA_HOME", JavaRuntime.getDefaultVMInstall().getInstallLocation().getAbsolutePath());

/*
* Note if we needed to provide better, more detailed feedback as we're stopping the job there are some starting points here.
* https://www.vogella.com/tutorials/EclipseJobs/article.html From
* https://stackoverflow.com/questions/29793071/rcp-no-progress-dialog-when-starting-a-job it seems that job.setUser(true) is no
* longer enough to result in the creation of a progress dialog.
* Per: https://stackoverflow.com/questions/29793071/rcp-no-progress-dialog-when-starting-a-job it seems that job.setUser(true)
* is no longer enough to result in the creation of a progress dialog.
*/
Job job = new Job("Stopping server via " + buildTypeName + " plugin") {

Expand All @@ -862,7 +863,7 @@ protected IStatus run(IProgressMonitor monitor) {

for (int elapsed = 0; completed == false && elapsed < STOP_TIMEOUT_SECONDS; elapsed++) {
if (monitor.isCanceled()) {
p.destroyForcibly();
p.destroy();
return Status.CANCEL_STATUS;
}
completed = p.waitFor(1, TimeUnit.SECONDS);
Expand Down Expand Up @@ -907,8 +908,8 @@ public void done(IJobChangeEvent event) {
@Override
public void run() {

String msg = "The Liberty plugin stop command issued for project " + projectName + " timed out after "
+ STOP_TIMEOUT_SECONDS + " seconds.";
String msg = "The Liberty Maven or Gradle stop command issued for project " + projectName
+ " timed out after " + STOP_TIMEOUT_SECONDS + " seconds.";
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg);
}
Expand Down Expand Up @@ -937,10 +938,8 @@ public void run() {
job.setUser(true);
runningJobs.put(job, Boolean.TRUE);
job.schedule();
} catch (

Exception e) {
String msg = "An error was detected while processing the Liberty plugin stop command on project " + projectName;
} catch (Exception e) {
String msg = "An error was detected while processing the Liberty Maven or Gradle stop command on project " + projectName;
if (Trace.isEnabled()) {
Trace.getTracer().trace(Trace.TRACE_TOOLS, msg, e);
}
Expand Down Expand Up @@ -1100,6 +1099,9 @@ public void refreshDashboardView(boolean reportError) {
}
}

/**
* Cancel running jobs and avoid error message, e.g. on closing Eclipse IDE
*/
public void cancelRunningJobs() {
runningJobs.keySet().forEach(j -> j.cancel());
}
Expand Down

0 comments on commit 14fbf4f

Please sign in to comment.