| 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 pubspec; | 5 library pubspec; |
| 6 | 6 |
| 7 import 'package:yaml/yaml.dart'; | 7 import 'package:yaml/yaml.dart'; |
| 8 import 'package:pathos/path.dart' as path; | 8 import 'package:pathos/path.dart' as path; |
| 9 | 9 |
| 10 import 'io.dart'; | 10 import 'io.dart'; |
| 11 import 'package.dart'; | 11 import 'package.dart'; |
| 12 import 'source.dart'; | 12 import 'source.dart'; |
| 13 import 'source_registry.dart'; | 13 import 'source_registry.dart'; |
| 14 import 'utils.dart'; | 14 import 'utils.dart'; |
| 15 import 'version.dart'; | 15 import 'version.dart'; |
| 16 | 16 |
| 17 /// The parsed and validated contents of a pubspec file. | 17 /// The parsed and validated contents of a pubspec file. |
| 18 class Pubspec { | 18 class Pubspec { |
| 19 /// This package's name. | 19 /// This package's name. |
| 20 final String name; | 20 final String name; |
| 21 | 21 |
| 22 /// This package's version. | 22 /// This package's version. |
| 23 final Version version; | 23 final Version version; |
| 24 | 24 |
| 25 /// The packages this package depends on. | 25 /// The packages this package depends on. |
| 26 final List<PackageRef> dependencies; | 26 final List<PackageDep> dependencies; |
| 27 | 27 |
| 28 /// The packages this package depends on when it is the root package. | 28 /// The packages this package depends on when it is the root package. |
| 29 final List<PackageRef> devDependencies; | 29 final List<PackageDep> devDependencies; |
| 30 | 30 |
| 31 /// The environment-related metadata. | 31 /// The environment-related metadata. |
| 32 final PubspecEnvironment environment; | 32 final PubspecEnvironment environment; |
| 33 | 33 |
| 34 /// All pubspec fields. This includes the fields from which other properties | 34 /// All pubspec fields. This includes the fields from which other properties |
| 35 /// are derived. | 35 /// are derived. |
| 36 final Map<String, Object> fields; | 36 final Map<String, Object> fields; |
| 37 | 37 |
| 38 /// Loads the pubspec for a package [name] located in [packageDir]. | 38 /// Loads the pubspec for a package [name] located in [packageDir]. |
| 39 factory Pubspec.load(String name, String packageDir, SourceRegistry sources) { | 39 factory Pubspec.load(String name, String packageDir, SourceRegistry sources) { |
| (...skipping 18 matching lines...) Expand all Loading... |
| 58 } | 58 } |
| 59 } | 59 } |
| 60 | 60 |
| 61 Pubspec(this.name, this.version, this.dependencies, this.devDependencies, | 61 Pubspec(this.name, this.version, this.dependencies, this.devDependencies, |
| 62 this.environment, [Map<String, Object> fields]) | 62 this.environment, [Map<String, Object> fields]) |
| 63 : this.fields = fields == null ? {} : fields; | 63 : this.fields = fields == null ? {} : fields; |
| 64 | 64 |
| 65 Pubspec.empty() | 65 Pubspec.empty() |
| 66 : name = null, | 66 : name = null, |
| 67 version = Version.none, | 67 version = Version.none, |
| 68 dependencies = <PackageRef>[], | 68 dependencies = <PackageDep>[], |
| 69 devDependencies = <PackageRef>[], | 69 devDependencies = <PackageDep>[], |
| 70 environment = new PubspecEnvironment(), | 70 environment = new PubspecEnvironment(), |
| 71 fields = {}; | 71 fields = {}; |
| 72 | 72 |
| 73 /// Whether or not the pubspec has no contents. | 73 /// Whether or not the pubspec has no contents. |
| 74 bool get isEmpty => | 74 bool get isEmpty => |
| 75 name == null && version == Version.none && dependencies.isEmpty; | 75 name == null && version == Version.none && dependencies.isEmpty; |
| 76 | 76 |
| 77 // TODO(rnystrom): Instead of allowing a null argument here, split this up | 77 // TODO(rnystrom): Instead of allowing a null argument here, split this up |
| 78 // into load(), parse(), and _parse() like LockFile does. | 78 // into load(), parse(), and _parse() like LockFile does. |
| 79 /// Parses the pubspec stored at [filePath] whose text is [contents]. If the | 79 /// Parses the pubspec stored at [filePath] whose text is [contents]. If the |
| (...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 226 } | 226 } |
| 227 | 227 |
| 228 var goodScheme = new RegExp(r'^https?:'); | 228 var goodScheme = new RegExp(r'^https?:'); |
| 229 if (!goodScheme.hasMatch(url)) { | 229 if (!goodScheme.hasMatch(url)) { |
| 230 throw new FormatException( | 230 throw new FormatException( |
| 231 'The "$field" field should be an "http:" or "https:" URL, but ' | 231 'The "$field" field should be an "http:" or "https:" URL, but ' |
| 232 'was "$url".'); | 232 'was "$url".'); |
| 233 } | 233 } |
| 234 } | 234 } |
| 235 | 235 |
| 236 List<PackageRef> _parseDependencies(String pubspecPath, SourceRegistry sources, | 236 List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources, |
| 237 yaml) { | 237 yaml) { |
| 238 var dependencies = <PackageRef>[]; | 238 var dependencies = <PackageDep>[]; |
| 239 | 239 |
| 240 // Allow an empty dependencies key. | 240 // Allow an empty dependencies key. |
| 241 if (yaml == null) return dependencies; | 241 if (yaml == null) return dependencies; |
| 242 | 242 |
| 243 if (yaml is! Map || yaml.keys.any((e) => e is! String)) { | 243 if (yaml is! Map || yaml.keys.any((e) => e is! String)) { |
| 244 throw new FormatException( | 244 throw new FormatException( |
| 245 'The pubspec dependencies should be a map of package names, but ' | 245 'The pubspec dependencies should be a map of package names, but ' |
| 246 'was ${yaml}.'); | 246 'was ${yaml}.'); |
| 247 } | 247 } |
| 248 | 248 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 276 source = sources[sourceName]; | 276 source = sources[sourceName]; |
| 277 description = spec[sourceName]; | 277 description = spec[sourceName]; |
| 278 } else { | 278 } else { |
| 279 throw new FormatException( | 279 throw new FormatException( |
| 280 'Dependency specification $spec should be a string or a mapping.'); | 280 'Dependency specification $spec should be a string or a mapping.'); |
| 281 } | 281 } |
| 282 | 282 |
| 283 description = source.parseDescription(pubspecPath, description, | 283 description = source.parseDescription(pubspecPath, description, |
| 284 fromLockFile: false); | 284 fromLockFile: false); |
| 285 | 285 |
| 286 dependencies.add(new PackageRef( | 286 dependencies.add(new PackageDep( |
| 287 name, source, versionConstraint, description)); | 287 name, source, versionConstraint, description)); |
| 288 }); | 288 }); |
| 289 | 289 |
| 290 return dependencies; | 290 return dependencies; |
| 291 } | 291 } |
| 292 | 292 |
| 293 /// The environment-related metadata in the pubspec. Corresponds to the data | 293 /// The environment-related metadata in the pubspec. Corresponds to the data |
| 294 /// under the "environment:" key in the pubspec. | 294 /// under the "environment:" key in the pubspec. |
| 295 class PubspecEnvironment { | 295 class PubspecEnvironment { |
| 296 /// The version constraint specifying which SDK versions this package works | 296 /// The version constraint specifying which SDK versions this package works |
| 297 /// with. | 297 /// with. |
| 298 final VersionConstraint sdkVersion; | 298 final VersionConstraint sdkVersion; |
| 299 | 299 |
| 300 PubspecEnvironment([VersionConstraint sdk]) | 300 PubspecEnvironment([VersionConstraint sdk]) |
| 301 : sdkVersion = sdk != null ? sdk : VersionConstraint.any; | 301 : sdkVersion = sdk != null ? sdk : VersionConstraint.any; |
| 302 } | 302 } |
| OLD | NEW |