Skip to content

Commit 305feb6

Browse files
author
Vitaliy Boyko
committed
Merge branch '1.0.1-develop' of https://github.com/magento/magento2-phpstorm-plugin into 243-adjusting-path-detection
� Conflicts: � src/com/magento/idea/magento2plugin/actions/generation/generator/util/NamespaceBuilder.java
2 parents 24f4770 + 06c1505 commit 305feb6

File tree

34 files changed

+1708
-106
lines changed

34 files changed

+1708
-106
lines changed

Diff for: gradle-tasks/pmd/ruleset.xml

+9-2
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,13 @@
1313
<description>
1414
Magento PhpStorm rules
1515
</description>
16-
<rule ref="category/java/bestpractices.xml" />
17-
<rule ref="category/java/codestyle.xml"/>
16+
<rule ref="category/java/bestpractices.xml">
17+
<exclude name="JUnit4TestShouldUseTestAnnotation"/>
18+
</rule>
19+
<rule ref="category/java/codestyle.xml">
20+
<exclude name="AtLeastOneConstructor" />
21+
<exclude name="LongVariable" />
22+
</rule>
1823
<rule ref="category/java/design.xml">
1924
<exclude name="LawOfDemeter"/>
2025
</rule>
@@ -24,6 +29,8 @@
2429
<rule ref="category/java/errorprone.xml">
2530
<exclude name="BeanMembersShouldSerialize"/>
2631
</rule>
32+
<exclude-pattern>.*/resources/.*</exclude-pattern>
33+
<exclude-pattern>.*/testData/.*</exclude-pattern>
2734
<rule ref="category/java/multithreading.xml"/>
2835
<rule ref="category/java/performance.xml"/>
2936
<rule ref="category/java/security.xml" />

Diff for: resources/META-INF/plugin.xml

+2
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@
6060
<action id="MagentoCreateACronjob" class="com.magento.idea.magento2plugin.actions.generation.NewCronjobAction" />
6161
<action id="MagentoCreateAViewModel" class="com.magento.idea.magento2plugin.actions.generation.NewViewModelAction" />
6262
<action id="MagentoCreateAGraphQlResolver" class="com.magento.idea.magento2plugin.actions.generation.NewGraphQlResolverAction" />
63+
<action id="MagentoCreateCLICommand" class="com.magento.idea.magento2plugin.actions.generation.NewCLICommandAction" />
6364
<add-to-group group-id="NewGroup" anchor="last"/>
6465
</group>
6566

@@ -161,6 +162,7 @@
161162
<internalFileTemplate name="Magento GraphQL Resolver Class"/>
162163
<internalFileTemplate name="Magento Cronjob Class"/>
163164
<internalFileTemplate name="Magento Crontab Xml"/>
165+
<internalFileTemplate name="Magento CLI Command"/>
164166
</extensions>
165167

166168
<extensions defaultExtensionNs="com.jetbrains.php">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#if (${CLI_COMMAND_INTERFACE})
2+
<type name="${CLI_COMMAND_INTERFACE}">
3+
<arguments>
4+
<argument name="commands" xsi:type="array">
5+
#end
6+
<item name="${CLI_COMMAND_DI_NAME}" xsi:type="object">${CLI_COMMAND_CLASS}</item>
7+
#if (${CLI_COMMAND_INTERFACE})
8+
</argument>
9+
</arguments>
10+
</type>
11+
#end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!--
2+
/*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html>
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">
13+
Each CLI Command must be register in the related module di.xml.
14+
Declare your Command class in Magento\Framework\Console\CommandListInterface and configure the command name using dependency injection
15+
</font>
16+
</td>
17+
</tr>
18+
<tr>
19+
<td>
20+
<font face="verdana" size="-1">
21+
<a href="https://devdocs.magento.com/guides/v2.3/extension-dev-guide/cli-cmds/cli-howto.html">Create a new CLI Command in Magento.</a>
22+
</font>
23+
</td>
24+
</tr>
25+
</table>
26+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
27+
<tr>
28+
<td colspan="3"><font face="verdana" size="-1">Predefined variables explanation:</font></td>
29+
</tr>
30+
<tr>
31+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_DI_NAME}</b></font></nobr></td>
32+
<td width="10">&nbsp;</td>
33+
<td width="100%" valign="top"><font face="verdana" size="-1">A CLI Command name used for DI to the CommandListInterface.</font></td>
34+
</tr>
35+
<tr>
36+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_CLASS}</b></font></nobr></td>
37+
<td width="10">&nbsp;</td>
38+
<td width="100%" valign="top"><font face="verdana" size="-1">A class of the CLI Command.</font></td>
39+
</tr>
40+
</table>
41+
</body>
42+
</html>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
#parse("PHP File Header.php")
3+
4+
#if (${NAMESPACE})
5+
namespace ${NAMESPACE};
6+
#end
7+
8+
use Symfony\Component\Console\Command\Command;
9+
use Symfony\Component\Console\Input\InputInterface;
10+
use Symfony\Component\Console\Output\OutputInterface;
11+
12+
class ${NAME} extends Command
13+
{
14+
/**
15+
* @inheritDoc
16+
*/
17+
protected function configure()
18+
{
19+
$this->setName('${CLI_COMMAND_NAME}');
20+
$this->setDescription('${CLI_COMMAND_DESCRIPTION}');
21+
parent::configure();
22+
}
23+
24+
/**
25+
* CLI command description
26+
*
27+
* @param InputInterface $input
28+
* @param OutputInterface $output
29+
*
30+
* @return void
31+
*/
32+
protected function execute(InputInterface $input, OutputInterface $output): void
33+
{
34+
// todo: implement CLI command logic here
35+
}
36+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
<!--
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<html lang="en">
8+
<body>
9+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
10+
<tr>
11+
<td>
12+
<font face="verdana" size="-1">
13+
Magento enables your component to add commands to our Symfony-like command-line interface (CLI).
14+
<a href="https://devdocs.magento.com/guides/v2.3/extension-dev-guide/cli-cmds/cli-howto.html">
15+
Read more</a> about Magneto CLI commands.
16+
</font>
17+
</td>
18+
</tr>
19+
</table>
20+
21+
<table width="100%" border="0" cellpadding="5" cellspacing="0" style="border-collapse: collapse">
22+
<tr>
23+
<td colspan="3"><font face="verdana" size="-1">Template's variables:</font></td>
24+
</tr>
25+
<tr>
26+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAMESPACE}</b></font></nobr></td>
27+
<td width="10">&nbsp;</td>
28+
<td width="100%" valign="top"><font face="verdana" size="-1">Created PHP CLI command class namespace.</font></td>
29+
</tr>
30+
<tr>
31+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
32+
<td width="10">&nbsp;</td>
33+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the CLI command name.</font></td>
34+
</tr>
35+
<tr>
36+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${NAME}</b></font></nobr></td>
37+
<td width="10">&nbsp;</td>
38+
<td width="100%" valign="top"><font face="verdana" size="-1">PHP class for the CLI command name.</font></td>
39+
</tr>
40+
<tr>
41+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_NAME}</b></font></nobr></td>
42+
<td width="10">&nbsp;</td>
43+
<td width="100%" valign="top"><font face="verdana" size="-1">Name of the CLI used under the bin/magento.</font></td>
44+
</tr>
45+
<tr>
46+
<td valign="top"><nobr><font face="verdana" size="-2"><b>${CLI_COMMAND_DESCRIPTION}</b></font></nobr></td>
47+
<td width="10">&nbsp;</td>
48+
<td width="100%" valign="top"><font face="verdana" size="-1">Description of the CLI command used under the bin/magento.</font></td>
49+
</tr>
50+
</table>
51+
</body>
52+
</html>

Diff for: resources/magento2/common.properties

+7
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,10 @@ common.notAvailable=N/A
2727
common.classInheritance=Inherit Class
2828
common.license.proprietary=Proprietary
2929
common.description=Description
30+
common.parentDirectory=Parent Directory
31+
common.cliCommandName=Command Name
32+
common.cli.create.new.cli.command.title=Create a new Magento 2 CLI Command
33+
common.cli.generate.error=New CLI Command Generation Error
34+
common.cli.class.title=CLI Command Class
35+
common.validationErrorTitle=Validation Error
36+
common.defaultConsoleDirectory=Console
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation;
7+
8+
import com.intellij.ide.IdeView;
9+
import com.intellij.openapi.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
14+
import com.intellij.openapi.project.Project;
15+
import com.intellij.psi.PsiDirectory;
16+
import com.magento.idea.magento2plugin.MagentoIcons;
17+
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCLICommandDialog;
18+
import org.jetbrains.annotations.NotNull;
19+
20+
@SuppressWarnings({"PMD.FieldNamingConventions", "PMD.OnlyOneReturn"})
21+
public class NewCLICommandAction extends AnAction {
22+
public static String ACTION_NAME = "Magento 2 CLI Command";
23+
public static String ACTION_DESCRIPTION = "Create a new Magento 2 CLI Command";
24+
25+
public NewCLICommandAction() {
26+
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
27+
}
28+
29+
@Override
30+
public void actionPerformed(@NotNull final AnActionEvent event) {
31+
final DataContext context = event.getDataContext();
32+
final IdeView view = LangDataKeys.IDE_VIEW.getData(context);
33+
if (view == null) {
34+
return;
35+
}
36+
37+
final Project project = CommonDataKeys.PROJECT.getData(context);
38+
if (project == null) {
39+
return;
40+
}
41+
42+
final PsiDirectory directory = view.getOrChooseDirectory();
43+
if (directory == null) {
44+
return;
45+
}
46+
47+
NewCLICommandDialog.open(project, directory);
48+
}
49+
50+
@Override
51+
public boolean isDumbAware() {
52+
return false;
53+
}
54+
}

Diff for: src/com/magento/idea/magento2plugin/actions/generation/NewCronjobAction.java

+13-9
Original file line numberDiff line numberDiff line change
@@ -2,40 +2,45 @@
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.actionSystem.AnAction;
10+
import com.intellij.openapi.actionSystem.AnActionEvent;
11+
import com.intellij.openapi.actionSystem.CommonDataKeys;
12+
import com.intellij.openapi.actionSystem.DataContext;
13+
import com.intellij.openapi.actionSystem.LangDataKeys;
914
import com.intellij.openapi.project.Project;
1015
import com.intellij.psi.PsiDirectory;
1116
import com.magento.idea.magento2plugin.MagentoIcons;
1217
import com.magento.idea.magento2plugin.actions.generation.dialog.NewCronjobDialog;
13-
import com.magento.idea.magento2plugin.indexes.CronGroupIndex;
1418
import org.jetbrains.annotations.NotNull;
1519

20+
@SuppressWarnings({"PMD.FieldNamingConventions", "PMD.OnlyOneReturn"})
1621
public class NewCronjobAction extends AnAction {
1722
public static String ACTION_NAME = "Magento 2 Cronjob";
1823
public static String ACTION_DESCRIPTION = "Create a new Magento 2 cronjob";
1924

20-
NewCronjobAction() {
25+
public NewCronjobAction() {
2126
super(ACTION_NAME, ACTION_DESCRIPTION, MagentoIcons.MODULE);
2227
}
2328

2429
@Override
25-
public void actionPerformed(@NotNull AnActionEvent e) {
26-
DataContext dataContext = e.getDataContext();
27-
IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
30+
public void actionPerformed(final @NotNull AnActionEvent event) {
31+
final DataContext dataContext = event.getDataContext();
32+
final IdeView view = LangDataKeys.IDE_VIEW.getData(dataContext);
2833

2934
if (view == null) {
3035
return;
3136
}
3237

33-
Project project = CommonDataKeys.PROJECT.getData(dataContext);
38+
final Project project = CommonDataKeys.PROJECT.getData(dataContext);
3439
if (project == null) {
3540
return;
3641
}
3742

38-
PsiDirectory directory = view.getOrChooseDirectory();
43+
final PsiDirectory directory = view.getOrChooseDirectory();
3944
if (directory == null) {
4045
return;
4146
}
@@ -48,4 +53,3 @@ public boolean isDumbAware() {
4853
return false;
4954
}
5055
}
51-
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
/*
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
6+
package com.magento.idea.magento2plugin.actions.generation.data;
7+
8+
@SuppressWarnings({"PMD.CommentSize", "PMD.DataClass"})
9+
public class CLICommandClassData {
10+
private final String className;
11+
private final String parentDirectory;
12+
private final String commandName;
13+
private final String description;
14+
private final String namespace;
15+
private final String moduleName;
16+
17+
/**
18+
* CLI Command PHP class data class.
19+
*
20+
* @param cliClassName PHP class name
21+
* @param parentDirectory Prent directory of a PHP class
22+
* @param cliCommandName CLI Command name
23+
* @param description CLI Command description
24+
* @param namespace namespace of a PHP class
25+
* @param moduleName CLI Command module name
26+
*/
27+
public CLICommandClassData(
28+
final String cliClassName,
29+
final String parentDirectory,
30+
final String cliCommandName,
31+
final String description,
32+
final String namespace,
33+
final String moduleName
34+
) {
35+
this.className = cliClassName;
36+
this.parentDirectory = parentDirectory;
37+
this.commandName = cliCommandName;
38+
this.description = description;
39+
this.namespace = namespace;
40+
this.moduleName = moduleName;
41+
}
42+
43+
public String getClassName() {
44+
return className;
45+
}
46+
47+
public String getParentDirectory() {
48+
return parentDirectory;
49+
}
50+
51+
public String getCommandName() {
52+
return commandName;
53+
}
54+
55+
public String getCommandDescription() {
56+
return description;
57+
}
58+
59+
public String getNamespace() {
60+
return namespace;
61+
}
62+
63+
public String getModuleName() {
64+
return moduleName;
65+
}
66+
}

0 commit comments

Comments
 (0)