@@ -8,6 +8,7 @@ import 'package:file/memory.dart';
8
8
import 'package:file_testing/file_testing.dart' ;
9
9
import 'package:flutter_tools/src/android/gradle_errors.dart' ;
10
10
import 'package:flutter_tools/src/android/gradle_utils.dart' ;
11
+ import 'package:flutter_tools/src/base/bot_detector.dart' ;
11
12
import 'package:flutter_tools/src/base/file_system.dart' ;
12
13
import 'package:flutter_tools/src/base/logger.dart' ;
13
14
import 'package:flutter_tools/src/base/platform.dart' ;
@@ -17,6 +18,7 @@ import 'package:flutter_tools/src/project.dart';
17
18
18
19
import '../../src/common.dart' ;
19
20
import '../../src/context.dart' ;
21
+ import '../../src/fakes.dart' ;
20
22
21
23
void main () {
22
24
group ('gradleErrors' , () {
@@ -38,53 +40,13 @@ void main() {
38
40
jvm11RequiredHandler,
39
41
outdatedGradleHandler,
40
42
sslExceptionHandler,
43
+ zipExceptionHandler,
41
44
])
42
45
);
43
46
});
44
47
});
45
48
46
49
group ('network errors' , () {
47
- testUsingContext ('retries and deletes zip if gradle fails to unzip' , () async {
48
- globals.fs.file ('foo/.gradle/fizz.zip' ).createSync (recursive: true );
49
- const String errorMessage = r'''
50
- Exception in thread "main" java.util.zip.ZipException: error in opening zip file
51
- at java.util.zip.ZipFile.open(Native Method)
52
- at java.util.zip.ZipFile.(ZipFile.java:225)
53
- at java.util.zip.ZipFile.(ZipFile.java:155)
54
- at java.util.zip.ZipFile.(ZipFile.java:169)
55
- at org.gradle.wrapper.Install.unzip(Install.java:214)
56
- at org.gradle.wrapper.Install.access$600(Install.java:27)
57
- at org.gradle.wrapper.Install$1.call(Install.java:74)
58
- at org.gradle.wrapper.Install$1.call(Install.java:48)
59
- at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
60
- at org.gradle.wrapper.Install.createDist(Install.java:48)
61
- at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
62
- at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
63
- [!] Gradle threw an error while trying to update itself. Retrying the update...
64
- Exception in thread "main" java.util.zip.ZipException: error in opening zip file
65
- at java.util.zip.ZipFile.open(Native Method)
66
- at java.util.zip.ZipFile.(ZipFile.java:225)
67
- at java.util.zip.ZipFile.(ZipFile.java:155)
68
- at java.util.zip.ZipFile.(ZipFile.java:169)
69
- at org.gradle.wrapper.Install.unzip(Install.java:214)
70
- at org.gradle.wrapper.Install.access$600(Install.java:27)
71
- at org.gradle.wrapper.Install$1.call(Install.java:74)
72
- at org.gradle.wrapper.Install$1.call(Install.java:48)
73
- at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
74
- at org.gradle.wrapper.Install.createDist(Install.java:48)
75
- at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
76
- at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)
77
- ''' ;
78
-
79
- expect (formatTestErrorMessage (errorMessage, networkErrorHandler), isTrue);
80
- expect (await networkErrorHandler.handler (), equals (GradleBuildStatus .retry));
81
- expect (globals.fs.file ('foo/.gradle/fizz.zip' ), isNot (exists));
82
- }, overrides: < Type , Generator > {
83
- FileSystem : () => MemoryFileSystem .test (),
84
- ProcessManager : () => FakeProcessManager .any (),
85
- Platform : () => FakePlatform (environment: < String , String > {'HOME' : 'foo/' }),
86
- });
87
-
88
50
testUsingContext ('retries if gradle fails while downloading' , () async {
89
51
const String errorMessage = r'''
90
52
Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle.org/distributions/gradle-4.1.1-all.zip
@@ -1122,6 +1084,121 @@ at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:108)'''
1122
1084
});
1123
1085
});
1124
1086
1087
+ group ('Zip exception' , () {
1088
+ testWithoutContext ('pattern' , () {
1089
+ expect (
1090
+ zipExceptionHandler.test (r'''
1091
+ Exception in thread "main" java.util.zip.ZipException: error in opening zip file
1092
+ at java.util.zip.ZipFile.open(Native Method)
1093
+ at java.util.zip.ZipFile.(ZipFile.java:225)
1094
+ at java.util.zip.ZipFile.(ZipFile.java:155)
1095
+ at java.util.zip.ZipFile.(ZipFile.java:169)
1096
+ at org.gradle.wrapper.Install.unzip(Install.java:214)
1097
+ at org.gradle.wrapper.Install.access$600(Install.java:27)
1098
+ at org.gradle.wrapper.Install$1.call(Install.java:74)
1099
+ at org.gradle.wrapper.Install$1.call(Install.java:48)
1100
+ at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:65)
1101
+ at org.gradle.wrapper.Install.createDist(Install.java:48)
1102
+ at org.gradle.wrapper.WrapperExecutor.execute(WrapperExecutor.java:128)
1103
+ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)'''
1104
+ ),
1105
+ isTrue,
1106
+ );
1107
+ });
1108
+
1109
+ testUsingContext ('suggestion' , () async {
1110
+ globals.fs.file ('foo/.gradle/fizz.zip' ).createSync (recursive: true );
1111
+
1112
+ final GradleBuildStatus result = await zipExceptionHandler.handler ();
1113
+
1114
+ expect (result, equals (GradleBuildStatus .retry));
1115
+ expect (globals.fs.file ('foo/.gradle/fizz.zip' ), exists);
1116
+ expect (
1117
+ testLogger.errorText,
1118
+ contains (
1119
+ '[!] Your .gradle directory under the home directory might be corrupted.\n '
1120
+ )
1121
+ );
1122
+ expect (testLogger.statusText, '' );
1123
+ }, overrides: < Type , Generator > {
1124
+ Platform : () => FakePlatform (environment: < String , String > {'HOME' : 'foo/' }),
1125
+ FileSystem : () => MemoryFileSystem .test (),
1126
+ ProcessManager : () => FakeProcessManager .empty (),
1127
+ BotDetector : () => const FakeBotDetector (false ),
1128
+ });
1129
+
1130
+ testUsingContext ('suggestion if running as bot' , () async {
1131
+ globals.fs.file ('foo/.gradle/fizz.zip' ).createSync (recursive: true );
1132
+
1133
+ final GradleBuildStatus result = await zipExceptionHandler.handler ();
1134
+
1135
+ expect (result, equals (GradleBuildStatus .retry));
1136
+ expect (globals.fs.file ('foo/.gradle/fizz.zip' ), isNot (exists));
1137
+
1138
+ expect (
1139
+ testLogger.errorText,
1140
+ contains (
1141
+ '[!] Your .gradle directory under the home directory might be corrupted.\n '
1142
+ )
1143
+ );
1144
+ expect (
1145
+ testLogger.statusText,
1146
+ contains ('Deleting foo/.gradle\n ' ),
1147
+ );
1148
+ }, overrides: < Type , Generator > {
1149
+ Platform : () => FakePlatform (environment: < String , String > {'HOME' : 'foo/' }),
1150
+ FileSystem : () => MemoryFileSystem .test (),
1151
+ ProcessManager : () => FakeProcessManager .empty (),
1152
+ BotDetector : () => const FakeBotDetector (true ),
1153
+ });
1154
+
1155
+ testUsingContext ('suggestion if stdin has terminal and user entered y' , () async {
1156
+ globals.fs.file ('foo/.gradle/fizz.zip' ).createSync (recursive: true );
1157
+
1158
+ final GradleBuildStatus result = await zipExceptionHandler.handler ();
1159
+
1160
+ expect (result, equals (GradleBuildStatus .retry));
1161
+ expect (globals.fs.file ('foo/.gradle/fizz.zip' ), isNot (exists));
1162
+ expect (
1163
+ testLogger.errorText,
1164
+ contains (
1165
+ '[!] Your .gradle directory under the home directory might be corrupted.\n '
1166
+ )
1167
+ );
1168
+ expect (
1169
+ testLogger.statusText,
1170
+ contains ('Deleting foo/.gradle\n ' ),
1171
+ );
1172
+ }, overrides: < Type , Generator > {
1173
+ Platform : () => FakePlatform (environment: < String , String > {'HOME' : 'foo/' }),
1174
+ FileSystem : () => MemoryFileSystem .test (),
1175
+ ProcessManager : () => FakeProcessManager .empty (),
1176
+ AnsiTerminal : () => _TestPromptTerminal ('y' ),
1177
+ BotDetector : () => const FakeBotDetector (false ),
1178
+ });
1179
+
1180
+ testUsingContext ('suggestion if stdin has terminal and user entered n' , () async {
1181
+ globals.fs.file ('foo/.gradle/fizz.zip' ).createSync (recursive: true );
1182
+
1183
+ final GradleBuildStatus result = await zipExceptionHandler.handler ();
1184
+
1185
+ expect (result, equals (GradleBuildStatus .retry));
1186
+ expect (globals.fs.file ('foo/.gradle/fizz.zip' ), exists);
1187
+ expect (
1188
+ testLogger.errorText,
1189
+ contains (
1190
+ '[!] Your .gradle directory under the home directory might be corrupted.\n '
1191
+ )
1192
+ );
1193
+ expect (testLogger.statusText, '' );
1194
+ }, overrides: < Type , Generator > {
1195
+ Platform : () => FakePlatform (environment: < String , String > {'HOME' : 'foo/' }),
1196
+ FileSystem : () => MemoryFileSystem .test (),
1197
+ ProcessManager : () => FakeProcessManager .empty (),
1198
+ AnsiTerminal : () => _TestPromptTerminal ('n' ),
1199
+ BotDetector : () => const FakeBotDetector (false ),
1200
+ });
1201
+ });
1125
1202
}
1126
1203
1127
1204
bool formatTestErrorMessage (String errorMessage, GradleHandledError error) {
@@ -1162,4 +1239,7 @@ class _TestPromptTerminal extends AnsiTerminal {
1162
1239
}) {
1163
1240
return Future <String >.value (promptResult);
1164
1241
}
1242
+
1243
+ @override
1244
+ bool get stdinHasTerminal => true ;
1165
1245
}
0 commit comments