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

Side by Side Diff: utils/pub/package.dart

Issue 10392089: Add a Pub source that checks packages out from Git. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Update both RegExps Created 8 years, 7 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/packages_dir.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2012, 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 /** 5 /**
6 * A named, versioned, unit of code and resource reuse. 6 * A named, versioned, unit of code and resource reuse.
7 */ 7 */
8 class Package implements Hashable { 8 class Package implements Hashable {
9 /** 9 /**
10 * Loads the package whose root directory is [packageDir]. 10 * Loads the package whose root directory is [packageDir].
11 */ 11 */
12 static Future<Package> load(String packageDir) { 12 static Future<Package> load(String packageDir, SourceRegistry sources) {
13 final pubspecPath = join(packageDir, 'pubspec'); 13 final pubspecPath = join(packageDir, 'pubspec');
14 14
15 return _parsePubspec(pubspecPath).transform((dependencies) { 15 return _parsePubspec(pubspecPath, sources).transform((dependencies) {
16 return new Package._(packageDir, dependencies); 16 return new Package._(packageDir, dependencies);
17 }); 17 });
18 } 18 }
19 19
20 /** 20 /**
21 * The path to the directory containing the package. 21 * The path to the directory containing the package.
22 */ 22 */
23 final String dir; 23 final String dir;
24 24
25 /** 25 /**
(...skipping 24 matching lines...) Expand all
50 50
51 /** 51 /**
52 * Returns a debug string for the package. 52 * Returns a debug string for the package.
53 */ 53 */
54 String toString() => '$name ($dir)'; 54 String toString() => '$name ($dir)';
55 55
56 /** 56 /**
57 * Parses the pubspec at the given path and returns the list of package 57 * Parses the pubspec at the given path and returns the list of package
58 * dependencies it exposes. 58 * dependencies it exposes.
59 */ 59 */
60 static Future<List<PackageId>> _parsePubspec(String path) { 60 static Future<List<PackageId>> _parsePubspec(String path,
61 SourceRegistry sources) {
61 final completer = new Completer<List<PackageId>>(); 62 final completer = new Completer<List<PackageId>>();
62 63
63 // TODO(rnystrom): Handle the directory not existing. 64 // TODO(rnystrom): Handle the directory not existing.
64 // TODO(rnystrom): Error-handling. 65 // TODO(rnystrom): Error-handling.
65 final readFuture = readTextFile(path); 66 final readFuture = readTextFile(path);
66 readFuture.handleException((error) { 67 readFuture.handleException((error) {
67 // If there is no pubspec, we implicitly treat that as a package with no 68 // If there is no pubspec, we implicitly treat that as a package with no
68 // dependencies. 69 // dependencies.
69 // TODO(rnystrom): Distinguish file not found from other real errors. 70 // TODO(rnystrom): Distinguish file not found from other real errors.
70 completer.complete(<PackageId>[]); 71 completer.complete(<PackageId>[]);
(...skipping 10 matching lines...) Expand all
81 if (parsedPubspec is! Map) { 82 if (parsedPubspec is! Map) {
82 completer.completeException('The pubspec must be a YAML mapping.'); 83 completer.completeException('The pubspec must be a YAML mapping.');
83 } 84 }
84 85
85 if (!parsedPubspec.containsKey('dependencies')) { 86 if (!parsedPubspec.containsKey('dependencies')) {
86 completer.complete(<String>[]); 87 completer.complete(<String>[]);
87 return; 88 return;
88 } 89 }
89 90
90 var dependencies = parsedPubspec['dependencies']; 91 var dependencies = parsedPubspec['dependencies'];
91 if (dependencies.some((e) => e is! String)) { 92 if (dependencies is! Map ||
93 dependencies.getKeys().some((e) => e is! String)) {
92 completer.completeException( 94 completer.completeException(
93 'The pubspec dependencies must be a list of package names.'); 95 'The pubspec dependencies must be a map of package names.');
94 } 96 }
95 97
96 var dependencyIds = 98 var dependencyIds = <PackageId>[];
97 dependencies.map((name) => new PackageId(name, Source.defaultSource)); 99 dependencies.forEach((name, spec) {
100 var fullName, source;
101 // TODO(nweiz): parse the version once we have version handling
102 if (spec == null || spec is String) {
103 fullName = name;
104 source = sources.defaultSource;
105 } else if (spec is Map) {
106 spec.remove('version');
107
108 var sourceNames = spec.getKeys();
109 if (sourceNames.length > 1) {
110 completer.completeException(
111 'Dependency $name may not have multiple sources: '
112 '$sourceNames.');
113 return;
114 }
115
116 var sourceName = only(sourceNames);
117 if (sourceName is! String) {
118 completer.completeException(
119 'Source name $sourceName must be a string.');
120 return;
121 }
122 source = sources[sourceName];
123
124 // TODO(nweiz): At some point we want fullName to be able to be an
125 // arbitrary object that's parsed by the source.
126 fullName = spec[sourceName];
127 if (fullName is! String) {
128 completer.completeException(
129 'Source identifier $fullName must be a string.');
130 return;
131 }
132 } else {
133 completer.completeException(
134 'Dependency specification $spec must be a string or a mapping.');
135 return;
136 }
137
138 var id = new PackageId(fullName, source);
139 var nameFromSource = source.packageName(id);
140 if (nameFromSource != name) {
141 completer.completeException(
142 'Dependency name "$name" doesn\'t match name "$nameFromSource" '
143 'from source "${source.name}".');
144 return;
145 }
146
147 dependencyIds.add(id);
148 });
98 completer.complete(dependencyIds); 149 completer.complete(dependencyIds);
99 }); 150 });
100 151
101 return completer.future; 152 return completer.future;
102 } 153 }
103 } 154 }
104 155
105 /** 156 /**
106 * A unique identifier for a package. A given package id specifies a single 157 * A unique identifier for a package. A given package id specifies a single
107 * chunk of code and resources. 158 * chunk of code and resources.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
146 197
147 String toString() => "$fullName from ${source.name}"; 198 String toString() => "$fullName from ${source.name}";
148 199
149 int compareTo(Comparable other) { 200 int compareTo(Comparable other) {
150 if (other is! PackageId) throw new IllegalArgumentException(other); 201 if (other is! PackageId) throw new IllegalArgumentException(other);
151 var sourceComp = this.source.name.compareTo(other.source.name); 202 var sourceComp = this.source.name.compareTo(other.source.name);
152 if (sourceComp != 0) return sourceComp; 203 if (sourceComp != 0) return sourceComp;
153 return this.fullName.compareTo(other.fullName); 204 return this.fullName.compareTo(other.fullName);
154 } 205 }
155 } 206 }
OLDNEW
« no previous file with comments | « utils/pub/io.dart ('k') | utils/pub/packages_dir.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698