Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 pub.barback; | 5 library pub.barback; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 | 8 |
| 9 import 'package:barback/barback.dart'; | 9 import 'package:barback/barback.dart'; |
| 10 | 10 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 50 if (!completer.isCompleted) completer.completeError(error); | 50 if (!completer.isCompleted) completer.completeError(error); |
| 51 }); | 51 }); |
| 52 | 52 |
| 53 return completer.future.whenComplete(() { | 53 return completer.future.whenComplete(() { |
| 54 for (var subscription in subscriptions) { | 54 for (var subscription in subscriptions) { |
| 55 subscription.cancel(); | 55 subscription.cancel(); |
| 56 } | 56 } |
| 57 }); | 57 }); |
| 58 }); | 58 }); |
| 59 } | 59 } |
| 60 | |
| 61 /// Parses a library identifier to an asset id. | |
| 62 /// | |
| 63 /// A library identifier is a string of the form "package_name" or | |
| 64 /// "package_name/path/to/library". It does not have a trailing extension. If it | |
| 65 /// just has a package name, it expands to lib/${package}.dart in that package. | |
| 66 /// Otherwise, it expands to lib/${path}.dart in that package. | |
| 67 AssetId libraryIdentifierToId(String identifier) { | |
|
Bob Nystrom
2013/09/10 20:31:09
Throw an ArgumentError on an empty string.
nweiz
2013/09/10 21:44:52
Throwing a FormatError instead, since it's likely
| |
| 68 // Convert the concise asset name in the pubspec (of the form "package" | |
| 69 // or "package/library") to an AssetId that points to an actual dart | |
| 70 // file ("package/lib/package.dart" or "package/lib/library.dart", | |
| 71 // respectively). | |
| 72 var parts = split1(identifier, "/"); | |
| 73 if (parts.length == 1) parts.add(parts.single); | |
| 74 return new AssetId(parts.first, 'lib/' + parts.last + '.dart'); | |
| 75 } | |
| 76 | |
| 77 final _libraryPathRegexp = new RegExp(r"^lib/(.*)\.dart$"); | |
|
Bob Nystrom
2013/09/10 20:31:09
Capitalize "e" in "exp". (I wish the class was nam
nweiz
2013/09/10 21:44:52
Done.
| |
| 78 | |
| 79 /// Converts [id] to a library identifier. | |
| 80 /// | |
| 81 /// A library identifier is a string of the form "package_name" or | |
| 82 /// "package_name/path/to/library". It does not have a trailing extension. If it | |
| 83 /// just has a package name, it expands to lib/${package}.dart in that package. | |
| 84 /// Otherwise, it expands to lib/${path}.dart in that package. | |
| 85 /// | |
| 86 /// This will throw an [ArgumentError] if [id] doesn't represent a library in | |
| 87 /// `lib/`. | |
| 88 String idToLibraryIdentifier(AssetId id) { | |
| 89 var match = _libraryPathRegexp.firstMatch(id.path); | |
| 90 if (match == null) { | |
| 91 throw new ArgumentError("Asset id $id doesn't identify a library."); | |
| 92 } | |
| 93 | |
| 94 if (match[1] == id.package) return id.package; | |
| 95 return '${id.package}/${match[1]}'; | |
| 96 } | |
| 97 | |
| 98 /// Converts [id] to a "package:" URI. | |
| 99 /// | |
| 100 /// This will throw an [ArgumentError] if [id] doesn't represent a library in | |
| 101 /// `lib/`. | |
| 102 Uri idToPackageUri(AssetId id) { | |
| 103 if (!id.path.startsWith('lib/')) { | |
| 104 throw new ArgumentError("Asset id $id doesn't identify a library."); | |
| 105 } | |
| 106 | |
| 107 return new Uri(scheme: 'package', path: id.path.replaceFirst('lib/', '')); | |
| 108 } | |
| OLD | NEW |