Skip to content

Commit e0af1c5

Browse files
authored
Merge pull request #2081 from piotrkwiecinski/mage-os-support
feature: mage-os support
2 parents e5b0966 + 2722381 commit e0af1c5

File tree

4 files changed

+48
-25
lines changed

4 files changed

+48
-25
lines changed

src/com/magento/idea/magento2plugin/magento/packages/Package.java

+1
Original file line numberDiff line numberDiff line change
@@ -19,4 +19,5 @@ public class Package { //NOPMD
1919
public static String vendorModuleNameSeparator = "_";
2020
public static String fqnSeparator = "\\";
2121
public static String composerType = "project";
22+
public static String mageOsFrameworkRootComposer = "vendor/mage-os/framework";
2223
}

src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@
77

88
import java.util.ArrayList;
99
import java.util.Arrays;
10+
import java.util.Comparator;
1011
import java.util.List;
1112

1213
public enum MagentoVersion {
1314

1415
ENTERPRISE_EDITION("magento/product-enterprise-edition", 1, "Adobe Commerce"),
15-
COMMUNITY_EDITION("magento/product-community-edition", 2, "Magento Open Source");
16+
COMMUNITY_EDITION("magento/product-community-edition", 2, "Magento Open Source"),
17+
MAGEOS_COMMUNITY_EDITION("mage-os/product-community-edition", 3, "Mage-OS Community Edition");
1618

1719
private final String name;
1820
private final int priority;
@@ -52,9 +54,7 @@ public static List<MagentoVersion> getVersions() {
5254
final List<MagentoVersion> versions = new ArrayList<>(
5355
Arrays.asList(MagentoVersion.values())
5456
);
55-
versions.sort(
56-
(version1, version2) -> version1.getPriority() > version2.getPriority() ? 1 : 0
57-
);
57+
versions.sort(Comparator.comparingInt(MagentoVersion::getPriority));
5858

5959
return versions;
6060
}

src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java

+40-21
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.List;
1717
import java.util.Map;
1818
import org.apache.commons.lang3.StringUtils;
19+
import org.apache.commons.lang3.tuple.ImmutablePair;
1920
import org.jetbrains.annotations.NotNull;
2021
import org.jetbrains.annotations.Nullable;
2122

@@ -47,32 +48,20 @@ private GetMagentoVersionUtil() {
4748
final Map<String, String> foundMagentoPackages = new HashMap<>();
4849

4950
for (final JsonObject packageItem : packages) {
50-
final JsonProperty nameProperty = packageItem.findProperty(
51-
ComposerLock.PACKAGE_NAME_PROP
52-
);
51+
final @Nullable ImmutablePair<String, String> magentoPackage = findMagentoPackage(
52+
packageItem,
53+
versionNames);
5354

54-
if (nameProperty == null || nameProperty.getValue() == null) {
55+
if (magentoPackage == null) {
5556
continue;
5657
}
57-
final String name = StringUtils.strip(nameProperty.getValue().getText(), "\"");
5858

59-
if (versionNames.contains(name)) {
60-
final JsonProperty versionProperty = packageItem.findProperty(
61-
ComposerLock.PACKAGE_VERSION_PROP
62-
);
63-
64-
if (versionProperty == null || versionProperty.getValue() == null) {
65-
continue;
66-
}
59+
foundMagentoPackages.put(magentoPackage.getLeft(), magentoPackage.getRight());
6760

68-
final String value = StringUtils.strip(
69-
versionProperty.getValue().getText(), "\""
70-
);
71-
foundMagentoPackages.put(name, value);
72-
73-
if (MagentoVersion.ENTERPRISE_EDITION.getName().equals(name)) {
74-
break;
75-
}
61+
if (foundMagentoPackages.containsKey(MagentoVersion.ENTERPRISE_EDITION.getName())
62+
|| foundMagentoPackages.containsKey(
63+
MagentoVersion.MAGEOS_COMMUNITY_EDITION.getName())) {
64+
break;
7665
}
7766
}
7867

@@ -87,4 +76,34 @@ private GetMagentoVersionUtil() {
8776

8877
return null;
8978
}
79+
80+
private static @Nullable ImmutablePair<String, String> findMagentoPackage(
81+
final JsonObject packageItem,
82+
final List<String> versionNames
83+
) {
84+
final JsonProperty nameProperty = packageItem.findProperty(
85+
ComposerLock.PACKAGE_NAME_PROP
86+
);
87+
88+
if (nameProperty == null || nameProperty.getValue() == null) {
89+
return null;
90+
}
91+
final String name = StringUtils.strip(nameProperty.getValue().getText(), "\"");
92+
93+
if (!versionNames.contains(name)) {
94+
return null;
95+
}
96+
97+
final JsonProperty versionProperty = packageItem.findProperty(
98+
ComposerLock.PACKAGE_VERSION_PROP
99+
);
100+
101+
if (versionProperty == null || versionProperty.getValue() == null) {
102+
return null;
103+
}
104+
105+
final String value = StringUtils.strip(versionProperty.getValue().getText(), "\"");
106+
107+
return ImmutablePair.of(name, value);
108+
}
90109
}

src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java

+3
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ public static boolean isMagentoFolderValid(final String path) {
3737
) != null || VfsUtil.findRelativeFile(
3838
file,
3939
Package.frameworkRootGit.split(Package.V_FILE_SEPARATOR)
40+
) != null || VfsUtil.findRelativeFile(
41+
file,
42+
Package.mageOsFrameworkRootComposer.split(Package.V_FILE_SEPARATOR)
4043
) != null;
4144
}
4245

0 commit comments

Comments
 (0)