Skip to content

Commit 370fbc9

Browse files
author
Vitaliy
authored
Merge branch '2.1.0-develop' into issue-322
2 parents 8b459cd + c99c08d commit 370fbc9

23 files changed

+309
-1213
lines changed

.github/ISSUE_TEMPLATE/bug_report.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ If applicable, add screenshots to help explain your problem.
3939

4040
**Please complete the following information:** (*)
4141

42-
- OS: [e.g. iOS]
43-
- PhpStorm/Intellij version [e.g. 2019.3.3]
44-
- Version [e.g. 1.0.0]
42+
- OS: [e.g. MacOS or Ubuntu Linux 20.04]
43+
- PhpStorm/Intellij version: [e.g. 2019.3.3]
44+
- Plugin Version: [e.g. 1.0.0]
4545

4646
**Additional context**
4747

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
If relevant, please provide a list of fixed issues in the format magento/magento2-phpstorm-plugin#<issue_number>.
2121
There could be 1 or more issues linked here and it will help us find some more information about the reasoning behind this change.
2222
-->
23-
1. magento/magento2-phpstorm-plugin#<issue_number>: Issue title
23+
1. Fixes magento/magento2-phpstorm-plugin#<issue_number>
2424

2525
**Questions or comments**
2626
<!---

.github/workflows/gradle.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ on:
99

1010
jobs:
1111
build-linux:
12-
1312
runs-on: ubuntu-latest
1413

1514
steps:
@@ -18,6 +17,14 @@ jobs:
1817
uses: actions/setup-java@v1
1918
with:
2019
java-version: 1.8
20+
- uses: actions/cache@v2
21+
with:
22+
path: |
23+
~/.gradle/caches
24+
~/.gradle/wrapper
25+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
26+
restore-keys: |
27+
${{ runner.os }}-gradle-
2128
- name: Gradle wrapper
2229
run: gradle wrapper
2330
- name: Grant execute permission for gradlew
@@ -26,7 +33,6 @@ jobs:
2633
run: ./gradlew test -i --no-daemon
2734

2835
build-windows:
29-
3036
runs-on: windows-latest
3137

3238
steps:
@@ -35,6 +41,14 @@ jobs:
3541
uses: actions/setup-java@v1
3642
with:
3743
java-version: 1.8
44+
- uses: actions/cache@v2
45+
with:
46+
path: |
47+
~/.gradle/caches
48+
~/.gradle/wrapper
49+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
50+
restore-keys: |
51+
${{ runner.os }}-gradle-
3852
- name: Gradle wrapper
3953
run: gradle wrapper
4054
- name: Grant execute permission for gradlew
@@ -43,7 +57,6 @@ jobs:
4357
run: ./gradlew test -i --no-daemon
4458

4559
build-macos:
46-
4760
runs-on: macos-latest
4861

4962
steps:
@@ -52,6 +65,14 @@ jobs:
5265
uses: actions/setup-java@v1
5366
with:
5467
java-version: 1.8
68+
- uses: actions/cache@v2
69+
with:
70+
path: |
71+
~/.gradle/caches
72+
~/.gradle/wrapper
73+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
74+
restore-keys: |
75+
${{ runner.os }}-gradle-
5576
- name: Gradle wrapper
5677
run: gradle wrapper
5778
- name: Grant execute permission for gradlew
@@ -60,7 +81,6 @@ jobs:
6081
run: ./gradlew test -i --no-daemon
6182

6283
static-tests:
63-
6484
runs-on: ubuntu-latest
6585

6686
steps:
@@ -69,6 +89,14 @@ jobs:
6989
uses: actions/setup-java@v1
7090
with:
7191
java-version: 1.8
92+
- uses: actions/cache@v2
93+
with:
94+
path: |
95+
~/.gradle/caches
96+
~/.gradle/wrapper
97+
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle*') }}
98+
restore-keys: |
99+
${{ runner.os }}-gradle-
72100
- name: Gradle wrapper
73101
run: gradle wrapper
74102
- name: Grant execute permission for gradlew

resources/magento2/common.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ common.theme.target=Target Theme
2323
common.area.target=Target Area
2424
common.name=Name
2525
common.className=Class Name
26+
common.pluginName=Plugin Name
2627
common.directoryPath=Directory Path
2728
common.methodType=Method Type
2829
common.sortOrder=Sort Order

resources/magento2/validation.properties

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
validator.notEmpty=The {0} field must not be empty
22
validator.package.validPath=Please specify a valid Magento 2 installation path
3-
validator.alphaNumericCharacters=The {0} must contain letters and numbers only
3+
validator.alphaNumericCharacters=The {0} field must contain letters and numbers only
44
validator.alphaNumericAndUnderscoreCharacters={0} must contain letters, numbers and underscores only
5-
validator.alreadyDeclared={0} is already declared in the {1} module.
6-
validator.startWithNumberOrCapitalLetter=The {0} must start from a number or a capital letter
7-
validator.onlyNumbers={0} must contain numbers only
5+
validator.alreadyDeclared={0} is already declared in the {1} module
6+
validator.startWithNumberOrCapitalLetter=The {0} field must start with a number or a capital letter
7+
validator.onlyNumbers=The {0} field must contain numbers only
88
validator.mustNotBeNegative={0} must not be negative
9-
validator.identifier={0} must contain letters, numbers, dashes, and underscores only
9+
validator.identifier=The {0} field must contain letters, numbers, dashes, and underscores only
1010
validator.class.isNotValid=The {0} field does not contain a valid class name
1111
validator.class.shouldBeUnique=Duplicated class {0}
12-
validator.namespace.isNotValid=The {0} is not valid namespace name
13-
validator.directory.isNotValid={0} is not valid
12+
validator.namespace.isNotValid=The {0} field does not contain a valid namespace
13+
validator.directory.isNotValid=The {0} field does not contain a valid directory
1414
validator.directory.php.isNotValid=The {0} field does not contain a valid PHP directory
15+
validator.command.isNotValid=The {0} field does not contain a valid Magento 2 CLI command
1516
validator.module.noSuchModule=No such module {0}
1617
validator.file.alreadyExists={0} already exists
1718
validator.file.cantBeCreated={0} can't be created

src/com/magento/idea/magento2plugin/actions/generation/dialog/AbstractDialog.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import javax.swing.JComponent;
2727
import javax.swing.JDialog;
2828
import javax.swing.JOptionPane;
29+
import javax.swing.JTextArea;
2930
import javax.swing.JTextField;
3031

3132
/**
@@ -185,6 +186,8 @@ private String resolveFieldValueByComponentType(final Object field) {
185186
return ((JTextField) field).getText();
186187
} else if (field instanceof JComboBox) {
187188
return ((JComboBox) field).getSelectedItem().toString();
189+
} else if (field instanceof JTextArea) {
190+
return ((JTextArea) field).getText();
188191
}
189192
return null;
190193
}

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.form

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
109109
</constraints>
110110
<properties>
111-
<text resource-bundle="magento2/common" key="common.name"/>
111+
<text resource-bundle="magento2/common" key="common.pluginName"/>
112112
</properties>
113113
</component>
114114
<component id="9431c" class="javax.swing.JTextField" binding="pluginName">

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAPluginDialog.java

Lines changed: 52 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@
1111
import com.magento.idea.magento2plugin.actions.generation.CreateAPluginAction;
1212
import com.magento.idea.magento2plugin.actions.generation.data.PluginDiXmlData;
1313
import com.magento.idea.magento2plugin.actions.generation.data.PluginFileData;
14-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.CreateAPluginDialogValidator;
14+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.IdentifierRule;
18+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
19+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NumericRule;
20+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
1521
import com.magento.idea.magento2plugin.actions.generation.generator.PluginClassGenerator;
1622
import com.magento.idea.magento2plugin.actions.generation.generator.PluginDiXmlGenerator;
1723
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
@@ -21,7 +27,6 @@
2127
import com.magento.idea.magento2plugin.magento.packages.Package;
2228
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
2329
import java.awt.event.ActionEvent;
24-
import java.awt.event.ActionListener;
2530
import java.awt.event.KeyEvent;
2631
import java.awt.event.WindowAdapter;
2732
import java.awt.event.WindowEvent;
@@ -35,24 +40,57 @@
3540
import javax.swing.KeyStroke;
3641
import org.jetbrains.annotations.NotNull;
3742

38-
@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"})
43+
@SuppressWarnings({
44+
"PMD.TooManyFields",
45+
"PMD.DataClass",
46+
"PMD.UnusedPrivateMethod",
47+
"PMD.ExcessiveImports"
48+
})
3949
public class CreateAPluginDialog extends AbstractDialog {
4050
@NotNull
4151
private final Project project;
4252
private final Method targetMethod;
4353
private final PhpClass targetClass;
44-
@NotNull
45-
private final CreateAPluginDialogValidator validator;
4654
private JPanel contentPane;
4755
private JButton buttonOK;
4856
private JButton buttonCancel;
49-
private JTextField pluginClassName;
50-
private JTextField pluginDirectory;
5157
private JComboBox pluginType;
52-
private FilteredComboBox pluginModule;
5358
private JComboBox pluginArea;
59+
60+
private static final String CLASS_NAME = "class name";
61+
private static final String DIRECTORY = "directory path";
62+
private static final String SORT_ORDER = "sort order";
63+
private static final String PLUGIN_NAME = "plugin name";
64+
private static final String TARGET_MODULE = "target module";
65+
66+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
67+
message = {NotEmptyRule.MESSAGE, TARGET_MODULE})
68+
private FilteredComboBox pluginModule;
69+
70+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
71+
message = {NotEmptyRule.MESSAGE, CLASS_NAME})
72+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
73+
message = {PhpClassRule.MESSAGE, CLASS_NAME})
74+
private JTextField pluginClassName;
75+
76+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
77+
message = {NotEmptyRule.MESSAGE, DIRECTORY})
78+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
79+
message = {DirectoryRule.MESSAGE, DIRECTORY})
80+
private JTextField pluginDirectory;
81+
82+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
83+
message = {NotEmptyRule.MESSAGE, SORT_ORDER})
84+
@FieldValidation(rule = RuleRegistry.NUMERIC,
85+
message = {NumericRule.MESSAGE, SORT_ORDER})
5486
private JTextField pluginSortOrder;
87+
88+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
89+
message = {NotEmptyRule.MESSAGE, PLUGIN_NAME})
90+
@FieldValidation(rule = RuleRegistry.IDENTIFIER,
91+
message = {IdentifierRule.MESSAGE, PLUGIN_NAME})
5592
private JTextField pluginName;
93+
5694
private JLabel pluginDirectoryName;//NOPMD
5795
private JLabel selectPluginModule;//NOPMD
5896
private JLabel pluginTypeLabel;//NOPMD
@@ -77,25 +115,15 @@ public CreateAPluginDialog(
77115
this.project = project;
78116
this.targetMethod = targetMethod;
79117
this.targetClass = targetClass;
80-
this.validator = CreateAPluginDialogValidator.getInstance(this);
81118

82119
setContentPane(contentPane);
83120
setModal(true);
84121
getRootPane().setDefaultButton(buttonOK);
85122
fillPluginTypeOptions();
86123
fillTargetAreaOptions();
87124

88-
buttonOK.addActionListener(new ActionListener() {
89-
public void actionPerformed(final ActionEvent event) {
90-
onOK();
91-
}
92-
});
93-
94-
buttonCancel.addActionListener(new ActionListener() {
95-
public void actionPerformed(final ActionEvent event) {
96-
onCancel();
97-
}
98-
});
125+
buttonOK.addActionListener((final ActionEvent event) -> onOK());
126+
buttonCancel.addActionListener((final ActionEvent event) -> onCancel());
99127

100128
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
101129
addWindowListener(new WindowAdapter() {
@@ -104,11 +132,9 @@ public void windowClosing(final WindowEvent event) {
104132
}
105133
});
106134

107-
contentPane.registerKeyboardAction(new ActionListener() {
108-
public void actionPerformed(final ActionEvent event) {
109-
onCancel();
110-
}
111-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
135+
contentPane.registerKeyboardAction(
136+
(final ActionEvent event) -> onCancel(),
137+
KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
112138
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113139
);
114140
}
@@ -126,7 +152,7 @@ private void fillTargetAreaOptions() {
126152
}
127153

128154
protected void onOK() {
129-
if (!validator.validate(project)) {
155+
if (!validateFormFields()) {
130156
return;
131157
}
132158
new PluginClassGenerator(new PluginFileData(

src/com/magento/idea/magento2plugin/actions/generation/dialog/CreateAnObserverDialog.java

Lines changed: 34 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,12 @@
1010
import com.magento.idea.magento2plugin.actions.generation.CreateAnObserverAction;
1111
import com.magento.idea.magento2plugin.actions.generation.data.ObserverEventsXmlData;
1212
import com.magento.idea.magento2plugin.actions.generation.data.ObserverFileData;
13-
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.CreateAnObserverDialogValidator;
13+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.FieldValidation;
14+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.annotation.RuleRegistry;
15+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.AlphanumericWithUnderscoreRule;
16+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.DirectoryRule;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.NotEmptyRule;
18+
import com.magento.idea.magento2plugin.actions.generation.dialog.validator.rule.PhpClassRule;
1419
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverClassGenerator;
1520
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverEventsXmlGenerator;
1621
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
@@ -36,26 +41,47 @@
3641
"PMD.MissingSerialVersionUID",
3742
"PMD.DataClass",
3843
"PMD.UnusedPrivateField",
44+
"PMD.ExcessiveImports",
3945
})
4046
public class CreateAnObserverDialog extends AbstractDialog {
4147
@NotNull
4248
private final Project project;
43-
@NotNull
44-
private final CreateAnObserverDialogValidator validator;
4549
private final String targetEvent;
4650
private JPanel contentPane;
4751
private JButton buttonOK;
4852
private JButton buttonCancel;
49-
private JTextField observerClassName;
50-
private JTextField observerDirectory;
51-
private FilteredComboBox observerModule;
5253
private JComboBox observerArea;
53-
private JTextField observerName;
5454
private JLabel observerClassNameLabel;
5555
private JLabel observerDirectoryName;
5656
private JLabel selectObserverModule;
5757
private JLabel observerAreaLabel;
5858
private JLabel observerNameLabel;
59+
private static final String OBSERVER_MODULE = "target module";
60+
private static final String OBSERVER_CLASS = "class name";
61+
private static final String OBSERVER_DIRECTORY = "directory";
62+
private static final String OBSERVER_NAME = "name";
63+
64+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
65+
message = {NotEmptyRule.MESSAGE, OBSERVER_MODULE})
66+
private FilteredComboBox observerModule;
67+
68+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
69+
message = {NotEmptyRule.MESSAGE, OBSERVER_CLASS})
70+
@FieldValidation(rule = RuleRegistry.PHP_CLASS,
71+
message = {PhpClassRule.MESSAGE, OBSERVER_CLASS})
72+
private JTextField observerClassName;
73+
74+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
75+
message = {NotEmptyRule.MESSAGE, OBSERVER_DIRECTORY})
76+
@FieldValidation(rule = RuleRegistry.DIRECTORY,
77+
message = {DirectoryRule.MESSAGE, OBSERVER_DIRECTORY})
78+
private JTextField observerDirectory;
79+
80+
@FieldValidation(rule = RuleRegistry.NOT_EMPTY,
81+
message = {NotEmptyRule.MESSAGE, OBSERVER_NAME})
82+
@FieldValidation(rule = RuleRegistry.ALPHANUMERIC_WITH_UNDERSCORE,
83+
message = {AlphanumericWithUnderscoreRule.MESSAGE, OBSERVER_NAME})
84+
private JTextField observerName;
5985

6086
/**
6187
* Constructor.
@@ -68,7 +94,6 @@ public CreateAnObserverDialog(@NotNull final Project project, final String targe
6894

6995
this.project = project;
7096
this.targetEvent = targetEvent;
71-
this.validator = CreateAnObserverDialogValidator.getInstance(this);
7297

7398
setContentPane(contentPane);
7499
setModal(true);
@@ -119,7 +144,7 @@ private void fillTargetAreaOptions() {
119144
* Perform code generation using input data.
120145
*/
121146
private void onOK() {
122-
if (!validator.validate(project)) {
147+
if (!validateFormFields()) {
123148
return;
124149
}
125150
new ObserverClassGenerator(new ObserverFileData(

0 commit comments

Comments
 (0)