| 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 engine.sdk.io; | 5 @deprecated |
| 6 | 6 library analyzer.src.generated.sdk_io; |
| 7 |
| 8 import 'dart:collection'; |
| 7 import 'dart:io'; | 9 import 'dart:io'; |
| 8 | 10 |
| 9 import 'package:analyzer/src/context/context.dart' as newContext; | 11 import 'package:analyzer/dart/ast/ast.dart'; |
| 10 import 'package:analyzer/src/generated/java_engine.dart'; | 12 import 'package:analyzer/exception/exception.dart'; |
| 11 | 13 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'ast.dart'; | 14 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 13 import 'engine.dart'; | 15 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 14 import 'error.dart'; | 16 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'java_core.dart'; | 17 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'java_engine_io.dart'; | 18 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 17 import 'java_io.dart'; | 19 import 'package:analyzer/src/generated/java_io.dart'; |
| 18 import 'parser.dart'; | 20 import 'package:analyzer/src/generated/parser.dart'; |
| 19 import 'scanner.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 20 import 'sdk.dart'; | 22 import 'package:analyzer/src/generated/source_io.dart'; |
| 21 import 'source_io.dart'; | 23 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; |
| 24 import 'package:analyzer/src/summary/summary_sdk.dart'; |
| 25 import 'package:path/path.dart' as pathos; |
| 26 |
| 27 /** |
| 28 * An abstract implementation of a Dart SDK in which the available libraries are |
| 29 * stored in a library map. Subclasses are responsible for populating the |
| 30 * library map. |
| 31 */ |
| 32 @deprecated |
| 33 abstract class AbstractDartSdk implements DartSdk { |
| 34 /** |
| 35 * A mapping from Dart library URI's to the library represented by that URI. |
| 36 */ |
| 37 LibraryMap libraryMap = new LibraryMap(); |
| 38 |
| 39 /** |
| 40 * The [AnalysisOptions] to use to create the [context]. |
| 41 */ |
| 42 AnalysisOptions _analysisOptions; |
| 43 |
| 44 /** |
| 45 * The flag that specifies whether an SDK summary should be used. This is a |
| 46 * temporary flag until summaries are enabled by default. |
| 47 */ |
| 48 bool _useSummary = false; |
| 49 |
| 50 /** |
| 51 * The [AnalysisContext] which is used for all of the sources in this SDK. |
| 52 */ |
| 53 InternalAnalysisContext _analysisContext; |
| 54 |
| 55 /** |
| 56 * The mapping from Dart URI's to the corresponding sources. |
| 57 */ |
| 58 Map<String, Source> _uriToSourceMap = new HashMap<String, Source>(); |
| 59 |
| 60 /** |
| 61 * Set the [options] for this SDK analysis context. Throw [StateError] if the |
| 62 * context has been already created. |
| 63 */ |
| 64 void set analysisOptions(AnalysisOptions options) { |
| 65 if (_analysisContext != null) { |
| 66 throw new StateError( |
| 67 'Analysis options cannot be changed after context creation.'); |
| 68 } |
| 69 _analysisOptions = options; |
| 70 } |
| 71 |
| 72 @override |
| 73 AnalysisContext get context { |
| 74 if (_analysisContext == null) { |
| 75 _analysisContext = new SdkAnalysisContext(_analysisOptions); |
| 76 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); |
| 77 _analysisContext.sourceFactory = factory; |
| 78 if (_useSummary) { |
| 79 bool strongMode = _analysisOptions?.strongMode ?? false; |
| 80 PackageBundle sdkBundle = getSummarySdkBundle(strongMode); |
| 81 if (sdkBundle != null) { |
| 82 _analysisContext.resultProvider = new SdkSummaryResultProvider( |
| 83 _analysisContext, sdkBundle, strongMode); |
| 84 } |
| 85 } |
| 86 } |
| 87 return _analysisContext; |
| 88 } |
| 89 |
| 90 @override |
| 91 List<SdkLibrary> get sdkLibraries => libraryMap.sdkLibraries; |
| 92 |
| 93 @override |
| 94 List<String> get uris => libraryMap.uris; |
| 95 |
| 96 /** |
| 97 * Return `true` if the SDK summary will be used when available. |
| 98 */ |
| 99 bool get useSummary => _useSummary; |
| 100 |
| 101 /** |
| 102 * Specify whether SDK summary should be used. |
| 103 */ |
| 104 void set useSummary(bool use) { |
| 105 if (_analysisContext != null) { |
| 106 throw new StateError( |
| 107 'The "useSummary" flag cannot be changed after context creation.'); |
| 108 } |
| 109 _useSummary = use; |
| 110 } |
| 111 |
| 112 /** |
| 113 * Add the extensions from one or more sdk extension files to this sdk. The |
| 114 * [extensions] should be a table mapping the names of extensions to the paths |
| 115 * where those extensions can be found. |
| 116 */ |
| 117 void addExtensions(Map<String, String> extensions) { |
| 118 extensions.forEach((String uri, String path) { |
| 119 String shortName = uri.substring(uri.indexOf(':') + 1); |
| 120 SdkLibraryImpl library = new SdkLibraryImpl(shortName); |
| 121 library.path = path; |
| 122 libraryMap.setLibrary(uri, library); |
| 123 }); |
| 124 } |
| 125 |
| 126 @override |
| 127 Source fromFileUri(Uri uri) { |
| 128 JavaFile file = new JavaFile.fromUri(uri); |
| 129 |
| 130 String path = _getPath(file); |
| 131 if (path == null) { |
| 132 return null; |
| 133 } |
| 134 try { |
| 135 return new FileBasedSource(file, Uri.parse(path)); |
| 136 } on FormatException catch (exception, stackTrace) { |
| 137 AnalysisEngine.instance.logger.logInformation( |
| 138 "Failed to create URI: $path", |
| 139 new CaughtException(exception, stackTrace)); |
| 140 } |
| 141 return null; |
| 142 } |
| 143 |
| 144 String getRelativePathFromFile(JavaFile file); |
| 145 |
| 146 @override |
| 147 SdkLibrary getSdkLibrary(String dartUri) => libraryMap.getLibrary(dartUri); |
| 148 |
| 149 /** |
| 150 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
| 151 * This method should not be used outside of `analyzer` and `analyzer_cli` |
| 152 * packages. |
| 153 */ |
| 154 PackageBundle getSummarySdkBundle(bool strongMode); |
| 155 |
| 156 FileBasedSource internalMapDartUri(String dartUri) { |
| 157 // TODO(brianwilkerson) Figure out how to unify the implementations in the |
| 158 // two subclasses. |
| 159 String libraryName; |
| 160 String relativePath; |
| 161 int index = dartUri.indexOf('/'); |
| 162 if (index >= 0) { |
| 163 libraryName = dartUri.substring(0, index); |
| 164 relativePath = dartUri.substring(index + 1); |
| 165 } else { |
| 166 libraryName = dartUri; |
| 167 relativePath = ""; |
| 168 } |
| 169 SdkLibrary library = getSdkLibrary(libraryName); |
| 170 if (library == null) { |
| 171 return null; |
| 172 } |
| 173 String srcPath; |
| 174 if (relativePath.isEmpty) { |
| 175 srcPath = library.path; |
| 176 } else { |
| 177 String libraryPath = library.path; |
| 178 int index = libraryPath.lastIndexOf(JavaFile.separator); |
| 179 if (index == -1) { |
| 180 index = libraryPath.lastIndexOf('/'); |
| 181 if (index == -1) { |
| 182 return null; |
| 183 } |
| 184 } |
| 185 String prefix = libraryPath.substring(0, index + 1); |
| 186 srcPath = '$prefix$relativePath'; |
| 187 } |
| 188 String filePath = srcPath.replaceAll('/', JavaFile.separator); |
| 189 try { |
| 190 JavaFile file = new JavaFile(filePath); |
| 191 return new FileBasedSource(file, Uri.parse(dartUri)); |
| 192 } on FormatException { |
| 193 return null; |
| 194 } |
| 195 } |
| 196 |
| 197 @override |
| 198 Source mapDartUri(String dartUri) { |
| 199 Source source = _uriToSourceMap[dartUri]; |
| 200 if (source == null) { |
| 201 source = internalMapDartUri(dartUri); |
| 202 _uriToSourceMap[dartUri] = source; |
| 203 } |
| 204 return source; |
| 205 } |
| 206 |
| 207 String _getPath(JavaFile file) { |
| 208 List<SdkLibrary> libraries = libraryMap.sdkLibraries; |
| 209 int length = libraries.length; |
| 210 List<String> paths = new List(length); |
| 211 String filePath = getRelativePathFromFile(file); |
| 212 if (filePath == null) { |
| 213 return null; |
| 214 } |
| 215 for (int i = 0; i < length; i++) { |
| 216 SdkLibrary library = libraries[i]; |
| 217 String libraryPath = library.path.replaceAll('/', JavaFile.separator); |
| 218 if (filePath == libraryPath) { |
| 219 return library.shortName; |
| 220 } |
| 221 paths[i] = libraryPath; |
| 222 } |
| 223 for (int i = 0; i < length; i++) { |
| 224 SdkLibrary library = libraries[i]; |
| 225 String libraryPath = paths[i]; |
| 226 int index = libraryPath.lastIndexOf(JavaFile.separator); |
| 227 if (index >= 0) { |
| 228 String prefix = libraryPath.substring(0, index + 1); |
| 229 if (filePath.startsWith(prefix)) { |
| 230 String relPath = filePath |
| 231 .substring(prefix.length) |
| 232 .replaceAll(JavaFile.separator, '/'); |
| 233 return '${library.shortName}/$relPath'; |
| 234 } |
| 235 } |
| 236 } |
| 237 return null; |
| 238 } |
| 239 } |
| 22 | 240 |
| 23 /** | 241 /** |
| 24 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is | 242 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is |
| 25 * something like... | 243 * something like... |
| 26 * | 244 * |
| 27 * dart-sdk/ | 245 * dart-sdk/ |
| 28 * bin/ | 246 * bin/ |
| 29 * dart[.exe] <-- VM | 247 * dart[.exe] <-- VM |
| 30 * lib/ | 248 * lib/ |
| 31 * core/ | 249 * core/ |
| 32 * core.dart | 250 * core.dart |
| 33 * ... other core library files ... | 251 * ... other core library files ... |
| 34 * ... other libraries ... | 252 * ... other libraries ... |
| 35 * util/ | 253 * util/ |
| 36 * ... Dart utilities ... | 254 * ... Dart utilities ... |
| 37 * Chromium/ <-- Dartium typically exists in a sibling directory | 255 * Chromium/ <-- Dartium typically exists in a sibling directory |
| 256 * |
| 257 * This class is deprecated. Please use FolderBasedDartSdk instead. |
| 38 */ | 258 */ |
| 39 class DirectoryBasedDartSdk implements DartSdk { | 259 @deprecated |
| 260 class DirectoryBasedDartSdk extends AbstractDartSdk { |
| 40 /** | 261 /** |
| 41 * The default SDK, or `null` if the default SDK either has not yet been | 262 * The default SDK, or `null` if the default SDK either has not yet been |
| 42 * created or cannot be created for some reason. | 263 * created or cannot be created for some reason. |
| 43 */ | 264 */ |
| 44 static DirectoryBasedDartSdk _DEFAULT_SDK; | 265 static DirectoryBasedDartSdk _DEFAULT_SDK; |
| 45 | 266 |
| 46 /** | 267 /** |
| 47 * The name of the directory within the SDK directory that contains | 268 * The name of the directory within the SDK directory that contains |
| 48 * executables. | 269 * executables. |
| 49 */ | 270 */ |
| (...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 182 return null; | 403 return null; |
| 183 } | 404 } |
| 184 JavaFile sdkDirectory = new JavaFile(sdkProperty); | 405 JavaFile sdkDirectory = new JavaFile(sdkProperty); |
| 185 if (!sdkDirectory.exists()) { | 406 if (!sdkDirectory.exists()) { |
| 186 return null; | 407 return null; |
| 187 } | 408 } |
| 188 return sdkDirectory; | 409 return sdkDirectory; |
| 189 } | 410 } |
| 190 | 411 |
| 191 /** | 412 /** |
| 192 * The [AnalysisContext] which is used for all of the sources in this sdk. | |
| 193 */ | |
| 194 InternalAnalysisContext _analysisContext; | |
| 195 | |
| 196 /** | |
| 197 * The directory containing the SDK. | 413 * The directory containing the SDK. |
| 198 */ | 414 */ |
| 199 JavaFile _sdkDirectory; | 415 JavaFile _sdkDirectory; |
| 200 | 416 |
| 201 /** | 417 /** |
| 418 * The directory within the SDK directory that contains the libraries. |
| 419 */ |
| 420 JavaFile _libraryDirectory; |
| 421 |
| 422 /** |
| 202 * The revision number of this SDK, or `"0"` if the revision number cannot be | 423 * The revision number of this SDK, or `"0"` if the revision number cannot be |
| 203 * discovered. | 424 * discovered. |
| 204 */ | 425 */ |
| 205 String _sdkVersion; | 426 String _sdkVersion; |
| 206 | 427 |
| 207 /** | 428 /** |
| 208 * The file containing the dart2js executable. | 429 * The file containing the dart2js executable. |
| 209 */ | 430 */ |
| 210 JavaFile _dart2jsExecutable; | 431 JavaFile _dart2jsExecutable; |
| 211 | 432 |
| 212 /** | 433 /** |
| 213 * The file containing the Dartium executable. | 434 * The file containing the Dartium executable. |
| 214 */ | 435 */ |
| 215 JavaFile _dartiumExecutable; | 436 JavaFile _dartiumExecutable; |
| 216 | 437 |
| 217 /** | 438 /** |
| 218 * The file containing the pub executable. | 439 * The file containing the pub executable. |
| 219 */ | 440 */ |
| 220 JavaFile _pubExecutable; | 441 JavaFile _pubExecutable; |
| 221 | 442 |
| 222 /** | 443 /** |
| 223 * The file containing the VM executable. | 444 * The file containing the VM executable. |
| 224 */ | 445 */ |
| 225 JavaFile _vmExecutable; | 446 JavaFile _vmExecutable; |
| 226 | 447 |
| 227 /** | 448 /** |
| 228 * A mapping from Dart library URI's to the library represented by that URI. | |
| 229 */ | |
| 230 LibraryMap _libraryMap; | |
| 231 | |
| 232 /** | |
| 233 * Initialize a newly created SDK to represent the Dart SDK installed in the | 449 * Initialize a newly created SDK to represent the Dart SDK installed in the |
| 234 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path | 450 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path |
| 235 * should be used when it is available | 451 * should be used when it is available |
| 236 */ | 452 */ |
| 237 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 453 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
| 238 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 454 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
| 239 _libraryMap = initialLibraryMap(useDart2jsPaths); | 455 libraryMap = initialLibraryMap(useDart2jsPaths); |
| 240 } | |
| 241 | |
| 242 @override | |
| 243 AnalysisContext get context { | |
| 244 if (_analysisContext == null) { | |
| 245 if (AnalysisEngine.instance.useTaskModel) { | |
| 246 _analysisContext = new newContext.SdkAnalysisContext(); | |
| 247 } else { | |
| 248 _analysisContext = new SdkAnalysisContext(); | |
| 249 } | |
| 250 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]); | |
| 251 _analysisContext.sourceFactory = factory; | |
| 252 List<String> uris = this.uris; | |
| 253 ChangeSet changeSet = new ChangeSet(); | |
| 254 for (String uri in uris) { | |
| 255 changeSet.addedSource(factory.forUri(uri)); | |
| 256 } | |
| 257 _analysisContext.applyChanges(changeSet); | |
| 258 } | |
| 259 return _analysisContext; | |
| 260 } | 456 } |
| 261 | 457 |
| 262 /** | 458 /** |
| 263 * Return the file containing the dart2js executable, or `null` if it does not | 459 * Return the file containing the dart2js executable, or `null` if it does not |
| 264 * exist. | 460 * exist. |
| 265 */ | 461 */ |
| 266 JavaFile get dart2JsExecutable { | 462 JavaFile get dart2JsExecutable { |
| 267 if (_dart2jsExecutable == null) { | 463 if (_dart2jsExecutable == null) { |
| 268 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( | 464 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( |
| 269 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 465 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 323 bool get hasDocumentation => docDirectory.exists(); | 519 bool get hasDocumentation => docDirectory.exists(); |
| 324 | 520 |
| 325 /** | 521 /** |
| 326 * Return `true` if the Dartium binary is available. | 522 * Return `true` if the Dartium binary is available. |
| 327 */ | 523 */ |
| 328 bool get isDartiumInstalled => dartiumExecutable != null; | 524 bool get isDartiumInstalled => dartiumExecutable != null; |
| 329 | 525 |
| 330 /** | 526 /** |
| 331 * Return the directory within the SDK directory that contains the libraries. | 527 * Return the directory within the SDK directory that contains the libraries. |
| 332 */ | 528 */ |
| 333 JavaFile get libraryDirectory => | 529 JavaFile get libraryDirectory { |
| 334 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); | 530 if (_libraryDirectory == null) { |
| 531 _libraryDirectory = |
| 532 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); |
| 533 } |
| 534 return _libraryDirectory; |
| 535 } |
| 335 | 536 |
| 336 /** | 537 /** |
| 337 * Return the file containing the Pub executable, or `null` if it does not exi
st. | 538 * Return the file containing the Pub executable, or `null` if it does not exi
st. |
| 338 */ | 539 */ |
| 339 JavaFile get pubExecutable { | 540 JavaFile get pubExecutable { |
| 340 if (_pubExecutable == null) { | 541 if (_pubExecutable == null) { |
| 341 _pubExecutable = _verifyExecutable(new JavaFile.relative( | 542 _pubExecutable = _verifyExecutable(new JavaFile.relative( |
| 342 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 543 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
| 343 OSUtilities.isWindows() | 544 OSUtilities.isWindows() |
| 344 ? _PUB_EXECUTABLE_NAME_WIN | 545 ? _PUB_EXECUTABLE_NAME_WIN |
| 345 : _PUB_EXECUTABLE_NAME)); | 546 : _PUB_EXECUTABLE_NAME)); |
| 346 } | 547 } |
| 347 return _pubExecutable; | 548 return _pubExecutable; |
| 348 } | 549 } |
| 349 | 550 |
| 350 @override | |
| 351 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; | |
| 352 | |
| 353 /** | 551 /** |
| 354 * Return the revision number of this SDK, or `"0"` if the revision number | 552 * Return the revision number of this SDK, or `"0"` if the revision number |
| 355 * cannot be discovered. | 553 * cannot be discovered. |
| 356 */ | 554 */ |
| 357 @override | 555 @override |
| 358 String get sdkVersion { | 556 String get sdkVersion { |
| 359 if (_sdkVersion == null) { | 557 if (_sdkVersion == null) { |
| 360 _sdkVersion = DartSdk.DEFAULT_VERSION; | 558 _sdkVersion = DartSdk.DEFAULT_VERSION; |
| 361 JavaFile revisionFile = | 559 JavaFile revisionFile = |
| 362 new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); | 560 new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); |
| 363 try { | 561 try { |
| 364 String revision = revisionFile.readAsStringSync(); | 562 String revision = revisionFile.readAsStringSync(); |
| 365 if (revision != null) { | 563 if (revision != null) { |
| 366 _sdkVersion = revision.trim(); | 564 _sdkVersion = revision.trim(); |
| 367 } | 565 } |
| 368 } on FileSystemException { | 566 } on FileSystemException { |
| 369 // Fall through to return the default. | 567 // Fall through to return the default. |
| 370 } | 568 } |
| 371 } | 569 } |
| 372 return _sdkVersion; | 570 return _sdkVersion; |
| 373 } | 571 } |
| 374 | 572 |
| 375 @override | |
| 376 List<String> get uris => _libraryMap.uris; | |
| 377 | |
| 378 /** | 573 /** |
| 379 * Return the name of the file containing the VM executable. | 574 * Return the name of the file containing the VM executable. |
| 380 */ | 575 */ |
| 381 String get vmBinaryName { | 576 String get vmBinaryName { |
| 382 if (OSUtilities.isWindows()) { | 577 if (OSUtilities.isWindows()) { |
| 383 return _VM_EXECUTABLE_NAME_WIN; | 578 return _VM_EXECUTABLE_NAME_WIN; |
| 384 } else { | 579 } else { |
| 385 return _VM_EXECUTABLE_NAME; | 580 return _VM_EXECUTABLE_NAME; |
| 386 } | 581 } |
| 387 } | 582 } |
| (...skipping 20 matching lines...) Expand all Loading... |
| 408 new JavaFile.relative( | 603 new JavaFile.relative( |
| 409 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | 604 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
| 410 _SDK_LIBRARY_METADATA_DIR), | 605 _SDK_LIBRARY_METADATA_DIR), |
| 411 _SDK_LIBRARY_METADATA_LIB_DIR), | 606 _SDK_LIBRARY_METADATA_LIB_DIR), |
| 412 _LIBRARIES_FILE); | 607 _LIBRARIES_FILE); |
| 413 yield new JavaFile.relative( | 608 yield new JavaFile.relative( |
| 414 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | 609 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
| 415 _LIBRARIES_FILE); | 610 _LIBRARIES_FILE); |
| 416 } | 611 } |
| 417 | 612 |
| 418 @override | |
| 419 Source fromFileUri(Uri uri) { | |
| 420 JavaFile file = new JavaFile.fromUri(uri); | |
| 421 String filePath = file.getAbsolutePath(); | |
| 422 String libPath = libraryDirectory.getAbsolutePath(); | |
| 423 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { | |
| 424 return null; | |
| 425 } | |
| 426 filePath = filePath.substring(libPath.length + 1); | |
| 427 for (SdkLibrary library in _libraryMap.sdkLibraries) { | |
| 428 String libraryPath = library.path; | |
| 429 if (filePath.replaceAll('\\', '/') == libraryPath) { | |
| 430 String path = library.shortName; | |
| 431 try { | |
| 432 return new FileBasedSource(file, parseUriWithException(path)); | |
| 433 } on URISyntaxException catch (exception, stackTrace) { | |
| 434 AnalysisEngine.instance.logger.logInformation( | |
| 435 "Failed to create URI: $path", | |
| 436 new CaughtException(exception, stackTrace)); | |
| 437 return null; | |
| 438 } | |
| 439 } | |
| 440 libraryPath = new JavaFile(libraryPath).getParent(); | |
| 441 if (filePath.startsWith("$libraryPath${JavaFile.separator}")) { | |
| 442 String path = | |
| 443 "${library.shortName}/${filePath.substring(libraryPath.length + 1)}"
; | |
| 444 try { | |
| 445 return new FileBasedSource(file, parseUriWithException(path)); | |
| 446 } on URISyntaxException catch (exception, stackTrace) { | |
| 447 AnalysisEngine.instance.logger.logInformation( | |
| 448 "Failed to create URI: $path", | |
| 449 new CaughtException(exception, stackTrace)); | |
| 450 return null; | |
| 451 } | |
| 452 } | |
| 453 } | |
| 454 return null; | |
| 455 } | |
| 456 | |
| 457 /** | 613 /** |
| 458 * Return the directory where dartium can be found (the directory that will be | 614 * Return the directory where dartium can be found (the directory that will be |
| 459 * the working directory if Dartium is invoked without changing the default), | 615 * the working directory if Dartium is invoked without changing the default), |
| 460 * assuming that the Editor was installed in the [installDir]. | 616 * assuming that the Editor was installed in the [installDir]. |
| 461 */ | 617 */ |
| 462 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => | 618 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => |
| 463 new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); | 619 new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); |
| 464 | 620 |
| 465 /** | 621 /** |
| 466 * Return the auxiliary documentation file for the library with the given | 622 * Return the auxiliary documentation file for the library with the given |
| 467 * [libraryName], or `null` if no such file exists. | 623 * [libraryName], or `null` if no such file exists. |
| 468 */ | 624 */ |
| 469 JavaFile getDocFileFor(String libraryName) { | 625 JavaFile getDocFileFor(String libraryName) { |
| 470 JavaFile dir = docDirectory; | 626 JavaFile dir = docDirectory; |
| 471 if (!dir.exists()) { | 627 if (!dir.exists()) { |
| 472 return null; | 628 return null; |
| 473 } | 629 } |
| 474 JavaFile libDir = new JavaFile.relative(dir, libraryName); | 630 JavaFile libDir = new JavaFile.relative(dir, libraryName); |
| 475 JavaFile docFile = | 631 JavaFile docFile = |
| 476 new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); | 632 new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); |
| 477 if (docFile.exists()) { | 633 if (docFile.exists()) { |
| 478 return docFile; | 634 return docFile; |
| 479 } | 635 } |
| 480 return null; | 636 return null; |
| 481 } | 637 } |
| 482 | 638 |
| 483 @override | 639 @override |
| 484 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri); | 640 PackageBundle getLinkedBundle() => null; |
| 641 |
| 642 @override |
| 643 String getRelativePathFromFile(JavaFile file) { |
| 644 String filePath = file.getAbsolutePath(); |
| 645 String libPath = libraryDirectory.getAbsolutePath(); |
| 646 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { |
| 647 return null; |
| 648 } |
| 649 return filePath.substring(libPath.length + 1); |
| 650 } |
| 651 |
| 652 /** |
| 653 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
| 654 * This method should not be used outside of `analyzer` and `analyzer_cli` |
| 655 * packages. |
| 656 */ |
| 657 PackageBundle getSummarySdkBundle(bool strongMode) { |
| 658 String rootPath = directory.getAbsolutePath(); |
| 659 String name = strongMode ? 'strong.sum' : 'spec.sum'; |
| 660 String path = pathos.join(rootPath, 'lib', '_internal', name); |
| 661 try { |
| 662 File file = new File(path); |
| 663 if (file.existsSync()) { |
| 664 List<int> bytes = file.readAsBytesSync(); |
| 665 return new PackageBundle.fromBuffer(bytes); |
| 666 } |
| 667 } catch (exception, stackTrace) { |
| 668 AnalysisEngine.instance.logger.logError( |
| 669 'Failed to load SDK analysis summary from $path', |
| 670 new CaughtException(exception, stackTrace)); |
| 671 } |
| 672 return null; |
| 673 } |
| 485 | 674 |
| 486 /** | 675 /** |
| 487 * Read all of the configuration files to initialize the library maps. The | 676 * Read all of the configuration files to initialize the library maps. The |
| 488 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it | 677 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it |
| 489 * is available. Return the initialized library map. | 678 * is available. Return the initialized library map. |
| 490 */ | 679 */ |
| 491 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 680 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 492 List<String> searchedPaths = <String>[]; | 681 List<String> searchedPaths = <String>[]; |
| 493 var lastStackTrace = null; | 682 var lastStackTrace = null; |
| 494 var lastException = null; | 683 var lastException = null; |
| 495 for (JavaFile librariesFile in _libraryMapLocations) { | 684 for (JavaFile librariesFile in _libraryMapLocations) { |
| 496 try { | 685 try { |
| 497 String contents = librariesFile.readAsStringSync(); | 686 String contents = librariesFile.readAsStringSync(); |
| 498 return new SdkLibrariesReader(useDart2jsPaths) | 687 return new SdkLibrariesReader(useDart2jsPaths) |
| 499 .readFromFile(librariesFile, contents); | 688 .readFromFile(librariesFile, contents); |
| 500 } catch (exception, stackTrace) { | 689 } catch (exception, stackTrace) { |
| 501 searchedPaths.add(librariesFile.getAbsolutePath()); | 690 searchedPaths.add(librariesFile.getAbsolutePath()); |
| 502 lastException = exception; | 691 lastException = exception; |
| 503 lastStackTrace = stackTrace; | 692 lastStackTrace = stackTrace; |
| 504 } | 693 } |
| 505 } | 694 } |
| 506 AnalysisEngine.instance.logger.logError( | 695 AnalysisEngine.instance.logger.logError( |
| 507 "Could not initialize the library map from $searchedPaths", | 696 "Could not initialize the library map from $searchedPaths", |
| 508 new CaughtException(lastException, lastStackTrace)); | 697 new CaughtException(lastException, lastStackTrace)); |
| 509 return new LibraryMap(); | 698 return new LibraryMap(); |
| 510 } | 699 } |
| 511 | 700 |
| 512 @override | 701 @override |
| 513 Source mapDartUri(String dartUri) { | 702 FileBasedSource internalMapDartUri(String dartUri) { |
| 514 String libraryName; | 703 String libraryName; |
| 515 String relativePath; | 704 String relativePath; |
| 516 int index = dartUri.indexOf('/'); | 705 int index = dartUri.indexOf('/'); |
| 517 if (index >= 0) { | 706 if (index >= 0) { |
| 518 libraryName = dartUri.substring(0, index); | 707 libraryName = dartUri.substring(0, index); |
| 519 relativePath = dartUri.substring(index + 1); | 708 relativePath = dartUri.substring(index + 1); |
| 520 } else { | 709 } else { |
| 521 libraryName = dartUri; | 710 libraryName = dartUri; |
| 522 relativePath = ""; | 711 relativePath = ""; |
| 523 } | 712 } |
| 524 SdkLibrary library = getSdkLibrary(libraryName); | 713 SdkLibrary library = getSdkLibrary(libraryName); |
| 525 if (library == null) { | 714 if (library == null) { |
| 526 return null; | 715 return null; |
| 527 } | 716 } |
| 528 try { | 717 try { |
| 529 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); | 718 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); |
| 530 if (!relativePath.isEmpty) { | 719 if (!relativePath.isEmpty) { |
| 531 file = file.getParentFile(); | 720 file = file.getParentFile(); |
| 532 file = new JavaFile.relative(file, relativePath); | 721 file = new JavaFile.relative(file, relativePath); |
| 533 } | 722 } |
| 534 return new FileBasedSource(file, parseUriWithException(dartUri)); | 723 return new FileBasedSource(file, Uri.parse(dartUri)); |
| 535 } on URISyntaxException { | 724 } on FormatException { |
| 536 return null; | 725 return null; |
| 537 } | 726 } |
| 538 } | 727 } |
| 539 | 728 |
| 540 /** | 729 /** |
| 541 * Return the given [file] if it exists and is executable, or `null` if it | 730 * Return the given [file] if it exists and is executable, or `null` if it |
| 542 * does not exist or is not executable. | 731 * does not exist or is not executable. |
| 543 */ | 732 */ |
| 544 JavaFile _verifyExecutable(JavaFile file) => | 733 JavaFile _verifyExecutable(JavaFile file) => |
| 545 file.isExecutable() ? file : null; | 734 file.isExecutable() ? file : null; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 561 * "builtin/builtin_runtime.dart", | 750 * "builtin/builtin_runtime.dart", |
| 562 * category: "Server", | 751 * category: "Server", |
| 563 * platforms: VM_PLATFORM), | 752 * platforms: VM_PLATFORM), |
| 564 * | 753 * |
| 565 * "compiler" : const LibraryInfo( | 754 * "compiler" : const LibraryInfo( |
| 566 * "compiler/compiler.dart", | 755 * "compiler/compiler.dart", |
| 567 * category: "Tools", | 756 * category: "Tools", |
| 568 * platforms: 0), | 757 * platforms: 0), |
| 569 * }; | 758 * }; |
| 570 */ | 759 */ |
| 760 @deprecated |
| 571 class SdkLibrariesReader { | 761 class SdkLibrariesReader { |
| 572 /** | 762 /** |
| 573 * A flag indicating whether the dart2js path should be used when it is | 763 * A flag indicating whether the dart2js path should be used when it is |
| 574 * available. | 764 * available. |
| 575 */ | 765 */ |
| 576 final bool _useDart2jsPaths; | 766 final bool _useDart2jsPaths; |
| 577 | 767 |
| 578 /** | 768 /** |
| 579 * Initialize a newly created library reader to use the dart2js path if | 769 * Initialize a newly created library reader to use the dart2js path if |
| 580 * [_useDart2jsPaths] is `true`. | 770 * [_useDart2jsPaths] is `true`. |
| (...skipping 20 matching lines...) Expand all Loading... |
| 601 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 791 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 602 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 792 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 603 // If any syntactic errors were found then don't try to visit the AST | 793 // If any syntactic errors were found then don't try to visit the AST |
| 604 // structure. | 794 // structure. |
| 605 if (!errorListener.errorReported) { | 795 if (!errorListener.errorReported) { |
| 606 unit.accept(libraryBuilder); | 796 unit.accept(libraryBuilder); |
| 607 } | 797 } |
| 608 return libraryBuilder.librariesMap; | 798 return libraryBuilder.librariesMap; |
| 609 } | 799 } |
| 610 } | 800 } |
| OLD | NEW |