16
16
import java .util .List ;
17
17
import java .util .Map ;
18
18
import org .apache .commons .lang3 .StringUtils ;
19
+ import org .apache .commons .lang3 .tuple .ImmutablePair ;
19
20
import org .jetbrains .annotations .NotNull ;
20
21
import org .jetbrains .annotations .Nullable ;
21
22
@@ -47,32 +48,20 @@ private GetMagentoVersionUtil() {
47
48
final Map <String , String > foundMagentoPackages = new HashMap <>();
48
49
49
50
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 );
53
54
54
- if (nameProperty == null || nameProperty . getValue () == null ) {
55
+ if (magentoPackage == null ) {
55
56
continue ;
56
57
}
57
- final String name = StringUtils .strip (nameProperty .getValue ().getText (), "\" " );
58
58
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 ());
67
60
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 ;
76
65
}
77
66
}
78
67
@@ -87,4 +76,34 @@ private GetMagentoVersionUtil() {
87
76
88
77
return null ;
89
78
}
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
+ }
90
109
}
0 commit comments