OLD | NEW |
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, 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.command.cache_add; | 5 library pub.command.cache_add; |
6 | 6 |
7 import 'dart:async'; | 7 import 'dart:async'; |
8 | 8 |
9 import 'package:pub_semver/pub_semver.dart'; | 9 import 'package:pub_semver/pub_semver.dart'; |
10 | 10 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
52 constraint = new VersionConstraint.parse(argResults["version"]); | 52 constraint = new VersionConstraint.parse(argResults["version"]); |
53 } on FormatException catch (error) { | 53 } on FormatException catch (error) { |
54 usageException(error.message); | 54 usageException(error.message); |
55 } | 55 } |
56 } | 56 } |
57 | 57 |
58 // TODO(rnystrom): Support installing from git too. | 58 // TODO(rnystrom): Support installing from git too. |
59 var source = cache.sources["hosted"]; | 59 var source = cache.sources["hosted"]; |
60 | 60 |
61 // TODO(rnystrom): Allow specifying the server. | 61 // TODO(rnystrom): Allow specifying the server. |
62 var pubspecs = await source.getVersions(package, package); | 62 var ids = await source.getVersions( |
63 var versions = pubspecs.map((pubspec) => pubspec.version) | 63 new PackageRef(package, 'hosted', package)); |
| 64 var versions = ids.map((id) => id.version) |
64 .where(constraint.allows).toList(); | 65 .where(constraint.allows).toList(); |
65 | 66 |
66 if (versions.isEmpty) { | 67 if (versions.isEmpty) { |
67 // TODO(rnystrom): Show most recent unmatching version? | 68 // TODO(rnystrom): Show most recent unmatching version? |
68 fail("Package $package has no versions that match $constraint."); | 69 fail("Package $package has no versions that match $constraint."); |
69 } | 70 } |
70 | 71 |
71 downloadVersion(version) async { | 72 downloadVersion(version) async { |
72 var id = new PackageId(package, source.name, version, package); | 73 var id = new PackageId(package, source.name, version, package); |
73 if (cache.contains(id)) { | 74 if (cache.contains(id)) { |
(...skipping 11 matching lines...) Expand all Loading... |
85 // Install them in ascending order. | 86 // Install them in ascending order. |
86 versions.sort(); | 87 versions.sort(); |
87 await Future.forEach(versions, downloadVersion); | 88 await Future.forEach(versions, downloadVersion); |
88 } else { | 89 } else { |
89 // Pick the best matching version. | 90 // Pick the best matching version. |
90 versions.sort(Version.prioritize); | 91 versions.sort(Version.prioritize); |
91 await downloadVersion(versions.last); | 92 await downloadVersion(versions.last); |
92 } | 93 } |
93 } | 94 } |
94 } | 95 } |
OLD | NEW |