Files
sdk/utils/pub/source.dart
T
nweiz@google.com 3085912d01 Add support for pub install.
This CL does several things:

* Adds explicit infrastructure for package sources.
* Adds the Dart SDK as such a source.
* Adds an explicit class for managing the packages/ directory (AppCache, as
  opposed to SystemCache).
* Adds an "install" command that installs to packages/, backed up by the system
  cache.

Review URL: https://chromiumcodereview.appspot.com//10340005

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge/dart@7398 260f80e4-7a28-3924-810f-c04153c831b5
2012-05-07 19:58:32 +00:00

72 lines
2.5 KiB
Dart

// 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 application's "packages" directory.
*
* [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.fullName`, 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.fullName;
}