Skip to content

Commit

Permalink
Fixing debugger when running testing framework (#124)
Browse files Browse the repository at this point in the history
  • Loading branch information
machaval authored Sep 30, 2024
1 parent 872808c commit f80bb26
Show file tree
Hide file tree
Showing 19 changed files with 154 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.intellij.openapi.project.Project;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.als.component.ALSLanguageService;
import org.mule.tooling.commons.AnypointNotification;

public class RestartALSServerAction extends AnAction {

Expand All @@ -27,7 +28,7 @@ public void actionPerformed(@NotNull AnActionEvent e) {
Project project = e.getProject();
if (project != null) {
ALSLanguageService.getInstance(project).restart();
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "ALS server restarted", "The ALS server was restarted successfully.", NotificationType.INFORMATION));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "ALS server restarted", "The ALS server was restarted successfully.", NotificationType.INFORMATION));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,13 @@
import com.intellij.util.Alarm;
import com.intellij.util.concurrency.AppExecutorUtil;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mule.tooling.als.settings.DialectsRegistry;
import org.mule.tooling.als.utils.LSPUtils;
import org.mule.tooling.commons.AnypointNotification;
import org.mule.tooling.lang.dw.util.ScalaUtils;
import org.mulesoft.als.logger.PrintLnLogger$;
import org.mulesoft.als.server.EmptyJvmSerializationProps$;
Expand Down Expand Up @@ -353,7 +354,7 @@ private void scheduleUpdateDialect(VirtualFileEvent event, ALSLanguageExtension.
return;
}
registerDialect(value);
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Updating dialect", "Dialect '" + event.getFileName() + "' was updated as changes where detected.", NotificationType.INFORMATION));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Updating dialect", "Dialect '" + event.getFileName() + "' was updated as changes where detected.", NotificationType.INFORMATION));
}, 500);
}

Expand Down Expand Up @@ -383,9 +384,9 @@ private void registerDialect(ALSLanguageExtension.Dialect supportedLanguage) {
try {
Future<Object> objectFuture = languageServer.workspaceService().executeCommand(executeCommandParams);
resultOf(objectFuture);
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Dialect registered successfully", "Dialect '" + supportedLanguage.getDialectUrl() + "' was registered.", NotificationType.INFORMATION));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Dialect registered successfully", "Dialect '" + supportedLanguage.getDialectUrl() + "' was registered.", NotificationType.INFORMATION));
} catch (Exception e) {
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Unable to register dialect", "Unable to register dialect `" + supportedLanguage.getDialectUrl() + "`\nReason:\n" + e.getMessage(), NotificationType.ERROR));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Unable to register dialect", "Unable to register dialect `" + supportedLanguage.getDialectUrl() + "`\nReason:\n" + e.getMessage(), NotificationType.ERROR));
}
}

Expand All @@ -402,7 +403,7 @@ public void registerUserDefinedDialects() {
String dialectUrl = dialect.get().getDialectUrl();
try {
if (new File(new URI(dialectUrl)).exists() && !dialectUrl.isBlank()) {
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Registering dialect", "Dialect '" + dialectLocation.getName() + "'.", NotificationType.INFORMATION));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Registering dialect", "Dialect '" + dialectLocation.getName() + "'.", NotificationType.INFORMATION));
registerDialect(dialect.get());
//If file doesn't exists don't register it
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.Nullable;
import org.mule.tooling.commons.AnypointNotification;
import org.mulesoft.lsp.feature.common.Position;
import org.mulesoft.lsp.feature.common.TextDocumentIdentifier;
import scala.concurrent.Await;
Expand Down Expand Up @@ -42,7 +43,7 @@ public static <T> Optional<T> resultOf(Future<T> objectFuture) {
try {
return Optional.of(Await.result(objectFuture, Duration.apply(30, TimeUnit.SECONDS)));
} catch (InterruptedException | TimeoutException e) {
Notifications.Bus.notify(new Notification(Notifications.SYSTEM_MESSAGES_GROUP_ID, "Error while executing future", "Unable to execute ALS Future. Reason: \n" + e.getMessage(), NotificationType.ERROR));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Error while executing future", "Unable to execute ALS Future. Reason: \n" + e.getMessage(), NotificationType.ERROR));
return Optional.empty();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.bat.testintegration.BatTestFramework;
import org.mule.tooling.bat.utils.BatUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import com.intellij.psi.PsiFile;
import com.intellij.psi.search.FilenameIndex;
import com.intellij.psi.search.GlobalSearchScope;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.launcher.configuration.runner.WeaveCommandLineState;
import org.mule.tooling.lang.dw.launcher.configuration.runner.WeaveRunnerHelper;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.mule.tooling.commons;

public class AnypointNotification {

public static String ANYPOINT_NOTIFICATION = "AnypointNotification";
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.ui.components.JBScrollPane;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.mule.tooling.commons.AnypointNotification;
import org.mule.tooling.lang.dw.WeaveFileType;
import org.mule.tooling.lang.dw.settings.DataWeaveSettingsState;

Expand Down Expand Up @@ -105,7 +106,7 @@ Image runDot(String dot) {
final int err = p.waitFor();
return ImageIO.read(imageFile);
} catch (Exception e) {
Notifications.Bus.notify(new Notification("Data Weave", "Unable to run dot cmd", "Unable to run dot command line from '" + cmdPath + "'", NotificationType.ERROR));
Notifications.Bus.notify(new Notification(AnypointNotification.ANYPOINT_NOTIFICATION, "Unable to run dot cmd", "Unable to run dot command line from '" + cmdPath + "'", NotificationType.ERROR));
return null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,7 @@

import com.intellij.execution.ExecutionException;
import com.intellij.execution.Executor;
import com.intellij.execution.configurations.ConfigurationFactory;
import com.intellij.execution.configurations.JavaRunConfigurationModule;
import com.intellij.execution.configurations.ModuleBasedConfiguration;
import com.intellij.execution.configurations.ModuleRunProfile;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.RunConfigurationWithSuppressedDefaultDebugAction;
import com.intellij.execution.configurations.RunProfileState;
import com.intellij.execution.configurations.RuntimeConfigurationException;
import com.intellij.execution.configurations.*;
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.module.Module;
import com.intellij.openapi.module.ModuleManager;
Expand All @@ -19,7 +12,6 @@
import com.intellij.openapi.util.InvalidDataException;
import com.intellij.openapi.util.JDOMExternalizerUtil;
import com.intellij.openapi.util.WriteExternalException;
import org.apache.commons.lang.StringUtils;
import org.jdom.Element;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -28,107 +20,109 @@
import java.util.Arrays;
import java.util.Collection;

public class WeaveConfiguration extends ModuleBasedConfiguration implements ModuleRunProfile, RunConfigurationWithSuppressedDefaultDebugAction, WeaveBasedConfiguration {

public static final String PREFIX = "DataWeaveConfig-";
public static final String WEAVE_NAME_IDENTIFIER = PREFIX + "WeaveNameIdentifier";
public static final String WEAVE_SCENARIO = PREFIX + "WeaveScenario";
public static final String WEAVE_OUTPUT = PREFIX + "WeaveOutput";


private Project project;
private String nameIdentifier;
private String scenario;
private String outputPath;


protected WeaveConfiguration(String name, @NotNull ConfigurationFactory factory, Project project) {
super(name, new JavaRunConfigurationModule(project, true), factory);
this.project = project;
}


@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new WeaveRunnerEditor(this);
}

@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
return new WeaveRunnerCommandLine(executionEnvironment, this);
}

@Override
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
this.nameIdentifier = JDOMExternalizerUtil.readField(element, WEAVE_NAME_IDENTIFIER);
this.scenario = JDOMExternalizerUtil.readField(element, WEAVE_SCENARIO);
this.outputPath = JDOMExternalizerUtil.readField(element, WEAVE_OUTPUT);
getConfigurationModule().readExternal(element);
}


@Override
public void writeExternal(Element element) throws WriteExternalException {
super.writeExternal(element);
// Stores the values of this class into the parent
JDOMExternalizerUtil.writeField(element, WEAVE_NAME_IDENTIFIER, this.getNameIdentifier());
JDOMExternalizerUtil.writeField(element, WEAVE_SCENARIO, this.getScenario());
JDOMExternalizerUtil.writeField(element, WEAVE_OUTPUT, this.getOutputPath());
getConfigurationModule().writeExternal(element);
}

@Override
public Collection<Module> getValidModules() {
final ModuleManager moduleManager = ModuleManager.getInstance(this.project);
return Arrays.asList(moduleManager.getModules());
}


@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (getModule() == null) {
throw new RuntimeConfigurationException("Module can not be empty.");
import static org.apache.commons.lang3.StringUtils.isBlank;

public class WeaveConfiguration extends ModuleBasedConfiguration<JavaRunConfigurationModule, Element> implements ModuleRunProfile, RunConfigurationWithSuppressedDefaultDebugAction, WeaveBasedConfiguration {

public static final String PREFIX = "DataWeaveConfig-";
public static final String WEAVE_NAME_IDENTIFIER = PREFIX + "WeaveNameIdentifier";
public static final String WEAVE_SCENARIO = PREFIX + "WeaveScenario";
public static final String WEAVE_OUTPUT = PREFIX + "WeaveOutput";


private Project project;
private String nameIdentifier;
private String scenario;
private String outputPath;


protected WeaveConfiguration(String name, @NotNull ConfigurationFactory factory, Project project) {
super(name, new JavaRunConfigurationModule(project, true), factory);
this.project = project;
}


@NotNull
@Override
public SettingsEditor<? extends RunConfiguration> getConfigurationEditor() {
return new WeaveRunnerEditor(this);
}

@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull ExecutionEnvironment executionEnvironment) throws ExecutionException {
return new WeaveRunnerCommandLine(executionEnvironment, this);
}

@Override
public void readExternal(Element element) throws InvalidDataException {
super.readExternal(element);
this.nameIdentifier = JDOMExternalizerUtil.readField(element, WEAVE_NAME_IDENTIFIER);
this.scenario = JDOMExternalizerUtil.readField(element, WEAVE_SCENARIO);
this.outputPath = JDOMExternalizerUtil.readField(element, WEAVE_OUTPUT);
getConfigurationModule().readExternal(element);
}


@Override
public void writeExternal(Element element) throws WriteExternalException {
super.writeExternal(element);
// Stores the values of this class into the parent
JDOMExternalizerUtil.writeField(element, WEAVE_NAME_IDENTIFIER, this.getNameIdentifier());
JDOMExternalizerUtil.writeField(element, WEAVE_SCENARIO, this.getScenario());
JDOMExternalizerUtil.writeField(element, WEAVE_OUTPUT, this.getOutputPath());
getConfigurationModule().writeExternal(element);
}

if (StringUtils.isBlank(getNameIdentifier())) {
throw new RuntimeConfigurationException(getNameIdentifier() + " weave name identifier can not be empty.");
@Override
public Collection<Module> getValidModules() {
final ModuleManager moduleManager = ModuleManager.getInstance(this.project);
return Arrays.asList(moduleManager.getModules());
}
super.checkConfiguration();
}

public String getNameIdentifier() {
return nameIdentifier;
}

public void setNameIdentifier(String nameIdentifier) {
this.nameIdentifier = nameIdentifier;
}
@Override
public void checkConfiguration() throws RuntimeConfigurationException {
if (getModule() == null) {
throw new RuntimeConfigurationException("Module can not be empty.");
}

if (isBlank(getNameIdentifier())) {
throw new RuntimeConfigurationException(getNameIdentifier() + " weave name identifier can not be empty.");
}
super.checkConfiguration();
}

public String getNameIdentifier() {
return nameIdentifier;
}

public void setNameIdentifier(String nameIdentifier) {
this.nameIdentifier = nameIdentifier;
}

public String getScenario() {
return scenario;
}
public String getScenario() {
return scenario;
}

public String getOutputPath() {
return outputPath;
}
public String getOutputPath() {
return outputPath;
}

public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}
public void setOutputPath(String outputPath) {
this.outputPath = outputPath;
}

public void setScenario(String scenario) {
this.scenario = scenario;
}
public void setScenario(String scenario) {
this.scenario = scenario;
}

public Module getModule() {
return getConfigurationModule().getModule();
}
public Module getModule() {
return getConfigurationModule().getModule();
}

@Override
public String getWorkingDirectory() {
return project.getBasePath();
}
@Override
public String getWorkingDirectory() {
return project.getBasePath();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import com.intellij.openapi.util.Ref;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang3.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.launcher.configuration.ui.test.WeaveTestConfigurationType;
import org.mule.tooling.lang.dw.parser.psi.WeaveDocument;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.intellij.execution.runners.ExecutionEnvironment;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.vfs.VirtualFile;
import org.apache.commons.lang.StringUtils;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.launcher.configuration.WeaveConfiguration;
import org.mule.tooling.lang.dw.service.Scenario;
Expand All @@ -14,6 +13,9 @@
import org.mule.weave.v2.parser.ast.variables.NameIdentifier;
import scala.Option;

import static org.apache.commons.lang3.StringUtils.isBlank;
import static org.apache.commons.lang3.StringUtils.isNotBlank;

public class WeaveRunnerCommandLine extends WeaveCommandLineState {

//Mule Main Class
Expand All @@ -37,7 +39,7 @@ protected JavaParameters createJavaParameters() {
javaParams.getProgramParametersList().add("-debug");
}
final String scenario = model.getScenario();
if (!StringUtils.isBlank(scenario)) {
if (!isBlank(scenario)) {
VirtualFile resolve = VirtualFileSystemUtils.resolve(model.getModule(), NameIdentifier.apply(model.getNameIdentifier(), Option.<String>empty()));
if (resolve != null) {
final WeaveRuntimeService instance = WeaveRuntimeService.getInstance(project);
Expand All @@ -50,11 +52,11 @@ protected JavaParameters createJavaParameters() {

//Set user.dir to module home
final String workingDirectory = model.getWorkingDirectory();
if (StringUtils.isNotBlank(workingDirectory)) {
if (isNotBlank(workingDirectory)) {
javaParams.getVMParametersList().addProperty("user.dir", workingDirectory);
}

if (StringUtils.isNotBlank(model.getOutputPath())) {
if (isNotBlank(model.getOutputPath())) {
javaParams.getProgramParametersList().add("-output", model.getOutputPath());
}

Expand Down
Loading

0 comments on commit f80bb26

Please sign in to comment.