| 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 /** | 5 /** |
| 6 * A source from which to install packages. | 6 * A source from which to install packages. |
| 7 * | 7 * |
| 8 * Each source has many packages that it looks up using [PackageId]s. The source | 8 * Each source has many packages that it looks up using [PackageId]s. The source |
| 9 * is responsible for installing these packages to the package cache. | 9 * is responsible for installing these packages to the package cache. |
| 10 */ | 10 */ |
| 11 class Source { | 11 class Source { |
| 12 /** | 12 /** |
| 13 * The default [Source] from which to fetch packages if no other [Source] is | |
| 14 * specified. | |
| 15 */ | |
| 16 static Source defaultSource; | |
| 17 | |
| 18 /** | |
| 19 * Looks up a source based on its name. | |
| 20 */ | |
| 21 static Source fromName(String name) { | |
| 22 // TODO(nweiz): add a more principled way of registering sources here once | |
| 23 // we have more than one source. Especially important for plugins. | |
| 24 if (name == 'sdk') return defaultSource; | |
| 25 throw 'Unknown source "$name"'; | |
| 26 } | |
| 27 | |
| 28 /** | |
| 29 * The name of the source. Should be lower-case, suitable for use in a | 13 * The name of the source. Should be lower-case, suitable for use in a |
| 30 * filename, and unique accross all sources. | 14 * filename, and unique accross all sources. |
| 31 */ | 15 */ |
| 32 abstract String get name(); | 16 abstract String get name(); |
| 33 | 17 |
| 34 /** | 18 /** |
| 35 * Whether this source's packages should be cached in Pub's global cache | 19 * Whether this source's packages should be cached in Pub's global cache |
| 36 * directory. | 20 * directory. |
| 37 * | 21 * |
| 38 * A source should be cached if it requires network access to retrieve | 22 * A source should be cached if it requires network access to retrieve |
| (...skipping 23 matching lines...) Expand all Loading... |
| 62 * resolution logic. | 46 * resolution logic. |
| 63 * | 47 * |
| 64 * This method should be light-weight. It doesn't need to validate that the | 48 * This method should be light-weight. It doesn't need to validate that the |
| 65 * given package exists. | 49 * given package exists. |
| 66 * | 50 * |
| 67 * The package name should be lower-case and suitable for use in a filename. | 51 * The package name should be lower-case and suitable for use in a filename. |
| 68 * It may contain forward slashes. | 52 * It may contain forward slashes. |
| 69 */ | 53 */ |
| 70 String packageName(PackageId id) => id.fullName; | 54 String packageName(PackageId id) => id.fullName; |
| 71 } | 55 } |
| OLD | NEW |