diff --git a/src/com/magento/idea/magento2plugin/magento/packages/Package.java b/src/com/magento/idea/magento2plugin/magento/packages/Package.java index 3bf3d2bd2..9ed340294 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/Package.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/Package.java @@ -19,4 +19,5 @@ public class Package { //NOPMD public static String vendorModuleNameSeparator = "_"; public static String fqnSeparator = "\\"; public static String composerType = "project"; + public static String mageOsFrameworkRootComposer = "vendor/mage-os/framework"; } diff --git a/src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java b/src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java index 810a8faab..9b80d125c 100644 --- a/src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java +++ b/src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java @@ -7,12 +7,14 @@ import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; public enum MagentoVersion { ENTERPRISE_EDITION("magento/product-enterprise-edition", 1, "Adobe Commerce"), - COMMUNITY_EDITION("magento/product-community-edition", 2, "Magento Open Source"); + COMMUNITY_EDITION("magento/product-community-edition", 2, "Magento Open Source"), + MAGEOS_COMMUNITY_EDITION("mage-os/product-community-edition", 3, "Mage-OS Community Edition"); private final String name; private final int priority; @@ -52,9 +54,7 @@ public static List getVersions() { final List versions = new ArrayList<>( Arrays.asList(MagentoVersion.values()) ); - versions.sort( - (version1, version2) -> version1.getPriority() > version2.getPriority() ? 1 : 0 - ); + versions.sort(Comparator.comparingInt(MagentoVersion::getPriority)); return versions; } diff --git a/src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java b/src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java index f5fc10444..e59854887 100644 --- a/src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java +++ b/src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Map; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.tuple.ImmutablePair; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -47,32 +48,20 @@ private GetMagentoVersionUtil() { final Map foundMagentoPackages = new HashMap<>(); for (final JsonObject packageItem : packages) { - final JsonProperty nameProperty = packageItem.findProperty( - ComposerLock.PACKAGE_NAME_PROP - ); + final @Nullable ImmutablePair magentoPackage = findMagentoPackage( + packageItem, + versionNames); - if (nameProperty == null || nameProperty.getValue() == null) { + if (magentoPackage == null) { continue; } - final String name = StringUtils.strip(nameProperty.getValue().getText(), "\""); - if (versionNames.contains(name)) { - final JsonProperty versionProperty = packageItem.findProperty( - ComposerLock.PACKAGE_VERSION_PROP - ); - - if (versionProperty == null || versionProperty.getValue() == null) { - continue; - } + foundMagentoPackages.put(magentoPackage.getLeft(), magentoPackage.getRight()); - final String value = StringUtils.strip( - versionProperty.getValue().getText(), "\"" - ); - foundMagentoPackages.put(name, value); - - if (MagentoVersion.ENTERPRISE_EDITION.getName().equals(name)) { - break; - } + if (foundMagentoPackages.containsKey(MagentoVersion.ENTERPRISE_EDITION.getName()) + || foundMagentoPackages.containsKey( + MagentoVersion.MAGEOS_COMMUNITY_EDITION.getName())) { + break; } } @@ -87,4 +76,34 @@ private GetMagentoVersionUtil() { return null; } + + private static @Nullable ImmutablePair findMagentoPackage( + final JsonObject packageItem, + final List versionNames + ) { + final JsonProperty nameProperty = packageItem.findProperty( + ComposerLock.PACKAGE_NAME_PROP + ); + + if (nameProperty == null || nameProperty.getValue() == null) { + return null; + } + final String name = StringUtils.strip(nameProperty.getValue().getText(), "\""); + + if (!versionNames.contains(name)) { + return null; + } + + final JsonProperty versionProperty = packageItem.findProperty( + ComposerLock.PACKAGE_VERSION_PROP + ); + + if (versionProperty == null || versionProperty.getValue() == null) { + return null; + } + + final String value = StringUtils.strip(versionProperty.getValue().getText(), "\""); + + return ImmutablePair.of(name, value); + } } diff --git a/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java b/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java index bd94ef7dc..5c9cb1548 100644 --- a/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java +++ b/src/com/magento/idea/magento2plugin/util/magento/MagentoBasePathUtil.java @@ -37,6 +37,9 @@ public static boolean isMagentoFolderValid(final String path) { ) != null || VfsUtil.findRelativeFile( file, Package.frameworkRootGit.split(Package.V_FILE_SEPARATOR) + ) != null || VfsUtil.findRelativeFile( + file, + Package.mageOsFrameworkRootComposer.split(Package.V_FILE_SEPARATOR) ) != null; }