Skip to content

Commit

Permalink
Merge pull request #972 from Iamwade/963-bug-composer-json-generation
Browse files Browse the repository at this point in the history
963: Bug during composer json generation
  • Loading branch information
bohdan-harniuk authored Feb 11, 2022
2 parents c8d2559 + e69522f commit f287948
Showing 1 changed file with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import com.magento.idea.magento2plugin.actions.generation.generator.util.FileFromTemplateGenerator;
import com.magento.idea.magento2plugin.indexes.ModuleIndex;
import com.magento.idea.magento2plugin.magento.files.ComposerJson;
import com.magento.idea.magento2plugin.util.CamelCaseToHyphen;
import java.util.List;
import java.util.Properties;
import org.jetbrains.annotations.NotNull;
Expand All @@ -28,10 +27,10 @@

public class ModuleComposerJsonGenerator extends FileGenerator {

private static final String ANY_VERSION = "*";
private final ModuleComposerJsonData moduleComposerJsonData;
private final FileFromTemplateGenerator fileFromTemplateGenerator;
private final DirectoryGenerator directoryGenerator;
private final CamelCaseToHyphen camelCaseToHyphen;
private final ModuleIndex moduleIndex;

/**
Expand All @@ -48,7 +47,6 @@ public ModuleComposerJsonGenerator(
this.moduleComposerJsonData = moduleComposerJsonData;
this.fileFromTemplateGenerator = new FileFromTemplateGenerator(project);
this.directoryGenerator = DirectoryGenerator.getInstance();
this.camelCaseToHyphen = CamelCaseToHyphen.getInstance();
this.moduleIndex = new ModuleIndex(project);
}

Expand Down Expand Up @@ -158,10 +156,9 @@ private String getDependenciesString(final List dependenciesList) {
private Pair<String, String> getDependencyData(
final String dependency
) {
String version = "*";
String moduleName = camelCaseToHyphen.convert(dependency).replace(
"_-", "/"
);
String version = "";
String moduleName = "";

try {
final PsiDirectory moduleDir = moduleIndex.getModuleDirectoryByModuleName(dependency);

Expand All @@ -184,20 +181,20 @@ private Pair<String, String> getDependencyData(
composerJsonFile.getText()
);
final JSONObject jsonObject = (JSONObject) obj;
final String versionJsonElement = jsonObject.get("version").toString();
final String nameJsonElement = jsonObject.get("name").toString();

if (versionJsonElement != null) {
version = versionJsonElement;
if (jsonObject.get("name") == null) {
return Pair.create("", "");
}
moduleName = jsonObject.get("name").toString().trim();
version = jsonObject.get("version") == null
? ANY_VERSION : jsonObject.get("version").toString();

if (!ANY_VERSION.equals(version)) {
final int minorVersionSeparator = version.lastIndexOf('.');
version = new StringBuilder(version)
.replace(minorVersionSeparator + 1, version.length(),"*")
.replace(minorVersionSeparator + 1, version.length(), ANY_VERSION)
.toString();
}

if (nameJsonElement != null) {
moduleName = nameJsonElement;
}
}
} else {
return Pair.create("", "");
Expand Down

0 comments on commit f287948

Please sign in to comment.