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 hosted_source; | 5 library hosted_source; |
6 | 6 |
7 import 'dart:io' as io; | 7 import 'dart:io' as io; |
8 import 'dart:json'; | 8 import 'dart:json'; |
9 import 'dart:uri'; | 9 import 'dart:uri'; |
10 | 10 |
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
119 bool descriptionsEqual(description1, description2) => | 119 bool descriptionsEqual(description1, description2) => |
120 _parseDescription(description1) == _parseDescription(description2); | 120 _parseDescription(description1) == _parseDescription(description2); |
121 | 121 |
122 /** | 122 /** |
123 * Ensures that [description] is a valid hosted package description. | 123 * Ensures that [description] is a valid hosted package description. |
124 * | 124 * |
125 * There are two valid formats. A plain string refers to a package with the | 125 * There are two valid formats. A plain string refers to a package with the |
126 * given name from the default host, while a map with keys "name" and "url" | 126 * given name from the default host, while a map with keys "name" and "url" |
127 * refers to a package with the given name from the host at the given URL. | 127 * refers to a package with the given name from the host at the given URL. |
128 */ | 128 */ |
129 void validateDescription(description, [bool fromLockFile=false]) { | 129 void validateDescription(description, {bool fromLockFile: false}) { |
130 _parseDescription(description); | 130 _parseDescription(description); |
131 } | 131 } |
132 | 132 |
133 /** | 133 /** |
134 * Parses the description for a package. | 134 * Parses the description for a package. |
135 * | 135 * |
136 * If the package parses correctly, this returns a (name, url) pair. If not, | 136 * If the package parses correctly, this returns a (name, url) pair. If not, |
137 * this throws a descriptive FormatException. | 137 * this throws a descriptive FormatException. |
138 */ | 138 */ |
139 Pair<String, String> _parseDescription(description) { | 139 Pair<String, String> _parseDescription(description) { |
(...skipping 13 matching lines...) Expand all Loading... |
153 | 153 |
154 var name = description["name"]; | 154 var name = description["name"]; |
155 if (name is! String) { | 155 if (name is! String) { |
156 throw new FormatException("The 'name' key must have a string value."); | 156 throw new FormatException("The 'name' key must have a string value."); |
157 } | 157 } |
158 | 158 |
159 var url = description.containsKey("url") ? description["url"] : defaultUrl; | 159 var url = description.containsKey("url") ? description["url"] : defaultUrl; |
160 return new Pair<String, String>(name, url); | 160 return new Pair<String, String>(name, url); |
161 } | 161 } |
162 } | 162 } |
OLD | NEW |