OLD | NEW |
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 library git_source; | 5 library git_source; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import '../../pkg/path/lib/path.dart' as path; | 9 import '../../pkg/path/lib/path.dart' as path; |
10 | 10 |
11 import 'git.dart' as git; | 11 import 'git.dart' as git; |
12 import 'io.dart'; | 12 import 'io.dart'; |
| 13 import 'log.dart' as log; |
13 import 'package.dart'; | 14 import 'package.dart'; |
14 import 'source.dart'; | 15 import 'source.dart'; |
15 import 'source_registry.dart'; | 16 import 'source_registry.dart'; |
16 import 'utils.dart'; | 17 import 'utils.dart'; |
17 | 18 |
18 /// A package source that installs packages from Git repos. | 19 /// A package source that installs packages from Git repos. |
19 class GitSource extends Source { | 20 class GitSource extends Source { |
20 final String name = "git"; | 21 final String name = "git"; |
21 | 22 |
22 final bool shouldCache = true; | 23 final bool shouldCache = true; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
60 }); | 61 }); |
61 } | 62 } |
62 | 63 |
63 /// Returns the path to the revision-specific cache of [id]. | 64 /// Returns the path to the revision-specific cache of [id]. |
64 Future<String> systemCacheDirectory(PackageId id) { | 65 Future<String> systemCacheDirectory(PackageId id) { |
65 return _revisionAt(id).then((rev) { | 66 return _revisionAt(id).then((rev) { |
66 var revisionCacheName = '${id.name}-$rev'; | 67 var revisionCacheName = '${id.name}-$rev'; |
67 return path.join(systemCacheRoot, revisionCacheName); | 68 return path.join(systemCacheRoot, revisionCacheName); |
68 }); | 69 }); |
69 } | 70 } |
| 71 |
70 /// Ensures [description] is a Git URL. | 72 /// Ensures [description] is a Git URL. |
71 void validateDescription(description, {bool fromLockFile: false}) { | 73 dynamic parseDescription(String containingPath, description, |
| 74 {bool fromLockFile: false}) { |
| 75 // TODO(rnystrom): Handle git URLs that are relative file paths (#8570). |
| 76 // TODO(rnystrom): Now that this function can modify the description, it |
| 77 // may as well canonicalize it to a map so that other code in the source |
| 78 // can assume that. |
72 // A single string is assumed to be a Git URL. | 79 // A single string is assumed to be a Git URL. |
73 if (description is String) return; | 80 if (description is String) return description; |
74 if (description is! Map || !description.containsKey('url')) { | 81 if (description is! Map || !description.containsKey('url')) { |
75 throw new FormatException("The description must be a Git URL or a map " | 82 throw new FormatException("The description must be a Git URL or a map " |
76 "with a 'url' key."); | 83 "with a 'url' key."); |
77 } | 84 } |
78 description = new Map.from(description); | |
79 description.remove('url'); | |
80 description.remove('ref'); | |
81 if (fromLockFile) description.remove('resolved-ref'); | |
82 | 85 |
83 if (!description.isEmpty) { | 86 var parsed = new Map.from(description); |
84 var plural = description.length > 1; | 87 parsed.remove('url'); |
85 var keys = description.keys.join(', '); | 88 parsed.remove('ref'); |
| 89 if (fromLockFile) parsed.remove('resolved-ref'); |
| 90 |
| 91 if (!parsed.isEmpty) { |
| 92 var plural = parsed.length > 1; |
| 93 var keys = parsed.keys.join(', '); |
86 throw new FormatException("Invalid key${plural ? 's' : ''}: $keys."); | 94 throw new FormatException("Invalid key${plural ? 's' : ''}: $keys."); |
87 } | 95 } |
| 96 |
| 97 return description; |
88 } | 98 } |
89 | 99 |
90 /// Two Git descriptions are equal if both their URLs and their refs are | 100 /// Two Git descriptions are equal if both their URLs and their refs are |
91 /// equal. | 101 /// equal. |
92 bool descriptionsEqual(description1, description2) { | 102 bool descriptionsEqual(description1, description2) { |
93 // TODO(nweiz): Do we really want to throw an error if you have two | 103 // TODO(nweiz): Do we really want to throw an error if you have two |
94 // dependencies on some repo, one of which specifies a ref and one of which | 104 // dependencies on some repo, one of which specifies a ref and one of which |
95 // doesn't? If not, how do we handle that case in the version solver? | 105 // doesn't? If not, how do we handle that case in the version solver? |
96 return _getUrl(description1) == _getUrl(description2) && | 106 return _getUrl(description1) == _getUrl(description2) && |
97 _getRef(description1) == _getRef(description2); | 107 _getRef(description1) == _getRef(description2); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
190 return description['ref']; | 200 return description['ref']; |
191 } | 201 } |
192 | 202 |
193 /// Returns [description] if it's a description, or [PackageId.description] if | 203 /// Returns [description] if it's a description, or [PackageId.description] if |
194 /// it's a [PackageId]. | 204 /// it's a [PackageId]. |
195 _getDescription(description) { | 205 _getDescription(description) { |
196 if (description is PackageId) return description.description; | 206 if (description is PackageId) return description.description; |
197 return description; | 207 return description; |
198 } | 208 } |
199 } | 209 } |
OLD | NEW |