| OLD | NEW |
| 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 package.map.provider; | 5 library 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:analysis_server/src/analysis_server.dart'; | |
| 12 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 13 import 'package:analyzer/src/generated/engine.dart'; | 12 import 'package:analyzer/src/generated/engine.dart'; |
| 13 import 'package:analyzer/src/generated/sdk_io.dart'; |
| 14 import 'package:path/path.dart'; | 14 import 'package:path/path.dart'; |
| 15 | 15 |
| 16 /** | 16 /** |
| 17 * Data structure output by PackageMapProvider. This contains both the package | 17 * Data structure output by PackageMapProvider. This contains both the package |
| 18 * map and dependency information. | 18 * map and dependency information. |
| 19 */ | 19 */ |
| 20 class PackageMapInfo { | 20 class PackageMapInfo { |
| 21 /** | 21 /** |
| 22 * The package map itself. This is a map from package name to a list of | 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. | 23 * the folders containing source code for the package. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 61 * in the event that [PUB_LIST_COMMAND] fails. | 61 * in the event that [PUB_LIST_COMMAND] fails. |
| 62 */ | 62 */ |
| 63 static const String PUBSPEC_LOCK_NAME = 'pubspec.lock'; | 63 static const String PUBSPEC_LOCK_NAME = 'pubspec.lock'; |
| 64 | 64 |
| 65 /** | 65 /** |
| 66 * [ResourceProvider] that is used to create the [Folder]s that populate the | 66 * [ResourceProvider] that is used to create the [Folder]s that populate the |
| 67 * package map. | 67 * package map. |
| 68 */ | 68 */ |
| 69 final ResourceProvider resourceProvider; | 69 final ResourceProvider resourceProvider; |
| 70 | 70 |
| 71 PubPackageMapProvider(this.resourceProvider); | 71 /** |
| 72 * Sdk that we use to find the pub executable. |
| 73 */ |
| 74 final DirectoryBasedDartSdk sdk; |
| 75 |
| 76 PubPackageMapProvider(this.resourceProvider, this.sdk); |
| 72 | 77 |
| 73 @override | 78 @override |
| 74 PackageMapInfo computePackageMap(Folder folder) { | 79 PackageMapInfo computePackageMap(Folder folder) { |
| 75 // TODO(paulberry) make this asynchronous so that we can (a) do other | 80 // TODO(paulberry) make this asynchronous so that we can (a) do other |
| 76 // analysis while it's in progress, and (b) time out if it takes too long | 81 // analysis while it's in progress, and (b) time out if it takes too long |
| 77 // to respond. | 82 // to respond. |
| 78 String executable = SHARED_SDK.pubExecutable.getAbsolutePath(); | 83 String executable = sdk.pubExecutable.getAbsolutePath(); |
| 79 io.ProcessResult result; | 84 io.ProcessResult result; |
| 80 try { | 85 try { |
| 81 result = io.Process.runSync( | 86 result = io.Process.runSync( |
| 82 executable, [PUB_LIST_COMMAND], workingDirectory: folder.path); | 87 executable, [PUB_LIST_COMMAND], workingDirectory: folder.path); |
| 83 } on io.ProcessException catch (exception, stackTrace) { | 88 } on io.ProcessException catch (exception, stackTrace) { |
| 84 AnalysisEngine.instance.logger.logInformation( | 89 AnalysisEngine.instance.logger.logInformation( |
| 85 "Error running pub $PUB_LIST_COMMAND\n${exception}\n${stackTrace}"); | 90 "Error running pub $PUB_LIST_COMMAND\n${exception}\n${stackTrace}"); |
| 86 } | 91 } |
| 87 if (result.exitCode != 0) { | 92 if (result.exitCode != 0) { |
| 88 AnalysisEngine.instance.logger.logInformation( | 93 AnalysisEngine.instance.logger.logInformation( |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 156 */ | 161 */ |
| 157 PackageMapInfo _error(Folder folder) { | 162 PackageMapInfo _error(Folder folder) { |
| 158 // Even if an error occurs, we still need to know the dependencies, so that | 163 // Even if an error occurs, we still need to know the dependencies, so that |
| 159 // we'll know when to try running "pub list-package-dirs" again. | 164 // we'll know when to try running "pub list-package-dirs" again. |
| 160 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when | 165 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when |
| 161 // an error occurs, so just assume there is one dependency, "pubspec.lock". | 166 // an error occurs, so just assume there is one dependency, "pubspec.lock". |
| 162 List<String> dependencies = <String>[join(folder.path, PUBSPEC_LOCK_NAME)]; | 167 List<String> dependencies = <String>[join(folder.path, PUBSPEC_LOCK_NAME)]; |
| 163 return new PackageMapInfo(null, dependencies.toSet()); | 168 return new PackageMapInfo(null, dependencies.toSet()); |
| 164 } | 169 } |
| 165 } | 170 } |
| OLD | NEW |