From eb4b6dc91b606926e25ad4863032512c15ed6f52 Mon Sep 17 00:00:00 2001 From: Emmanuel Garcia Date: Wed, 5 Feb 2020 17:48:04 -0800 Subject: [PATCH] Retry Gradle command when failing to download a resource (#50223) --- .../lib/src/android/gradle_errors.dart | 5 +- .../android/gradle_errors_test.dart | 61 +++++++++++++------ 2 files changed, 46 insertions(+), 20 deletions(-) diff --git a/packages/flutter_tools/lib/src/android/gradle_errors.dart b/packages/flutter_tools/lib/src/android/gradle_errors.dart index 7187c28f23..fddea7c7b2 100644 --- a/packages/flutter_tools/lib/src/android/gradle_errors.dart +++ b/packages/flutter_tools/lib/src/android/gradle_errors.dart @@ -108,6 +108,7 @@ final GradleHandledError networkErrorHandler = GradleHandledError( 'javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake', 'java.net.SocketException: Connection reset', 'java.io.FileNotFoundException', + 'Gateway Time-out' ]), handler: ({ String line, @@ -116,8 +117,8 @@ final GradleHandledError networkErrorHandler = GradleHandledError( bool shouldBuildPluginAsAar, }) async { globals.printError( - '$warningMark Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + '$warningMark Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ); return GradleBuildStatus.retry; }, diff --git a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart index 0c7a01c78a..a7ddeeba9d 100644 --- a/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart +++ b/packages/flutter_tools/test/general.shard/android/gradle_errors_test.dart @@ -39,7 +39,7 @@ void main() { }); group('network errors', () { - testUsingContext('throws toolExit if gradle fails while downloading', () async { + testUsingContext('retries if gradle fails while downloading', () async { const String errorMessage = ''' Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle.org/distributions/gradle-4.1.1-all.zip at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1872) @@ -59,13 +59,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)'''; expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); }); - testUsingContext('throw toolExit if gradle fails downloading with proxy error', () async { + testUsingContext('retries if gradle fails downloading with proxy error', () async { const String errorMessage = ''' Exception in thread "main" java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 400 Bad Request" at sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124) @@ -87,13 +87,13 @@ at org.gradle.wrapper.GradleWrapperMain.main(GradleWrapperMain.java:61)'''; expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); }); - testUsingContext('throws toolExit if gradle times out waiting for exclusive access to zip', () async { + testUsingContext('retries if gradle times out waiting for exclusive access to zip', () async { const String errorMessage = ''' Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached waiting for exclusive access to file: /User/documents/gradle-5.6.2-all.zip at org.gradle.wrapper.ExclusiveFileAccessManager.access(ExclusiveFileAccessManager.java:61) @@ -106,13 +106,13 @@ Exception in thread "main" java.lang.RuntimeException: Timeout of 120000 reached expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); }); - testUsingContext('throws toolExit if remote host closes connection', () async { + testUsingContext('retries if remote host closes connection', () async { const String errorMessage = ''' Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host closed connection during handshake @@ -141,13 +141,13 @@ Exception in thread "main" javax.net.ssl.SSLHandshakeException: Remote host clos expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); }); - testUsingContext('throws toolExit if file opening fails', () async { + testUsingContext('retries if file opening fails', () async { const String errorMessage = r''' Downloading https://services.gradle.org/distributions/gradle-3.5.0-all.zip Exception in thread "main" java.io.FileNotFoundException: https://downloads.gradle-dn.com/distributions/gradle-3.5.0-all.zip @@ -168,13 +168,13 @@ Exception in thread "main" java.io.FileNotFoundException: https://downloads.grad expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); }); - testUsingContext('throws toolExit if the connection is reset', () async { + testUsingContext('retries if the connection is reset', () async { const String errorMessage = ''' Downloading https://services.gradle.org/distributions/gradle-5.6.2-all.zip Exception in thread "main" java.net.SocketException: Connection reset @@ -206,8 +206,33 @@ Exception in thread "main" java.net.SocketException: Connection reset expect(testLogger.errorText, contains( - 'Gradle threw an error while trying to update itself. ' - 'Retrying the update...' + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' + ) + ); + }); + + testUsingContext('retries if Gradle could not get a resource', () async { + const String errorMessage = ''' +A problem occurred configuring root project 'android'. +> Could not resolve all artifacts for configuration ':classpath'. + > Could not resolve net.sf.proguard:proguard-gradle:6.0.3. + Required by: + project : > com.android.tools.build:gradle:3.3.0 + > Could not resolve net.sf.proguard:proguard-gradle:6.0.3. + > Could not parse POM https://jcenter.bintray.com/net/sf/proguard/proguard-gradle/6.0.3/proguard-gradle-6.0.3.pom + > Could not resolve net.sf.proguard:proguard-parent:6.0.3. + > Could not resolve net.sf.proguard:proguard-parent:6.0.3. + > Could not get resource 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'. + > Could not GET 'https://jcenter.bintray.com/net/sf/proguard/proguard-parent/6.0.3/proguard-parent-6.0.3.pom'. Received status code 504 from server: Gateway Time-out'''; + + expect(testErrorMessage(errorMessage, networkErrorHandler), isTrue); + expect(await networkErrorHandler.handler(), equals(GradleBuildStatus.retry)); + + expect(testLogger.errorText, + contains( + 'Gradle threw an error while downloading artifacts from the network. ' + 'Retrying to download...' ) ); });