Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(701)

Unified Diff: utils/pub/source.dart

Issue 10340005: Add support for pub install. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Code review changes Created 8 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « utils/pub/sdk_source.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/source.dart
diff --git a/utils/pub/source.dart b/utils/pub/source.dart
new file mode 100644
index 0000000000000000000000000000000000000000..3e4eb087c0be0f89a957844e13fef924311c8778
--- /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 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;
+}
« no previous file with comments | « utils/pub/sdk_source.dart ('k') | utils/pub/system_cache.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698