Skip to content

Commit

Permalink
Display warning message if runs Liberty action from main Actions menu (
Browse files Browse the repository at this point in the history
…#53)

* Display warning message if user tries to start Liberty action from main Actions menu

Signed-off-by: Kathryn Kodama <[email protected]>

* Update error message

Signed-off-by: Kathryn Kodama <[email protected]>
  • Loading branch information
kathrynkodama authored Jul 13, 2021
1 parent cd1c12f commit ac45516
Show file tree
Hide file tree
Showing 11 changed files with 62 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@

public class LibertyDevCustomStartAction extends LibertyGeneralAction {

@Override
protected void executeLibertyAction() {
public LibertyDevCustomStartAction() {
setActionCmd("start Liberty dev mode with custom parameters");
}

@Override
protected void executeLibertyAction() {
String msg;
String initialVal;
if (projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

public class LibertyDevRunTestsAction extends LibertyGeneralAction {

public LibertyDevRunTestsAction() {
setActionCmd("run tests with Liberty dev mode");
}

@Override
protected void executeLibertyAction() {
setActionCmd("run tests with Liberty dev mode");
String runTestsCommand = " ";
ShellTerminalWidget widget = LibertyProjectUtil.getTerminalWidget(project, projectName, false);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,15 @@

public class LibertyDevStartAction extends LibertyGeneralAction {

public LibertyDevStartAction() {
setActionCmd("start Liberty dev mode");
}

@Override
protected void executeLibertyAction() {
setActionCmd("start Liberty dev mode");
ShellTerminalWidget widget = LibertyProjectUtil.getTerminalWidget(project, projectName, true);
String startCmd = null;

if (projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
startCmd = "mvn io.openliberty.tools:liberty-maven-plugin:dev -f \"" + buildFile.getCanonicalPath() + "\"";
} else if (projectType.equals(Constants.LIBERTY_GRADLE_PROJECT)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@

public class LibertyDevStartContainerAction extends LibertyGeneralAction {

public LibertyDevStartContainerAction() {
setActionCmd("start Liberty dev mode in a container");
}

@Override
protected void executeLibertyAction() {
setActionCmd("start Liberty dev mode in a container");
String startCmd = null;
if (projectType.equals(Constants.LIBERTY_MAVEN_PROJECT)) {
startCmd = "mvn io.openliberty.tools:liberty-maven-plugin:devc -f \"" + buildFile.getCanonicalPath() + "\"";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,12 @@

public class LibertyDevStopAction extends LibertyGeneralAction {

public LibertyDevStopAction() {
setActionCmd("stop Liberty dev mode");
}

@Override
protected void executeLibertyAction() {
setActionCmd("stop Liberty dev mode");
ShellTerminalWidget widget = LibertyProjectUtil.getTerminalWidget(project, projectName, false);
String stopCmd = "q";
if (widget == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
package io.openliberty.tools.intellij.actions;

import com.intellij.notification.Notification;
import com.intellij.notification.NotificationListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import io.openliberty.tools.intellij.LibertyPluginIcons;
import io.openliberty.tools.intellij.util.Constants;
import io.openliberty.tools.intellij.util.LibertyProjectUtil;
import org.jetbrains.annotations.NotNull;
Expand All @@ -22,19 +27,22 @@ public class LibertyGeneralAction extends AnAction {
public void actionPerformed(@NotNull AnActionEvent e) {
project = LibertyProjectUtil.getProject(e.getDataContext());
if (project == null) {
log.debug("Unable to " + actionCmd + ", could not resolve project");
String msg = "Unable to " + actionCmd + ": Could not resolve project. Ensure you run the Liberty action from the Liberty tool window";
notifyError(msg);
log.debug(msg);
return;
}

buildFile = (VirtualFile) e.getDataContext().getData(Constants.LIBERTY_BUILD_FILE);
if (buildFile == null) {
log.debug("Unable to " + actionCmd + ", could not resolve configuration file for " + project.getName());
String msg = "Unable to " + actionCmd + ": Could not resolve configuration file for " + project.getName() + ". Ensure you run the Liberty action from the Liberty tool window";
notifyError(msg);
log.debug(msg);
return;
}

projectName = (String) e.getDataContext().getData(Constants.LIBERTY_PROJECT_NAME);
projectType = (String) e.getDataContext().getData(Constants.LIBERTY_PROJECT_TYPE);

executeLibertyAction();
}

Expand All @@ -46,5 +54,15 @@ protected void executeLibertyAction() {
// must be implemented by individual actions
}

protected void notifyError(String errMsg) {
Notification notif = new Notification("Liberty"
, LibertyPluginIcons.libertyIcon
, "Liberty action was not able to start"
, ""
, errMsg
, NotificationType.WARNING
, NotificationListener.URL_OPENING_LISTENER);
Notifications.Bus.notify(notif, project);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@

public class ViewEffectivePom extends LibertyGeneralAction {

public ViewEffectivePom() {
setActionCmd("view effective POM");
}

@Override
protected void executeLibertyAction() {
setActionCmd("view effective POM");
// open build file
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, buildFile), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@

public class ViewGradleConfig extends LibertyGeneralAction {

@Override
protected void executeLibertyAction() {
public ViewGradleConfig() {
setActionCmd("view Gradle configuration file");
}

@Override
protected void executeLibertyAction() {
// open build file
FileEditorManager.getInstance(project).openTextEditor(new OpenFileDescriptor(project, buildFile), true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@

public class ViewIntegrationTestReport extends LibertyGeneralAction {

@Override
protected void executeLibertyAction() {
public ViewIntegrationTestReport() {
setActionCmd("view integration test report");
}

@Override
protected void executeLibertyAction() {
// get path to project folder
final VirtualFile parentFile = buildFile.getParent();
File failsafeReportFile = Paths.get(parentFile.getCanonicalPath(), "target", "site", "failsafe-report.html").normalize().toAbsolutePath().toFile();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@

public class ViewTestReport extends LibertyGeneralAction {

public ViewTestReport() {
setActionCmd("view Gradle test report");
}

@Override
protected void executeLibertyAction() {
setActionCmd("view Gradle test report");
// get path to project folder
final VirtualFile parentFile = buildFile.getParent();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,12 @@

public class ViewUnitTestReport extends LibertyGeneralAction {

public ViewUnitTestReport() {
setActionCmd("view unit test report");
}

@Override
protected void executeLibertyAction() {
setActionCmd("view unit test report");
// get path to project folder
final VirtualFile parentFile = buildFile.getParent();
File surefireReportFile = Paths.get(parentFile.getCanonicalPath(), "target", "site", "surefire-report.html").normalize().toAbsolutePath().toFile();
Expand Down

0 comments on commit ac45516

Please sign in to comment.