Chromium Code Reviews| Index: sdk/lib/_internal/pub/lib/src/hosted_source.dart |
| diff --git a/sdk/lib/_internal/pub/lib/src/hosted_source.dart b/sdk/lib/_internal/pub/lib/src/hosted_source.dart |
| index 1b4ecda3389d8b5cce87fcf5fb1b0a2868dff9f9..d552a588aef2cb0cb76f6869ad8d33274a05e778 100644 |
| --- a/sdk/lib/_internal/pub/lib/src/hosted_source.dart |
| +++ b/sdk/lib/_internal/pub/lib/src/hosted_source.dart |
| @@ -99,12 +99,9 @@ class HostedSource extends Source { |
| Future<String> systemCacheDirectory(PackageId id) { |
| var parsed = _parseDescription(id.description); |
| var url = _getSourceDirectory(parsed.last); |
|
nweiz
2013/05/06 23:02:25
This variable should probably be "dir" or somethin
Bob Nystrom
2013/05/07 21:03:09
Done.
|
| - var urlDir = replace(url, new RegExp(r'[<>:"\\/|?*%]'), (match) { |
| - return '%${match[0].codeUnitAt(0)}'; |
| - }); |
| return new Future.value( |
| - path.join(systemCacheRoot, urlDir, "${parsed.first}-${id.version}")); |
| + path.join(systemCacheRoot, url, "${parsed.first}-${id.version}")); |
| } |
| String packageName(description) => _parseDescription(description).first; |
| @@ -123,19 +120,21 @@ class HostedSource extends Source { |
| return description; |
| } |
| - List<Package> getCachedPackages() { |
| + List<Package> getCachedPackages([String url]) { |
| + if (url == null) url = _defaultUrl; |
| + |
| var cacheDir = path.join(systemCacheRoot, |
| - _getSourceDirectory(_defaultUrl)); |
| + _getSourceDirectory(url)); |
| if (!dirExists(cacheDir)) return []; |
| return listDir(path.join(cacheDir)).map((entry) { |
| // TODO(keertip): instead of catching exception in pubspec parse with |
| - // sdk dependency, fix to parse and report usage of sdk dependency. |
| + // sdk dependency, fix to parse and report usage of sdk dependency. |
| // dartbug.com/10190 |
| try { |
| return new Package.load(null, entry, systemCache.sources); |
| } on ArgumentError catch (e) { |
| - log.error(e); |
| + log.error(e); |
| } |
| }).where((package) => package != null).toList(); |
| } |
| @@ -161,14 +160,52 @@ class HostedSource extends Source { |
| // Otherwise re-throw the original exception. |
| throw error; |
| } |
| +} |
| + |
| +/// This is the modified hosted source used when pub install or updated are run |
|
nweiz
2013/05/06 23:02:25
"updated" -> "update"
Bob Nystrom
2013/05/07 22:20:33
Done.
|
| +/// with "--offline". This uses the system cache to get the list of available |
| +/// packages and does no network access. |
| +class OfflineHostedSource extends HostedSource { |
|
nweiz
2013/05/06 23:02:25
I don't like making "--offline" hosted-specific. I
Bob Nystrom
2013/05/07 22:20:33
I considered that too, but didn't want to implemen
|
| + /// Gets the list of all versions of [name] that are in the system cache. |
| + Future<List<Version>> getVersions(String name, description) { |
| + return new Future(() { |
| + var parsed = _parseDescription(description); |
| + var server = parsed.last; |
| + log.io("Finding versions of $name in " |
| + "${systemCache.rootDir}/${_getSourceDirectory(server)}"); |
| + return getCachedPackages(server) |
| + .where((package) => package.name == name) |
| + .map((package) => package.version) |
| + .toList(); |
| + }).then((versions) { |
| + // If there are no versions in the cache, report a clearer error. |
| + if (versions.isEmpty) fail('Could not find package "$name" in cache.'); |
| + return versions; |
| + }); |
| + } |
| + |
| + Future<bool> install(PackageId id, String destPath) { |
| + // Since HostedSource returns `true` for [shouldCache], install will only |
| + // be called for uncached packages. |
| + throw new UnsupportedError("Cannot install packages when offline."); |
| + } |
| + |
| + Future<Pubspec> describe(PackageId id) { |
| + // getVersions() will only return packages that are already cached. |
|
nweiz
2013/05/06 23:02:25
"getVersions()" -> "[getVersions]", same for "desc
Bob Nystrom
2013/05/07 22:20:33
Done.
|
| + // SystemCache should only call describe() on a package after its failed to |
|
nweiz
2013/05/06 23:02:25
"its" -> "it's" or "it has"
Bob Nystrom
2013/05/07 22:20:33
Done.
|
| + // find it in the cache, so this code should not be reached. |
| + throw new UnsupportedError("Cannot describe packages when offline."); |
| + } |
| } |
| /// The URL of the default package repository. |
| final _defaultUrl = "https://pub.dartlang.org"; |
| String _getSourceDirectory(String url) { |
| - return url.replaceAll(new RegExp(r"^https?://"), ""); |
| + url = url.replaceAll(new RegExp(r"^https?://"), ""); |
| + return replace(url, new RegExp(r'[<>:"\\/|?*%]'), |
| + (match) => '%${match[0].codeUnitAt(0)}'); |
| } |
| /// Parses [description] into its server and package name components, then |