1616import java .util .List ;
1717import java .util .Map ;
1818import org .apache .commons .lang3 .StringUtils ;
19+ import org .apache .commons .lang3 .tuple .ImmutablePair ;
1920import org .jetbrains .annotations .NotNull ;
2021import 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}
0 commit comments