| OLD | NEW |
| 1 // Copyright (c) 2015, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2015, 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 analyzer_cli.src.driver; | 5 library analyzer_cli.src.driver; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:convert'; | 8 import 'dart:convert'; |
| 9 import 'dart:io'; | 9 import 'dart:io'; |
| 10 | 10 |
| (...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 266 /*Map<String, Uri> map = */pkgfile.parse(bytes, fileUri); | 266 /*Map<String, Uri> map = */pkgfile.parse(bytes, fileUri); |
| 267 // TODO(pquitslund): plug into new resolver once implemented | 267 // TODO(pquitslund): plug into new resolver once implemented |
| 268 // https://github.com/dart-lang/sdk/issues/23615 | 268 // https://github.com/dart-lang/sdk/issues/23615 |
| 269 } catch (e) { | 269 } catch (e) { |
| 270 printAndFail( | 270 printAndFail( |
| 271 'Unable to read package config data from $packageConfigPath: $e'); | 271 'Unable to read package config data from $packageConfigPath: $e'); |
| 272 } | 272 } |
| 273 printAndFail( | 273 printAndFail( |
| 274 'Package config files are not supported yet. For status see: https://g
ithub.com/dart-lang/sdk/issues/23373'); | 274 'Package config files are not supported yet. For status see: https://g
ithub.com/dart-lang/sdk/issues/23373'); |
| 275 } else if (options.packageRootPath != null) { | 275 } else if (options.packageRootPath != null) { |
| 276 Map<String, List<fileSystem.Folder>> packageMap = |
| 277 _PackageRootPackageMapBuilder.buildPackageMap( |
| 278 options.packageRootPath); |
| 279 if (packageMap != null) { |
| 280 resolvers.add(new SdkExtUriResolver(packageMap)); |
| 281 } |
| 276 JavaFile packageDirectory = new JavaFile(options.packageRootPath); | 282 JavaFile packageDirectory = new JavaFile(options.packageRootPath); |
| 277 resolvers.add(new PackageUriResolver([packageDirectory])); | 283 resolvers.add(new PackageUriResolver([packageDirectory])); |
| 278 } else { | 284 } else { |
| 279 PubPackageMapProvider pubPackageMapProvider = | 285 PubPackageMapProvider pubPackageMapProvider = |
| 280 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); | 286 new PubPackageMapProvider(PhysicalResourceProvider.INSTANCE, sdk); |
| 281 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( | 287 PackageMapInfo packageMapInfo = pubPackageMapProvider.computePackageMap( |
| 282 PhysicalResourceProvider.INSTANCE.getResource('.')); | 288 PhysicalResourceProvider.INSTANCE.getResource('.')); |
| 283 Map<String, List<fileSystem.Folder>> packageMap = | 289 Map<String, List<fileSystem.Folder>> packageMap = |
| 284 packageMapInfo.packageMap; | 290 packageMapInfo.packageMap; |
| 285 if (packageMap != null) { | 291 if (packageMap != null) { |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 429 } | 435 } |
| 430 return true; | 436 return true; |
| 431 } | 437 } |
| 432 | 438 |
| 433 /// Convert [sourcePath] into an absolute path. | 439 /// Convert [sourcePath] into an absolute path. |
| 434 static String _normalizeSourcePath(String sourcePath) { | 440 static String _normalizeSourcePath(String sourcePath) { |
| 435 return path.normalize(new File(sourcePath).absolute.path); | 441 return path.normalize(new File(sourcePath).absolute.path); |
| 436 } | 442 } |
| 437 } | 443 } |
| 438 | 444 |
| 445 /// [SdkExtUriResolver] needs a Map from package name to folder. In the case |
| 446 /// that the analyzer is invoked with a --package-root option, we need to |
| 447 /// manually create this mapping. Given [packageRootPath], |
| 448 /// [_PackageRootPackageMapBuilder] creates a simple mapping from package name |
| 449 /// to full path on disk (resolving any symbolic links). |
| 450 class _PackageRootPackageMapBuilder { |
| 451 static Map<String, List<fileSystem.Folder>> buildPackageMap( |
| 452 String packageRootPath) { |
| 453 var packageRoot = new Directory(packageRootPath); |
| 454 var packages = packageRoot.listSync(followLinks: false); |
| 455 var result = new Map<String, List<fileSystem.Folder>>(); |
| 456 for (var package in packages) { |
| 457 var packageName = path.basename(package.path); |
| 458 var realPath = package.resolveSymbolicLinksSync(); |
| 459 result[packageName] = [ |
| 460 PhysicalResourceProvider.INSTANCE.getFolder(realPath) |
| 461 ]; |
| 462 } |
| 463 return result; |
| 464 } |
| 465 } |
| 466 |
| 439 /// Provides a framework to read command line options from stdin and feed them | 467 /// Provides a framework to read command line options from stdin and feed them |
| 440 /// to a callback. | 468 /// to a callback. |
| 441 class _BatchRunner { | 469 class _BatchRunner { |
| 442 /// Run the tool in 'batch' mode, receiving command lines through stdin and | 470 /// Run the tool in 'batch' mode, receiving command lines through stdin and |
| 443 /// returning pass/fail status through stdout. This feature is intended for | 471 /// returning pass/fail status through stdout. This feature is intended for |
| 444 /// use in unit testing. | 472 /// use in unit testing. |
| 445 static void runAsBatch(List<String> sharedArgs, _BatchRunnerHandler handler) { | 473 static void runAsBatch(List<String> sharedArgs, _BatchRunnerHandler handler) { |
| 446 outSink.writeln('>>> BATCH START'); | 474 outSink.writeln('>>> BATCH START'); |
| 447 Stopwatch stopwatch = new Stopwatch(); | 475 Stopwatch stopwatch = new Stopwatch(); |
| 448 stopwatch.start(); | 476 stopwatch.start(); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms'); | 514 '>>> TEST $resultPassString ${stopwatch.elapsedMilliseconds}ms'); |
| 487 } catch (e, stackTrace) { | 515 } catch (e, stackTrace) { |
| 488 errorSink.writeln(e); | 516 errorSink.writeln(e); |
| 489 errorSink.writeln(stackTrace); | 517 errorSink.writeln(stackTrace); |
| 490 errorSink.writeln('>>> EOF STDERR'); | 518 errorSink.writeln('>>> EOF STDERR'); |
| 491 outSink.writeln('>>> TEST CRASH'); | 519 outSink.writeln('>>> TEST CRASH'); |
| 492 } | 520 } |
| 493 }); | 521 }); |
| 494 } | 522 } |
| 495 } | 523 } |
| OLD | NEW |