Skip to content

963: Bug during composer json generation #972

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
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 @@ -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;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

jsonObject can be null as well.

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