Skip to content

Commit

Permalink
Fix preview and how tests are being generated (#123)
Browse files Browse the repository at this point in the history
* Fixing preview

* Fixing adding tests
  • Loading branch information
machaval authored Aug 13, 2024
1 parent dcabbca commit 872808c
Show file tree
Hide file tree
Showing 19 changed files with 922 additions and 705 deletions.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.mule.tooling.lang.dw;

public class WeaveConstants {
public static final int MODIFICATIONS_DELAY = 500;
public static final int MODIFICATIONS_DELAY = 1000;
public static final int SERVER_TIMEOUT = 1000;
public static final int LONG_TIMEOUT = 60 * 1000; //two seconds
public static final String INTEGRATION_TEST_FOLDER_NAME = "resources";
public static final String MODULE_INTEGRATION_TEST_FOLDER_NAME = "dw";
public static final String RESOURCES_FOLDER = "resources";
public static final String TEST_FOLDER = "dw";
public static final String TEST_BASE_FOLDER_NAME = "test";
public static final String NO_SCENARIO = "No scenario";
public static final String DEFAULT_SCENARIO_NAME = "default_scenario";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
public class DevelopToolingWindowFactory implements ToolWindowFactory {
@Override
public void createToolWindowContent(@NotNull Project project, @NotNull ToolWindow toolWindow) {
toolWindow.getContentManager().addContent(ContentFactory.SERVICE.getInstance().createContent(new AstGraphToolingWindowPanel(project), "AST", false));
toolWindow.getContentManager().addContent(ContentFactory.SERVICE.getInstance().createContent(new VariableGraphToolingWindowPanel(project), "Scope Graph", false));
toolWindow.getContentManager().addContent(ContentFactory.SERVICE.getInstance().createContent(new TypeGraphToolingWindowPanel(project), "Type Graph", false));
toolWindow.getContentManager().addContent(ContentFactory.SERVICE.getInstance().createContent(new DependencyGraphToolingWindowPanel(project), "Dependency Graph", false));
toolWindow.getContentManager().addContent(ContentFactory.getInstance().createContent(new AstGraphToolingWindowPanel(project), "AST", false));
toolWindow.getContentManager().addContent(ContentFactory.getInstance().createContent(new VariableGraphToolingWindowPanel(project), "Scope Graph", false));
toolWindow.getContentManager().addContent(ContentFactory.getInstance().createContent(new TypeGraphToolingWindowPanel(project), "Type Graph", false));
toolWindow.getContentManager().addContent(ContentFactory.getInstance().createContent(new DependencyGraphToolingWindowPanel(project), "Dependency Graph", false));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,11 @@ public void checkConfiguration() throws RuntimeConfigurationException {
@Override
public List<String> getTests() {
final ArrayList<String> tests = new ArrayList<>();
if (WeaveUtils.getDWITFolder(getModule()) != null && kind.shouldRunDWIT()) {
if (WeaveUtils.getDWTestResourceFolder(getModule()) != null && kind.shouldRunDWIT()) {
tests.add("dw::test::DWITTestRunner");
}

if (WeaveUtils.getDWMITFolder(getModule()) != null && kind.shouldRunDWMIT()) {
if (WeaveUtils.getDWTestFolder(getModule()) != null && kind.shouldRunDWMIT()) {
tests.add("dw::test::DWMITTestRunner");
}

Expand All @@ -122,12 +122,12 @@ public boolean isUpdateResult() {

@Override
public void addAdditionalVMParameters(JavaParameters javaParams) {
final VirtualFile dwitFolder = WeaveUtils.getDWITFolder(getModule());
final VirtualFile dwitFolder = WeaveUtils.getDWTestResourceFolder(getModule());
if (dwitFolder != null && dwitFolder.getCanonicalPath() != null) {
javaParams.getVMParametersList().addProperty("dwitDir", dwitFolder.getCanonicalPath());
}

VirtualFile dwmitFolder = WeaveUtils.getDWMITFolder(getModule());
VirtualFile dwmitFolder = WeaveUtils.getDWTestFolder(getModule());
if (dwmitFolder != null && dwmitFolder.getCanonicalPath() != null) {
javaParams.getVMParametersList().addProperty("dwmitDir", dwmitFolder.getCanonicalPath());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ root ::= Document

Document ::= Header ('---' Body) ? | Body {
implements=["com.intellij.psi.NavigatablePsiElement" "com.intellij.psi.PsiQualifiedNamedElement"]
methods=[getPresentation getQualifiedName getName setName isMappingDocument isModuleDocument getElementIcon]
methods=[getPresentation getQualifiedName getName setName isMappingDocument isModuleDocument getElementIcon getOutput]
}

Header::= (Directive)+
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiElement;
import com.intellij.psi.PsiFile;
import com.intellij.psi.PsiFileFactory;
import com.intellij.psi.PsiParserFacade;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.NotNull;
import org.mule.tooling.lang.dw.WeaveFileType;
import org.mule.tooling.lang.dw.refactor.utils.RefactorUtils;
Expand Down Expand Up @@ -51,8 +53,9 @@ public static WeaveHeader createHeader(Project project) {

public static WeaveDocument createFile(Project project, String text) {
String name = "dummy.dwl";
return (WeaveDocument) PsiFileFactory.getInstance(project).
createFileFromText(name, WeaveFileType.getInstance(), text).getChildren()[0];
PsiFile fileFromText = PsiFileFactory.getInstance(project).
createFileFromText(name, WeaveFileType.getInstance(), text);
return PsiTreeUtil.findChildOfType(fileFromText, WeaveDocument.class);
}

public static WeaveDoExpression createDoBlock(Project project, PsiElement value) {
Expand All @@ -67,10 +70,16 @@ public static PsiElement createBlockSeparator(Project project) {

@NotNull
public static PsiElement createNewLine(Project project) {
PsiParserFacade helper = PsiParserFacade.SERVICE.getInstance(project);
PsiParserFacade helper = PsiParserFacade.getInstance(project);
return helper.createWhiteSpaceFromText("\n");
}

@NotNull
public static WeaveExpression createExpression(Project project, String text) {
WeaveDocument file = createFile(project, text);
return file.getBody().getExpression();
}

@NotNull
public static WeaveFunctionCallExpression createFunctionCall(Project project, String functionName, List<String> argNames) {
WeaveDocument file = createFile(project, functionName + "(" + StringUtil.join(argNames, ",") + ")");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ public static Icon getElementIcon(WeaveDocument document, final int flags) {
return document.isMappingDocument() ? WeaveIcons.DataWeaveMappingIcon : WeaveIcons.DataWeaveModuleIcon;
}

public static @Nullable WeaveOutputDirective getOutput(WeaveDocument weaveDocument) {
return PsiTreeUtil.findChildOfType(weaveDocument.getHeader(), WeaveOutputDirective.class);
}


public static Icon getElementIcon(WeaveFunctionDefinition functionDefinition, final int flags) {
return PlatformIcons.FUNCTION_ICON;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,16 @@ public static Collection<WeaveInputDirective> getInputTypes(WeaveDocument weaveD
return PsiTreeUtil.findChildrenOfAnyType(weaveDocument.getHeader(), WeaveInputDirective.class);
}


@Nullable
public static WeaveDocument getWeaveDocument(PsiFile psiFile) {
if (psiFile == null) {
return null;
}
PsiElement[] children = psiFile.getChildren();
if (children.length > 0) {
for (PsiElement child : children) {
if (child instanceof WeaveDocument) {
return (WeaveDocument) child;
}
for (PsiElement child : children) {
if (child instanceof WeaveDocument) {
return (WeaveDocument) child;
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ private JComponent createOutputPanel() {
public DefaultActionGroup createActions() {
DefaultActionGroup group = new DefaultActionGroup();
group.add(new SaveOutputAction());
group.add(new CreateTestAction());
group.add(showDiffAction);
return group;
}
Expand Down Expand Up @@ -139,6 +140,7 @@ public void onPreviewResult(PreviewExecutedSuccessfulEvent result, VirtualFile e
}
} else if (extension != null) {
setDocumentContent(content);
show(EDITOR_PANEL);
} else {
changePanel(new MessagePanel("Unable to render the output for extension " + extension), messagePanel, MESSAGE_PANEL);
}
Expand Down Expand Up @@ -189,6 +191,37 @@ public void close() {
this.currentFile = null;
}

private class CreateTestAction extends AnAction {


public CreateTestAction() {
super("Create Mapping Test", "Create mapping test", AllIcons.Nodes.Test);
}

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void update(@NotNull AnActionEvent e) {
super.update(e);
e.getPresentation().setEnabled(outputEditor != null);
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
WeaveDocument document = WeavePsiUtils.getWeaveDocument(currentFile);
WeaveRuntimeService manager = WeaveRuntimeService.getInstance(myProject);
Scenario currentScenario = manager.getCurrentScenarioFor(document);
if (currentScenario != null) {
manager.createTest(currentFile, currentScenario);
}
}


}

private class SaveOutputAction extends AnAction {


Expand All @@ -198,7 +231,7 @@ public SaveOutputAction() {

@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
return ActionUpdateThread.BGT;
}

@Override
Expand All @@ -211,7 +244,7 @@ public void update(@NotNull AnActionEvent e) {
public void actionPerformed(@NotNull AnActionEvent e) {
Scenario scenario = getOrCreateScenario();
String ext = outputType.getDefaultExtension();
scenario.addOutput("out." + ext, outputDocument.getText(), myProject);
scenario.addOutput(Scenario.OUTPUT_FILE_NAME + "." + ext, outputDocument.getText(), myProject);
}

private Scenario getOrCreateScenario() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.mule.tooling.lang.dw.preview;

import com.intellij.ProjectTopics;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ReadAction;
Expand Down Expand Up @@ -122,9 +121,9 @@ public void selectionChanged(@NotNull FileEditorManagerEvent e) {
}

connection[0] = myProject.getMessageBus().connect(PreviewToolWindowPanel.this);
connection[0].subscribe(ProjectTopics.PROJECT_ROOTS, new ModuleRootListener() {
connection[0].subscribe(ModuleRootListener.TOPIC, new ModuleRootListener() {
@Override
public void rootsChanged(ModuleRootEvent event) {
public void rootsChanged(@NotNull ModuleRootEvent event) {
dependenciesChanges.submit(() -> {
if (agentRuntimeManager.isWeaveRuntimeInstalled()) {
showFile(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public class WeavePreviewComponent implements Disposable {

private final Project myProject;
private PsiFile currentFile;
private boolean runOnChange = true;
private boolean runOnChange = false;

private final Alarm myDocumentAlarm = new Alarm(Alarm.ThreadToUse.POOLED_THREAD, this);
private PreviewToolWindowFactory.NameChanger nameChanger;
Expand Down Expand Up @@ -156,7 +156,7 @@ public void setSelected(@NotNull AnActionEvent e, boolean state) {
group.add(new AnAction("Run", "Execute", AllIcons.RunConfigurations.TestState.Run) {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.EDT;
return ActionUpdateThread.BGT;
}

@Override
Expand All @@ -169,6 +169,24 @@ public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(runAvailable());
}
});

group.add(new AnAction("Restart Agent", "Restart agent", AllIcons.Actions.Refresh) {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
return ActionUpdateThread.BGT;
}

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final WeaveAgentService agentComponent = WeaveAgentService.getInstance(myProject);
agentComponent.scheduleRestart();
}

@Override
public void update(@NotNull AnActionEvent e) {
e.getPresentation().setEnabled(runAvailable());
}
});
group.add(new ToggleAction("Run on Editor Changes", "Run on editor changes", AllIcons.Ide.IncomingChangesOn) {
@Override
public @NotNull ActionUpdateThread getActionUpdateThread() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public void keyReleased(KeyEvent e) {

private void validateInputName() {
String inputName = getInputName();
VirtualFile dwitFolder = manager.findOrCreateMappingTestFolder(currentFile);
VirtualFile dwitFolder = manager.findOrCreateMappingResourceFolder(currentFile);
if (dwitFolder != null) {
VirtualFile child = dwitFolder.findChild(inputName);
if (child != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public void doIntroduceFunction(@NotNull Project project, PsiFile psiFile, PsiEl
WeaveFqnIdentifier elementOfClassAtRange = PsiTreeUtil.findElementOfClassAtRange(psiFile, startOffset, endOffset, WeaveFqnIdentifier.class);
return new RenameVariable(elementOfClassAtRange, arg.getParamName());
}));
}).collect(Collectors.toList());
}).toList();

WeaveRefactorFunctionData finalWeaveRefactorFunctionData = weaveRefactorFunctionData;
simpleRefactor(() -> {
Expand Down
Loading

0 comments on commit 872808c

Please sign in to comment.