From f7489fd5b6a5f18c891d076ec609774fc811ac0c Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Tue, 14 Dec 2021 13:30:03 +0200 Subject: [PATCH 1/6] 698: Added to remove substring the module from module name. Added prefix the "module-" for composerPackageName. --- .../generation/dialog/NewModuleDialog.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 0e2a18f9e..bb215d323 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -107,6 +107,7 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList private final ModuleIndex moduleIndex; private final CamelCaseToHyphen camelCaseToHyphen; private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11"; + private static final String DEFAULT_MODULE_PREFIX = "module"; /** * Constructor. @@ -246,7 +247,18 @@ public String getPackageName() { } public String getModuleName() { - return this.moduleName.getText().trim(); + return this.removeSubstringFormString(DEFAULT_MODULE_PREFIX, this.moduleName.getText().trim()); + } + + /** + * + * @param target String + * @param replacement String + * @return String + */ + private String removeSubstringFormString(@NotNull String target, @NotNull String replacement) { + String moduleRegex = "(?i)" + target; + return replacement.replaceAll(moduleRegex, ""); } /** @@ -332,6 +344,7 @@ public static void open( private String getComposerPackageName() { return camelCaseToHyphen.convert(getPackageName()) .concat("/") + .concat(DEFAULT_MODULE_PREFIX + "-") .concat(camelCaseToHyphen.convert(getModuleName())); } From d58cb8b68ec7f606a96a378e0b98d41de115db92 Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Tue, 14 Dec 2021 22:49:27 +0200 Subject: [PATCH 2/6] 698: Changed composer.json files for test. Changed of tests testGenerateModuleFileWithoutDependencies, testGenerateModuleFile --- .../generateFileInRoot/composer.json | 4 ++-- .../generateModuleFile/composer.json | 4 ++-- .../generateModuleFileWithoutDependencies/composer.json | 4 ++-- .../generation/generator/ModuleComposerJsonGeneratorTest.java | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateFileInRoot/composer.json b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateFileInRoot/composer.json index fd8914d3b..9f3e0e708 100644 --- a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateFileInRoot/composer.json +++ b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateFileInRoot/composer.json @@ -1,5 +1,5 @@ { - "name": "test/module", + "name": "test/module-test", "version": "1.0.0-dev", "description": "test-description", "type": "magento2-module", @@ -17,7 +17,7 @@ "registration.php" ], "psr-4": { - "TestWithDependencies\\Module\\": "" + "TestWithDependencies\\Test\\": "" } } } diff --git a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFile/composer.json b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFile/composer.json index fd8914d3b..9f3e0e708 100644 --- a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFile/composer.json +++ b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFile/composer.json @@ -1,5 +1,5 @@ { - "name": "test/module", + "name": "test/module-test", "version": "1.0.0-dev", "description": "test-description", "type": "magento2-module", @@ -17,7 +17,7 @@ "registration.php" ], "psr-4": { - "TestWithDependencies\\Module\\": "" + "TestWithDependencies\\Test\\": "" } } } diff --git a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFileWithoutDependencies/composer.json b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFileWithoutDependencies/composer.json index b5cb1a879..c87b41bd1 100644 --- a/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFileWithoutDependencies/composer.json +++ b/testData/actions/generation/generator/ModuleComposerJsonGenerator/generateModuleFileWithoutDependencies/composer.json @@ -1,5 +1,5 @@ { - "name": "test/module", + "name": "test/module-test", "version": "1.0.0-dev", "description": "test-description", "type": "magento2-module", @@ -15,7 +15,7 @@ "registration.php" ], "psr-4": { - "TestWithoutDependencies\\Module\\": "" + "TestWithoutDependencies\\Test\\": "" } } } diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java index 48346d78e..c5ae77c8a 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java @@ -102,10 +102,10 @@ private PsiFile generateComposerJson( ); final ModuleComposerJsonData composerJsonData = new ModuleComposerJsonData( packageName, - "Module", + "Test", projectDir, "test-description", - "test/module", + "test/module-test", "1.0.0-dev", licenses, dependencies, From db5625fc206164438a0eb4245430a74864b33ea2 Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Tue, 14 Dec 2021 22:56:32 +0200 Subject: [PATCH 3/6] 698: Changed of tests testGenerateModuleFileWithoutDependencies, testGenerateModuleFile. Changed of expectedDirectories. --- .../generation/generator/ModuleComposerJsonGeneratorTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java index c5ae77c8a..f02c36460 100644 --- a/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java +++ b/tests/com/magento/idea/magento2plugin/actions/generation/generator/ModuleComposerJsonGeneratorTest.java @@ -25,7 +25,7 @@ public void testGenerateModuleFile() { final PsiDirectory projectDir = getProjectDirectory(); final String expectedDirectory = - projectDir.getVirtualFile().getPath() + "/TestWithDependencies/Module"; + projectDir.getVirtualFile().getPath() + "/TestWithDependencies/Test"; final PsiFile composerJson = generateComposerJson( true, projectDir, @@ -65,7 +65,7 @@ public void testGenerateModuleFileWithoutDependencies() { final PsiFile expectedFile = myFixture.configureByFile(filePath); final PsiDirectory projectDir = getProjectDirectory(); final String expectedDirectory = projectDir.getVirtualFile().getPath() - + "/TestWithoutDependencies/Module"; + + "/TestWithoutDependencies/Test"; final PsiFile composerJson = generateComposerJson( true, projectDir, From c4c39f8fd469c1fb537f8f2a89465b9e4f434ac7 Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Wed, 15 Dec 2021 11:45:41 +0200 Subject: [PATCH 4/6] 698: Changed Javadoc. Refactor. --- .../generation/dialog/NewModuleDialog.java | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index bb215d323..eca3913bd 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -246,17 +246,26 @@ public String getPackageName() { return this.packageName.getText().trim(); } + /** + * Getter for Module Name. + * + * @return String + */ public String getModuleName() { - return this.removeSubstringFormString(DEFAULT_MODULE_PREFIX, this.moduleName.getText().trim()); + return this.removeSubstringFormString( + DEFAULT_MODULE_PREFIX, this.moduleName.getText().trim() + ); } /** - * + * Remove substring from string. * @param target String * @param replacement String * @return String */ - private String removeSubstringFormString(@NotNull String target, @NotNull String replacement) { + private String removeSubstringFormString( + @NotNull String target, @NotNull String replacement + ) { String moduleRegex = "(?i)" + target; return replacement.replaceAll(moduleRegex, ""); } From 49bf302c4aba9397fa63833ffe2c031c987d4916 Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Wed, 15 Dec 2021 12:36:16 +0200 Subject: [PATCH 5/6] 698: Changed of parameters for function removeSubstringFormString to final. --- .../actions/generation/dialog/NewModuleDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index eca3913bd..22bd658e9 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -264,9 +264,9 @@ public String getModuleName() { * @return String */ private String removeSubstringFormString( - @NotNull String target, @NotNull String replacement + final @NotNull String target, final @NotNull String replacement ) { - String moduleRegex = "(?i)" + target; + final String moduleRegex = "(?i)" + target; return replacement.replaceAll(moduleRegex, ""); } From 25867b382dec3b6f75962fb0070581ca2ead2d0b Mon Sep 17 00:00:00 2001 From: "artemii.karkusha" Date: Thu, 16 Dec 2021 10:25:52 +0200 Subject: [PATCH 6/6] 698: Moved properties on top of class NewModuleDialog. Removed of function removeSubstringFormString. --- .../generation/dialog/NewModuleDialog.java | 21 +++---------------- 1 file changed, 3 insertions(+), 18 deletions(-) diff --git a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java index 22bd658e9..203177405 100644 --- a/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java +++ b/src/com/magento/idea/magento2plugin/actions/generation/dialog/NewModuleDialog.java @@ -53,6 +53,8 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList private static final String MODULE_VERSION = "module version"; private static final String MODULE_NAME = "module name"; private static final String PACKAGE_NAME = "package name"; + private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11"; + private static final String DEFAULT_MODULE_PREFIX = "module"; @FieldValidation(rule = RuleRegistry.NOT_EMPTY, message = {NotEmptyRule.MESSAGE, PACKAGE_NAME}) @@ -106,8 +108,6 @@ public class NewModuleDialog extends AbstractDialog implements ListSelectionList private String detectedPackageName; private final ModuleIndex moduleIndex; private final CamelCaseToHyphen camelCaseToHyphen; - private static final String MAGENTO_BEFORE_DECLARATIVE_SCHEMA_VERSION = "2.2.11"; - private static final String DEFAULT_MODULE_PREFIX = "module"; /** * Constructor. @@ -252,22 +252,7 @@ public String getPackageName() { * @return String */ public String getModuleName() { - return this.removeSubstringFormString( - DEFAULT_MODULE_PREFIX, this.moduleName.getText().trim() - ); - } - - /** - * Remove substring from string. - * @param target String - * @param replacement String - * @return String - */ - private String removeSubstringFormString( - final @NotNull String target, final @NotNull String replacement - ) { - final String moduleRegex = "(?i)" + target; - return replacement.replaceAll(moduleRegex, ""); + return this.moduleName.getText().trim(); } /**