Skip to content

Commit

Permalink
Handle closed tabs due to errors or external actions.
Browse files Browse the repository at this point in the history
Signed-off-by: Edward Mezarina <mezarina@us.ibm.com>
  • Loading branch information
mezarin committed May 31, 2022
1 parent ca883ba commit c3681a0
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 15 deletions.
76 changes: 61 additions & 15 deletions bundles/liberty/src/liberty/tools/DevModeOperations.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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();
Expand Down
9 changes: 9 additions & 0 deletions bundles/liberty/src/liberty/tools/ui/terminal/ProjectTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("<Closed>")) {
return true;
}
}

return false;
}

/**
* Cleans up the objects associated with the terminal object represented by the input project name.
*
Expand Down

0 comments on commit c3681a0

Please sign in to comment.