From c3681a0fefbb320489c9e0622a1ab027b6993d0a Mon Sep 17 00:00:00 2001 From: Edward Mezarina Date: Sun, 29 May 2022 20:03:03 -0400 Subject: [PATCH] Handle closed tabs due to errors or external actions. Signed-off-by: Edward Mezarina --- .../src/liberty/tools/DevModeOperations.java | 76 +++++++++++++++---- .../liberty/tools/ui/terminal/ProjectTab.java | 9 +++ .../ui/terminal/ProjectTabController.java | 19 +++++ 3 files changed, 89 insertions(+), 15 deletions(-) diff --git a/bundles/liberty/src/liberty/tools/DevModeOperations.java b/bundles/liberty/src/liberty/tools/DevModeOperations.java index ee084a63..094fa76d 100644 --- a/bundles/liberty/src/liberty/tools/DevModeOperations.java +++ b/bundles/liberty/src/liberty/tools/DevModeOperations.java @@ -92,14 +92,21 @@ public void start() { // Check if the start action has already been issued. State terminalState = projectTabController.getTerminalState(projectName); if (terminalState != null && terminalState == ProjectTab.State.STARTED) { - Dialog.displayWarningMessage( - "A start action has already been issued on project " + projectName + ". Select \"" + DashboardView.APP_MENU_ACTION_STOP - + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START + "\" on the menu."); - return; + // Check if the the terminal tab associated with this call was marked as closed. This scenario may occur if a previous + // attempt to start the server in development mode was issued successfully, but there was a failure in the process or + // there was an unexpected case that caused the terminal process to end. If that is the case, clean up the objects + // associated with the previous instance to allow users to restart development mode. + if (projectTabController.isProjectTabMarkedClosed(projectName)) { + projectTabController.cleanupTerminal(projectName); + } else { + Dialog.displayWarningMessage("A start action has already been issued on project " + projectName + ". Select \"" + + DashboardView.APP_MENU_ACTION_STOP + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START + + "\" on the menu."); + return; + } } try { - // Get the absolute path to the application project. String projectPath = Project.getPath(project); if (projectPath == null) { @@ -144,11 +151,18 @@ public void startWithParms() { // Check if the start action has already been issued. State terminalState = projectTabController.getTerminalState(projectName); if (terminalState != null && terminalState == ProjectTab.State.STARTED) { - - Dialog.displayWarningMessage( - "A start action has already been issued on project " + projectName + ". Select \"" + DashboardView.APP_MENU_ACTION_STOP - + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START_PARMS + "\" on the menu."); - return; + // Check if the the terminal tab associated with this call was marked as closed. This scenario may occur if a previous + // attempt to start the server in development mode was issued successfully, but there was a failure in the process or + // there was an unexpected case that caused the terminal process to end. If that is the case, clean up the objects + // associated with the previous instance to allow users to restart development mode. + if (projectTabController.isProjectTabMarkedClosed(projectName)) { + projectTabController.cleanupTerminal(projectName); + } else { + Dialog.displayWarningMessage("A start action has already been issued on project " + projectName + ". Select \"" + + DashboardView.APP_MENU_ACTION_STOP + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START_PARMS + + "\" on the menu."); + return; + } } try { @@ -204,11 +218,18 @@ public void startInContainer() { // Check if the start action has already been issued. State terminalState = projectTabController.getTerminalState(projectName); if (terminalState != null && terminalState == ProjectTab.State.STARTED) { - - Dialog.displayWarningMessage( - "A start action has already been issued on project " + projectName + ". Select \"" + DashboardView.APP_MENU_ACTION_STOP - + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START_IN_CONTAINER + "\" on the menu."); - return; + // Check if the the terminal tab associated with this call was marked as closed. This scenario may occur if a previous + // attempt to start the server in development mode was issued successfully, but there was a failure in the process or + // there was an unexpected case that caused the terminal process to end. If that is the case, clean up the objects + // associated with the previous instance to allow users to restart development mode. + if (projectTabController.isProjectTabMarkedClosed(projectName)) { + projectTabController.cleanupTerminal(projectName); + } else { + Dialog.displayWarningMessage("A start action has already been issued on project " + projectName + ". Select \"" + + DashboardView.APP_MENU_ACTION_STOP + "\" prior to selecting \"" + DashboardView.APP_MENU_ACTION_START_IN_CONTAINER + + "\" on the menu."); + return; + } } try { @@ -262,6 +283,18 @@ public void stop() { return; } + // Check if the the terminal tab associated with this call was marked as closed. This scenario may occur if a previous + // attempt to start the server in development mode was issued successfully, but there was a failure in the process or + // there was an unexpected case that caused the terminal process to end. Note that objects associated with the previous + // start attempt will be cleaned up on the next restart attempt. + if (projectTabController.isProjectTabMarkedClosed(projectName)) { + Dialog.displayWarningMessage("The terminal tab running project " + projectName + + " is not active due to an unexpected error or external action. Review the terminal output for more details. " + + "Once the circumstance that caused the terminal tab to be inactive is determined and resolved, " + + "select a start action on the menu prior to selecting the \"" + DashboardView.APP_MENU_ACTION_STOP + "\" action."); + return; + } + try { // Prepare the development mode command to stop the server. String cmd = "exit" + System.lineSeparator(); @@ -313,6 +346,19 @@ public void runTests() { return; } + // Check if the the terminal tab associated with this call was marked as closed. This scenario may occur if a previous + // attempt to start the server in development mode was issued successfully, but there was a failure in the process or + // there was an unexpected case that caused the terminal process to end. Note that objects associated with the previous + // start attempt will be cleaned up on the next restart attempt. + if (projectTabController.isProjectTabMarkedClosed(projectName)) { + Dialog.displayWarningMessage("The terminal tab running project " + projectName + + " is not active due to an unexpected error or external action. Review the terminal output for more details. " + + "Once the circumstance that caused the terminal tab to be inactive is determined and resolved, " + + "select a start action on the menu prior to selecting the \"" + DashboardView.APP_MENU_ACTION_RUN_TESTS + + "\" action."); + return; + } + try { // Prepare the development mode command to run a test. String cmd = System.lineSeparator(); diff --git a/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTab.java b/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTab.java index d7d88f79..ff949428 100644 --- a/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTab.java +++ b/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTab.java @@ -225,6 +225,15 @@ private CTabItem getActiveProjectTab() { return item; } + /** + * Returns the tab's title text. + * + * @return The tab's title text. + */ + public String getTitle() { + return projectTab.getText(); + } + /** * Returns the current state. * diff --git a/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTabController.java b/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTabController.java index 4968fa4f..8ad8c7e8 100644 --- a/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTabController.java +++ b/bundles/liberty/src/liberty/tools/ui/terminal/ProjectTabController.java @@ -148,6 +148,25 @@ public void setProjectConnector(String projectName, ITerminalConnector terminalC projectTabMap.put(projectName, projectTab); } + /** + * Returns true if the tab title associated with the input project name was marked as closed. False, otherwise. + * + * @param projectName The application project name. + * + * @return true if the tab title associated with the input project name was marked as closed. False, otherwise. + */ + public boolean isProjectTabMarkedClosed(String projectName) { + ProjectTab projectTab = projectTabMap.get(projectName); + if (projectTab != null) { + String tabTitle = projectTab.getTitle(); + if (tabTitle.startsWith("")) { + return true; + } + } + + return false; + } + /** * Cleans up the objects associated with the terminal object represented by the input project name. *