13
13
14
14
import java .io .IOException ;
15
15
import java .nio .charset .StandardCharsets ;
16
+ import java .util .Objects ;
16
17
17
- public class FlutterSdkVersion implements Comparable <FlutterSdkVersion > {
18
+ public final class FlutterSdkVersion implements Comparable <FlutterSdkVersion > {
18
19
/**
19
20
* The version for which the distributed icons can be used.
20
21
*/
21
22
@ VisibleForTesting
23
+ @ NotNull
22
24
public static final FlutterSdkVersion DISTRIBUTED_ICONS = new FlutterSdkVersion ("3.1.0" );
25
+
23
26
/**
24
27
* The minimum version we suggest people use.
25
28
*/
29
+ @ NotNull
26
30
private static final FlutterSdkVersion MIN_SUPPORTED_SDK = new FlutterSdkVersion ("0.0.12" );
27
31
28
32
/**
@@ -31,31 +35,37 @@ public class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
31
35
* Before this version there were issues if you ran the app from the command
32
36
* line without the flag after running
33
37
*/
38
+ @ NotNull
34
39
private static final FlutterSdkVersion MIN_SAFE_TRACK_WIDGET_CREATION_SDK = new FlutterSdkVersion ("0.10.2" );
35
40
36
41
/**
37
42
* The version that supports --dart-define in the run command.
38
43
*/
44
+ @ NotNull
39
45
private static final FlutterSdkVersion MIN_DART_DEFINE_SDK = new FlutterSdkVersion ("1.12.0" );
40
46
41
47
/**
42
48
* The version of the stable channel that supports --androidx in the create command.
43
49
*/
50
+ @ NotNull
44
51
private static final FlutterSdkVersion MIN_PUB_OUTDATED_SDK = new FlutterSdkVersion ("1.16.4" );
45
52
46
53
/**
47
54
* The version that supports --platform in flutter create.
48
55
*/
56
+ @ NotNull
49
57
private static final FlutterSdkVersion MIN_CREATE_PLATFORMS_SDK = new FlutterSdkVersion ("1.20.0" );
50
58
51
59
/**
52
60
* The version that supports --config-only when configuring Xcode for opening a project.
53
61
*/
62
+ @ NotNull
54
63
private static final FlutterSdkVersion MIN_XCODE_CONFIG_ONLY = new FlutterSdkVersion ("1.22.0-12.0.pre" );
55
64
56
65
/**
57
66
* The last version of stable that does not support --platform in flutter create.
58
67
*/
68
+ @ NotNull
59
69
private static final FlutterSdkVersion MAX_STABLE_NO_PLATFORMS_SDK = new FlutterSdkVersion ("1.22.6" );
60
70
61
71
/**
@@ -75,16 +85,19 @@ public class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
75
85
/**
76
86
* The version that includes the skeleton template.
77
87
*/
88
+ @ NotNull
78
89
private static final FlutterSdkVersion MIN_SKELETON_TEMPLATE = new FlutterSdkVersion ("2.5.0" );
79
90
80
91
/**
81
92
* The version that includes the skeleton template.
82
93
*/
94
+ @ NotNull
83
95
private static final FlutterSdkVersion MIN_PLUGIN_FFI_TEMPLATE = new FlutterSdkVersion ("3.0.0" );
84
96
85
97
/**
86
98
* The version that includes the skeleton template.
87
99
*/
100
+ @ NotNull
88
101
private static final FlutterSdkVersion MIN_EMPTY_PROJECT = new FlutterSdkVersion ("3.6.0-0.1.pre" );
89
102
90
103
/**
@@ -127,29 +140,29 @@ public class FlutterSdkVersion implements Comparable<FlutterSdkVersion> {
127
140
private final String versionText ;
128
141
@ Nullable
129
142
private final Version betaVersion ;
130
- private final int masterVersion ;
143
+ private final int mainVersion ;
131
144
132
145
@ VisibleForTesting
133
146
public FlutterSdkVersion (@ Nullable String versionString ) {
134
147
versionText = versionString ;
135
148
if (versionString != null ) {
136
- final String [] split = versionString .split ("-" );
149
+ final @ NotNull String [] split = versionString .split ("-" );
137
150
version = Version .parseVersion (split [0 ]);
138
151
139
152
if (split .length > 1 ) {
140
153
betaVersion = Version .parseVersion (split [1 ]);
141
- final String [] parts = split [1 ].split ("\\ ." );
142
- masterVersion = parts .length > 3 ? Integer .parseInt (parts [3 ]) : 0 ;
154
+ final @ NotNull String [] parts = split [1 ].split ("\\ ." );
155
+ mainVersion = parts .length > 3 ? Integer .parseInt (parts [3 ]) : 0 ;
143
156
}
144
157
else {
145
158
betaVersion = null ;
146
- masterVersion = 0 ;
159
+ mainVersion = 0 ;
147
160
}
148
161
}
149
162
else {
150
163
version = null ;
151
164
betaVersion = null ;
152
- masterVersion = 0 ;
165
+ mainVersion = 0 ;
153
166
}
154
167
}
155
168
@@ -172,7 +185,8 @@ private static FlutterSdkVersion readFromFile(@Nullable VirtualFile file) {
172
185
return new FlutterSdkVersion (versionString );
173
186
}
174
187
175
- private static String readVersionString (VirtualFile file ) {
188
+ @ Nullable
189
+ private static String readVersionString (@ NotNull VirtualFile file ) {
176
190
try {
177
191
final String data = new String (file .contentsToByteArray (), StandardCharsets .UTF_8 );
178
192
for (String line : data .split ("\n " )) {
@@ -191,42 +205,40 @@ private static String readVersionString(VirtualFile file) {
191
205
}
192
206
}
193
207
208
+ private boolean supportsVersion (@ NotNull FlutterSdkVersion otherVersion ) {
209
+ return this .compareTo (otherVersion ) >= 0 ;
210
+ }
211
+
194
212
public boolean isMinRecommendedSupported () {
195
- assert (MIN_SUPPORTED_SDK .version != null );
196
- return version != null && version .compareTo (MIN_SUPPORTED_SDK .version ) >= 0 ;
213
+ return supportsVersion (MIN_SUPPORTED_SDK );
197
214
}
198
215
199
216
public boolean isTrackWidgetCreationRecommended () {
200
- assert (MIN_SAFE_TRACK_WIDGET_CREATION_SDK .version != null );
201
- return version != null && version .compareTo (MIN_SAFE_TRACK_WIDGET_CREATION_SDK .version ) >= 0 ;
217
+ return supportsVersion (MIN_SAFE_TRACK_WIDGET_CREATION_SDK );
202
218
}
203
219
204
220
public boolean isDartDefineSupported () {
205
- //noinspection ConstantConditions
206
- return version != null && version .compareTo (MIN_DART_DEFINE_SDK .version ) >= 0 ;
221
+ return supportsVersion (MIN_DART_DEFINE_SDK );
207
222
}
208
223
209
224
public boolean isXcodeConfigOnlySupported () {
210
- //noinspection ConstantConditions
211
- return version != null && version .compareTo (MIN_XCODE_CONFIG_ONLY .version ) >= 0 ;
225
+ return supportsVersion (MIN_XCODE_CONFIG_ONLY );
212
226
}
213
227
214
228
public boolean flutterCreateSupportsPlatforms () {
215
- //noinspection ConstantConditions
216
- return version != null && version .compareTo (MIN_CREATE_PLATFORMS_SDK .version ) >= 0 ;
229
+ return supportsVersion (MIN_CREATE_PLATFORMS_SDK );
217
230
}
218
231
219
232
public boolean stableChannelSupportsPlatforms () {
220
- //noinspection ConstantConditions
221
- return version != null && version .compareTo (MAX_STABLE_NO_PLATFORMS_SDK .version ) > 0 ;
233
+ return supportsVersion (MAX_STABLE_NO_PLATFORMS_SDK );
222
234
}
223
235
224
236
public boolean flutterRunSupportsDevToolsUrl () {
225
- return version != null && this .compareTo (MIN_PASS_DEVTOOLS_SDK ) >= 0 && this .compareTo (MIN_OPTIONAL_PASS_DEVTOOLS_SDK ) < 0 ;
237
+ return this .compareTo (MIN_PASS_DEVTOOLS_SDK ) >= 0 && this .compareTo (MIN_OPTIONAL_PASS_DEVTOOLS_SDK ) < 0 ;
226
238
}
227
239
228
240
public boolean useDaemonForDevTools () {
229
- return version != null && this . compareTo (MIN_PASS_DEVTOOLS_SDK ) >= 0 ;
241
+ return supportsVersion (MIN_PASS_DEVTOOLS_SDK );
230
242
}
231
243
232
244
public boolean flutterTestSupportsMachineMode () {
@@ -238,76 +250,77 @@ public boolean flutterTestSupportsFiltering() {
238
250
}
239
251
240
252
public boolean isPubOutdatedSupported () {
241
- //noinspection ConstantConditions
242
- return version != null && version .compareTo (MIN_PUB_OUTDATED_SDK .version ) >= 0 ;
253
+ return supportsVersion (MIN_PUB_OUTDATED_SDK );
243
254
}
244
255
245
256
public boolean isSkeletonTemplateAvailable () {
246
- return version != null && version . compareTo (MIN_SKELETON_TEMPLATE . version ) >= 0 ;
257
+ return supportsVersion (MIN_SKELETON_TEMPLATE ) ;
247
258
}
248
259
249
260
public boolean isPluginFfiTemplateAvailable () {
250
- return version != null && version . compareTo (MIN_PLUGIN_FFI_TEMPLATE . version ) >= 0 ;
261
+ return supportsVersion (MIN_PLUGIN_FFI_TEMPLATE ) ;
251
262
}
252
263
253
264
public boolean isEmptyProjectAvailable () {
254
- return version != null && version . compareTo (MIN_EMPTY_PROJECT . version ) >= 0 ;
265
+ return supportsVersion (MIN_EMPTY_PROJECT ) ;
255
266
}
256
267
257
268
public boolean isUriMappingSupportedForWeb () {
258
- return version != null && this . compareTo (MIN_URI_MAPPING_FOR_WEB ) >= 0 ;
269
+ return supportsVersion (MIN_URI_MAPPING_FOR_WEB );
259
270
}
260
271
261
272
public boolean isWebPlatformStable () {
262
- return version != null && this . compareTo (MIN_STABLE_WEB_PLATFORM ) >= 0 ;
273
+ return supportsVersion (MIN_STABLE_WEB_PLATFORM );
263
274
}
264
275
265
276
public boolean isWindowsPlatformStable () {
266
- return version != null && this . compareTo (MIN_STABLE_WINDOWS_PLATFORM ) >= 0 ;
277
+ return supportsVersion (MIN_STABLE_WINDOWS_PLATFORM );
267
278
}
268
279
269
280
public boolean isLinuxPlatformStable () {
270
- return version != null && this . compareTo (MIN_STABLE_LINUX_PLATFORM ) >= 0 ;
281
+ return supportsVersion (MIN_STABLE_LINUX_PLATFORM );
271
282
}
272
283
273
284
public boolean isMacOSPlatformStable () {
274
- return version != null && this . compareTo (MIN_STABLE_MACOS_PLATFORM ) >= 0 ;
285
+ return supportsVersion (MIN_STABLE_MACOS_PLATFORM );
275
286
}
276
287
277
288
public boolean canUseDistributedIcons () {
278
- return version != null && this . compareTo (DISTRIBUTED_ICONS ) >= 0 ;
289
+ return supportsVersion (DISTRIBUTED_ICONS );
279
290
}
280
291
281
292
public boolean canUseDevToolsPathUrls () {
282
- return version != null && this . compareTo (MIN_SUPPORTS_DEVTOOLS_PATH_URLS ) >= 0 ;
293
+ return supportsVersion (MIN_SUPPORTS_DEVTOOLS_PATH_URLS );
283
294
}
284
295
285
296
public boolean canUseToolEventStream () {
286
- return version != null && this . compareTo (MIN_SUPPORTS_TOOL_EVENT_STREAM ) >= 0 ;
297
+ return supportsVersion (MIN_SUPPORTS_TOOL_EVENT_STREAM );
287
298
}
288
299
289
300
public boolean canUseDeepLinksTool () {
290
- return version != null && this . compareTo (MIN_SUPPORTS_DEEP_LINKS_TOOL ) >= 0 ;
301
+ return supportsVersion (MIN_SUPPORTS_DEEP_LINKS_TOOL );
291
302
}
292
303
293
304
public boolean canUseDevToolsMultiEmbed () {
294
- return version != null && this . compareTo (MIN_SUPPORTS_DEVTOOLS_MULTI_EMBED ) >= 0 ;
305
+ return supportsVersion (MIN_SUPPORTS_DEVTOOLS_MULTI_EMBED );
295
306
}
296
307
308
+ @ SuppressWarnings ("BooleanMethodIsAlwaysInverted" )
297
309
public boolean canUseDtd () {
298
- return version != null && this . compareTo (MIN_SUPPORTS_DTD ) >= 0 ;
310
+ return supportsVersion (MIN_SUPPORTS_DTD );
299
311
}
300
312
301
313
public boolean sdkIsSupported () {
302
- return version != null && this . compareTo (MIN_SDK_SUPPORTED ) >= 0 ;
314
+ return supportsVersion (MIN_SDK_SUPPORTED );
303
315
}
304
316
305
317
public boolean isValid () {
306
318
return version != null ;
307
319
}
308
320
321
+ @ NotNull
309
322
public String fullVersion () {
310
- return version == null ? "unknown version" : version .toString ();
323
+ return version == null ? "unknown version" : Objects . requireNonNull ( version .toString () );
311
324
}
312
325
313
326
/**
@@ -319,21 +332,21 @@ public String getVersionText() {
319
332
}
320
333
321
334
@ Override
335
+ @ NotNull
322
336
public String toString () {
323
- return version == null ? "unknown version" : version .toCompactString ();
337
+ return version == null ? "unknown version" : Objects . requireNonNull ( version .toCompactString () );
324
338
}
325
339
326
340
@ Override
327
341
public int compareTo (@ NotNull FlutterSdkVersion otherVersion ) {
328
- // TODO(messick) Remove "version != null" prior to calling this method everywhere in this file.
329
342
if (version == null ) return -1 ;
330
343
if (otherVersion .version == null ) return 1 ;
331
344
final int standardComparisonResult = version .compareTo (otherVersion .version );
332
345
if (standardComparisonResult != 0 ) {
333
346
return standardComparisonResult ;
334
347
}
335
348
336
- // Check for beta version strings if standard versions are equivalent .
349
+ // If standard versions are equivalent, check for beta version strings .
337
350
if (betaVersion == null && otherVersion .betaVersion == null ) {
338
351
return 0 ;
339
352
}
@@ -350,15 +363,16 @@ else if (otherVersion.betaVersion == null) {
350
363
return betaComparisonResult ;
351
364
}
352
365
353
- // Check master version ints if both have master version ints and versions are otherwise equivalent.
354
- // Otherwise, the version without a master version is further ahead.
355
- if (masterVersion != 0 && otherVersion .masterVersion != 0 ) {
356
- return Integer .compare (masterVersion , otherVersion .masterVersion );
366
+ // If both have main version ints and the versions are otherwise equivalent,
367
+ // compare the main version ints.
368
+ // Otherwise, the version without a main version is further ahead.
369
+ if (mainVersion != 0 && otherVersion .mainVersion != 0 ) {
370
+ return Integer .compare (mainVersion , otherVersion .mainVersion );
357
371
}
358
- else if (masterVersion != 0 ) {
372
+ else if (mainVersion != 0 ) {
359
373
return -1 ;
360
374
}
361
- else if (otherVersion .masterVersion != 0 ) {
375
+ else if (otherVersion .mainVersion != 0 ) {
362
376
return 1 ;
363
377
}
364
378
else {
0 commit comments