-
Notifications
You must be signed in to change notification settings - Fork 105
UCT-687: Enhanced Magento 2 version resolved #747
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
eduard13
merged 3 commits into
magento:4.2.0-develop
from
Iamwade:incorrect-display-of-magento-2-version
Nov 10, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
src/com/magento/idea/magento2plugin/magento/files/ComposerLock.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.magento.files; | ||
|
||
public final class ComposerLock { // NOPMD | ||
|
||
public static final String FILE_NAME = "composer.lock"; | ||
public static final String PACKAGES_PROP = "packages"; | ||
public static final String PACKAGE_NAME_PROP = "name"; | ||
public static final String PACKAGE_VERSION_PROP = "version"; | ||
} |
69 changes: 69 additions & 0 deletions
69
src/com/magento/idea/magento2plugin/magento/packages/code/MagentoVersion.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.magento.packages.code; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public enum MagentoVersion { | ||
|
||
ENTERPRISE_EDITION("magento/product-enterprise-edition", 1), | ||
COMMUNITY_EDITION("magento/product-community-edition", 2); | ||
|
||
private final String name; | ||
private final int priority; | ||
|
||
/** | ||
* Magento version Enum constructor. | ||
* | ||
* @param name String | ||
* @param priority int | ||
*/ | ||
MagentoVersion(final String name, final int priority) { | ||
this.name = name; | ||
this.priority = priority; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public int getPriority() { | ||
return priority; | ||
} | ||
|
||
/** | ||
* Get Magento Versions List. | ||
* | ||
* @return List[MagentoVersion] | ||
*/ | ||
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 | ||
); | ||
|
||
return versions; | ||
} | ||
|
||
/** | ||
* Get Magento Packages names. | ||
* | ||
* @return List[String] | ||
*/ | ||
public static List<String> getVersionsNames() { | ||
final List<String> names = new ArrayList<>(); | ||
|
||
for (final MagentoVersion version : MagentoVersion.values()) { | ||
names.add(version.getName()); | ||
} | ||
|
||
return names; | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
src/com/magento/idea/magento2plugin/project/util/GetMagentoVersionUtil.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
/* | ||
* Copyright © Magento, Inc. All rights reserved. | ||
* See COPYING.txt for license details. | ||
*/ | ||
|
||
package com.magento.idea.magento2plugin.project.util; | ||
|
||
import com.intellij.json.psi.JsonObject; | ||
import com.intellij.json.psi.JsonProperty; | ||
import com.intellij.psi.util.PsiTreeUtil; | ||
import com.magento.idea.magento2plugin.magento.files.ComposerLock; | ||
import com.magento.idea.magento2plugin.magento.packages.code.MagentoVersion; | ||
import java.util.Collection; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
import org.apache.commons.lang.StringUtils; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public final class GetMagentoVersionUtil { | ||
|
||
private GetMagentoVersionUtil() { | ||
} | ||
|
||
/** | ||
* Find Magento Package version in composer.lock json object. | ||
* | ||
* @param object JsonObject | ||
* | ||
* @return String | ||
*/ | ||
@SuppressWarnings("PMD.CyclomaticComplexity") | ||
public static @Nullable String getVersion(final @NotNull JsonObject object) { | ||
final JsonProperty packagesProperty = object.findProperty(ComposerLock.PACKAGES_PROP); | ||
|
||
if (packagesProperty == null) { | ||
return null; | ||
} | ||
final Collection<JsonObject> packages = PsiTreeUtil.findChildrenOfType( | ||
packagesProperty, | ||
JsonObject.class | ||
); | ||
final List<MagentoVersion> versions = MagentoVersion.getVersions(); | ||
final List<String> versionNames = MagentoVersion.getVersionsNames(); | ||
final Map<String, String> foundMagentoPackages = new HashMap<>(); | ||
|
||
for (final JsonObject packageItem : packages) { | ||
final JsonProperty nameProperty = packageItem.findProperty( | ||
ComposerLock.PACKAGE_NAME_PROP | ||
); | ||
|
||
if (nameProperty == null || nameProperty.getValue() == 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; | ||
} | ||
|
||
final String value = StringUtils.strip( | ||
versionProperty.getValue().getText(), "\"" | ||
); | ||
foundMagentoPackages.put(name, value); | ||
|
||
if (MagentoVersion.ENTERPRISE_EDITION.getName().equals(name)) { | ||
break; | ||
} | ||
} | ||
} | ||
|
||
for (final MagentoVersion version : versions) { | ||
if (foundMagentoPackages.containsKey(version.getName())) { | ||
return foundMagentoPackages.get(version.getName()); | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these composer packages? If yes - how is supposed to work with projects installed via GitHub?
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@eduard13, it was not supported in the previous functional and is not supposed to be supported for now. We need correct version lookup for the UCT version auto-detection. You can create new issue for adding support of dev Magento version resolving, or I'll create issue for that later.
Thanks, Bohdan