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.source.path; | 5 library pub.source.path; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:path/path.dart' as path; | 9 import 'package:path/path.dart' as path; |
10 | 10 |
11 import '../io.dart'; | 11 import '../io.dart'; |
12 import '../package.dart'; | 12 import '../package.dart'; |
13 import '../pubspec.dart'; | 13 import '../pubspec.dart'; |
14 import '../source.dart'; | 14 import '../source.dart'; |
15 import '../utils.dart'; | 15 import '../utils.dart'; |
16 | 16 |
17 /// A package [Source] that installs packages from a given local file path. | 17 /// A package [Source] that gets packages from a given local file path. |
18 class PathSource extends Source { | 18 class PathSource extends Source { |
19 final name = 'path'; | 19 final name = 'path'; |
20 final shouldCache = false; | 20 final shouldCache = false; |
21 | 21 |
22 Future<Pubspec> describeUncached(PackageId id) { | 22 Future<Pubspec> describeUncached(PackageId id) { |
23 return new Future.sync(() { | 23 return new Future.sync(() { |
24 _validatePath(id.name, id.description); | 24 _validatePath(id.name, id.description); |
25 return new Pubspec.load(id.description["path"], systemCache.sources, | 25 return new Pubspec.load(id.description["path"], systemCache.sources, |
26 expectedName: id.name); | 26 expectedName: id.name); |
27 }); | 27 }); |
28 } | 28 } |
29 | 29 |
30 bool descriptionsEqual(description1, description2) { | 30 bool descriptionsEqual(description1, description2) { |
31 // Compare real paths after normalizing and resolving symlinks. | 31 // Compare real paths after normalizing and resolving symlinks. |
32 var path1 = canonicalize(description1["path"]); | 32 var path1 = canonicalize(description1["path"]); |
33 var path2 = canonicalize(description2["path"]); | 33 var path2 = canonicalize(description2["path"]); |
34 return path1 == path2; | 34 return path1 == path2; |
35 } | 35 } |
36 | 36 |
37 Future<bool> install(PackageId id, String destination) { | 37 Future<bool> get(PackageId id, String destination) { |
38 return new Future.sync(() { | 38 return new Future.sync(() { |
39 try { | 39 try { |
40 _validatePath(id.name, id.description); | 40 _validatePath(id.name, id.description); |
41 } on FormatException catch(err) { | 41 } on FormatException catch(err) { |
42 return false; | 42 return false; |
43 } | 43 } |
44 | 44 |
45 createPackageSymlink(id.name, id.description["path"], destination, | 45 createPackageSymlink(id.name, id.description["path"], destination, |
46 relative: id.description["relative"]); | 46 relative: id.description["relative"]); |
47 return true; | 47 return true; |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 if (dirExists(dir)) return; | 112 if (dirExists(dir)) return; |
113 | 113 |
114 if (fileExists(dir)) { | 114 if (fileExists(dir)) { |
115 fail("Path dependency for package '$name' must refer to a " | 115 fail("Path dependency for package '$name' must refer to a " |
116 "directory, not a file. Was '$dir'."); | 116 "directory, not a file. Was '$dir'."); |
117 } | 117 } |
118 | 118 |
119 fail("Could not find package '$name' at '$dir'."); | 119 fail("Could not find package '$name' at '$dir'."); |
120 } | 120 } |
121 } | 121 } |
OLD | NEW |