Skip to content

#186: Extend the new Magento 2 module generation with the ability to … #266

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 6 commits into from
Feb 12, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@
package com.magento.idea.magento2plugin.actions.generation.data;

import com.intellij.psi.PsiDirectory;
import java.util.List;

@SuppressWarnings({"PMD.DataClass"})
public class ModuleXmlData {
private final String packageName;
private final String moduleName;
private final String setupVersion;
private final PsiDirectory baseDir;
private final List<String> moduleSequences;
private final boolean createModuleDirs;

/**
Expand All @@ -29,12 +31,14 @@ public ModuleXmlData(
final String moduleName,
final String setupVersion,
final PsiDirectory baseDir,
final List<String> moduleSequences,
final boolean createModuleDirs
) {
this.packageName = packageName;
this.moduleName = moduleName;
this.setupVersion = setupVersion;
this.baseDir = baseDir;
this.moduleSequences = moduleSequences;
this.createModuleDirs = createModuleDirs;
}

Expand All @@ -54,6 +58,10 @@ public String getSetupVersion() {
return this.setupVersion;
}

public List<String> getModuleSequences() {
return moduleSequences;
}

public boolean isCreateModuleDirs() {
return this.createModuleDirs;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ private void generateModuleXml() {
getModuleName(),
getSetupVersion(),
getBaseDir(),
getModuleDependencies(),
true
), project).generate(NewModuleAction.actionName, true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator;
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
import com.magento.idea.magento2plugin.magento.packages.Package;
import java.util.List;
import java.util.Properties;
import org.jetbrains.annotations.NotNull;

Expand Down Expand Up @@ -74,5 +75,30 @@ protected void fillAttributes(final Properties attributes) {
if (moduleXmlData.getSetupVersion() != null) {
attributes.setProperty("SETUP_VERSION", moduleXmlData.getSetupVersion());
}

final String sequences = this.getSequencesString(moduleXmlData.getModuleSequences());
if (!sequences.isEmpty()) {
attributes.setProperty(
"SEQUENCES",
sequences
);
}
}

private String getSequencesString(final List sequences) {
String result = "";
final Object[] dependencies = sequences.toArray();
final boolean noDependency = dependencies.length == 1 && dependencies[0]
.equals(ModuleXml.NO_SEQUENCES_LABEL);

if (noDependency) {
return result;
}

for (final Object o : dependencies) {
result = result.concat(String.format("<module name=\"%s\"/>", o.toString()));
}

return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;


public class MagentoModuleGenerator extends WebProjectTemplate<MagentoProjectGeneratorSettings> {
public static String actionName = "Magento 2 Module";

Expand Down Expand Up @@ -133,7 +132,7 @@ private PsiFile generateComposerJson(
* @param project Project
* @param baseDir Base directory
* @param settings Settings
* @return
* @return void
*/
private PsiFile generateRegistrationPhp(
@NotNull final Project project,
Expand Down Expand Up @@ -165,6 +164,7 @@ private void generateModuleXml(
settings.getModuleName(),
settings.getModuleVersion(),
baseDir,
new ArrayList<>(),
false
);
final ModuleXmlGenerator moduleXmlGenerator =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public class ModuleXml implements ModuleFileInterface {
public static final String FILE_NAME = "module.xml";
public static final String MODULE_ATTR_NAME = "name";
public static final String TEMPLATE = "Magento Module XML";
public static final String NO_SEQUENCES_LABEL = "None";
private static final ModuleXml INSTANCE = new ModuleXml();

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_Module"/>
<module name="Test_Module">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_InventoryApi"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_Module"/>
<module name="Test_Module">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_InventoryApi"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Test_Module1" setup_version="1.0.0"/>
<module name="Test_Module1" setup_version="1.0.0">
<sequence>
<module name="Magento_Catalog"/>
<module name="Magento_InventoryApi"/>
</sequence>
</module>
</config>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
import com.magento.idea.magento2plugin.magento.packages.File;
import com.magento.idea.magento2plugin.magento.packages.Package;
import java.util.Arrays;

public class ModuleXmlGeneratorHaveSetupVersionTest extends BaseGeneratorTestCase {

Expand All @@ -24,6 +25,7 @@ public void testGenerateModuleFile() {
"Module1",
"1.0.0",
projectDir,
Arrays.asList("Magento_Catalog", "Magento_InventoryApi"),
true
);
final ModuleXmlGenerator moduleXmlGenerator = new ModuleXmlGenerator(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.magento.idea.magento2plugin.magento.files.ModuleXml;
import com.magento.idea.magento2plugin.magento.packages.File;
import com.magento.idea.magento2plugin.magento.packages.Package;
import java.util.Arrays;

public class ModuleXmlGeneratorTest extends BaseGeneratorTestCase {

Expand All @@ -29,6 +30,7 @@ public void testGenerateModuleFile() {
"Module",
null,
projectDir,
Arrays.asList("Magento_Catalog", "Magento_InventoryApi"),
true
);
final ModuleXmlGenerator moduleXmlGenerator = new ModuleXmlGenerator(
Expand Down Expand Up @@ -60,6 +62,7 @@ public void testGenerateFileInRoot() {
"Module",
null,
projectDir,
Arrays.asList("Magento_Catalog", "Magento_InventoryApi"),
false
);
final ModuleXmlGenerator moduleXmlGenerator = new ModuleXmlGenerator(
Expand Down