Skip to content

Commit

Permalink
feature: mage-os support
Browse files Browse the repository at this point in the history
  • Loading branch information
piotrkwiecinski committed Jul 11, 2024
1 parent 424c0c0 commit 3020b1c
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 25 deletions.
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

0 comments on commit 3020b1c

Please sign in to comment.