| Index: sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
|
| diff --git a/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart b/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
|
| index 99b3919556d7d4a30415c24eaa59a2063c2f5447..e58280af1bf3b3112ee1e978e9821481ee78bc80 100644
|
| --- a/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
|
| +++ b/sdk/lib/_internal/pub/lib/src/barback/build_environment.dart
|
| @@ -162,6 +162,61 @@ class BuildEnvironment {
|
| });
|
| }
|
|
|
| + /// Return all URLs serving [assetPath] in this environment.
|
| + List<Uri> getUrlsForAssetPath(String assetPath) {
|
| + // Check the three (mutually-exclusive) places the path could be pointing.
|
| + var urls = _lookUpPathInServerRoot(assetPath);
|
| + if (urls.isEmpty) urls = _lookUpPathInPackagesDirectory(assetPath);
|
| + if (urls.isEmpty) urls = _lookUpPathInDependency(assetPath);
|
| + return urls.toList();
|
| + }
|
| +
|
| + /// Look up [assetPath] in the root directories of servers running in the
|
| + /// entrypoint package.
|
| + Iterable<Uri> _lookUpPathInServerRoot(String assetPath) {
|
| + // Find all of the servers whose root directories contain the asset and
|
| + // generate appropriate URLs for each.
|
| + return servers
|
| + .where((server) => path.isWithin(server.rootDirectory, assetPath))
|
| + .map((server) {
|
| + var relativePath = path.relative(assetPath, from: server.rootDirectory);
|
| + return server.url.resolveUri(path.toUri(relativePath));
|
| + });
|
| + }
|
| +
|
| + /// Look up [assetPath] in the "packages" directory in the entrypoint package.
|
| + Iterable<Uri> _lookUpPathInPackagesDirectory(String assetPath) {
|
| + var components = path.split(path.relative(assetPath));
|
| + if (components.first != "packages") return [];
|
| + if (!graph.packages.containsKey(components[1])) return [];
|
| + return servers.map((server) =>
|
| + server.url.resolveUri(path.toUri(assetPath)));
|
| + }
|
| +
|
| + /// Look up [assetPath] in the "lib" or "asset" directory of a dependency
|
| + /// package.
|
| + Iterable<Uri> _lookUpPathInDependency(String assetPath) {
|
| + for (var package in graph.packages.values) {
|
| + var libDir = path.join(package.dir, 'lib');
|
| + var assetDir = path.join(package.dir, 'asset');
|
| +
|
| + var uri;
|
| + if (path.isWithin(libDir, assetPath)) {
|
| + uri = path.toUri(path.join('packages', package.name,
|
| + path.relative(assetPath, from: libDir)));
|
| + } else if (path.isWithin(assetDir, assetPath)) {
|
| + uri = path.toUri(path.join('assets', package.name,
|
| + path.relative(assetPath, from: assetDir)));
|
| + } else {
|
| + continue;
|
| + }
|
| +
|
| + return servers.map((server) => server.url.resolveUri(uri));
|
| + }
|
| +
|
| + return [];
|
| + }
|
| +
|
| /// Determines if [sourcePath] is contained within any of the directories
|
| /// that are visible to this build environment.
|
| bool containsPath(String sourcePath) {
|
|
|