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 source.pub_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 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
64 io.ProcessResult result; | 64 io.ProcessResult result; |
65 try { | 65 try { |
66 result = _runPubList(folder); | 66 result = _runPubList(folder); |
67 } on io.ProcessException catch (exception, stackTrace) { | 67 } on io.ProcessException catch (exception, stackTrace) { |
68 AnalysisEngine.instance.logger.logInformation( | 68 AnalysisEngine.instance.logger.logInformation( |
69 "Error running pub $PUB_LIST_COMMAND\n$exception\n$stackTrace"); | 69 "Error running pub $PUB_LIST_COMMAND\n$exception\n$stackTrace"); |
70 } | 70 } |
71 if (result == null || result.exitCode != 0) { | 71 if (result == null || result.exitCode != 0) { |
72 String exitCode = | 72 String exitCode = |
73 result != null ? 'exit code ${result.exitCode}' : 'null'; | 73 result != null ? 'exit code ${result.exitCode}' : 'null'; |
74 AnalysisEngine.instance.logger.logInformation( | 74 AnalysisEngine.instance.logger |
75 "pub $PUB_LIST_COMMAND failed: $exitCode"); | 75 .logInformation("pub $PUB_LIST_COMMAND failed: $exitCode"); |
76 return computePackageMapError(folder); | 76 return computePackageMapError(folder); |
77 } | 77 } |
78 try { | 78 try { |
79 PackageMapInfo packageMap = | 79 PackageMapInfo packageMap = |
80 parsePackageMap(JSON.decode(result.stdout), folder); | 80 parsePackageMap(JSON.decode(result.stdout), folder); |
81 return packageMap; | 81 return packageMap; |
82 } catch (exception, stackTrace) { | 82 } catch (exception, stackTrace) { |
83 AnalysisEngine.instance.logger.logError( | 83 AnalysisEngine.instance.logger.logError( |
84 "Malformed output from pub $PUB_LIST_COMMAND\n$exception\n$stackTrace"
); | 84 "Malformed output from pub $PUB_LIST_COMMAND\n$exception\n$stackTrace"
); |
85 } | 85 } |
86 | 86 |
87 return computePackageMapError(folder); | 87 return computePackageMapError(folder); |
88 } | 88 } |
89 | 89 |
90 /** | 90 /** |
91 * Create a PackageMapInfo object representing an error condition. | 91 * Create a PackageMapInfo object representing an error condition. |
92 */ | 92 */ |
93 PackageMapInfo computePackageMapError(Folder folder) { | 93 PackageMapInfo computePackageMapError(Folder folder) { |
94 // Even if an error occurs, we still need to know the dependencies, so that | 94 // Even if an error occurs, we still need to know the dependencies, so that |
95 // we'll know when to try running "pub list-package-dirs" again. | 95 // we'll know when to try running "pub list-package-dirs" again. |
96 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when | 96 // Unfortunately, "pub list-package-dirs" doesn't tell us dependencies when |
97 // an error occurs, so just assume there is one dependency, "pubspec.lock". | 97 // an error occurs, so just assume there is one dependency, "pubspec.lock". |
98 List<String> dependencies = <String>[ | 98 List<String> dependencies = <String>[ |
99 resourceProvider.pathContext.join(folder.path, PUBSPEC_LOCK_NAME)]; | 99 resourceProvider.pathContext.join(folder.path, PUBSPEC_LOCK_NAME) |
| 100 ]; |
100 return new PackageMapInfo(null, dependencies.toSet()); | 101 return new PackageMapInfo(null, dependencies.toSet()); |
101 } | 102 } |
102 | 103 |
103 /** | 104 /** |
104 * Decode the JSON output from pub into a package map. Paths in the | 105 * Decode the JSON output from pub into a package map. Paths in the |
105 * output are considered relative to [folder]. | 106 * output are considered relative to [folder]. |
106 */ | 107 */ |
107 PackageMapInfo parsePackageMap(Map obj, Folder folder) { | 108 PackageMapInfo parsePackageMap(Map obj, Folder folder) { |
108 // The output of pub looks like this: | 109 // The output of pub looks like this: |
109 // { | 110 // { |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
148 } | 149 } |
149 } | 150 } |
150 } | 151 } |
151 return new PackageMapInfo(packageMap, dependencies); | 152 return new PackageMapInfo(packageMap, dependencies); |
152 } | 153 } |
153 | 154 |
154 /** | 155 /** |
155 * Run pub list to determine the packages and input files. | 156 * Run pub list to determine the packages and input files. |
156 */ | 157 */ |
157 io.ProcessResult _runPubListDefault(Folder folder) { | 158 io.ProcessResult _runPubListDefault(Folder folder) { |
158 return io.Process.runSync( | 159 return io.Process.runSync(sdk.pubExecutable.getAbsolutePath(), [ |
159 sdk.pubExecutable.getAbsolutePath(), | 160 PUB_LIST_COMMAND |
160 [PUB_LIST_COMMAND], | 161 ], workingDirectory: folder.path); |
161 workingDirectory: folder.path); | |
162 } | 162 } |
163 } | 163 } |
OLD | NEW |