diff --git a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java index bfbd9098..3017ead1 100644 --- a/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java +++ b/bundles/io.openliberty.tools.eclipse.ui/src/io/openliberty/tools/eclipse/DevModeOperations.java @@ -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 runningJobs = new ConcurrentHashMap(); + /** * Project terminal tab controller instance. */ @@ -779,19 +788,13 @@ 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 runningJobs = new ConcurrentHashMap(); - /** * Issues the Liberty plugin stop command to stop the Liberty server associated with the specified project. * @@ -799,7 +802,7 @@ private void handleStopActionError(String projectName, String baseMsg) { */ private void issueLPStopCommand(String projectName) { if (Trace.isEnabled()) { - Trace.getTracer().traceExit(Trace.TRACE_TOOLS, projectName); + Trace.getTracer().traceEntry(Trace.TRACE_TOOLS, projectName); } try { @@ -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") { @@ -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); @@ -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); } @@ -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); } @@ -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()); }