13
13
import top .hendrixshen .magiclib .api .i18n .I18n ;
14
14
import top .hendrixshen .magiclib .api .platform .DistType ;
15
15
import top .hendrixshen .magiclib .api .platform .Platform ;
16
+ import top .hendrixshen .magiclib .api .platform .PlatformType ;
16
17
import top .hendrixshen .magiclib .util .VersionUtil ;
17
18
import top .hendrixshen .magiclib .util .collect .SimplePredicate ;
18
19
import top .hendrixshen .magiclib .util .collect .ValueContainer ;
@@ -26,17 +27,19 @@ public class DependencyContainer<T> {
26
27
private final String value ;
27
28
private final DependencyType dependencyType ;
28
29
private final DistType distType ;
30
+ private final PlatformType platformType ;
29
31
private final List <String > versionPredicates ;
30
32
private final SimplePredicate <T > predicate ;
31
33
private final boolean optional ;
32
34
private final T obj ;
33
35
34
36
private DependencyContainer (String value , DependencyType dependencyType , DistType distType ,
35
- List < String > versionPredicates , SimplePredicate < T > predicate ,
36
- boolean optional , T obj ) {
37
+ PlatformType platformType , List < String > versionPredicates ,
38
+ SimplePredicate < T > predicate , boolean optional , T obj ) {
37
39
this .value = value ;
38
40
this .dependencyType = dependencyType ;
39
41
this .distType = distType ;
42
+ this .platformType = platformType ;
40
43
this .versionPredicates = versionPredicates ;
41
44
this .predicate = predicate ;
42
45
this .optional = optional ;
@@ -65,8 +68,19 @@ private DependencyContainer(String value, DependencyType dependencyType, DistTyp
65
68
}
66
69
}
67
70
71
+ // TODO: Remove this in the future
72
+ // For backward compatibility
73
+ PlatformType platformType ;
74
+
75
+ try {
76
+ platformType = dependency .platformType ();
77
+ } catch (NoSuchMethodError e ) {
78
+ platformType = PlatformType .ANY ;
79
+ }
80
+
68
81
return new DependencyContainer <>(dependency .value (), dependency .dependencyType (), dependency .distType (),
69
- Lists .newArrayList (dependency .versionPredicates ()), predicate , dependency .optional (), obj );
82
+ platformType , Lists .newArrayList (dependency .versionPredicates ()),
83
+ predicate , dependency .optional (), obj );
70
84
}
71
85
72
86
@ SuppressWarnings ("unchecked" )
@@ -101,6 +115,7 @@ private DependencyContainer(String value, DependencyType dependencyType, DistTyp
101
115
Annotations .getValue (annotationNode , "value" ),
102
116
dependencyType ,
103
117
Annotations .getValue (annotationNode , "distType" , DistType .class , DistType .ANY ),
118
+ Annotations .getValue (annotationNode , "platformType" , PlatformType .class , PlatformType .ANY ),
104
119
Lists .newArrayList (Annotations .getValue (annotationNode , "versionPredicates" , Lists .newArrayList ())),
105
120
predicate ,
106
121
Annotations .getValue (annotationNode , "optional" , Dependency .class ),
@@ -147,8 +162,18 @@ public ValueContainer<DependencyCheckResult> checkAsRequire() {
147
162
return ValueContainer .of (new DependencyCheckResult (this .optional ,
148
163
I18n .tr ("magiclib.dependency.result.mod_id." + (this .optional ?
149
164
"optional.success" : "require.fail" ) + ".not_found" , this .value ,
150
- this .versionPredicates .isEmpty () ? "[*]" : this .versionPredicates )
151
- ));
165
+ this .versionPredicates .isEmpty () ? "[*]" : this .versionPredicates )));
166
+ case PLATFORM :
167
+ PlatformType currentPlatformType = platform .getPlatformType ();
168
+
169
+ if (this .platformType .matches (currentPlatformType )) {
170
+ return ValueContainer .of (new DependencyCheckResult (true ,
171
+ I18n .tr ("magiclib.dependency.result.platform.require.success" , currentPlatformType )));
172
+ }
173
+
174
+ return ValueContainer .of (new DependencyCheckResult (false ,
175
+ I18n .tr ("magiclib.dependency.result.platform.require.fail" ,
176
+ this .platformType , currentPlatformType )));
152
177
case PREDICATE :
153
178
boolean testResult = this .predicate .test (this .obj );
154
179
return ValueContainer .of (new DependencyCheckResult (testResult , I18n .tr (
@@ -196,6 +221,16 @@ public ValueContainer<DependencyCheckResult> checkAsConflict() {
196
221
return ValueContainer .of (new DependencyCheckResult (true ,
197
222
I18n .tr ("magiclib.dependency.result.mod_id.conflict.success.not_found" ,
198
223
this .value )));
224
+ case PLATFORM :
225
+ PlatformType currentPlatformType = platform .getPlatformType ();
226
+
227
+ if (this .platformType .matches (currentPlatformType )) {
228
+ return ValueContainer .of (new DependencyCheckResult (false ,
229
+ I18n .tr ("magiclib.dependency.result.platform.conflict.fail" , this .platformType )));
230
+ }
231
+
232
+ return ValueContainer .of (new DependencyCheckResult (true ,
233
+ I18n .tr ("magiclib.dependency.result.platform.conflict.success" , this .platformType )));
199
234
case PREDICATE :
200
235
boolean testResult = this .predicate .test (this .obj );
201
236
return ValueContainer .of (new DependencyCheckResult (!testResult ,
0 commit comments