From f3be74273273df9c45ec4072f2cb3ebcb2cb56de Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Thu, 21 Jan 2021 09:40:33 +0200 Subject: [PATCH 01/11] 3.1.1 initial --- .github/workflows/gradle.yml | 2 +- CHANGELOG.md | 2 ++ build.gradle | 2 +- resources/META-INF/plugin.xml | 2 +- 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 912bc36b5..903b63260 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 3.1.0-develop ] + branches: [ master, 3.1.1-develop ] jobs: build-linux: diff --git a/CHANGELOG.md b/CHANGELOG.md index da21cd146..d72b36750 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,8 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). +## 3.1.1 + ## 3.1.0 ## 3.0.4 diff --git a/build.gradle b/build.gradle index 44045f4f1..09bebeaf5 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ repositories { } group 'com.magento.idea' -version '3.1.0' +version '3.1.1' apply plugin: 'org.jetbrains.intellij' apply plugin: 'java' diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 35d9f7eb1..fe9f0684e 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -7,7 +7,7 @@ com.magento.idea.magento2plugin Magento PhpStorm - 3.1.0 + 3.1.1 Magento Inc. Date: Fri, 22 Jan 2021 10:58:44 +0200 Subject: [PATCH 02/11] 3.1.0 changelog, fixed forms --- CHANGELOG.md | 11 +- .../actions/generation/NewDbSchemaAction.java | 2 +- .../dialog/NewMessageQueueDialog.form | 189 +++++++++--------- .../dialog/NewMessageQueueDialog.java | 3 +- 4 files changed, 101 insertions(+), 104 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d72b36750..f33da7cd6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,12 +2,17 @@ All notable changes to this project will be documented in this file. -The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). - -## 3.1.1 +The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). ## 3.1.0 +### Added + +- Code generation for message queue in [#411](https://github.com/magento/magento2-phpstorm-plugin/pull/411) +- Code generation for declarative schema [#453](https://github.com/magento/magento2-phpstorm-plugin/pull/453) +- Inspection warning for disabled observer [#432](https://github.com/magento/magento2-phpstorm-plugin/pull/432) +- The action item to the context menu to copy file path in the Magento format [#451](https://github.com/magento/magento2-phpstorm-plugin/pull/451) + ## 3.0.4 ### Fixed diff --git a/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java b/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java index aeb6e8ff8..f2a76930f 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/NewDbSchemaAction.java @@ -18,7 +18,7 @@ import org.jetbrains.annotations.NotNull; public class NewDbSchemaAction extends AnAction { - public static final String ACTION_NAME = "Declarative Schema XML"; + public static final String ACTION_NAME = "Magento 2 Declarative Schema XML"; public static final String ACTION_DESCRIPTION = "Create a new declarative schema XML"; /** diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form index 852059489..2de4e08ce 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form @@ -1,18 +1,17 @@
- + - + - - + @@ -89,14 +88,6 @@ - - - - - - - - @@ -105,38 +96,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -153,103 +112,137 @@ - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + + + + + + + + + - + + + + + + + + + - + - + - - - + - + + + - + - + - + - + - + - + - - - - - - - - - - - - - - - - - + - + - - - - - - - - - - - - - - - - - - - - - + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index fa108e58e..24107d59b 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -7,7 +7,6 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; -import com.magento.idea.magento2plugin.actions.generation.NewDataModelAction; import com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction; import com.magento.idea.magento2plugin.actions.generation.data.QueueCommunicationData; import com.magento.idea.magento2plugin.actions.generation.data.QueueConsumerData; @@ -143,7 +142,7 @@ public NewMessageQueueDialog(final Project project, final PsiDirectory directory setContentPane(contentPanel); setModal(true); - setTitle(NewDataModelAction.ACTION_DESCRIPTION); + setTitle(NewMessageQueueAction.ACTION_DESCRIPTION); getRootPane().setDefaultButton(buttonOK); buttonOK.addActionListener((final ActionEvent event) -> onOK()); From 3146290bd59eb453556b9baaf3c1f09b0b426727 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Fri, 22 Jan 2021 16:52:34 +0200 Subject: [PATCH 03/11] Fixed form for Message Queue --- README.md | 1 + .../dialog/NewMessageQueueDialog.form | 133 ++++++++++++------ .../dialog/NewMessageQueueDialog.java | 100 +++++++++---- .../packages/MessageQueueConnections.java | 59 ++++++++ 4 files changed, 229 insertions(+), 64 deletions(-) create mode 100644 src/com/magento/idea/magento2plugin/magento/packages/MessageQueueConnections.java diff --git a/README.md b/README.md index c03a8415e..f9a9616ee 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ [![Version](http://phpstorm.espend.de/badge/8024/version)](https://plugins.jetbrains.com/plugin/8024) [![Downloads](http://phpstorm.espend.de/badge/8024/downloads)](https://plugins.jetbrains.com/plugin/8024) ![merge-chance-badge](https://img.shields.io/endpoint?url=https%3A%2F%2Fmerge-chance.info%2Fbadge%3Frepo%3Dmagento/magento2-phpstorm-plugin) +[![Made With Love](https://img.shields.io/badge/Made%20With-Love-orange.svg)](https://magento.com) ## Installation diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form index 2de4e08ce..a4576a2e6 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form @@ -11,7 +11,7 @@ - + @@ -19,28 +19,6 @@ - - - - - - - - - - - - - - - - - - - - - - @@ -64,25 +42,28 @@ - + - + - + + - + - + - + + + - + @@ -90,27 +71,88 @@ - + - + + - + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -155,7 +197,7 @@ - + @@ -169,7 +211,9 @@ - + + + @@ -179,7 +223,7 @@ - + @@ -201,7 +245,9 @@ - + + + @@ -217,7 +263,9 @@ - + + + @@ -243,6 +291,11 @@ + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 24107d59b..9be596f8c 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -7,6 +7,7 @@ import com.intellij.openapi.project.Project; import com.intellij.psi.PsiDirectory; +import com.intellij.ui.DocumentAdapter; import com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction; import com.magento.idea.magento2plugin.actions.generation.data.QueueCommunicationData; import com.magento.idea.magento2plugin.actions.generation.data.QueueConsumerData; @@ -25,16 +26,19 @@ import com.magento.idea.magento2plugin.actions.generation.generator.QueueConsumerGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueuePublisherGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueueTopologyGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; +import com.magento.idea.magento2plugin.magento.files.ModelPhp; +import com.magento.idea.magento2plugin.ui.FilteredComboBox; +import com.magento.idea.magento2plugin.magento.packages.MessageQueueConnections; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; +import org.jetbrains.annotations.NotNull; + import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import javax.swing.JButton; -import javax.swing.JComponent; -import javax.swing.JPanel; -import javax.swing.JTextField; -import javax.swing.KeyStroke; +import javax.swing.*; +import javax.swing.event.DocumentEvent; @SuppressWarnings({ "PMD.TooManyFields", @@ -48,11 +52,12 @@ public class NewMessageQueueDialog extends AbstractDialog { private static final String QUEUE_NAME = "Queue Name"; private static final String CONSUMER_TYPE = "Consumer Type"; private static final String MAX_MESSAGES = "Maximum Messages"; - private static final String CONNECTION_NAME = "Connection Name"; private static final String EXCHANGE_NAME = "Exchange Name"; private static final String BINDING_ID = "Binding ID"; private static final String BINDING_TOPIC = "Binding Topic"; + private FilteredComboBox connectionName; + /* TODO: Improve validation */ @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, TOPIC_NAME}) @@ -64,15 +69,15 @@ public class NewMessageQueueDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, HANDLER_NAME}) - @FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE, + @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, message = {AlphanumericWithUnderscoreRule.MESSAGE, HANDLER_NAME}) private JTextField handlerName; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, HANDLER_TYPE}) - @FieldValidation(rule = RuleRegistry.PHP_CLASS_FQN, + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassFqnRule.MESSAGE, HANDLER_TYPE}) - private JTextField handlerType; + private JTextField handlerClass; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONSUMER_NAME}) @@ -92,9 +97,9 @@ public class NewMessageQueueDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, CONSUMER_TYPE}) - @FieldValidation(rule = RuleRegistry.PHP_CLASS_FQN, + @FieldValidation(rule = RuleRegistry.PHP_CLASS, message = {PhpClassFqnRule.MESSAGE, CONSUMER_TYPE}) - private JTextField consumerType; + private JTextField consumerClass; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, MAX_MESSAGES}) @@ -102,11 +107,6 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {NumericRule.MESSAGE, MAX_MESSAGES}) private JTextField maxMessages; - // TODO: Can this be made a dropdown? - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, - message = {NotEmptyRule.MESSAGE, CONNECTION_NAME}) - private JTextField connectionName; - @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, EXCHANGE_NAME}) @FieldValidation(rule = RuleRegistry.ALPHA_WITH_DASH, @@ -119,14 +119,19 @@ public class NewMessageQueueDialog extends AbstractDialog { message = {AlphaWithDashRule.MESSAGE, BINDING_ID}) private JTextField bindingId; - // TODO: New validation rule @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, BINDING_TOPIC}) private JTextField bindingTopic; + private JTextField consumerDirectory; + private JTextField handlerDirectory; + private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; + private JLabel handlerDirectoryLabel; + private JLabel handlerClassLabel; + private JLabel consumerDirectoryLabel; private final Project project; private final String moduleName; @@ -163,6 +168,19 @@ public void windowClosing(final WindowEvent event) { KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT ); + + this.topicName.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + updateIndefiersTextes(); + } + }); + this.handlerClass.getDocument().addDocumentListener(new DocumentAdapter() { + @Override + protected void textChanged(final @NotNull DocumentEvent event) { + updateBindingText(); + } + }); } /** @@ -194,7 +212,7 @@ private void generateCommunication() { new QueueCommunicationGenerator(project, new QueueCommunicationData( getTopicName(), getHandlerName(), - getHandlerType(), + getHandlerClass(), getHandlerMethod(), getModuleName() )).generate(NewMessageQueueAction.ACTION_NAME, true); @@ -204,7 +222,7 @@ private void generateConsumer() { new QueueConsumerGenerator(project, new QueueConsumerData( getConsumerName(), getQueueName(), - getConsumerType(), + getConsumerClass(), getMaxMessages(), getConnectionName(), getModuleName() @@ -239,8 +257,12 @@ public String getHandlerName() { return handlerName.getText().trim(); } - public String getHandlerType() { - return handlerType.getText().trim(); + public String getHandlerClass() { + return new NamespaceBuilder( + getModuleName(), + handlerClass.getText().trim(), + handlerDirectory.getText().trim() + ).getClassFqn(); } public String getHandlerMethod() { @@ -255,8 +277,12 @@ public String getQueueName() { return queueName.getText().trim(); } - public String getConsumerType() { - return consumerType.getText().trim(); + public String getConsumerClass() { + return new NamespaceBuilder( + getModuleName(), + consumerClass.getText().trim(), + consumerDirectory.getText().trim() + ).getClassFqn(); } public String getMaxMessages() { @@ -264,7 +290,7 @@ public String getMaxMessages() { } public String getConnectionName() { - return connectionName.getText().trim(); + return connectionName.getSelectedItem().toString(); } public String getExchangeName() { @@ -282,4 +308,30 @@ public String getBindingTopic() { public String getModuleName() { return moduleName; } + + /** + * Update identifier texts. + */ + public void updateIndefiersTextes() { + final String topicNameText = this.topicName.getText(); + this.handlerName.setText(topicNameText.concat(".handler")); + this.consumerName.setText(topicNameText); + this.queueName.setText(topicNameText); + } + + /** + * Update identifier texts. + */ + public void updateBindingText() { + final String handlerTypeText = this.handlerClass.getText(); + this.consumerClass.setText(handlerTypeText.replace("Handler", "").concat("Consumer")); + this.bindingId.setText(handlerTypeText.replace("Handler", "").concat("Binding")); + } + + @SuppressWarnings({"PMD.UnusedPrivateMethod"}) + private void createUIComponents() { + this.connectionName = new FilteredComboBox( + MessageQueueConnections.getList() + ); + } } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/MessageQueueConnections.java b/src/com/magento/idea/magento2plugin/magento/packages/MessageQueueConnections.java new file mode 100644 index 000000000..e3683914b --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/packages/MessageQueueConnections.java @@ -0,0 +1,59 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.packages; + +import java.util.ArrayList; +import java.util.List; + +public enum MessageQueueConnections { + DB("db"), + AMPQ("ampq"); + + private final String type; + + /** + * Queue connection constructor. + * + * @param type String + */ + MessageQueueConnections(final String type) { + this.type = type; + } + + /** + * Get connection type. + * + * @return String + */ + public String getType() { + return type; + } + + /** + * Get connection type by name. + * + * @param typeName type name + * @return Request Interface + */ + public static String getConnectionTypeByName(final String typeName) { + return MessageQueueConnections.valueOf(typeName).getType(); + } + + /** + * Get list of connection types. + * + * @return List connection types. + */ + public static List getList() { + final List typeList = new ArrayList<>(); + + for (final MessageQueueConnections type: MessageQueueConnections.values()) { + typeList.add(getConnectionTypeByName(type.name())); + } + + return typeList; + } +} From 2bf4a7e1786200066b13ee0c78068742c345e650 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Mon, 25 Jan 2021 09:41:38 +0200 Subject: [PATCH 04/11] Fixed form for Message Queue 2 --- .../dialog/NewMessageQueueDialog.form | 32 ++++++++++++++----- .../dialog/NewMessageQueueDialog.java | 1 + 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form index a4576a2e6..be0f45a43 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.form @@ -197,7 +197,7 @@ - + @@ -225,7 +225,7 @@ - + @@ -233,7 +233,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -251,7 +251,7 @@ - + @@ -259,7 +259,7 @@ - + @@ -269,7 +269,7 @@ - + @@ -293,9 +293,25 @@ - + + + + + + + + + + + + + + + + + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 9be596f8c..28d727ae1 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -132,6 +132,7 @@ public class NewMessageQueueDialog extends AbstractDialog { private JLabel handlerDirectoryLabel; private JLabel handlerClassLabel; private JLabel consumerDirectoryLabel; + private JLabel bindingTopicLabel; private final Project project; private final String moduleName; From 931bff89b138b3b9e5b82fd5d320e81625aaa971 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sun, 31 Jan 2021 18:25:28 +0200 Subject: [PATCH 05/11] Fixed Queue generation and form --- ...agento Message Queue Consumer Class.php.ft | 16 ++ ...ento Message Queue Consumer Class.php.html | 0 ...Magento Message Queue Handler Class.php.ft | 14 ++ ...gento Message Queue Handler Class.php.html | 1 + .../data/MessageQueueClassData.java | 85 +++++++++ .../generation/data/QueueConsumerData.java | 11 +- .../dialog/NewMessageQueueDialog.form | 178 +++++++++--------- .../dialog/NewMessageQueueDialog.java | 127 ++++++++++--- .../generator/MessageQueueClassGenerator.java | 145 ++++++++++++++ .../generator/QueueConsumerGenerator.java | 10 +- .../magento/files/MessageQueueClassPhp.java | 63 +++++++ .../generateConsumer/MyConsumer.php | 13 ++ .../generateHandler/MyHandler.php | 11 ++ .../queue_consumer.xml | 5 + .../queue_consumer.xml | 2 +- .../MessageQueueClassGeneratorTest.java | 87 +++++++++ .../generator/QueueConsumerGeneratorTest.java | 38 +++- 17 files changed, 677 insertions(+), 129 deletions(-) create mode 100644 resources/fileTemplates/internal/Magento Message Queue Consumer Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Message Queue Consumer Class.php.html create mode 100644 resources/fileTemplates/internal/Magento Message Queue Handler Class.php.ft create mode 100644 resources/fileTemplates/internal/Magento Message Queue Handler Class.php.html create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/data/MessageQueueClassData.java create mode 100644 src/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGenerator.java create mode 100644 src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java create mode 100644 testData/actions/generation/generator/MessageQueueClassGenerator/generateConsumer/MyConsumer.php create mode 100644 testData/actions/generation/generator/MessageQueueClassGenerator/generateHandler/MyHandler.php create mode 100644 testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerAmpqXmlFile/queue_consumer.xml rename testData/actions/generation/generator/QueueConsumerGenerator/{generateConsumerXmlFile => generateConsumerDbXmlFile}/queue_consumer.xml (66%) create mode 100644 tests/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGeneratorTest.java diff --git a/resources/fileTemplates/internal/Magento Message Queue Consumer Class.php.ft b/resources/fileTemplates/internal/Magento Message Queue Consumer Class.php.ft new file mode 100644 index 000000000..60bea44da --- /dev/null +++ b/resources/fileTemplates/internal/Magento Message Queue Consumer Class.php.ft @@ -0,0 +1,16 @@ + - + @@ -61,98 +61,113 @@ - + - + - + - + - + + + - - + - + - + + + + + + + + + + + + + + + - + - + - + - + - + - + - + - - - + - + - + - + + + - + - + - + + + + + + + - + - + - - - + - - + - + - + - - - @@ -197,7 +212,7 @@ - + @@ -205,108 +220,93 @@ - + - + - + - + - + - + - + - - - + - - - + + - + - + - + - - - + - + + - + - + + + - - - + - + - + - + - + - + - + - + - + - - - - - - - + - - - - - - + - + - + - + - + diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java index 28d727ae1..e444c0574 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewMessageQueueDialog.java @@ -9,6 +9,7 @@ import com.intellij.psi.PsiDirectory; import com.intellij.ui.DocumentAdapter; import com.magento.idea.magento2plugin.actions.generation.NewMessageQueueAction; +import com.magento.idea.magento2plugin.actions.generation.data.MessageQueueClassData; import com.magento.idea.magento2plugin.actions.generation.data.QueueCommunicationData; import com.magento.idea.magento2plugin.actions.generation.data.QueueConsumerData; import com.magento.idea.magento2plugin.actions.generation.data.QueuePublisherData; @@ -22,26 +23,32 @@ import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule; import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassFqnRule; +import com.magento.idea.magento2plugin.actions.generation.generator.MessageQueueClassGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueueCommunicationGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueueConsumerGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueuePublisherGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.QueueTopologyGenerator; import com.magento.idea.magento2plugin.actions.generation.generator.util.NamespaceBuilder; -import com.magento.idea.magento2plugin.magento.files.ModelPhp; -import com.magento.idea.magento2plugin.ui.FilteredComboBox; +import com.magento.idea.magento2plugin.magento.files.MessageQueueClassPhp; import com.magento.idea.magento2plugin.magento.packages.MessageQueueConnections; import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectoryUtil; -import org.jetbrains.annotations.NotNull; - import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; -import javax.swing.*; +import javax.swing.JButton; +import javax.swing.JComboBox; +import javax.swing.JComponent; +import javax.swing.JLabel; +import javax.swing.JPanel; +import javax.swing.JTextField; +import javax.swing.KeyStroke; import javax.swing.event.DocumentEvent; +import org.jetbrains.annotations.NotNull; @SuppressWarnings({ "PMD.TooManyFields", + "PMD.TooManyMethods", "PMD.ExcessiveImports", }) public class NewMessageQueueDialog extends AbstractDialog { @@ -56,7 +63,7 @@ public class NewMessageQueueDialog extends AbstractDialog { private static final String BINDING_ID = "Binding ID"; private static final String BINDING_TOPIC = "Binding Topic"; - private FilteredComboBox connectionName; + private JComboBox connectionName; /* TODO: Improve validation */ @FieldValidation(rule = RuleRegistry.NOT_EMPTY, @@ -121,6 +128,8 @@ public class NewMessageQueueDialog extends AbstractDialog { @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, BINDING_TOPIC}) + @FieldValidation(rule = RuleRegistry.ALPHA_WITH_PERIOD, + message = {AlphanumericWithUnderscoreRule.MESSAGE, BINDING_TOPIC}) private JTextField bindingTopic; private JTextField consumerDirectory; @@ -129,10 +138,13 @@ public class NewMessageQueueDialog extends AbstractDialog { private JPanel contentPanel; private JButton buttonOK; private JButton buttonCancel; - private JLabel handlerDirectoryLabel; - private JLabel handlerClassLabel; private JLabel consumerDirectoryLabel; - private JLabel bindingTopicLabel; + private JLabel consumerClassLabel; + private JLabel maxMessagesLabel; + private JLabel bindingTopicLabel;//NOPMD + private JLabel handlerClassLabel;//NOPMD + private JLabel consumerNameLabel;//NOPMD + private JLabel handlerDirectoryLabel;//NOPMD private final Project project; private final String moduleName; @@ -151,6 +163,10 @@ public NewMessageQueueDialog(final Project project, final PsiDirectory directory setTitle(NewMessageQueueAction.ACTION_DESCRIPTION); getRootPane().setDefaultButton(buttonOK); + for (final String connection : MessageQueueConnections.getList()) { + connectionName.addItem(connection); + } + buttonOK.addActionListener((final ActionEvent event) -> onOK()); buttonCancel.addActionListener((final ActionEvent event) -> onCancel()); @@ -182,6 +198,26 @@ protected void textChanged(final @NotNull DocumentEvent event) { updateBindingText(); } }); + + connectionName.addActionListener(e -> toggleConsumer()); + } + + private void toggleConsumer() { + if (getConnectionName().equals(MessageQueueConnections.AMPQ.getType())) { + consumerDirectoryLabel.setVisible(false); + consumerDirectory.setVisible(false); + consumerClass.setVisible(false); + consumerClassLabel.setVisible(false); + maxMessages.setVisible(false); + maxMessagesLabel.setVisible(false); + return; + } + consumerDirectoryLabel.setVisible(true); + consumerDirectory.setVisible(true); + consumerClass.setVisible(true); + consumerClassLabel.setVisible(true); + maxMessages.setVisible(true); + maxMessagesLabel.setVisible(true); } /** @@ -205,6 +241,10 @@ private void onOK() { generateConsumer(); generateTopology(); generatePublisher(); + generateHandlerClass(); + if (getConnectionName().equals(MessageQueueConnections.DB.getType())) { + generateConsumerClass(); + } this.setVisible(false); } } @@ -226,8 +266,9 @@ private void generateConsumer() { getConsumerClass(), getMaxMessages(), getConnectionName(), - getModuleName() - )).generate(NewMessageQueueAction.ACTION_NAME, true); + getModuleName(), + getHandlerClass().concat("::").concat(getHandlerMethod()) + )).generate(NewMessageQueueAction.ACTION_NAME, false); } private void generateTopology() { @@ -238,7 +279,7 @@ private void generateTopology() { getBindingTopic(), getQueueName(), getModuleName() - )).generate(NewMessageQueueAction.ACTION_NAME, true); + )).generate(NewMessageQueueAction.ACTION_NAME, false); } private void generatePublisher() { @@ -247,7 +288,29 @@ private void generatePublisher() { getConnectionName(), getExchangeName(), getModuleName() - )).generate(NewMessageQueueAction.ACTION_NAME, true); + )).generate(NewMessageQueueAction.ACTION_NAME, false); + } + + private void generateHandlerClass() { + @NotNull final NamespaceBuilder handlerNamespaceBuilder = getHandlerNamespaceBuilder(); + new MessageQueueClassGenerator(new MessageQueueClassData( + handlerClass.getText().trim(), + handlerNamespaceBuilder.getNamespace(), + handlerDirectory.getText().trim(), + handlerNamespaceBuilder.getClassFqn(), + MessageQueueClassPhp.Type.HANDLER + ), getModuleName(), project).generate(NewMessageQueueAction.ACTION_NAME, false); + } + + private void generateConsumerClass() { + @NotNull final NamespaceBuilder consumerNamespaceBuilder = getConsumerNamespaceBuilder(); + new MessageQueueClassGenerator(new MessageQueueClassData( + consumerClass.getText().trim(), + consumerNamespaceBuilder.getNamespace(), + consumerDirectory.getText().trim(), + consumerNamespaceBuilder.getClassFqn(), + MessageQueueClassPhp.Type.CONSUMER + ), getModuleName(), project).generate(NewMessageQueueAction.ACTION_NAME, false); } public String getTopicName() { @@ -258,12 +321,30 @@ public String getHandlerName() { return handlerName.getText().trim(); } - public String getHandlerClass() { + @NotNull + private NamespaceBuilder getHandlerNamespaceBuilder() { return new NamespaceBuilder( getModuleName(), handlerClass.getText().trim(), handlerDirectory.getText().trim() - ).getClassFqn(); + ); + } + + @NotNull + private NamespaceBuilder getConsumerNamespaceBuilder() { + return new NamespaceBuilder( + getModuleName(), + consumerClass.getText().trim(), + consumerDirectory.getText().trim() + ); + } + + public String getHandlerClass() { + return getHandlerNamespaceBuilder().getClassFqn(); + } + + public String getConsumerClass() { + return getConsumerNamespaceBuilder().getClassFqn(); } public String getHandlerMethod() { @@ -278,14 +359,6 @@ public String getQueueName() { return queueName.getText().trim(); } - public String getConsumerClass() { - return new NamespaceBuilder( - getModuleName(), - consumerClass.getText().trim(), - consumerDirectory.getText().trim() - ).getClassFqn(); - } - public String getMaxMessages() { return maxMessages.getText().trim(); } @@ -318,6 +391,7 @@ public void updateIndefiersTextes() { this.handlerName.setText(topicNameText.concat(".handler")); this.consumerName.setText(topicNameText); this.queueName.setText(topicNameText); + this.bindingTopic.setText(topicNameText); } /** @@ -328,11 +402,4 @@ public void updateBindingText() { this.consumerClass.setText(handlerTypeText.replace("Handler", "").concat("Consumer")); this.bindingId.setText(handlerTypeText.replace("Handler", "").concat("Binding")); } - - @SuppressWarnings({"PMD.UnusedPrivateMethod"}) - private void createUIComponents() { - this.connectionName = new FilteredComboBox( - MessageQueueConnections.getList() - ); - } } diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGenerator.java new file mode 100644 index 000000000..02d5cf79f --- /dev/null +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGenerator.java @@ -0,0 +1,145 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.command.WriteCommandAction; +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiDirectory; +import com.intellij.psi.PsiFile; +import com.jetbrains.php.lang.psi.PhpFile; +import com.jetbrains.php.lang.psi.elements.PhpClass; +import com.magento.idea.magento2plugin.actions.generation.data.MessageQueueClassData; +import com.magento.idea.magento2plugin.actions.generation.generator.util.DirectoryGenerator; +import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator; +import com.magento.idea.magento2plugin.bundles.CommonBundle; +import com.magento.idea.magento2plugin.bundles.ValidatorBundle; +import com.magento.idea.magento2plugin.indexes.ModuleIndex; +import com.magento.idea.magento2plugin.magento.files.MessageQueueClassPhp; +import com.magento.idea.magento2plugin.magento.packages.File; +import com.magento.idea.magento2plugin.util.GetFirstClassOfFile; +import com.magento.idea.magento2plugin.util.GetPhpClassByFQN; +import java.util.Properties; +import javax.swing.JOptionPane; + +public class MessageQueueClassGenerator extends FileGenerator { + private final MessageQueueClassData messageQueueClassDataName; + private final Project project; + private final DirectoryGenerator directoryGenerator; + private final FileFromTemplateGenerator fileFromTemplateGenerator; + private final ValidatorBundle validatorBundle; + private final CommonBundle commonBundle; + private final String moduleName; + private final GetFirstClassOfFile getFirstClassOfFile; + + /** + * Message queue handler constructor. + * + * @param messageQueueClassData MessageQueueHandlerData + * @param moduleName String + * @param project Project + */ + public MessageQueueClassGenerator( + final MessageQueueClassData messageQueueClassData, + final String moduleName, + final Project project + ) { + super(project); + + this.messageQueueClassDataName = messageQueueClassData; + this.directoryGenerator = DirectoryGenerator.getInstance(); + this.fileFromTemplateGenerator = FileFromTemplateGenerator.getInstance(project); + this.validatorBundle = new ValidatorBundle(); + this.commonBundle = new CommonBundle(); + this.getFirstClassOfFile = GetFirstClassOfFile.getInstance(); + this.project = project; + this.moduleName = moduleName; + } + + @Override + public PsiFile generate(final String actionName) { + final PsiFile[] handlerFiles = new PsiFile[1]; + + WriteCommandAction.runWriteCommandAction(project, () -> { + PhpClass handler = GetPhpClassByFQN.getInstance(project).execute( + messageQueueClassDataName.getFqn() + ); + + if (handler != null) { + final String errorMessage = this.validatorBundle.message( + "validator.file.alreadyExists", + "Handler Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + + return; + } + + handler = createHandlerClass(actionName); + + if (handler == null) { + final String errorMessage = this.validatorBundle.message( + "validator.file.cantBeCreated", + "Handler Class" + ); + JOptionPane.showMessageDialog( + null, + errorMessage, + commonBundle.message("common.error"), + JOptionPane.ERROR_MESSAGE + ); + + return; + } + + handlerFiles[0] = handler.getContainingFile(); + }); + + return handlerFiles[0]; + } + + @Override + protected void fillAttributes(final Properties attributes) { + attributes.setProperty("NAMESPACE", messageQueueClassDataName.getNamespace()); + attributes.setProperty("CLASS_NAME", messageQueueClassDataName.getName()); + } + + private PhpClass createHandlerClass(final String actionName) { + PsiDirectory parentDirectory = ModuleIndex.getInstance(project) + .getModuleDirectoryByModuleName(this.moduleName); + final PsiFile handlerFile; + final String[] handlerDirectories = messageQueueClassDataName.getPath().split( + File.separator + ); + for (final String handlerDirectory: handlerDirectories) { + parentDirectory = directoryGenerator.findOrCreateSubdirectory( + parentDirectory, handlerDirectory + ); + } + + final Properties attributes = getAttributes(); + + handlerFile = fileFromTemplateGenerator.generate( + new MessageQueueClassPhp( + messageQueueClassDataName.getName(), + messageQueueClassDataName.getType() + ), + attributes, + parentDirectory, + actionName + ); + + if (handlerFile == null) { + return null; + } + + return getFirstClassOfFile.execute((PhpFile) handlerFile); + } +} diff --git a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGenerator.java b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGenerator.java index 961b55bfa..5e1ada751 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGenerator.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGenerator.java @@ -14,6 +14,7 @@ import com.intellij.psi.xml.XmlTag; import com.magento.idea.magento2plugin.actions.generation.data.QueueConsumerData; import com.magento.idea.magento2plugin.actions.generation.generator.util.FindOrCreateQueueConsumerXml; +import com.magento.idea.magento2plugin.magento.packages.MessageQueueConnections; import java.util.Properties; public class QueueConsumerGenerator extends FileGenerator { @@ -58,9 +59,14 @@ public PsiFile generate(final String actionName) { final XmlTag consumerTag = rootTag.createChildTag("consumer", null, null, false); consumerTag.setAttribute("name", consumerData.getConsumerName()); consumerTag.setAttribute("queue", consumerData.getQueueName()); - consumerTag.setAttribute("consumerInstance", consumerData.getConsumerType()); consumerTag.setAttribute("connection", consumerData.getConnectionName()); - consumerTag.setAttribute("maxMessages", consumerData.getMaxMessages()); + + if (consumerData.getConnectionName().equals(MessageQueueConnections.DB.getType())) { + consumerTag.setAttribute("consumerInstance", consumerData.getConsumerClass()); + consumerTag.setAttribute("maxMessages", consumerData.getMaxMessages()); + } else { + consumerTag.setAttribute("handler", consumerData.getHandler()); + } rootTag.addSubTag(consumerTag, false); } diff --git a/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java b/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java new file mode 100644 index 000000000..a8d682c3a --- /dev/null +++ b/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java @@ -0,0 +1,63 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.magento.files; + +import com.intellij.lang.Language; +import com.jetbrains.php.lang.PhpLanguage; + +public class MessageQueueClassPhp implements ModuleFileInterface { + public static final String HANDLER_TEMPLATE = "Magento Message Queue Handler Class"; + public static final String CONSUMER_TEMPLATE = "Magento Message Queue Consumer Class"; + public static final String FILE_EXTENSION = "php"; + private String className; + private Type type; + + /** + * Constructor. + * + * @param className String + * @param type Type + */ + public MessageQueueClassPhp( + final String className, + Type type + ) { + this.className = className; + this.type = type; + } + + /** + * Set class name. + * + * @param className String + */ + public void setClassName(final String className) { + this.className = className; + } + + @Override + public String getFileName() { + return String.format("%s.%s", className, FILE_EXTENSION); + } + + @Override + public String getTemplate() { + if (type.equals(Type.CONSUMER)) { + return CONSUMER_TEMPLATE; + } + return HANDLER_TEMPLATE; + } + + @Override + public Language getLanguage() { + return PhpLanguage.INSTANCE; + } + + public enum Type { + HANDLER, + CONSUMER + } +} diff --git a/testData/actions/generation/generator/MessageQueueClassGenerator/generateConsumer/MyConsumer.php b/testData/actions/generation/generator/MessageQueueClassGenerator/generateConsumer/MyConsumer.php new file mode 100644 index 000000000..d4438997e --- /dev/null +++ b/testData/actions/generation/generator/MessageQueueClassGenerator/generateConsumer/MyConsumer.php @@ -0,0 +1,13 @@ + + + + diff --git a/testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerXmlFile/queue_consumer.xml b/testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerDbXmlFile/queue_consumer.xml similarity index 66% rename from testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerXmlFile/queue_consumer.xml rename to testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerDbXmlFile/queue_consumer.xml index ca08e43aa..f7f122ad5 100644 --- a/testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerXmlFile/queue_consumer.xml +++ b/testData/actions/generation/generator/QueueConsumerGenerator/generateConsumerDbXmlFile/queue_consumer.xml @@ -1,6 +1,6 @@ - diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGeneratorTest.java new file mode 100644 index 000000000..84cfc1d77 --- /dev/null +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/MessageQueueClassGeneratorTest.java @@ -0,0 +1,87 @@ +/* + * Copyright © Magento, Inc. All rights reserved. + * See COPYING.txt for license details. + */ + +package com.magento.idea.magento2plugin.actions.generation.generator; + +import com.intellij.openapi.project.Project; +import com.intellij.psi.PsiFile; +import com.magento.idea.magento2plugin.actions.generation.data.MessageQueueClassData; +import com.magento.idea.magento2plugin.magento.files.MessageQueueClassPhp; + +public class MessageQueueClassGeneratorTest extends BaseGeneratorTestCase { + private static final String MODULE_NAME = "Foo_Bar"; + + private static final String HANDLER_EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Queue/Handler"; + private static final String HANDLER_CLASS_NAME = "MyHandler"; + private static final String HANDLER_NAMESPACE = "Foo\\Bar\\Queue\\Handler"; + private static final String HANDLER_PATH = "Queue/Handler"; + private static final String HANDLER_FQN = "\\Foo\\Bar\\Queue\\Handler\\MyHandler"; + + private static final String CONSUMER_EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/Queue/Consumer"; + private static final String CONSUMER_CLASS_NAME = "MyConsumer"; + private static final String CONSUMER_NAMESPACE = "Foo\\Bar\\Queue\\Consumer"; + private static final String CONSUMER_PATH = "Queue/Consumer"; + private static final String CONSUMER_FQN = "\\Foo\\Bar\\Queue\\Handler\\MyConsumer"; + + /** + * Test handler class file generation. + */ + public void testGenerateHandler() { + final Project project = myFixture.getProject(); + final MessageQueueClassData messageQueueClassData = new MessageQueueClassData( + HANDLER_CLASS_NAME, + HANDLER_NAMESPACE, + HANDLER_PATH, + HANDLER_FQN, + MessageQueueClassPhp.Type.HANDLER + ); + final MessageQueueClassGenerator generator; + generator = new MessageQueueClassGenerator( + messageQueueClassData, + MODULE_NAME, + project + ); + + final PsiFile messageQueue = generator.generate("test"); + final String filePath = this.getFixturePath("MyHandler.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + HANDLER_EXPECTED_DIRECTORY, + messageQueue + ); + } + + /** + * Test consumer class file generation. + */ + public void testGenerateConsumer() { + final Project project = myFixture.getProject(); + final MessageQueueClassData messageQueueClassData = new MessageQueueClassData( + CONSUMER_CLASS_NAME, + CONSUMER_NAMESPACE, + CONSUMER_PATH, + CONSUMER_FQN, + MessageQueueClassPhp.Type.CONSUMER + ); + final MessageQueueClassGenerator generator; + generator = new MessageQueueClassGenerator( + messageQueueClassData, + MODULE_NAME, + project + ); + + final PsiFile messageQueue = generator.generate("test"); + final String filePath = this.getFixturePath("MyConsumer.php"); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + + assertGeneratedFileIsCorrect( + expectedFile, + CONSUMER_EXPECTED_DIRECTORY, + messageQueue + ); + } +} diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGeneratorTest.java index 65613f482..7b2813ed2 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/QueueConsumerGeneratorTest.java @@ -16,14 +16,16 @@ public class QueueConsumerGeneratorTest extends BaseGeneratorTestCase { private static final String QUEUE_NAME = "queue.name"; private static final String CONSUMER_TYPE = "Foo\\Bar\\Model\\Consumer"; private static final String MAX_MESSAGES = "100"; - private static final String CONNECTION_NAME = "amqp"; + private static final String CONNECTION_AMPQ = "amqp"; + private static final String CONNECTION_DB = "db"; private static final String MODULE_NAME = "Foo_Bar"; private static final String EXPECTED_DIRECTORY = "src/app/code/Foo/Bar/etc"; + private static final String HANDLER = "Foo/Bar/Handler.php::execute"; /** - * Tests for generation of queue_consumer.xml file. + * Tests for generation of queue_consumer.xml file for the DB connection type. */ - public void testGenerateConsumerXmlFile() { + public void testGenerateConsumerDbXmlFile() { final String filePath = this.getFixturePath(QueueConsumerXml.fileName); final PsiFile expectedFile = myFixture.configureByFile(filePath); final Project project = myFixture.getProject(); @@ -34,8 +36,34 @@ public void testGenerateConsumerXmlFile() { QUEUE_NAME, CONSUMER_TYPE, MAX_MESSAGES, - CONNECTION_NAME, - MODULE_NAME + CONNECTION_DB, + MODULE_NAME, + HANDLER + ) + ); + + final PsiFile file = consumerGenerator.generate(NewMessageQueueAction.ACTION_NAME); + + assertGeneratedFileIsCorrect(expectedFile, EXPECTED_DIRECTORY, file); + } + + /** + * Tests for generation of queue_consumer.xml file for the AMPQ connection type. + */ + public void testGenerateConsumerAmpqXmlFile() { + final String filePath = this.getFixturePath(QueueConsumerXml.fileName); + final PsiFile expectedFile = myFixture.configureByFile(filePath); + final Project project = myFixture.getProject(); + final QueueConsumerGenerator consumerGenerator = new QueueConsumerGenerator( + project, + new QueueConsumerData( + CONSUMER_NAME, + QUEUE_NAME, + CONSUMER_TYPE, + MAX_MESSAGES, + CONNECTION_AMPQ, + MODULE_NAME, + HANDLER ) ); From c065e45e66ae3eecf3ffab8a5000067a2eccabb3 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Sun, 31 Jan 2021 18:39:27 +0200 Subject: [PATCH 06/11] Fixed version --- .github/workflows/gradle.yml | 2 +- build.gradle | 2 +- resources/META-INF/plugin.xml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 903b63260..912bc36b5 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -5,7 +5,7 @@ name: Run automated tests on: pull_request: - branches: [ master, 3.1.1-develop ] + branches: [ master, 3.1.0-develop ] jobs: build-linux: diff --git a/build.gradle b/build.gradle index 09bebeaf5..44045f4f1 100644 --- a/build.gradle +++ b/build.gradle @@ -15,7 +15,7 @@ repositories { } group 'com.magento.idea' -version '3.1.1' +version '3.1.0' apply plugin: 'org.jetbrains.intellij' apply plugin: 'java' diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index fe9f0684e..35d9f7eb1 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -7,7 +7,7 @@ com.magento.idea.magento2plugin Magento PhpStorm - 3.1.1 + 3.1.0 Magento Inc. Date: Sun, 31 Jan 2021 18:43:26 +0200 Subject: [PATCH 07/11] Removed declare(strict_types=1); --- .../fileTemplates/internal/Magento Data Model Interface.php.ft | 1 - resources/fileTemplates/internal/Magento Data Model.php.ft | 1 - .../generator/DataModelGenerator/generateDataModel/Sample.php | 1 - .../generateDataModelWithoutInterface/Sample.php | 1 - .../generateDataModelInterface/SampleInterface.php | 1 - .../Model/Resolver/ImplementsBatchResolverInterface.php | 1 - .../Resolver/ImplementsBatchServiceContractResolverInterface.php | 1 - .../Model/Resolver/ImplementsResolverInterface.php | 1 - 8 files changed, 8 deletions(-) diff --git a/resources/fileTemplates/internal/Magento Data Model Interface.php.ft b/resources/fileTemplates/internal/Magento Data Model Interface.php.ft index 2efe47430..efa91463e 100644 --- a/resources/fileTemplates/internal/Magento Data Model Interface.php.ft +++ b/resources/fileTemplates/internal/Magento Data Model Interface.php.ft @@ -1,6 +1,5 @@ Date: Sun, 31 Jan 2021 18:45:44 +0200 Subject: [PATCH 08/11] Static fixes --- .../magento2plugin/magento/files/MessageQueueClassPhp.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java b/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java index a8d682c3a..5815ad8dc 100644 --- a/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java +++ b/src/com/magento/idea/magento2plugin/magento/files/MessageQueueClassPhp.java @@ -13,7 +13,7 @@ public class MessageQueueClassPhp implements ModuleFileInterface { public static final String CONSUMER_TEMPLATE = "Magento Message Queue Consumer Class"; public static final String FILE_EXTENSION = "php"; private String className; - private Type type; + private final Type type; /** * Constructor. @@ -23,7 +23,7 @@ public class MessageQueueClassPhp implements ModuleFileInterface { */ public MessageQueueClassPhp( final String className, - Type type + final Type type ) { this.className = className; this.type = type; From 8bfcf005882c4787627209a7fc3b213511469ef3 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 2 Feb 2021 15:25:44 +0200 Subject: [PATCH 09/11] Fixed null pointer --- .../inspections/xml/PluginDeclarationInspection.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java b/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java index 6fe323cdc..99412796d 100644 --- a/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java +++ b/src/com/magento/idea/magento2plugin/inspections/xml/PluginDeclarationInspection.java @@ -71,6 +71,9 @@ public void visitFile(final PsiFile file) { final XmlAttribute pluginNameAttribute = pluginXmlTag.getAttribute(ModuleDiXml.NAME_ATTR); + if (pluginNameAttribute == null) { + continue; + } final String pluginNameAttributeValue = pluginNameAttribute.getValue(); if (pluginNameAttributeValue == null) { From 8060d4c8ca38f6f6ce932aaff77a4f96aeed7157 Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Tue, 2 Feb 2021 15:44:25 +0200 Subject: [PATCH 10/11] Fixed generation of the new module --- .../idea/magento2plugin/util/magento/MagentoVersionUtil.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/com/magento/idea/magento2plugin/util/magento/MagentoVersionUtil.java b/src/com/magento/idea/magento2plugin/util/magento/MagentoVersionUtil.java index 230d22b21..7b5c22180 100644 --- a/src/com/magento/idea/magento2plugin/util/magento/MagentoVersionUtil.java +++ b/src/com/magento/idea/magento2plugin/util/magento/MagentoVersionUtil.java @@ -87,6 +87,10 @@ public static boolean compare(final String version1, final String version2) { return true; } + if (version1.isEmpty()) { + return false; + } + final String[] version1s = version1.split("\\."); final String[] version2s = version2.split("\\."); for (int i = 0; i < 2; i++) { From 2f786d1b203c81138df234d668f48e1fbb90798f Mon Sep 17 00:00:00 2001 From: Vitaliy Boyko Date: Wed, 3 Feb 2021 14:16:14 +0200 Subject: [PATCH 11/11] Di autocomplete update --- CHANGELOG.md | 4 ++++ .../di-autocomplete.php | 0 resources/META-INF/plugin.xml | 3 +-- 3 files changed, 5 insertions(+), 2 deletions(-) rename resources/{phpstorm.meta.php => .phpstorm.meta.php}/di-autocomplete.php (100%) diff --git a/CHANGELOG.md b/CHANGELOG.md index bf87ef1d0..fc13a881e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0). - Inspection warning for disabled observer [#432](https://github.com/magento/magento2-phpstorm-plugin/pull/432) - The action item to the context menu to copy file path in the Magento format [#451](https://github.com/magento/magento2-phpstorm-plugin/pull/451) +### Fixed + +- The null pointer exception on the Create Module Dialog + ## 3.0.4 ### Fixed diff --git a/resources/phpstorm.meta.php/di-autocomplete.php b/resources/.phpstorm.meta.php/di-autocomplete.php similarity index 100% rename from resources/phpstorm.meta.php/di-autocomplete.php rename to resources/.phpstorm.meta.php/di-autocomplete.php diff --git a/resources/META-INF/plugin.xml b/resources/META-INF/plugin.xml index 35d9f7eb1..e7fd64154 100644 --- a/resources/META-INF/plugin.xml +++ b/resources/META-INF/plugin.xml @@ -236,7 +236,6 @@ - + -