Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(586)

Unified Diff: utils/pub/pubspec.dart

Issue 12171002: Tweak SDK constraint checking a bit. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Clean up Package and Pubspec a bit. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/package.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/pubspec.dart
diff --git a/utils/pub/pubspec.dart b/utils/pub/pubspec.dart
index 492acd36c991eb2bf674670d54f7047ebdc7290c..f7c3579325c313111ec14cc705f20c18d7c7dd63 100644
--- a/utils/pub/pubspec.dart
+++ b/utils/pub/pubspec.dart
@@ -5,7 +5,9 @@
library pubspec;
import '../../pkg/yaml/lib/yaml.dart';
+import '../../pkg/path/lib/path.dart' as path;
+import 'io.dart';
import 'package.dart';
import 'source.dart';
import 'source_registry.dart';
@@ -30,6 +32,28 @@ class Pubspec {
/// are derived.
final Map<String, Object> fields;
+ /// Loads the pubspec for a package [name] located in [packageDir].
+ factory Pubspec.load(String name, String packageDir, SourceRegistry sources) {
+ var pubspecPath = path.join(packageDir, 'pubspec.yaml');
+ if (!fileExists(pubspecPath)) throw new PubspecNotFoundException(name);
+
+ try {
+ var pubspec = new Pubspec.parse(readTextFile(pubspecPath), sources);
+
+ if (pubspec.name == null) {
+ throw new PubspecHasNoNameException(name);
+ }
+
+ if (name != null && pubspec.name != name) {
+ throw new PubspecNameMismatchException(name, pubspec.name);
+ }
+
+ return pubspec;
+ } on FormatException catch (ex) {
+ throw 'Could not parse $pubspecPath:\n${ex.message}';
+ }
+ }
+
Pubspec(this.name, this.version, this.dependencies, this.environment,
[Map<String, Object> fields])
: this.fields = fields == null ? {} : fields;
« no previous file with comments | « utils/pub/package.dart ('k') | utils/pub/sdk_source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698