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

Side by Side Diff: pkg/analyzer/lib/source/pub_package_map_provider.dart

Issue 599133002: Move PubPackageMapProvider to its own file. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 2 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a 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. 3 // BSD-style license that can be found in the LICENSE file.
4 4
5 library source.package_map_provider; 5 library source.pub_package_map_provider;
6 6
7 import 'dart:collection'; 7 import 'dart:collection';
8 import 'dart:convert'; 8 import 'dart:convert';
9 import 'dart:io' as io; 9 import 'dart:io' as io;
10 10
11 import 'package:analyzer/file_system/file_system.dart'; 11 import 'package:analyzer/file_system/file_system.dart';
12 import 'package:analyzer/source/package_map_provider.dart';
12 import 'package:analyzer/src/generated/engine.dart'; 13 import 'package:analyzer/src/generated/engine.dart';
13 import 'package:analyzer/src/generated/sdk_io.dart'; 14 import 'package:analyzer/src/generated/sdk_io.dart';
14 import 'package:path/path.dart'; 15 import 'package:path/path.dart';
15 16
16 /** 17 /**
17 * Data structure output by PackageMapProvider. This contains both the package
18 * map and dependency information.
19 */
20 class PackageMapInfo {
21 /**
22 * The package map itself. This is a map from package name to a list of
23 * the folders containing source code for the package.
24 *
25 * `null` if an error occurred.
26 */
27 Map<String, List<Folder>> packageMap;
28
29 /**
30 * Dependency information. This is a set of the paths which were consulted
31 * in order to generate the package map. If any of these files is
32 * modified, the package map will need to be regenerated.
33 */
34 Set<String> dependencies;
35
36 PackageMapInfo(this.packageMap, this.dependencies);
37 }
38
39 /**
40 * A PackageMapProvider is an entity capable of determining the mapping from
41 * package name to source directory for a given folder.
42 */
43 abstract class PackageMapProvider {
44 /**
45 * Compute a package map for the given folder, if possible.
46 *
47 * If a package map can't be computed (e.g. because an error occurred), a
48 * [PackageMapInfo] will still be returned, but its packageMap will be null.
49 */
50 PackageMapInfo computePackageMap(Folder folder);
51 }
52
53 /**
54 * Implementation of PackageMapProvider that operates by executing pub. 18 * Implementation of PackageMapProvider that operates by executing pub.
55 */ 19 */
56 class PubPackageMapProvider implements PackageMapProvider { 20 class PubPackageMapProvider implements PackageMapProvider {
57 static const String PUB_LIST_COMMAND = 'list-package-dirs'; 21 static const String PUB_LIST_COMMAND = 'list-package-dirs';
58 22
59 /** 23 /**
60 * The name of the 'pubspec.lock' file, which we assume is the dependency 24 * The name of the 'pubspec.lock' file, which we assume is the dependency
61 * in the event that [PUB_LIST_COMMAND] fails. 25 * in the event that [PUB_LIST_COMMAND] fails.
62 */ 26 */
63 static const String PUBSPEC_LOCK_NAME = 'pubspec.lock'; 27 static const String PUBSPEC_LOCK_NAME = 'pubspec.lock';
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
161 */ 125 */
162 PackageMapInfo _error(Folder folder) { 126 PackageMapInfo _error(Folder folder) {
163 // Even if an error occurs, we still need to know the dependencies, so that 127 // Even if an error occurs, we still need to know the dependencies, so that
164 // we'll know when to try running "pub list-package-dirs" again. 128 // we'll know when to try running "pub list-package-dirs" again.
165 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when 129 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when
166 // an error occurs, so just assume there is one dependency, "pubspec.lock". 130 // an error occurs, so just assume there is one dependency, "pubspec.lock".
167 List<String> dependencies = <String>[join(folder.path, PUBSPEC_LOCK_NAME)]; 131 List<String> dependencies = <String>[join(folder.path, PUBSPEC_LOCK_NAME)];
168 return new PackageMapInfo(null, dependencies.toSet()); 132 return new PackageMapInfo(null, dependencies.toSet());
169 } 133 }
170 } 134 }
OLDNEW
« no previous file with comments | « pkg/analyzer/lib/source/package_map_provider.dart ('k') | pkg/analyzer/lib/src/analyzer_impl.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698