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

Unified Diff: sdk/lib/_internal/pub/lib/src/pubspec.dart

Issue 15347004: Gracefully handle pubspecs with dependencies using unknown sources. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Add tests for unknown sources in lockfiles. Created 7 years, 7 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
Index: sdk/lib/_internal/pub/lib/src/pubspec.dart
diff --git a/sdk/lib/_internal/pub/lib/src/pubspec.dart b/sdk/lib/_internal/pub/lib/src/pubspec.dart
index 69dc880ad27a2ebb081e3c2198eff6e428081c56..e01cab1583142c5776895616e536a151fba62243 100644
--- a/sdk/lib/_internal/pub/lib/src/pubspec.dart
+++ b/sdk/lib/_internal/pub/lib/src/pubspec.dart
@@ -214,11 +214,9 @@ class Pubspec {
}
}
-/**
- * Evaluates whether the given [url] for [field] is valid.
- *
- * Throws [FormatException] on an invalid url.
- */
+/// Evaluates whether the given [url] for [field] is valid.
+///
+/// Throws [FormatException] on an invalid url.
void _validateFieldUrl(url, String field) {
if (url is! String) {
throw new FormatException(
@@ -247,14 +245,16 @@ List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources,
}
yaml.forEach((name, spec) {
- var description, source;
+ var description;
+ var sourceName;
+
var versionConstraint = new VersionRange();
if (spec == null) {
description = name;
- source = sources.defaultSource;
+ sourceName = sources.defaultSource.name;
} else if (spec is String) {
description = name;
- source = sources.defaultSource;
+ sourceName = sources.defaultSource.name;
versionConstraint = new VersionConstraint.parse(spec);
} else if (spec is Map) {
if (spec.containsKey('version')) {
@@ -267,24 +267,27 @@ List<PackageDep> _parseDependencies(String pubspecPath, SourceRegistry sources,
'Dependency $name may only have one source: $sourceNames.');
}
- var sourceName = only(sourceNames);
+ sourceName = only(sourceNames);
if (sourceName is! String) {
throw new FormatException(
'Source name $sourceName should be a string.');
}
- source = sources[sourceName];
description = spec[sourceName];
} else {
throw new FormatException(
'Dependency specification $spec should be a string or a mapping.');
}
- description = source.parseDescription(pubspecPath, description,
- fromLockFile: false);
+ // If we have a valid source, use it to process the description. Allow
+ // unknown sources so pub doesn't choke on old pubspecs.
+ if (sources.contains(sourceName)) {
+ description = sources[sourceName].parseDescription(
+ pubspecPath, description, fromLockFile: false);
+ }
dependencies.add(new PackageDep(
- name, source, versionConstraint, description));
+ name, sourceName, versionConstraint, description));
});
return dependencies;
« no previous file with comments | « sdk/lib/_internal/pub/lib/src/path_source.dart ('k') | sdk/lib/_internal/pub/lib/src/solver/backtracking_solver.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698