Skip to content
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

feature: mage-os support #2081

Merged
merged 1 commit into from
Aug 11, 2024
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 @@ -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";
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -52,9 +54,7 @@ public static List<MagentoVersion> getVersions() {
final List<MagentoVersion> 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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

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

for (final JsonObject packageItem : packages) {
final JsonProperty nameProperty = packageItem.findProperty(
ComposerLock.PACKAGE_NAME_PROP
);
final @Nullable ImmutablePair<String, String> 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;
}
}

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

return null;
}

private static @Nullable ImmutablePair<String, String> findMagentoPackage(
final JsonObject packageItem,
final List<String> 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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Loading