Chromium Code Reviews| Index: utils/pub/source.dart |
| diff --git a/utils/pub/source.dart b/utils/pub/source.dart |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..7c2248461cd56aae4eeafd2386c3ab0c067bb720 |
| --- /dev/null |
| +++ b/utils/pub/source.dart |
| @@ -0,0 +1,71 @@ |
| +// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| +// for details. All rights reserved. Use of this source code is governed by a |
| +// BSD-style license that can be found in the LICENSE file. |
| + |
| +/** |
| + * A source from which to install packages. |
| + * |
| + * Each source has many packages that it looks up using [PackageId]s. The source |
| + * is responsible for installing these packages to the package cache. |
| + */ |
| +class Source { |
| + /** |
| + * The default [Source] from which to fetch packages if no other [Source] is |
| + * specified. |
| + */ |
| + static Source defaultSource; |
| + |
| + /** |
| + * Looks up a source based on its name. |
| + */ |
| + static Source fromName(String name) { |
| + // TODO(nweiz): add a more principled way of registering sources here once |
| + // we have more than one source. Especially important for plugins. |
| + if (name == 'sdk') return defaultSource; |
| + throw 'Unknown source "$name"'; |
| + } |
| + |
| + /** |
| + * The name of the source. Should be lower-case, suitable for use in a |
| + * filename, and unique accross all sources. |
| + */ |
| + abstract String get name(); |
| + |
| + /** |
| + * Whether this source's packages should be cached in Pub's global cache |
| + * directory. |
| + * |
| + * A source should be cached if it requires network access to retrieve |
| + * packages. It doesn't need to be cached if all packages are available |
| + * locally. |
| + */ |
| + abstract bool get shouldCache(); |
| + |
| + /** |
| + * Installs the package identified by [id] to [path]. Returns a [Future] that |
| + * completes when the installation was finished. The [Future] should resolve |
| + * to true if the package was found in the source and false if it wasn't. For |
| + * all other error conditions, it should complete with an exception. |
| + * |
| + * If [shouldCache] is true, [path] will be a path to this source's |
| + * subdirectory of the [PackageCache]'s cache directory. If [shouldCache] is |
| + * 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.
|
| + * |
| + * [path] is guaranteed not to exist, and its parent directory is guaranteed |
| + * to exist. |
| + */ |
| + abstract Future<bool> install(PackageId id, String path); |
| + |
| + /** |
| + * Returns the name of the package identified by [id]. By default, this is |
| + * just `id.name`, but some sources (e.g. Git) may have more complicated |
| + * resolution logic. |
| + * |
| + * This method should be light-weight. It doesn't need to validate that the |
| + * given package exists. |
| + * |
| + * The package name should be lower-case and suitable for use in a filename. |
| + * It may contain forward slashes. |
| + */ |
| + String packageName(PackageId id) => id.name; |
| +} |