Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(460)

Unified Diff: lib/src/source/path.dart

Issue 2044253003: Refactor Source and SourceRegistry. (Closed) Base URL: git@github.com:dart-lang/pub.git@master
Patch Set: Rename LiveSource to BoundSource. Created 4 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « lib/src/source/hosted.dart ('k') | lib/src/source/unknown.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: lib/src/source/path.dart
diff --git a/lib/src/source/path.dart b/lib/src/source/path.dart
index b700d337a0a93abf8e978fa1adeb736eb592f8ec..b239c5327953d316c963c588d235adcc2a77607b 100644
--- a/lib/src/source/path.dart
+++ b/lib/src/source/path.dart
@@ -12,12 +12,25 @@ import '../io.dart';
import '../package.dart';
import '../pubspec.dart';
import '../source.dart';
+import '../system_cache.dart';
import '../utils.dart';
/// A package [Source] that gets packages from a given local file path.
class PathSource extends Source {
+ final name = 'path';
+
+ BoundSource bind(SystemCache systemCache) =>
+ new BoundPathSource(this, systemCache);
+
+ /// Given a valid path reference description, returns the file path it
+ /// describes.
+ ///
+ /// This returned path may be relative or absolute and it is up to the caller
+ /// to know how to interpret a relative path.
+ String pathFromDescription(description) => description["path"];
+
/// Returns a reference to a path package named [name] at [path].
- static PackageRef refFor(String name, String path) {
+ PackageRef refFor(String name, String path) {
return new PackageRef(name, 'path', {
"path": path,
"relative": p.isRelative(path)
@@ -26,39 +39,13 @@ class PathSource extends Source {
/// Returns an ID for a path package with the given [name] and [version] at
/// [path].
- static PackageId idFor(String name, Version version, String path) {
+ PackageId idFor(String name, Version version, String path) {
return new PackageId(name, 'path', version, {
"path": path,
"relative": p.isRelative(path)
});
}
- /// Given a valid path reference description, returns the file path it
- /// describes.
- ///
- /// This returned path may be relative or absolute and it is up to the caller
- /// to know how to interpret a relative path.
- static String pathFromDescription(description) => description["path"];
-
- final name = 'path';
-
- Future<List<PackageId>> doGetVersions(PackageRef ref) async {
- // There's only one package ID for a given path. We just need to find the
- // version.
- var pubspec = _loadPubspec(ref);
- var id = new PackageId(ref.name, name, pubspec.version, ref.description);
- memoizePubspec(id, pubspec);
- return [id];
- }
-
- Future<Pubspec> doDescribe(PackageId id) async => _loadPubspec(id.toRef());
-
- Pubspec _loadPubspec(PackageRef ref) {
- var dir = _validatePath(ref.name, ref.description);
- return new Pubspec.load(dir, systemCache.sources,
- expectedName: ref.name);
- }
-
bool descriptionsEqual(description1, description2) {
// Compare real paths after normalizing and resolving symlinks.
var path1 = canonicalize(description1["path"]);
@@ -66,16 +53,6 @@ class PathSource extends Source {
return path1 == path2;
}
- Future get(PackageId id, String symlink) {
- return new Future.sync(() {
- var dir = _validatePath(id.name, id.description);
- createPackageSymlink(id.name, dir, symlink,
- relative: id.description["relative"]);
- });
- }
-
- String getDirectory(PackageId id) => id.description["path"];
-
/// Parses a path dependency.
///
/// This takes in a path string and returns a map. The "path" key will be the
@@ -149,6 +126,42 @@ class PathSource extends Source {
return sourcePath;
}
+}
+
+/// The [BoundSource] for [PathSource].
+class BoundPathSource extends BoundSource {
+ final PathSource source;
+
+ final SystemCache systemCache;
+
+ BoundPathSource(this.source, this.systemCache);
+
+ Future<List<PackageId>> doGetVersions(PackageRef ref) async {
+ // There's only one package ID for a given path. We just need to find the
+ // version.
+ var pubspec = _loadPubspec(ref);
+ var id = new PackageId(
+ ref.name, source.name, pubspec.version, ref.description);
+ memoizePubspec(id, pubspec);
+ return [id];
+ }
+
+ Future<Pubspec> doDescribe(PackageId id) async => _loadPubspec(id.toRef());
+
+ Pubspec _loadPubspec(PackageRef ref) {
+ var dir = _validatePath(ref.name, ref.description);
+ return new Pubspec.load(dir, systemCache.sources, expectedName: ref.name);
+ }
+
+ Future get(PackageId id, String symlink) {
+ return new Future.sync(() {
+ var dir = _validatePath(id.name, id.description);
+ createPackageSymlink(id.name, dir, symlink,
+ relative: id.description["relative"]);
+ });
+ }
+
+ String getDirectory(PackageId id) => id.description["path"];
/// Ensures that [description] is a valid path description and returns a
/// normalized path to the package.
« no previous file with comments | « lib/src/source/hosted.dart ('k') | lib/src/source/unknown.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698