Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 /** | |
| 6 * A source from which to install packages. | |
| 7 * | |
| 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. | |
| 10 */ | |
| 11 class Source { | |
| 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 | |
| 30 * filename, and unique accross all sources. | |
| 31 */ | |
| 32 abstract String get name(); | |
| 33 | |
| 34 /** | |
| 35 * Whether this source's packages should be cached in Pub's global cache | |
| 36 * directory. | |
| 37 * | |
| 38 * A source should be cached if it requires network access to retrieve | |
| 39 * packages. It doesn't need to be cached if all packages are available | |
| 40 * locally. | |
| 41 */ | |
| 42 abstract bool get shouldCache(); | |
| 43 | |
| 44 /** | |
| 45 * Installs the package identified by [id] to [path]. Returns a [Future] that | |
| 46 * completes when the installation was finished. The [Future] should resolve | |
| 47 * to true if the package was found in the source and false if it wasn't. For | |
| 48 * all other error conditions, it should complete with an exception. | |
| 49 * | |
| 50 * If [shouldCache] is true, [path] will be a path to this source's | |
| 51 * subdirectory of the [PackageCache]'s cache directory. If [shouldCache] is | |
| 52 * false, [path] will be a path to the package directory. | |
|
Bob Nystrom
2012/05/03 00:15:49
"package directory" -> 'application's "packages" d
nweiz
2012/05/04 01:03:43
Done.
| |
| 53 * | |
| 54 * [path] is guaranteed not to exist, and its parent directory is guaranteed | |
| 55 * to exist. | |
| 56 */ | |
| 57 abstract Future<bool> install(PackageId id, String path); | |
| 58 | |
| 59 /** | |
| 60 * Returns the name of the package identified by [id]. By default, this is | |
| 61 * just `id.name`, but some sources (e.g. Git) may have more complicated | |
| 62 * resolution logic. | |
| 63 * | |
| 64 * This method should be light-weight. It doesn't need to validate that the | |
| 65 * given package exists. | |
| 66 * | |
| 67 * The package name should be lower-case and suitable for use in a filename. | |
| 68 * It may contain forward slashes. | |
| 69 */ | |
| 70 String packageName(PackageId id) => id.name; | |
| 71 } | |
| OLD | NEW |