| 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 serve_packages; | 5 library serve_packages; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 | 9 |
| 10 import 'package:path/path.dart' as p; | 10 import 'package:path/path.dart' as p; |
| (...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 146 })); | 146 })); |
| 147 } | 147 } |
| 148 | 148 |
| 149 /// Serves the versions of [package] and all its dependencies that are | 149 /// Serves the versions of [package] and all its dependencies that are |
| 150 /// currently checked into the Dart repository. | 150 /// currently checked into the Dart repository. |
| 151 void serveRepoPackage(String package) { | 151 void serveRepoPackage(String package) { |
| 152 _addPackage(name) { | 152 _addPackage(name) { |
| 153 if (_packages.containsKey(name)) return; | 153 if (_packages.containsKey(name)) return; |
| 154 _packages[name] = []; | 154 _packages[name] = []; |
| 155 | 155 |
| 156 var root = packagePath(name); |
| 156 var pubspec = new Map.from(loadYaml( | 157 var pubspec = new Map.from(loadYaml( |
| 157 readTextFile(p.join(repoRoot, 'pkg', name, 'pubspec.yaml')))); | 158 readTextFile(p.join(root, 'pubspec.yaml')))); |
| 158 | 159 |
| 159 // Remove any SDK constraints since we don't have a valid SDK version | 160 // Remove any SDK constraints since we don't have a valid SDK version |
| 160 // while testing. | 161 // while testing. |
| 161 pubspec.remove('environment'); | 162 pubspec.remove('environment'); |
| 162 | 163 |
| 163 _packages[name].add(new _ServedPackage(pubspec, [ | 164 _packages[name].add(new _ServedPackage(pubspec, [ |
| 164 d.file('pubspec.yaml', yaml(pubspec)), | 165 d.file('pubspec.yaml', yaml(pubspec)), |
| 165 new d.DirectoryDescriptor.fromFilesystem('lib', | 166 new d.DirectoryDescriptor.fromFilesystem('lib', p.join(root, 'lib')) |
| 166 p.join(repoRoot, 'pkg', name, 'lib')) | |
| 167 ])); | 167 ])); |
| 168 | 168 |
| 169 if (pubspec.containsKey('dependencies')) { | 169 if (pubspec.containsKey('dependencies')) { |
| 170 pubspec['dependencies'].keys.forEach(_addPackage); | 170 pubspec['dependencies'].keys.forEach(_addPackage); |
| 171 } | 171 } |
| 172 } | 172 } |
| 173 | 173 |
| 174 _addPackage(package); | 174 _addPackage(package); |
| 175 } | 175 } |
| 176 | 176 |
| 177 /// Returns a Future that completes once all the [serve] calls have been fully | 177 /// Returns a Future that completes once all the [serve] calls have been fully |
| 178 /// processed. | 178 /// processed. |
| 179 Future _await() { | 179 Future _await() { |
| 180 if (_futures.futures.isEmpty) return new Future.value(); | 180 if (_futures.futures.isEmpty) return new Future.value(); |
| 181 return _futures.future.then((_) { | 181 return _futures.future.then((_) { |
| 182 _futures = new FutureGroup(); | 182 _futures = new FutureGroup(); |
| 183 }); | 183 }); |
| 184 } | 184 } |
| 185 } | 185 } |
| 186 | 186 |
| 187 /// A package that's intended to be served. | 187 /// A package that's intended to be served. |
| 188 class _ServedPackage { | 188 class _ServedPackage { |
| 189 final Map pubspec; | 189 final Map pubspec; |
| 190 final List<d.Descriptor> contents; | 190 final List<d.Descriptor> contents; |
| 191 | 191 |
| 192 Version get version => new Version.parse(pubspec['version']); | 192 Version get version => new Version.parse(pubspec['version']); |
| 193 | 193 |
| 194 _ServedPackage(this.pubspec, this.contents); | 194 _ServedPackage(this.pubspec, this.contents); |
| 195 } | 195 } |
| OLD | NEW |