| OLD | NEW |
| 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2017, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 import 'dart:async'; | 5 import 'dart:async'; |
| 6 import 'dart:convert'; | 6 import 'dart:convert'; |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'package:args/args.dart'; | 9 import 'package:args/args.dart'; |
| 10 | 10 |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 58 class HttpException implements Exception { | 58 class HttpException implements Exception { |
| 59 final Uri uri; | 59 final Uri uri; |
| 60 final int statusCode; | 60 final int statusCode; |
| 61 | 61 |
| 62 HttpException(this.uri, this.statusCode); | 62 HttpException(this.uri, this.statusCode); |
| 63 | 63 |
| 64 String toString() => '$uri: $statusCode'; | 64 String toString() => '$uri: $statusCode'; |
| 65 } | 65 } |
| 66 | 66 |
| 67 /// Reads the content of [uri] as text. | 67 /// Reads the content of [uri] as text. |
| 68 Future<String> readUriAsText(HttpClient client, Uri uri) async { | 68 Future<String> readUriAsText( |
| 69 HttpClient client, Uri uri, Duration timeout) async { |
| 69 HttpClientRequest request = await client.getUrl(uri); | 70 HttpClientRequest request = await client.getUrl(uri); |
| 70 HttpClientResponse response = await request.close(); | 71 HttpClientResponse response = await request.close(); |
| 71 if (response.statusCode != 200) { | 72 if (response.statusCode != 200) { |
| 72 response.drain(); | 73 response.drain(); |
| 73 throw new HttpException(uri, response.statusCode); | 74 throw new HttpException(uri, response.statusCode); |
| 74 } | 75 } |
| 75 return response.transform(UTF8.decoder).join(); | 76 if (timeout != null) { |
| 77 return response.timeout(timeout).transform(UTF8.decoder).join(); |
| 78 } else { |
| 79 return response.transform(UTF8.decoder).join(); |
| 80 } |
| 76 } | 81 } |
| 77 | 82 |
| 78 ArgParser createArgParser() { | 83 ArgParser createArgParser() { |
| 79 ArgParser argParser = new ArgParser(allowTrailingOptions: true); | 84 ArgParser argParser = new ArgParser(allowTrailingOptions: true); |
| 80 argParser.addFlag('help', help: "Help"); | 85 argParser.addFlag('help', help: "Help"); |
| 81 argParser.addFlag('verbose', | 86 argParser.addFlag('verbose', |
| 82 abbr: 'v', negatable: false, help: "Turn on logging output."); | 87 abbr: 'v', negatable: false, help: "Turn on logging output."); |
| 83 argParser.addFlag('no-cache', help: "Disable caching."); | 88 argParser.addFlag('no-cache', help: "Disable caching."); |
| 84 argParser.addOption('cache', | 89 argParser.addOption('cache', |
| 85 help: "Use <dir> for caching test output.\n" | 90 help: "Use <dir> for caching test output.\n" |
| 86 "Defaults to 'temp/gardening-cache/'."); | 91 "Defaults to 'temp/gardening-cache/'."); |
| 87 argParser.addFlag('logdog', | 92 argParser.addFlag('logdog', |
| 88 negatable: false, help: "Pull test results from logdog."); | 93 negatable: false, help: "Pull test results from logdog."); |
| 89 return argParser; | 94 return argParser; |
| 90 } | 95 } |
| 91 | 96 |
| 92 void processArgResults(ArgResults argResults) { | 97 void processArgResults(ArgResults argResults) { |
| 93 if (argResults['verbose']) { | 98 if (argResults['verbose']) { |
| 94 LOG = true; | 99 LOG = true; |
| 95 } | 100 } |
| 96 if (argResults['cache'] != null) { | 101 if (argResults['cache'] != null) { |
| 97 cache.base = Uri.base.resolve('${argResults['cache']}/'); | 102 cache.base = Uri.base.resolve('${argResults['cache']}/'); |
| 98 } | 103 } |
| 99 if (argResults['no-cache']) { | 104 if (argResults['no-cache']) { |
| 100 cache.base = null; | 105 cache.base = null; |
| 101 } | 106 } |
| 102 } | 107 } |
| OLD | NEW |