OLD | NEW |
1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 library test.util.io; | 5 library test.util.io; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 import 'dart:io'; | 8 import 'dart:io'; |
9 import 'dart:mirrors'; | 9 import 'dart:mirrors'; |
10 | 10 |
11 import 'package:path/path.dart' as p; | 11 import 'package:path/path.dart' as p; |
12 import 'package:pub_semver/pub_semver.dart'; | 12 import 'package:pub_semver/pub_semver.dart'; |
13 | 13 |
14 import '../backend/operating_system.dart'; | 14 import '../backend/operating_system.dart'; |
15 import '../runner/load_exception.dart'; | 15 import '../runner/application_exception.dart'; |
16 | 16 |
17 /// The root directory of the Dart SDK. | 17 /// The root directory of the Dart SDK. |
18 final String sdkDir = | 18 final String sdkDir = |
19 p.dirname(p.dirname(Platform.executable)); | 19 p.dirname(p.dirname(Platform.executable)); |
20 | 20 |
21 /// The version of the Dart SDK currently in use. | 21 /// The version of the Dart SDK currently in use. |
22 final Version _sdkVersion = new Version.parse( | 22 final Version _sdkVersion = new Version.parse( |
23 new File(p.join(p.dirname(p.dirname(Platform.executable)), 'version')) | 23 new File(p.join(p.dirname(p.dirname(Platform.executable)), 'version')) |
24 .readAsStringSync().trim()); | 24 .readAsStringSync().trim()); |
25 | 25 |
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
105 | 105 |
106 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid | 106 // IPv6 addresses in URLs need to be enclosed in square brackets to avoid |
107 // URL ambiguity with the ":" in the address. | 107 // URL ambiguity with the ":" in the address. |
108 if (address.type == InternetAddressType.IP_V6) { | 108 if (address.type == InternetAddressType.IP_V6) { |
109 return new Uri(scheme: "http", host: "[${address.address}]", port: port); | 109 return new Uri(scheme: "http", host: "[${address.address}]", port: port); |
110 } | 110 } |
111 | 111 |
112 return new Uri(scheme: "http", host: address.address, port: port); | 112 return new Uri(scheme: "http", host: address.address, port: port); |
113 } | 113 } |
114 | 114 |
115 /// Returns the package root for a Dart entrypoint at [path]. | 115 /// Returns the package root at [root]. |
116 /// | 116 /// |
117 /// If [override] is passed, that's used. If the package root doesn't exist, a | 117 /// If [override] is passed, that's used. If the package root doesn't exist, an |
118 /// [LoadException] is thrown. | 118 /// [ApplicationException] is thrown. |
119 String packageRootFor(String path, [String override]) { | 119 String packageRootFor(String root, [String override]) { |
120 var packageRoot = override == null | 120 if (root == null) root = p.current; |
121 ? p.join(p.dirname(path), 'packages') | 121 var packageRoot = override == null ? p.join(root, 'packages') : override; |
122 : override; | |
123 | 122 |
124 if (!new Directory(packageRoot).existsSync()) { | 123 if (!new Directory(packageRoot).existsSync()) { |
125 throw new LoadException(path, "Directory $packageRoot does not exist."); | 124 throw new ApplicationException( |
| 125 "Directory ${p.prettyUri(p.toUri(packageRoot))} does not exist."); |
126 } | 126 } |
127 | 127 |
128 return packageRoot; | 128 return packageRoot; |
129 } | 129 } |
130 | 130 |
131 /// The library name must be globally unique, or the wrong library path may be | 131 /// The library name must be globally unique, or the wrong library path may be |
132 /// returned. | 132 /// returned. |
133 String libraryPath(Symbol libraryName, {String packageRoot}) { | 133 String libraryPath(Symbol libraryName, {String packageRoot}) { |
134 var lib = currentMirrorSystem().findLibrary(libraryName); | 134 var lib = currentMirrorSystem().findLibrary(libraryName); |
135 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); | 135 if (lib.uri.scheme != 'package') return p.fromUri(lib.uri); |
136 | 136 |
137 // TODO(nweiz): is there a way to avoid assuming this is being run next to a | 137 // TODO(nweiz): is there a way to avoid assuming this is being run next to a |
138 // packages directory?. | 138 // packages directory?. |
139 if (packageRoot == null) packageRoot = p.absolute('packages'); | 139 if (packageRoot == null) packageRoot = p.absolute('packages'); |
140 return p.join(packageRoot, p.fromUri(lib.uri.path)); | 140 return p.join(packageRoot, p.fromUri(lib.uri.path)); |
141 } | 141 } |
OLD | NEW |