Skip to content

Commit f3ab2a3

Browse files
author
Vitaliy
authored
Merge pull request #245 from magento/243-adjusting-path-detection
243 adjusted Magento root validation
2 parents cddca4a + 283d5ca commit f3ab2a3

File tree

50 files changed

+2793
-1582
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+2793
-1582
lines changed

gradle-tasks/pmd/ruleset.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@
1515
</description>
1616
<rule ref="category/java/bestpractices.xml">
1717
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
18+
<exclude name="JUnit4TestShouldUseBeforeAnnotation"/>
1819
</rule>
1920
<rule ref="category/java/codestyle.xml">
2021
<exclude name="AtLeastOneConstructor" />
2122
<exclude name="LongVariable" />
23+
<exclude name="OnlyOneReturn" />
2224
</rule>
2325
<rule ref="category/java/design.xml">
2426
<exclude name="LawOfDemeter"/>
@@ -29,6 +31,7 @@
2931
</rule>
3032
<rule ref="category/java/errorprone.xml">
3133
<exclude name="BeanMembersShouldSerialize"/>
34+
<exclude name="DataflowAnomalyAnalysis"/>
3235
</rule>
3336
<exclude-pattern>.*/resources/.*</exclude-pattern>
3437
<exclude-pattern>.*/testData/.*</exclude-pattern>

src/com/magento/idea/magento2plugin/actions/generation/NewModuleAction.java

Lines changed: 44 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -2,88 +2,93 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation;
67

78
import com.intellij.ide.IdeView;
8-
import com.intellij.openapi.actionSystem.*;
9-
import com.intellij.openapi.editor.Editor;
9+
import com.intellij.openapi.actionSystem.AnActionEvent;
10+
import com.intellij.openapi.actionSystem.CommonDataKeys;
11+
import com.intellij.openapi.actionSystem.DataContext;
12+
import com.intellij.openapi.actionSystem.LangDataKeys;
13+
import com.intellij.openapi.actionSystem.PlatformDataKeys;
1014
import com.intellij.openapi.project.Project;
11-
import com.intellij.openapi.util.Pair;
1215
import com.intellij.psi.PsiDirectory;
1316
import com.intellij.psi.PsiElement;
14-
import com.intellij.psi.PsiFile;
15-
import com.jetbrains.php.lang.psi.PhpFile;
16-
import com.jetbrains.php.lang.psi.elements.PhpClass;
1717
import com.magento.idea.magento2plugin.MagentoIcons;
1818
import com.magento.idea.magento2plugin.actions.generation.dialog.NewModuleDialog;
1919
import com.magento.idea.magento2plugin.actions.generation.util.IsClickedDirectoryInsideProject;
2020
import com.magento.idea.magento2plugin.project.Settings;
2121
import com.magento.idea.magento2plugin.util.magento.GetModuleNameByDirectory;
2222
import org.jetbrains.annotations.NotNull;
23-
import org.jetbrains.annotations.Nullable;
2423

2524
public class NewModuleAction extends com.intellij.openapi.actionSystem.AnAction {
26-
public static String ACTION_NAME = "Magento 2 Module";
27-
public static String ACTION_DESCRIPTION = "Create a new Magento 2 module";
25+
public static String actionName = "Magento 2 Module";
26+
public static String actionDescription = "Create a new Magento 2 module";
2827

29-
NewModuleAction() {
30-
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
28+
/**
29+
* Constructor.
30+
*/
31+
public NewModuleAction() {
32+
super(actionName, actionDescription, MagentoIcons.MODULE);
3133
}
34+
3235
@Override
33-
public void actionPerformed(@NotNull AnActionEvent e) {
34-
DataContext dataContext = e.getDataContext();
35-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
36-
if (view != null) {
37-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
38-
if (project != null) {
39-
PsiDirectory initialBaseDir = view.getOrChooseDirectory();
40-
if (initialBaseDir != null) {
41-
this.invoke(project, initialBaseDir, this.getFile(dataContext), view, CommonDataKeys.EDITOR.getData(dataContext));
42-
}
36+
public void actionPerformed(final @NotNull AnActionEvent event) {
37+
final DataContext dataContext = event.getDataContext();
38+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
39+
if (view == null) {
40+
return;
41+
}
42+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
43+
if (project != null) {
44+
final PsiDirectory initialBaseDir = view.getOrChooseDirectory();
45+
if (initialBaseDir != null) {
46+
this.invoke(project, initialBaseDir);
4347
}
4448
}
4549
}
4650

47-
public void invoke(@NotNull Project project, @NotNull PsiDirectory initialBaseDir, @Nullable PsiFile file, @Nullable IdeView view, @Nullable Editor editor) {
48-
NewModuleDialog.open(project, initialBaseDir, file, view, editor);
51+
public void invoke(final @NotNull Project project, final @NotNull PsiDirectory initialBaseDir) {
52+
NewModuleDialog.open(project, initialBaseDir);
4953
}
5054

5155
@Override
5256
public boolean isDumbAware() {
5357
return false;
5458
}
5559

56-
@NotNull
57-
private String getActionName() {
58-
return this.getTemplatePresentation().getText();
59-
}
60-
61-
public PsiFile getFile(DataContext dataContext) {
62-
return CommonDataKeys.PSI_FILE.getData(dataContext);
63-
}
64-
65-
public void update(AnActionEvent event) {
66-
Project project = event.getData(PlatformDataKeys.PROJECT);
60+
/**
61+
* Inherit doc.
62+
*
63+
* @param event AnActionEvent
64+
*/
65+
@Override
66+
public void update(final AnActionEvent event) {
67+
final Project project = event.getData(PlatformDataKeys.PROJECT);
6768

6869
if (Settings.isEnabled(project)) {
69-
String magentoPath = Settings.getMagentoPath(project);
70+
final String magentoPath = Settings.getMagentoPath(project);
7071
if (magentoPath == null) {
7172
event.getPresentation().setVisible(false);
7273
return;
7374
}
74-
PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
75+
final PsiElement psiElement = event.getData(PlatformDataKeys.PSI_ELEMENT);
7576
if (!(psiElement instanceof PsiDirectory)) {
7677
event.getPresentation().setVisible(false);
7778
return;
7879
}
7980

80-
if(!IsClickedDirectoryInsideProject.getInstance().execute(project, (PsiDirectory) psiElement)) {
81+
if (!IsClickedDirectoryInsideProject.getInstance().execute(
82+
project,
83+
(PsiDirectory) psiElement)
84+
) {
8185
event.getPresentation().setVisible(false);
8286
return;
8387
}
8488

85-
GetModuleNameByDirectory getModuleName = GetModuleNameByDirectory.getInstance(project);
86-
String moduleName = getModuleName.execute((PsiDirectory) psiElement);
89+
final GetModuleNameByDirectory getModuleName = GetModuleNameByDirectory
90+
.getInstance(project);
91+
final String moduleName = getModuleName.execute((PsiDirectory) psiElement);
8792
if (moduleName == null) {
8893
event.getPresentation().setVisible(true);
8994
return;

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

Lines changed: 78 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
* Copyright © Magento, Inc. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
5+
56
package com.magento.idea.magento2plugin.actions.generation.dialog;
67

78
import com.intellij.openapi.project.Project;
@@ -15,41 +16,64 @@
1516
import com.magento.idea.magento2plugin.actions.generation.generator.PluginDiXmlGenerator;
1617
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
1718
import com.magento.idea.magento2plugin.magento.files.Plugin;
19+
import com.magento.idea.magento2plugin.magento.packages.Areas;
20+
import com.magento.idea.magento2plugin.magento.packages.File;
1821
import com.magento.idea.magento2plugin.magento.packages.Package;
1922
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
20-
import org.jetbrains.annotations.NotNull;
21-
import javax.swing.*;
22-
import java.awt.*;
23-
import java.awt.event.*;
24-
import com.magento.idea.magento2plugin.magento.packages.File;
23+
import java.awt.event.ActionEvent;
24+
import java.awt.event.ActionListener;
25+
import java.awt.event.KeyEvent;
26+
import java.awt.event.WindowAdapter;
27+
import java.awt.event.WindowEvent;
2528
import java.util.List;
29+
import javax.swing.JButton;
30+
import javax.swing.JComboBox;
31+
import javax.swing.JComponent;
32+
import javax.swing.JLabel;
33+
import javax.swing.JPanel;
34+
import javax.swing.JTextField;
35+
import javax.swing.KeyStroke;
36+
import org.jetbrains.annotations.NotNull;
2637

38+
@SuppressWarnings({"PMD.TooManyFields", "PMD.DataClass", "PMD.UnusedPrivateMethod"})
2739
public class CreateAPluginDialog extends AbstractDialog {
2840
@NotNull
2941
private final Project project;
30-
private Method targetMethod;
31-
private PhpClass targetClass;
42+
private final Method targetMethod;
43+
private final PhpClass targetClass;
3244
@NotNull
3345
private final CreateAPluginDialogValidator validator;
3446
private JPanel contentPane;
3547
private JButton buttonOK;
3648
private JButton buttonCancel;
3749
private JTextField pluginClassName;
38-
private JLabel pluginClassNameLabel;
3950
private JTextField pluginDirectory;
40-
private JLabel pluginDirectoryName;
41-
private JLabel selectPluginModule;
4251
private JComboBox pluginType;
43-
private JLabel pluginTypeLabel;
4452
private FilteredComboBox pluginModule;
4553
private JComboBox pluginArea;
46-
private JLabel pluginAreaLabel;
47-
private JTextField pluginName;
48-
private JLabel pluginNameLabel;
4954
private JTextField pluginSortOrder;
50-
private JLabel pluginSortOrderLabel;
51-
52-
public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpClass targetClass) {
55+
private JTextField pluginName;
56+
private JLabel pluginDirectoryName;//NOPMD
57+
private JLabel selectPluginModule;//NOPMD
58+
private JLabel pluginTypeLabel;//NOPMD
59+
private JLabel pluginAreaLabel;//NOPMD
60+
private JLabel pluginNameLabel;//NOPMD
61+
private JLabel pluginClassNameLabel;//NOPMD
62+
private JLabel pluginSortOrderLabel;//NOPMD
63+
64+
/**
65+
* Constructor.
66+
*
67+
* @param project Project
68+
* @param targetMethod Method
69+
* @param targetClass PhpClass
70+
*/
71+
public CreateAPluginDialog(
72+
final @NotNull Project project,
73+
final Method targetMethod,
74+
final PhpClass targetClass
75+
) {
76+
super();
5377
this.project = project;
5478
this.targetMethod = targetMethod;
5579
this.targetClass = targetClass;
@@ -62,44 +86,46 @@ public CreateAPluginDialog(@NotNull Project project, Method targetMethod, PhpCla
6286
fillTargetAreaOptions();
6387

6488
buttonOK.addActionListener(new ActionListener() {
65-
public void actionPerformed(ActionEvent e) {
89+
public void actionPerformed(final ActionEvent event) {
6690
onOK();
6791
}
6892
});
6993

7094
buttonCancel.addActionListener(new ActionListener() {
71-
public void actionPerformed(ActionEvent e) {
95+
public void actionPerformed(final ActionEvent event) {
7296
onCancel();
7397
}
7498
});
7599

76100
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
77101
addWindowListener(new WindowAdapter() {
78-
public void windowClosing(WindowEvent e) {
102+
public void windowClosing(final WindowEvent event) {
79103
onCancel();
80104
}
81105
});
82106

83107
contentPane.registerKeyboardAction(new ActionListener() {
84-
public void actionPerformed(ActionEvent e) {
108+
public void actionPerformed(final ActionEvent event) {
85109
onCancel();
86110
}
87-
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
111+
}, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
112+
JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT
113+
);
88114
}
89115

90116
private void fillPluginTypeOptions() {
91-
for (Plugin.PluginType pluginPrefixType: Plugin.PluginType.values()) {
117+
for (final Plugin.PluginType pluginPrefixType: Plugin.PluginType.values()) {
92118
pluginType.addItem(pluginPrefixType.toString());
93119
}
94120
}
95121

96122
private void fillTargetAreaOptions() {
97-
for(Package.Areas area: Package.Areas.values()) {
123+
for (final Areas area : Areas.values()) {
98124
pluginArea.addItem(area.toString());
99125
}
100126
}
101127

102-
private void onOK() {
128+
protected void onOK() {
103129
if (!validator.validate(project)) {
104130
return;
105131
}
@@ -154,27 +180,46 @@ public String getPluginModule() {
154180
return this.pluginModule.getSelectedItem().toString();
155181
}
156182

157-
public static void open(@NotNull Project project, Method targetMethod, PhpClass targetClass) {
158-
CreateAPluginDialog dialog = new CreateAPluginDialog(project, targetMethod, targetClass);
183+
/**
184+
* Open an action dialog.
185+
*
186+
* @param project Project
187+
* @param targetMethod Method
188+
* @param targetClass PhpClass
189+
*/
190+
public static void open(
191+
final @NotNull Project project,
192+
final Method targetMethod,
193+
final PhpClass targetClass
194+
) {
195+
final CreateAPluginDialog dialog = new CreateAPluginDialog(
196+
project,
197+
targetMethod,
198+
targetClass
199+
);
159200
dialog.pack();
160201
dialog.centerDialog(dialog);
161202
dialog.setVisible(true);
162203
}
163204

164205
private void createUIComponents() {
165-
List<String> allModulesList = ModuleIndex.getInstance(project).getEditableModuleNames();
206+
final List<String> allModulesList = ModuleIndex.getInstance(project)
207+
.getEditableModuleNames();
166208

167209
this.pluginModule = new FilteredComboBox(allModulesList);
168210
}
169211

170212
private String getNamespace() {
171-
String targetModule = getPluginModule();
172-
String namespace = targetModule.replace(Package.VENDOR_MODULE_NAME_SEPARATOR, Package.FQN_SEPARATOR);
173-
namespace = namespace.concat(Package.FQN_SEPARATOR);
174-
return namespace.concat(getPluginDirectory().replace(File.separator, Package.FQN_SEPARATOR));
213+
final String targetModule = getPluginModule();
214+
String namespace = targetModule.replace(
215+
Package.vendorModuleNameSeparator,
216+
Package.fqnSeparator
217+
);
218+
namespace = namespace.concat(Package.fqnSeparator);
219+
return namespace.concat(getPluginDirectory().replace(File.separator, Package.fqnSeparator));
175220
}
176221

177222
private String getPluginClassFqn() {
178-
return getNamespace().concat(Package.FQN_SEPARATOR).concat(getPluginClassName());
223+
return getNamespace().concat(Package.fqnSeparator).concat(getPluginClassName());
179224
}
180225
}

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverClassGenerator;
1515
import com.magento.idea.magento2plugin.actions.generation.generator.ObserverEventsXmlGenerator;
1616
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
17+
import com.magento.idea.magento2plugin.magento.packages.Areas;
1718
import com.magento.idea.magento2plugin.magento.packages.File;
1819
import com.magento.idea.magento2plugin.magento.packages.Package;
1920
import com.magento.idea.magento2plugin.ui.FilteredComboBox;
@@ -109,7 +110,7 @@ public static void open(@NotNull final Project project, final String targetEvent
109110
* Setup observer area combobox.
110111
*/
111112
private void fillTargetAreaOptions() {
112-
for (final Package.Areas area : Package.Areas.values()) {
113+
for (final Areas area : Areas.values()) {
113114
observerArea.addItem(area.toString());
114115
}
115116
}
@@ -171,19 +172,19 @@ private void createUIComponents() { //NOPMD
171172
private String getNamespace() {
172173
final String targetModule = getObserverModule();
173174
String namespace = targetModule.replace(
174-
Package.VENDOR_MODULE_NAME_SEPARATOR,
175-
Package.FQN_SEPARATOR
175+
Package.vendorModuleNameSeparator,
176+
Package.fqnSeparator
176177
);
177178

178-
namespace = namespace.concat(Package.FQN_SEPARATOR);
179+
namespace = namespace.concat(Package.fqnSeparator);
179180
return namespace.concat(getObserverDirectory().replace(
180181
File.separator,
181-
Package.FQN_SEPARATOR)
182+
Package.fqnSeparator)
182183
);
183184
}
184185

185186
private String getObserverClassFqn() {
186-
return getNamespace().concat(Package.FQN_SEPARATOR).concat(getObserverClassName());
187+
return getNamespace().concat(Package.fqnSeparator).concat(getObserverClassName());
187188
}
188189
}
189190

0 commit comments

Comments
 (0)