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 '../../pkg/yaml/lib/yaml.dart'; |
| 8 |
7 import 'package.dart'; | 9 import 'package.dart'; |
8 import 'source.dart'; | 10 import 'source.dart'; |
9 import 'source_registry.dart'; | 11 import 'source_registry.dart'; |
10 import 'utils.dart'; | 12 import 'utils.dart'; |
11 import 'version.dart'; | 13 import 'version.dart'; |
12 import '../../pkg/yaml/lib/yaml.dart'; | |
13 | 14 |
14 /// The parsed and validated contents of a pubspec file. | 15 /// The parsed and validated contents of a pubspec file. |
15 class Pubspec { | 16 class Pubspec { |
16 /// This package's name. | 17 /// This package's name. |
17 final String name; | 18 final String name; |
18 | 19 |
19 /// This package's version. | 20 /// This package's version. |
20 final Version version; | 21 final Version version; |
21 | 22 |
22 /// The packages this package depends on. | 23 /// The packages this package depends on. |
(...skipping 14 matching lines...) Expand all Loading... |
37 : name = null, | 38 : name = null, |
38 version = Version.none, | 39 version = Version.none, |
39 dependencies = <PackageRef>[], | 40 dependencies = <PackageRef>[], |
40 environment = new PubspecEnvironment(), | 41 environment = new PubspecEnvironment(), |
41 fields = {}; | 42 fields = {}; |
42 | 43 |
43 /// Whether or not the pubspec has no contents. | 44 /// Whether or not the pubspec has no contents. |
44 bool get isEmpty => | 45 bool get isEmpty => |
45 name == null && version == Version.none && dependencies.isEmpty; | 46 name == null && version == Version.none && dependencies.isEmpty; |
46 | 47 |
| 48 // TODO(rnystrom): Make this a static method to match corelib. |
47 /// Parses the pubspec whose text is [contents]. If the pubspec doesn't define | 49 /// Parses the pubspec whose text is [contents]. If the pubspec doesn't define |
48 /// version for itself, it defaults to [Version.none]. | 50 /// version for itself, it defaults to [Version.none]. |
49 factory Pubspec.parse(String contents, SourceRegistry sources) { | 51 factory Pubspec.parse(String contents, SourceRegistry sources) { |
50 var name = null; | 52 var name = null; |
51 var version = Version.none; | 53 var version = Version.none; |
52 | 54 |
53 if (contents.trim() == '') return new Pubspec.empty(); | 55 if (contents.trim() == '') return new Pubspec.empty(); |
54 | 56 |
55 var parsedPubspec = loadYaml(contents); | 57 var parsedPubspec = loadYaml(contents); |
56 if (parsedPubspec == null) return new Pubspec.empty(); | 58 if (parsedPubspec == null) return new Pubspec.empty(); |
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 /// The environment-related metadata in the pubspec. Corresponds to the data | 211 /// The environment-related metadata in the pubspec. Corresponds to the data |
210 /// under the "environment:" key in the pubspec. | 212 /// under the "environment:" key in the pubspec. |
211 class PubspecEnvironment { | 213 class PubspecEnvironment { |
212 /// The version constraint specifying which SDK versions this package works | 214 /// The version constraint specifying which SDK versions this package works |
213 /// with. | 215 /// with. |
214 final VersionConstraint sdkVersion; | 216 final VersionConstraint sdkVersion; |
215 | 217 |
216 PubspecEnvironment([VersionConstraint sdk]) | 218 PubspecEnvironment([VersionConstraint sdk]) |
217 : sdkVersion = sdk != null ? sdk : VersionConstraint.any; | 219 : sdkVersion = sdk != null ? sdk : VersionConstraint.any; |
218 } | 220 } |
OLD | NEW |