Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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.src.generated.sdk_io; | 5 library analyzer.src.generated.sdk2; |
| 6 | 6 |
| 7 import 'dart:collection'; | 7 import 'dart:collection'; |
| 8 import 'dart:io'; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:analyzer/dart/ast/ast.dart'; | 10 import 'package:analyzer/dart/ast/ast.dart'; |
| 11 import 'package:analyzer/file_system/file_system.dart'; | |
| 11 import 'package:analyzer/src/context/context.dart'; | 12 import 'package:analyzer/src/context/context.dart'; |
| 12 import 'package:analyzer/src/dart/scanner/reader.dart'; | 13 import 'package:analyzer/src/dart/scanner/reader.dart'; |
| 13 import 'package:analyzer/src/dart/scanner/scanner.dart'; | 14 import 'package:analyzer/src/dart/scanner/scanner.dart'; |
| 14 import 'package:analyzer/src/generated/engine.dart'; | 15 import 'package:analyzer/src/generated/engine.dart'; |
| 15 import 'package:analyzer/src/generated/error.dart'; | 16 import 'package:analyzer/src/generated/error.dart'; |
| 16 import 'package:analyzer/src/generated/java_core.dart'; | 17 import 'package:analyzer/src/generated/java_core.dart'; |
| 17 import 'package:analyzer/src/generated/java_engine.dart'; | 18 import 'package:analyzer/src/generated/java_engine.dart'; |
| 18 import 'package:analyzer/src/generated/java_engine_io.dart'; | 19 import 'package:analyzer/src/generated/java_engine_io.dart'; |
| 19 import 'package:analyzer/src/generated/java_io.dart'; | |
| 20 import 'package:analyzer/src/generated/parser.dart'; | 20 import 'package:analyzer/src/generated/parser.dart'; |
| 21 import 'package:analyzer/src/generated/sdk.dart'; | 21 import 'package:analyzer/src/generated/sdk.dart'; |
| 22 import 'package:analyzer/src/generated/source_io.dart'; | 22 import 'package:analyzer/src/generated/source_io.dart'; |
| 23 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; | 23 import 'package:analyzer/src/summary/idl.dart' show PackageBundle; |
| 24 import 'package:analyzer/src/summary/summary_sdk.dart'; | 24 import 'package:analyzer/src/summary/summary_sdk.dart'; |
| 25 import 'package:path/path.dart' as pathos; | 25 import 'package:path/path.dart' as pathos; |
| 26 import 'package:yaml/yaml.dart'; | |
| 26 | 27 |
| 27 /** | 28 /** |
| 28 * An abstract implementation of a Dart SDK in which the available libraries are | 29 * 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 * stored in a library map. Subclasses are responsible for populating the |
| 30 * library map. | 31 * library map. |
| 31 */ | 32 */ |
| 32 abstract class AbstractDartSdk implements DartSdk { | 33 abstract class AbstractDartSdk implements DartSdk { |
| 33 /** | 34 /** |
| 35 * The resource provider used to access the file system. | |
| 36 */ | |
| 37 ResourceProvider resourceProvider; | |
| 38 | |
| 39 /** | |
| 34 * A mapping from Dart library URI's to the library represented by that URI. | 40 * A mapping from Dart library URI's to the library represented by that URI. |
| 35 */ | 41 */ |
| 36 LibraryMap libraryMap = new LibraryMap(); | 42 LibraryMap libraryMap = new LibraryMap(); |
| 37 | 43 |
| 38 /** | 44 /** |
| 39 * The [AnalysisOptions] to use to create the [context]. | 45 * The [AnalysisOptions] to use to create the [context]. |
| 40 */ | 46 */ |
| 41 AnalysisOptions _analysisOptions; | 47 AnalysisOptions _analysisOptions; |
| 42 | 48 |
| 43 /** | 49 /** |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 101 * Specify whether SDK summary should be used. | 107 * Specify whether SDK summary should be used. |
| 102 */ | 108 */ |
| 103 void set useSummary(bool use) { | 109 void set useSummary(bool use) { |
| 104 if (_analysisContext != null) { | 110 if (_analysisContext != null) { |
| 105 throw new StateError( | 111 throw new StateError( |
| 106 'The "useSummary" flag cannot be changed after context creation.'); | 112 'The "useSummary" flag cannot be changed after context creation.'); |
| 107 } | 113 } |
| 108 _useSummary = use; | 114 _useSummary = use; |
| 109 } | 115 } |
| 110 | 116 |
| 111 /** | |
| 112 * Add the extensions from one or more sdk extension files to this sdk. The | |
| 113 * [extensions] should be a table mapping the names of extensions to the paths | |
| 114 * where those extensions can be found. | |
| 115 */ | |
| 116 void addExtensions(Map<String, String> extensions) { | |
| 117 extensions.forEach((String uri, String path) { | |
| 118 String shortName = uri.substring(uri.indexOf(':') + 1); | |
| 119 SdkLibraryImpl library = new SdkLibraryImpl(shortName); | |
| 120 library.path = path; | |
| 121 libraryMap.setLibrary(uri, library); | |
| 122 }); | |
| 123 } | |
| 124 | |
| 125 @override | 117 @override |
| 126 Source fromFileUri(Uri uri) { | 118 Source fromFileUri(Uri uri) { |
| 127 JavaFile file = new JavaFile.fromUri(uri); | 119 File file = resourceProvider.getFile(uri.toFilePath(windows: false)); |
| 128 | 120 |
| 129 String path = _getPath(file); | 121 String path = _getPath(file); |
| 130 if (path == null) { | 122 if (path == null) { |
| 131 return null; | 123 return null; |
| 132 } | 124 } |
| 133 try { | 125 try { |
| 134 return new FileBasedSource(file, parseUriWithException(path)); | 126 return file.createSource(parseUriWithException(path)); |
| 135 } on URISyntaxException catch (exception, stackTrace) { | 127 } on URISyntaxException catch (exception, stackTrace) { |
| 136 AnalysisEngine.instance.logger.logInformation( | 128 AnalysisEngine.instance.logger.logInformation( |
| 137 "Failed to create URI: $path", | 129 "Failed to create URI: $path", |
| 138 new CaughtException(exception, stackTrace)); | 130 new CaughtException(exception, stackTrace)); |
| 139 } | 131 } |
| 140 return null; | 132 return null; |
| 141 } | 133 } |
| 142 | 134 |
| 143 String getRelativePathFromFile(JavaFile file); | 135 String getRelativePathFromFile(File file); |
| 144 | 136 |
| 145 @override | 137 @override |
| 146 SdkLibrary getSdkLibrary(String dartUri) => libraryMap.getLibrary(dartUri); | 138 SdkLibrary getSdkLibrary(String dartUri) => libraryMap.getLibrary(dartUri); |
| 147 | 139 |
| 148 /** | 140 /** |
| 149 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. | 141 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
| 150 * This method should not be used outside of `analyzer` and `analyzer_cli` | 142 * This method should not be used outside of `analyzer` and `analyzer_cli` |
| 151 * packages. | 143 * packages. |
| 152 */ | 144 */ |
| 153 PackageBundle getSummarySdkBundle(bool strongMode); | 145 PackageBundle getSummarySdkBundle(bool strongMode); |
| 154 | 146 |
| 155 FileBasedSource internalMapDartUri(String dartUri) { | 147 Source internalMapDartUri(String dartUri) { |
| 156 // TODO(brianwilkerson) Figure out how to unify the implementations in the | 148 // TODO(brianwilkerson) Figure out how to unify the implementations in the |
| 157 // two subclasses. | 149 // two subclasses. |
| 158 String libraryName; | 150 String libraryName; |
| 159 String relativePath; | 151 String relativePath; |
| 160 int index = dartUri.indexOf('/'); | 152 int index = dartUri.indexOf('/'); |
| 161 if (index >= 0) { | 153 if (index >= 0) { |
| 162 libraryName = dartUri.substring(0, index); | 154 libraryName = dartUri.substring(0, index); |
| 163 relativePath = dartUri.substring(index + 1); | 155 relativePath = dartUri.substring(index + 1); |
| 164 } else { | 156 } else { |
| 165 libraryName = dartUri; | 157 libraryName = dartUri; |
| 166 relativePath = ""; | 158 relativePath = ""; |
| 167 } | 159 } |
| 168 SdkLibrary library = getSdkLibrary(libraryName); | 160 SdkLibrary library = getSdkLibrary(libraryName); |
| 169 if (library == null) { | 161 if (library == null) { |
| 170 return null; | 162 return null; |
| 171 } | 163 } |
| 172 String srcPath; | 164 String srcPath; |
| 173 if (relativePath.isEmpty) { | 165 if (relativePath.isEmpty) { |
| 174 srcPath = library.path; | 166 srcPath = library.path; |
| 175 } else { | 167 } else { |
| 176 String libraryPath = library.path; | 168 String libraryPath = library.path; |
| 177 int index = libraryPath.lastIndexOf(JavaFile.separator); | 169 int index = libraryPath.lastIndexOf(pathos.separator); |
|
scheglov
2016/08/03 15:54:52
Do we have tests for this code?
I was not able to
Brian Wilkerson
2016/08/03 17:16:10
No. This method is overridden by both of the subcl
| |
| 178 if (index == -1) { | 170 if (index == -1) { |
| 179 index = libraryPath.lastIndexOf('/'); | 171 index = libraryPath.lastIndexOf('/'); |
| 180 if (index == -1) { | 172 if (index == -1) { |
| 181 return null; | 173 return null; |
| 182 } | 174 } |
| 183 } | 175 } |
| 184 String prefix = libraryPath.substring(0, index + 1); | 176 String prefix = libraryPath.substring(0, index + 1); |
| 185 srcPath = '$prefix$relativePath'; | 177 srcPath = '$prefix$relativePath'; |
| 186 } | 178 } |
| 187 String filePath = srcPath.replaceAll('/', JavaFile.separator); | 179 String filePath = srcPath.replaceAll('/', pathos.separator); |
| 188 try { | 180 try { |
| 189 JavaFile file = new JavaFile(filePath); | 181 File file = resourceProvider.getFile(filePath); |
| 190 return new FileBasedSource(file, parseUriWithException(dartUri)); | 182 return file.createSource(parseUriWithException(dartUri)); |
| 191 } on URISyntaxException { | 183 } on URISyntaxException { |
| 192 return null; | 184 return null; |
| 193 } | 185 } |
| 194 } | 186 } |
| 195 | 187 |
| 196 @override | 188 @override |
| 197 Source mapDartUri(String dartUri) { | 189 Source mapDartUri(String dartUri) { |
| 198 Source source = _uriToSourceMap[dartUri]; | 190 Source source = _uriToSourceMap[dartUri]; |
| 199 if (source == null) { | 191 if (source == null) { |
| 200 source = internalMapDartUri(dartUri); | 192 source = internalMapDartUri(dartUri); |
| 201 _uriToSourceMap[dartUri] = source; | 193 _uriToSourceMap[dartUri] = source; |
| 202 } | 194 } |
| 203 return source; | 195 return source; |
| 204 } | 196 } |
| 205 | 197 |
| 206 String _getPath(JavaFile file) { | 198 String _getPath(File file) { |
| 207 List<SdkLibrary> libraries = libraryMap.sdkLibraries; | 199 List<SdkLibrary> libraries = libraryMap.sdkLibraries; |
| 208 int length = libraries.length; | 200 int length = libraries.length; |
| 209 List<String> paths = new List(length); | 201 List<String> paths = new List(length); |
| 210 String filePath = getRelativePathFromFile(file); | 202 String filePath = getRelativePathFromFile(file); |
| 211 if (filePath == null) { | 203 if (filePath == null) { |
| 212 return null; | 204 return null; |
| 213 } | 205 } |
| 214 for (int i = 0; i < length; i++) { | 206 for (int i = 0; i < length; i++) { |
| 215 SdkLibrary library = libraries[i]; | 207 SdkLibrary library = libraries[i]; |
| 216 String libraryPath = library.path.replaceAll('/', JavaFile.separator); | 208 String libraryPath = library.path.replaceAll('/', pathos.separator); |
| 217 if (filePath == libraryPath) { | 209 if (filePath == libraryPath) { |
| 218 return library.shortName; | 210 return library.shortName; |
| 219 } | 211 } |
| 220 paths[i] = libraryPath; | 212 paths[i] = libraryPath; |
| 221 } | 213 } |
| 222 for (int i = 0; i < length; i++) { | 214 for (int i = 0; i < length; i++) { |
| 223 SdkLibrary library = libraries[i]; | 215 SdkLibrary library = libraries[i]; |
| 224 String libraryPath = paths[i]; | 216 String libraryPath = paths[i]; |
| 225 int index = libraryPath.lastIndexOf(JavaFile.separator); | 217 int index = libraryPath.lastIndexOf(pathos.separator); |
| 226 if (index >= 0) { | 218 if (index >= 0) { |
| 227 String prefix = libraryPath.substring(0, index + 1); | 219 String prefix = libraryPath.substring(0, index + 1); |
| 228 if (filePath.startsWith(prefix)) { | 220 if (filePath.startsWith(prefix)) { |
| 229 String relPath = filePath | 221 String relPath = filePath |
| 230 .substring(prefix.length) | 222 .substring(prefix.length) |
| 231 .replaceAll(JavaFile.separator, '/'); | 223 .replaceAll(pathos.separator, '/'); |
| 232 return '${library.shortName}/$relPath'; | 224 return '${library.shortName}/$relPath'; |
| 233 } | 225 } |
| 234 } | 226 } |
| 235 } | 227 } |
| 236 return null; | 228 return null; |
| 237 } | 229 } |
| 238 } | 230 } |
| 239 | 231 |
| 240 /** | 232 /** |
| 233 * An SDK backed by URI mappings derived from an `_embedder.yaml` file. | |
| 234 */ | |
| 235 class EmbedderSdk extends AbstractDartSdk { | |
| 236 static const String _DART_COLON_PREFIX = 'dart:'; | |
| 237 | |
| 238 static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs'; | |
| 239 final Map<String, String> _urlMappings = new HashMap<String, String>(); | |
| 240 | |
| 241 EmbedderSdk( | |
| 242 ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) { | |
| 243 this.resourceProvider = resourceProvider; | |
| 244 embedderYamls?.forEach(_processEmbedderYaml); | |
| 245 } | |
| 246 | |
| 247 @override | |
| 248 // TODO(danrubel) Determine SDK version | |
| 249 String get sdkVersion => '0'; | |
| 250 | |
| 251 /** | |
| 252 * The url mappings for this SDK. | |
| 253 */ | |
| 254 Map<String, String> get urlMappings => _urlMappings; | |
| 255 | |
| 256 @override | |
| 257 String getRelativePathFromFile(File file) => file.path; | |
| 258 | |
| 259 @override | |
| 260 PackageBundle getSummarySdkBundle(bool strongMode) => null; | |
| 261 | |
| 262 @override | |
| 263 Source internalMapDartUri(String dartUri) { | |
| 264 String libraryName; | |
| 265 String relativePath; | |
| 266 int index = dartUri.indexOf('/'); | |
| 267 if (index >= 0) { | |
| 268 libraryName = dartUri.substring(0, index); | |
| 269 relativePath = dartUri.substring(index + 1); | |
| 270 } else { | |
| 271 libraryName = dartUri; | |
| 272 relativePath = ""; | |
| 273 } | |
| 274 SdkLibrary library = getSdkLibrary(libraryName); | |
| 275 if (library == null) { | |
| 276 return null; | |
| 277 } | |
| 278 String srcPath; | |
| 279 if (relativePath.isEmpty) { | |
| 280 srcPath = library.path; | |
| 281 } else { | |
| 282 String libraryPath = library.path; | |
| 283 int index = libraryPath.lastIndexOf(pathos.separator); | |
| 284 if (index == -1) { | |
| 285 index = libraryPath.lastIndexOf('/'); | |
| 286 if (index == -1) { | |
| 287 return null; | |
| 288 } | |
| 289 } | |
| 290 String prefix = libraryPath.substring(0, index + 1); | |
| 291 srcPath = '$prefix$relativePath'; | |
| 292 } | |
| 293 String filePath = srcPath.replaceAll('/', pathos.separator); | |
| 294 try { | |
| 295 File file = resourceProvider.getFile(filePath); | |
| 296 return file.createSource(parseUriWithException(dartUri)); | |
| 297 } on URISyntaxException { | |
| 298 return null; | |
| 299 } | |
| 300 } | |
| 301 | |
| 302 /** | |
| 303 * Install the mapping from [name] to [libDir]/[file]. | |
| 304 */ | |
| 305 void _processEmbeddedLibs(String name, String file, Folder libDir) { | |
| 306 if (!name.startsWith(_DART_COLON_PREFIX)) { | |
| 307 // SDK libraries must begin with 'dart:'. | |
| 308 return; | |
| 309 } | |
| 310 String libPath = libDir.canonicalizePath(file); | |
| 311 _urlMappings[name] = libPath; | |
| 312 SdkLibraryImpl library = new SdkLibraryImpl(name); | |
| 313 library.path = libPath; | |
| 314 libraryMap.setLibrary(name, library); | |
| 315 } | |
| 316 | |
| 317 /** | |
| 318 * Given the 'embedderYamls' from [EmbedderYamlLocator] check each one for the | |
| 319 * top level key 'embedded_libs'. Under the 'embedded_libs' key are key value | |
| 320 * pairs. Each key is a 'dart:' library uri and each value is a path | |
| 321 * (relative to the directory containing `_embedder.yaml`) to a dart script | |
| 322 * for the given library. For example: | |
| 323 * | |
| 324 * embedded_libs: | |
| 325 * 'dart:io': '../../sdk/io/io.dart' | |
| 326 * | |
| 327 * If a key doesn't begin with `dart:` it is ignored. | |
| 328 */ | |
| 329 void _processEmbedderYaml(Folder libDir, YamlMap map) { | |
| 330 YamlNode embedded_libs = map[_EMBEDDED_LIB_MAP_KEY]; | |
| 331 if (embedded_libs is YamlMap) { | |
| 332 embedded_libs.forEach((k, v) => _processEmbeddedLibs(k, v, libDir)); | |
| 333 } | |
| 334 } | |
| 335 } | |
| 336 | |
| 337 /** | |
| 241 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is | 338 * A Dart SDK installed in a specified directory. Typical Dart SDK layout is |
| 242 * something like... | 339 * something like... |
| 243 * | 340 * |
| 244 * dart-sdk/ | 341 * dart-sdk/ |
| 245 * bin/ | 342 * bin/ |
| 246 * dart[.exe] <-- VM | 343 * dart[.exe] <-- VM |
| 247 * lib/ | 344 * lib/ |
| 248 * core/ | 345 * core/ |
| 249 * core.dart | 346 * core.dart |
| 250 * ... other core library files ... | 347 * ... other core library files ... |
| 251 * ... other libraries ... | 348 * ... other libraries ... |
| 252 * util/ | 349 * util/ |
| 253 * ... Dart utilities ... | 350 * ... Dart utilities ... |
| 254 * Chromium/ <-- Dartium typically exists in a sibling directory | 351 * Chromium/ <-- Dartium typically exists in a sibling directory |
| 255 */ | 352 */ |
| 256 class DirectoryBasedDartSdk extends AbstractDartSdk { | 353 class FolderBasedDartSdk extends AbstractDartSdk { |
| 257 /** | |
| 258 * The default SDK, or `null` if the default SDK either has not yet been | |
| 259 * created or cannot be created for some reason. | |
| 260 */ | |
| 261 static DirectoryBasedDartSdk _DEFAULT_SDK; | |
| 262 | |
| 263 /** | 354 /** |
| 264 * The name of the directory within the SDK directory that contains | 355 * The name of the directory within the SDK directory that contains |
| 265 * executables. | 356 * executables. |
| 266 */ | 357 */ |
| 267 static String _BIN_DIRECTORY_NAME = "bin"; | 358 static String _BIN_DIRECTORY_NAME = "bin"; |
| 268 | 359 |
| 269 /** | 360 // /** |
| 270 * The name of the directory on non-Mac that contains dartium. | 361 // * The name of the directory on non-Mac that contains dartium. |
| 271 */ | 362 // */ |
| 272 static String _DARTIUM_DIRECTORY_NAME = "chromium"; | 363 // static String _DARTIUM_DIRECTORY_NAME = "chromium"; |
| 273 | 364 // |
| 274 /** | 365 // /** |
| 275 * The name of the dart2js executable on non-windows operating systems. | 366 // * The name of the dart2js executable on non-windows operating systems. |
| 276 */ | 367 // */ |
| 277 static String _DART2JS_EXECUTABLE_NAME = "dart2js"; | 368 // static String _DART2JS_EXECUTABLE_NAME = "dart2js"; |
| 278 | 369 // |
| 279 /** | 370 // /** |
| 280 * The name of the file containing the dart2js executable on Windows. | 371 // * The name of the file containing the dart2js executable on Windows. |
| 281 */ | 372 // */ |
| 282 static String _DART2JS_EXECUTABLE_NAME_WIN = "dart2js.bat"; | 373 // static String _DART2JS_EXECUTABLE_NAME_WIN = "dart2js.bat"; |
| 283 | 374 // |
| 284 /** | 375 // /** |
| 285 * The name of the file containing the Dartium executable on Linux. | 376 // * The name of the file containing the Dartium executable on Linux. |
| 286 */ | 377 // */ |
| 287 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome"; | 378 // static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome"; |
| 288 | 379 // |
| 289 /** | 380 // /** |
| 290 * The name of the file containing the Dartium executable on Macintosh. | 381 // * The name of the file containing the Dartium executable on Macintosh. |
| 291 */ | 382 // */ |
| 292 static String _DARTIUM_EXECUTABLE_NAME_MAC = | 383 // static String _DARTIUM_EXECUTABLE_NAME_MAC = |
| 293 "Chromium.app/Contents/MacOS/Chromium"; | 384 // "Chromium.app/Contents/MacOS/Chromium"; |
| 294 | 385 // |
| 295 /** | 386 // /** |
| 296 * The name of the file containing the Dartium executable on Windows. | 387 // * The name of the file containing the Dartium executable on Windows. |
| 297 */ | 388 // */ |
| 298 static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe"; | 389 // static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe"; |
| 299 | 390 // |
| 300 /** | 391 // /** |
| 301 * The name of the [System] property whose value is the path to the default | 392 // * The name of the [System] property whose value is the path to the default |
| 302 * Dart SDK directory. | 393 // * Dart SDK directory. |
| 303 */ | 394 // */ |
| 304 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; | 395 // static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; |
|
scheglov
2016/08/03 15:54:52
Did you want to remove this code, or you will need
Brian Wilkerson
2016/08/03 17:16:10
I think I can remove it because I think that I can
| |
| 305 | 396 |
| 306 /** | 397 /** |
| 307 * The name of the directory within the SDK directory that contains | 398 * The name of the directory within the SDK directory that contains |
| 308 * documentation for the libraries. | 399 * documentation for the libraries. |
| 309 */ | 400 */ |
| 310 static String _DOCS_DIRECTORY_NAME = "docs"; | 401 static String _DOCS_DIRECTORY_NAME = "docs"; |
| 311 | 402 |
| 312 /** | 403 // /** |
| 313 * The suffix added to the name of a library to derive the name of the file | 404 // * The suffix added to the name of a library to derive the name of the file |
| 314 * containing the documentation for that library. | 405 // * containing the documentation for that library. |
| 315 */ | 406 // */ |
| 316 static String _DOC_FILE_SUFFIX = "_api.json"; | 407 // static String _DOC_FILE_SUFFIX = "_api.json"; |
| 317 | 408 |
| 318 /** | 409 /** |
| 319 * The name of the directory within the SDK directory that contains the | 410 * The name of the directory within the SDK directory that contains the |
| 320 * sdk_library_metadata directory. | 411 * sdk_library_metadata directory. |
| 321 */ | 412 */ |
| 322 static String _INTERNAL_DIR = "_internal"; | 413 static String _INTERNAL_DIR = "_internal"; |
| 323 | 414 |
| 324 /** | 415 /** |
| 325 * The name of the sdk_library_metadata directory that contains the package | 416 * The name of the sdk_library_metadata directory that contains the package |
| 326 * holding the libraries.dart file. | 417 * holding the libraries.dart file. |
| (...skipping 26 matching lines...) Expand all Loading... | |
| 353 * The name of the pub executable on non-windows operating systems. | 444 * The name of the pub executable on non-windows operating systems. |
| 354 */ | 445 */ |
| 355 static String _PUB_EXECUTABLE_NAME = "pub"; | 446 static String _PUB_EXECUTABLE_NAME = "pub"; |
| 356 | 447 |
| 357 /** | 448 /** |
| 358 * The name of the file within the SDK directory that contains the version | 449 * The name of the file within the SDK directory that contains the version |
| 359 * number of the SDK. | 450 * number of the SDK. |
| 360 */ | 451 */ |
| 361 static String _VERSION_FILE_NAME = "version"; | 452 static String _VERSION_FILE_NAME = "version"; |
| 362 | 453 |
| 363 /** | 454 // /** |
| 364 * The name of the file containing the VM executable on the Windows operating | 455 // * The name of the file containing the VM executable on the Windows operatin g |
| 365 * system. | 456 // * system. |
| 366 */ | 457 // */ |
| 367 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; | 458 // static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; |
| 368 | 459 // |
| 369 /** | 460 // /** |
| 370 * The name of the file containing the VM executable on non-Windows operating | 461 // * The name of the file containing the VM executable on non-Windows operatin g |
| 371 * systems. | 462 // * systems. |
| 372 */ | 463 // */ |
| 373 static String _VM_EXECUTABLE_NAME = "dart"; | 464 // static String _VM_EXECUTABLE_NAME = "dart"; |
| 374 | |
| 375 /** | |
| 376 * Return the default Dart SDK, or `null` if the directory containing the | |
| 377 * default SDK cannot be determined (or does not exist). | |
| 378 */ | |
| 379 static DirectoryBasedDartSdk get defaultSdk { | |
| 380 if (_DEFAULT_SDK == null) { | |
| 381 JavaFile sdkDirectory = defaultSdkDirectory; | |
| 382 if (sdkDirectory == null) { | |
| 383 return null; | |
| 384 } | |
| 385 _DEFAULT_SDK = new DirectoryBasedDartSdk(sdkDirectory); | |
| 386 } | |
| 387 return _DEFAULT_SDK; | |
| 388 } | |
| 389 | |
| 390 /** | |
| 391 * Return the default directory for the Dart SDK, or `null` if the directory | |
| 392 * cannot be determined (or does not exist). The default directory is provided | |
| 393 * by a system property named `com.google.dart.sdk`. | |
| 394 */ | |
| 395 static JavaFile get defaultSdkDirectory { | |
| 396 String sdkProperty = | |
| 397 JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NAME); | |
| 398 if (sdkProperty == null) { | |
| 399 return null; | |
| 400 } | |
| 401 JavaFile sdkDirectory = new JavaFile(sdkProperty); | |
| 402 if (!sdkDirectory.exists()) { | |
| 403 return null; | |
| 404 } | |
| 405 return sdkDirectory; | |
| 406 } | |
| 407 | 465 |
| 408 /** | 466 /** |
| 409 * The directory containing the SDK. | 467 * The directory containing the SDK. |
| 410 */ | 468 */ |
| 411 JavaFile _sdkDirectory; | 469 Folder _sdkDirectory; |
| 412 | 470 |
| 413 /** | 471 /** |
| 414 * The directory within the SDK directory that contains the libraries. | 472 * The directory within the SDK directory that contains the libraries. |
| 415 */ | 473 */ |
| 416 JavaFile _libraryDirectory; | 474 Folder _libraryDirectory; |
| 417 | 475 |
| 418 /** | 476 /** |
| 419 * The revision number of this SDK, or `"0"` if the revision number cannot be | 477 * The revision number of this SDK, or `"0"` if the revision number cannot be |
| 420 * discovered. | 478 * discovered. |
| 421 */ | 479 */ |
| 422 String _sdkVersion; | 480 String _sdkVersion; |
| 423 | 481 |
| 424 /** | 482 // /** |
| 425 * The file containing the dart2js executable. | 483 // * The file containing the dart2js executable. |
| 426 */ | 484 // */ |
| 427 JavaFile _dart2jsExecutable; | 485 // File _dart2jsExecutable; |
| 428 | 486 // |
| 429 /** | 487 // /** |
| 430 * The file containing the Dartium executable. | 488 // * The file containing the Dartium executable. |
| 431 */ | 489 // */ |
| 432 JavaFile _dartiumExecutable; | 490 // File _dartiumExecutable; |
| 433 | 491 |
| 434 /** | 492 /** |
| 435 * The file containing the pub executable. | 493 * The file containing the pub executable. |
| 436 */ | 494 */ |
| 437 JavaFile _pubExecutable; | 495 File _pubExecutable; |
| 438 | 496 |
| 439 /** | 497 // /** |
| 440 * The file containing the VM executable. | 498 // * The file containing the VM executable. |
| 441 */ | 499 // */ |
| 442 JavaFile _vmExecutable; | 500 // File _vmExecutable; |
| 443 | 501 |
| 444 /** | 502 /** |
| 445 * Initialize a newly created SDK to represent the Dart SDK installed in the | 503 * Initialize a newly created SDK to represent the Dart SDK installed in the |
| 446 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path | 504 * [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path |
| 447 * should be used when it is available | 505 * should be used when it is available |
| 448 */ | 506 */ |
| 449 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { | 507 FolderBasedDartSdk(ResourceProvider resourceProvider, this._sdkDirectory, |
| 450 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | 508 [bool useDart2jsPaths = false]) { |
| 509 this.resourceProvider = resourceProvider; | |
| 451 libraryMap = initialLibraryMap(useDart2jsPaths); | 510 libraryMap = initialLibraryMap(useDart2jsPaths); |
| 452 } | 511 } |
| 453 | 512 |
| 454 /** | 513 // /** |
| 455 * Return the file containing the dart2js executable, or `null` if it does not | 514 // * Return the file containing the dart2js executable, or `null` if it does n ot |
| 456 * exist. | 515 // * exist. |
| 457 */ | 516 // */ |
| 458 JavaFile get dart2JsExecutable { | 517 // File get dart2JsExecutable { |
| 459 if (_dart2jsExecutable == null) { | 518 // if (_dart2jsExecutable == null) { |
| 460 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( | 519 // _dart2jsExecutable = _verifyExecutable(_sdkDirectory |
| 461 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 520 // .getChildAssumingFolder(_BIN_DIRECTORY_NAME) |
| 462 OSUtilities.isWindows() | 521 // .getChildAssumingFile(OSUtilities.isWindows() |
| 463 ? _DART2JS_EXECUTABLE_NAME_WIN | 522 // ? _DART2JS_EXECUTABLE_NAME_WIN |
| 464 : _DART2JS_EXECUTABLE_NAME)); | 523 // : _DART2JS_EXECUTABLE_NAME)); |
| 465 } | 524 // } |
| 466 return _dart2jsExecutable; | 525 // return _dart2jsExecutable; |
| 467 } | 526 // } |
| 468 | 527 // |
| 469 /** | 528 // /** |
| 470 * Return the name of the file containing the Dartium executable. | 529 // * Return the name of the file containing the Dartium executable. |
| 471 */ | 530 // */ |
| 472 String get dartiumBinaryName { | 531 // String get dartiumBinaryName { |
| 473 if (OSUtilities.isWindows()) { | 532 // if (OSUtilities.isWindows()) { |
| 474 return _DARTIUM_EXECUTABLE_NAME_WIN; | 533 // return _DARTIUM_EXECUTABLE_NAME_WIN; |
| 475 } else if (OSUtilities.isMac()) { | 534 // } else if (OSUtilities.isMac()) { |
| 476 return _DARTIUM_EXECUTABLE_NAME_MAC; | 535 // return _DARTIUM_EXECUTABLE_NAME_MAC; |
| 477 } else { | 536 // } else { |
| 478 return _DARTIUM_EXECUTABLE_NAME_LINUX; | 537 // return _DARTIUM_EXECUTABLE_NAME_LINUX; |
| 479 } | 538 // } |
| 480 } | 539 // } |
| 481 | 540 // |
| 482 /** | 541 // /** |
| 483 * Return the file containing the Dartium executable, or `null` if it does not | 542 // * Return the file containing the Dartium executable, or `null` if it does n ot |
| 484 * exist. | 543 // * exist. |
| 485 */ | 544 // */ |
| 486 JavaFile get dartiumExecutable { | 545 // File get dartiumExecutable { |
| 487 if (_dartiumExecutable == null) { | 546 // if (_dartiumExecutable == null) { |
| 488 _dartiumExecutable = _verifyExecutable( | 547 // _dartiumExecutable = _verifyExecutable( |
| 489 new JavaFile.relative(dartiumWorkingDirectory, dartiumBinaryName)); | 548 // dartiumWorkingDirectory.getChildAssumingFile(dartiumBinaryName)); |
| 490 } | 549 // } |
| 491 return _dartiumExecutable; | 550 // return _dartiumExecutable; |
| 492 } | 551 // } |
| 493 | 552 // |
| 494 /** | 553 // /** |
| 495 * Return the directory where dartium can be found (the directory that will be | 554 // * Return the directory where dartium can be found (the directory that will be |
| 496 * the working directory is Dartium is invoked without changing the default). | 555 // * the working directory is Dartium is invoked without changing the default) . |
| 497 */ | 556 // */ |
| 498 JavaFile get dartiumWorkingDirectory => | 557 // Folder get dartiumWorkingDirectory => |
| 499 getDartiumWorkingDirectory(_sdkDirectory.getParentFile()); | 558 // getDartiumWorkingDirectory(_sdkDirectory.parent); |
| 500 | 559 |
| 501 /** | 560 /** |
| 502 * Return the directory containing the SDK. | 561 * Return the directory containing the SDK. |
| 503 */ | 562 */ |
| 504 JavaFile get directory => _sdkDirectory; | 563 Folder get directory => _sdkDirectory; |
| 505 | 564 |
| 506 /** | 565 /** |
| 507 * Return the directory containing documentation for the SDK. | 566 * Return the directory containing documentation for the SDK. |
| 508 */ | 567 */ |
| 509 JavaFile get docDirectory => | 568 Folder get docDirectory => |
| 510 new JavaFile.relative(_sdkDirectory, _DOCS_DIRECTORY_NAME); | 569 _sdkDirectory.getChildAssumingFolder(_DOCS_DIRECTORY_NAME); |
| 511 | 570 |
| 512 /** | 571 // /** |
| 513 * Return `true` if this SDK includes documentation. | 572 // * Return `true` if this SDK includes documentation. |
| 514 */ | 573 // */ |
| 515 bool get hasDocumentation => docDirectory.exists(); | 574 // bool get hasDocumentation => docDirectory.exists; |
| 516 | 575 // |
| 517 /** | 576 // /** |
| 518 * Return `true` if the Dartium binary is available. | 577 // * Return `true` if the Dartium binary is available. |
| 519 */ | 578 // */ |
| 520 bool get isDartiumInstalled => dartiumExecutable != null; | 579 // bool get isDartiumInstalled => dartiumExecutable != null; |
| 521 | 580 |
| 522 /** | 581 /** |
| 523 * Return the directory within the SDK directory that contains the libraries. | 582 * Return the directory within the SDK directory that contains the libraries. |
| 524 */ | 583 */ |
| 525 JavaFile get libraryDirectory { | 584 Folder get libraryDirectory { |
| 526 if (_libraryDirectory == null) { | 585 if (_libraryDirectory == null) { |
| 527 _libraryDirectory = | 586 _libraryDirectory = |
| 528 new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); | 587 _sdkDirectory.getChildAssumingFolder(_LIB_DIRECTORY_NAME); |
| 529 } | 588 } |
| 530 return _libraryDirectory; | 589 return _libraryDirectory; |
| 531 } | 590 } |
| 532 | 591 |
| 533 /** | 592 /** |
| 534 * Return the file containing the Pub executable, or `null` if it does not exi st. | 593 * Return the file containing the Pub executable, or `null` if it does not exi st. |
| 535 */ | 594 */ |
| 536 JavaFile get pubExecutable { | 595 File get pubExecutable { |
| 537 if (_pubExecutable == null) { | 596 if (_pubExecutable == null) { |
| 538 _pubExecutable = _verifyExecutable(new JavaFile.relative( | 597 _pubExecutable = _sdkDirectory |
| 539 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 598 .getChildAssumingFolder(_BIN_DIRECTORY_NAME) |
| 540 OSUtilities.isWindows() | 599 .getChildAssumingFile(OSUtilities.isWindows() |
| 541 ? _PUB_EXECUTABLE_NAME_WIN | 600 ? _PUB_EXECUTABLE_NAME_WIN |
| 542 : _PUB_EXECUTABLE_NAME)); | 601 : _PUB_EXECUTABLE_NAME); |
| 543 } | 602 } |
| 544 return _pubExecutable; | 603 return _pubExecutable; |
| 545 } | 604 } |
| 546 | 605 |
| 547 /** | 606 /** |
| 548 * Return the revision number of this SDK, or `"0"` if the revision number | 607 * Return the revision number of this SDK, or `"0"` if the revision number |
| 549 * cannot be discovered. | 608 * cannot be discovered. |
| 550 */ | 609 */ |
| 551 @override | 610 @override |
| 552 String get sdkVersion { | 611 String get sdkVersion { |
| 553 if (_sdkVersion == null) { | 612 if (_sdkVersion == null) { |
| 554 _sdkVersion = DartSdk.DEFAULT_VERSION; | 613 _sdkVersion = DartSdk.DEFAULT_VERSION; |
| 555 JavaFile revisionFile = | 614 File revisionFile = |
| 556 new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); | 615 _sdkDirectory.getChildAssumingFile(_VERSION_FILE_NAME); |
| 557 try { | 616 try { |
| 558 String revision = revisionFile.readAsStringSync(); | 617 String revision = revisionFile.readAsStringSync(); |
| 559 if (revision != null) { | 618 if (revision != null) { |
| 560 _sdkVersion = revision.trim(); | 619 _sdkVersion = revision.trim(); |
| 561 } | 620 } |
| 562 } on FileSystemException { | 621 } on FileSystemException { |
| 563 // Fall through to return the default. | 622 // Fall through to return the default. |
| 564 } | 623 } |
| 565 } | 624 } |
| 566 return _sdkVersion; | 625 return _sdkVersion; |
| 567 } | 626 } |
| 568 | 627 |
| 569 /** | 628 // /** |
| 570 * Return the name of the file containing the VM executable. | 629 // * Return the name of the file containing the VM executable. |
| 571 */ | 630 // */ |
| 572 String get vmBinaryName { | 631 // String get vmBinaryName { |
| 573 if (OSUtilities.isWindows()) { | 632 // if (OSUtilities.isWindows()) { |
| 574 return _VM_EXECUTABLE_NAME_WIN; | 633 // return _VM_EXECUTABLE_NAME_WIN; |
| 575 } else { | 634 // } else { |
| 576 return _VM_EXECUTABLE_NAME; | 635 // return _VM_EXECUTABLE_NAME; |
| 577 } | 636 // } |
| 578 } | 637 // } |
| 579 | 638 // |
| 580 /** | 639 // /** |
| 581 * Return the file containing the VM executable, or `null` if it does not | 640 // * Return the file containing the VM executable, or `null` if it does not |
| 582 * exist. | 641 // * exist. |
| 583 */ | 642 // */ |
| 584 JavaFile get vmExecutable { | 643 // File get vmExecutable { |
| 585 if (_vmExecutable == null) { | 644 // if (_vmExecutable == null) { |
| 586 _vmExecutable = _verifyExecutable(new JavaFile.relative( | 645 // _vmExecutable = _verifyExecutable(_sdkDirectory |
| 587 new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), | 646 // .getChildAssumingFolder(_BIN_DIRECTORY_NAME) |
| 588 vmBinaryName)); | 647 // .getChildAssumingFile(vmBinaryName)); |
| 589 } | 648 // } |
| 590 return _vmExecutable; | 649 // return _vmExecutable; |
| 591 } | 650 // } |
| 592 | 651 |
| 593 /** | 652 /** |
| 594 * Determine the search order for trying to locate the [_LIBRARIES_FILE]. | 653 * Determine the search order for trying to locate the [_LIBRARIES_FILE]. |
| 595 */ | 654 */ |
| 596 Iterable<JavaFile> get _libraryMapLocations sync* { | 655 Iterable<File> get _libraryMapLocations sync* { |
| 597 yield new JavaFile.relative( | 656 yield libraryDirectory |
| 598 new JavaFile.relative( | 657 .getChildAssumingFolder(_INTERNAL_DIR) |
| 599 new JavaFile.relative( | 658 .getChildAssumingFolder(_SDK_LIBRARY_METADATA_DIR) |
| 600 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | 659 .getChildAssumingFolder(_SDK_LIBRARY_METADATA_LIB_DIR) |
| 601 _SDK_LIBRARY_METADATA_DIR), | 660 .getChildAssumingFile(_LIBRARIES_FILE); |
| 602 _SDK_LIBRARY_METADATA_LIB_DIR), | 661 yield libraryDirectory |
| 603 _LIBRARIES_FILE); | 662 .getChildAssumingFolder(_INTERNAL_DIR) |
| 604 yield new JavaFile.relative( | 663 .getChildAssumingFile(_LIBRARIES_FILE); |
| 605 new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), | |
| 606 _LIBRARIES_FILE); | |
| 607 } | 664 } |
| 608 | 665 |
| 609 /** | 666 // /** |
| 610 * Return the directory where dartium can be found (the directory that will be | 667 // * Return the directory where dartium can be found (the directory that will be |
| 611 * the working directory if Dartium is invoked without changing the default), | 668 // * the working directory if Dartium is invoked without changing the default) , |
| 612 * assuming that the Editor was installed in the [installDir]. | 669 // * assuming that the Editor was installed in the [installDir]. |
| 613 */ | 670 // */ |
| 614 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => | 671 // Folder getDartiumWorkingDirectory(Folder installDir) => |
| 615 new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); | 672 // installDir.getChildAssumingFolder(_DARTIUM_DIRECTORY_NAME); |
| 616 | 673 // |
| 617 /** | 674 // /** |
| 618 * Return the auxiliary documentation file for the library with the given | 675 // * Return the auxiliary documentation file for the library with the given |
| 619 * [libraryName], or `null` if no such file exists. | 676 // * [libraryName], or `null` if no such file exists. |
| 620 */ | 677 // */ |
| 621 JavaFile getDocFileFor(String libraryName) { | 678 // File getDocFileFor(String libraryName) { |
| 622 JavaFile dir = docDirectory; | 679 // Folder libDir = docDirectory.getChildAssumingFolder(libraryName); |
| 623 if (!dir.exists()) { | 680 // File docFile = libDir.getChildAssumingFile("$libraryName$_DOC_FILE_SUFFIX" ); |
| 624 return null; | 681 // if (docFile.exists) { |
| 625 } | 682 // return docFile; |
| 626 JavaFile libDir = new JavaFile.relative(dir, libraryName); | 683 // } |
| 627 JavaFile docFile = | 684 // return null; |
| 628 new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); | 685 // } |
| 629 if (docFile.exists()) { | |
| 630 return docFile; | |
| 631 } | |
| 632 return null; | |
| 633 } | |
| 634 | 686 |
| 635 @override | 687 @override |
| 636 String getRelativePathFromFile(JavaFile file) { | 688 String getRelativePathFromFile(File file) { |
| 637 String filePath = file.getAbsolutePath(); | 689 String filePath = file.path; |
| 638 String libPath = libraryDirectory.getAbsolutePath(); | 690 String libPath = libraryDirectory.path; |
| 639 if (!filePath.startsWith("$libPath${JavaFile.separator}")) { | 691 if (!filePath.startsWith("$libPath${pathos.separator}")) { |
| 640 return null; | 692 return null; |
| 641 } | 693 } |
| 642 return filePath.substring(libPath.length + 1); | 694 return filePath.substring(libPath.length + 1); |
| 643 } | 695 } |
| 644 | 696 |
| 645 /** | 697 /** |
| 646 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. | 698 * Return the [PackageBundle] for this SDK, if it exists, or `null` otherwise. |
| 647 * This method should not be used outside of `analyzer` and `analyzer_cli` | 699 * This method should not be used outside of `analyzer` and `analyzer_cli` |
| 648 * packages. | 700 * packages. |
| 649 */ | 701 */ |
| 650 PackageBundle getSummarySdkBundle(bool strongMode) { | 702 PackageBundle getSummarySdkBundle(bool strongMode) { |
| 651 String rootPath = directory.getAbsolutePath(); | 703 String rootPath = directory.path; |
| 652 String name = strongMode ? 'strong.sum' : 'spec.sum'; | 704 String name = strongMode ? 'strong.sum' : 'spec.sum'; |
| 653 String path = pathos.join(rootPath, 'lib', '_internal', name); | 705 String path = pathos.join(rootPath, 'lib', '_internal', name); |
| 654 try { | 706 try { |
| 655 File file = new File(path); | 707 File file = resourceProvider.getFile(path); |
| 656 if (file.existsSync()) { | 708 if (file.exists) { |
| 657 List<int> bytes = file.readAsBytesSync(); | 709 List<int> bytes = file.readAsBytesSync(); |
| 658 return new PackageBundle.fromBuffer(bytes); | 710 return new PackageBundle.fromBuffer(bytes); |
| 659 } | 711 } |
| 660 } catch (exception, stackTrace) { | 712 } catch (exception, stackTrace) { |
| 661 AnalysisEngine.instance.logger.logError( | 713 AnalysisEngine.instance.logger.logError( |
| 662 'Failed to load SDK analysis summary from $path', | 714 'Failed to load SDK analysis summary from $path', |
| 663 new CaughtException(exception, stackTrace)); | 715 new CaughtException(exception, stackTrace)); |
| 664 } | 716 } |
| 665 return null; | 717 return null; |
| 666 } | 718 } |
| 667 | 719 |
| 668 /** | 720 /** |
| 669 * Read all of the configuration files to initialize the library maps. The | 721 * Read all of the configuration files to initialize the library maps. The |
| 670 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it | 722 * flag [useDart2jsPaths] is `true` if the dart2js path should be used when it |
| 671 * is available. Return the initialized library map. | 723 * is available. Return the initialized library map. |
| 672 */ | 724 */ |
| 673 LibraryMap initialLibraryMap(bool useDart2jsPaths) { | 725 LibraryMap initialLibraryMap(bool useDart2jsPaths) { |
| 674 List<String> searchedPaths = <String>[]; | 726 List<String> searchedPaths = <String>[]; |
| 675 var lastStackTrace = null; | 727 var lastStackTrace = null; |
| 676 var lastException = null; | 728 var lastException = null; |
| 677 for (JavaFile librariesFile in _libraryMapLocations) { | 729 for (File librariesFile in _libraryMapLocations) { |
| 678 try { | 730 try { |
| 679 String contents = librariesFile.readAsStringSync(); | 731 String contents = librariesFile.readAsStringSync(); |
| 680 return new SdkLibrariesReader(useDart2jsPaths) | 732 return new SdkLibrariesReader(useDart2jsPaths) |
| 681 .readFromFile(librariesFile, contents); | 733 .readFromFile(librariesFile, contents); |
| 682 } catch (exception, stackTrace) { | 734 } catch (exception, stackTrace) { |
| 683 searchedPaths.add(librariesFile.getAbsolutePath()); | 735 searchedPaths.add(librariesFile.path); |
| 684 lastException = exception; | 736 lastException = exception; |
| 685 lastStackTrace = stackTrace; | 737 lastStackTrace = stackTrace; |
| 686 } | 738 } |
| 687 } | 739 } |
| 688 AnalysisEngine.instance.logger.logError( | 740 AnalysisEngine.instance.logger.logError( |
| 689 "Could not initialize the library map from $searchedPaths", | 741 "Could not initialize the library map from $searchedPaths", |
| 690 new CaughtException(lastException, lastStackTrace)); | 742 new CaughtException(lastException, lastStackTrace)); |
| 691 return new LibraryMap(); | 743 return new LibraryMap(); |
| 692 } | 744 } |
| 693 | 745 |
| 694 @override | 746 @override |
| 695 FileBasedSource internalMapDartUri(String dartUri) { | 747 Source internalMapDartUri(String dartUri) { |
| 696 String libraryName; | 748 String libraryName; |
| 697 String relativePath; | 749 String relativePath; |
| 698 int index = dartUri.indexOf('/'); | 750 int index = dartUri.indexOf('/'); |
| 699 if (index >= 0) { | 751 if (index >= 0) { |
| 700 libraryName = dartUri.substring(0, index); | 752 libraryName = dartUri.substring(0, index); |
| 701 relativePath = dartUri.substring(index + 1); | 753 relativePath = dartUri.substring(index + 1); |
| 702 } else { | 754 } else { |
| 703 libraryName = dartUri; | 755 libraryName = dartUri; |
| 704 relativePath = ""; | 756 relativePath = ""; |
| 705 } | 757 } |
| 706 SdkLibrary library = getSdkLibrary(libraryName); | 758 SdkLibrary library = getSdkLibrary(libraryName); |
| 707 if (library == null) { | 759 if (library == null) { |
| 708 return null; | 760 return null; |
| 709 } | 761 } |
| 710 try { | 762 try { |
| 711 JavaFile file = new JavaFile.relative(libraryDirectory, library.path); | 763 File file = libraryDirectory.getChildAssumingFile(library.path); |
| 712 if (!relativePath.isEmpty) { | 764 if (!relativePath.isEmpty) { |
| 713 file = file.getParentFile(); | 765 file = file.parent.getChildAssumingFile(relativePath); |
| 714 file = new JavaFile.relative(file, relativePath); | |
| 715 } | 766 } |
| 716 return new FileBasedSource(file, parseUriWithException(dartUri)); | 767 return file.createSource(parseUriWithException(dartUri)); |
| 717 } on URISyntaxException { | 768 } on URISyntaxException { |
| 718 return null; | 769 return null; |
| 719 } | 770 } |
| 720 } | 771 } |
| 721 | 772 |
| 722 /** | 773 /** |
| 723 * Return the given [file] if it exists and is executable, or `null` if it | 774 * Return the default directory for the Dart SDK, or `null` if the directory |
| 724 * does not exist or is not executable. | 775 * cannot be determined (or does not exist). The default directory is provided |
| 776 * by a system property named `com.google.dart.sdk`. | |
| 725 */ | 777 */ |
| 726 JavaFile _verifyExecutable(JavaFile file) => | 778 static Folder defaultSdkDirectory(ResourceProvider resourceProvider) { |
| 727 file.isExecutable() ? file : null; | 779 // TODO(brianwilkerson) This is currently only being used in the analysis |
| 780 // server's Driver class to find the default SDK. The command-line analyzer | |
| 781 // uses cli_utils to find the SDK. Not sure why they're different. | |
| 782 String sdkProperty = getSdkProperty(resourceProvider); | |
| 783 if (sdkProperty == null) { | |
| 784 return null; | |
| 785 } | |
| 786 Folder sdkDirectory = resourceProvider.getFolder(sdkProperty); | |
| 787 if (!sdkDirectory.exists) { | |
| 788 return null; | |
| 789 } | |
| 790 return sdkDirectory; | |
| 791 } | |
| 792 | |
| 793 static String getSdkProperty(ResourceProvider resourceProvider) { | |
| 794 String exec = io.Platform.executable; | |
| 795 if (exec.length == 0) { | |
| 796 return null; | |
| 797 } | |
| 798 pathos.Context pathContext = resourceProvider.pathContext; | |
| 799 // Might be "xcodebuild/ReleaseIA32/dart" with "sdk" sibling | |
| 800 String outDir = pathContext.dirname(pathContext.dirname(exec)); | |
| 801 String sdkPath = pathContext.join(pathContext.dirname(outDir), "sdk"); | |
| 802 if (resourceProvider.getFolder(sdkPath).exists) { | |
| 803 return sdkPath; | |
| 804 } | |
| 805 // probably be "dart-sdk/bin/dart" | |
| 806 return pathContext.dirname(pathContext.dirname(exec)); | |
| 807 } | |
| 728 } | 808 } |
| 729 | 809 |
| 730 /** | 810 /** |
| 731 * An object used to read and parse the libraries file | 811 * An object used to read and parse the libraries file |
| 732 * (dart-sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart) for informat ion | 812 * (dart-sdk/lib/_internal/sdk_library_metadata/lib/libraries.dart) for informat ion |
| 733 * about the libraries in an SDK. The library information is represented as a | 813 * about the libraries in an SDK. The library information is represented as a |
| 734 * Dart file containing a single top-level variable whose value is a const map. | 814 * Dart file containing a single top-level variable whose value is a const map. |
| 735 * The keys of the map are the names of libraries defined in the SDK and the | 815 * The keys of the map are the names of libraries defined in the SDK and the |
| 736 * values in the map are info objects defining the library. For example, a | 816 * values in the map are info objects defining the library. For example, a |
| 737 * subset of a typical SDK might have a libraries file that looks like the | 817 * subset of a typical SDK might have a libraries file that looks like the |
| (...skipping 22 matching lines...) Expand all Loading... | |
| 760 /** | 840 /** |
| 761 * Initialize a newly created library reader to use the dart2js path if | 841 * Initialize a newly created library reader to use the dart2js path if |
| 762 * [_useDart2jsPaths] is `true`. | 842 * [_useDart2jsPaths] is `true`. |
| 763 */ | 843 */ |
| 764 SdkLibrariesReader(this._useDart2jsPaths); | 844 SdkLibrariesReader(this._useDart2jsPaths); |
| 765 | 845 |
| 766 /** | 846 /** |
| 767 * Return the library map read from the given [file], given that the content | 847 * Return the library map read from the given [file], given that the content |
| 768 * of the file is already known to be [libraryFileContents]. | 848 * of the file is already known to be [libraryFileContents]. |
| 769 */ | 849 */ |
| 770 LibraryMap readFromFile(JavaFile file, String libraryFileContents) => | 850 LibraryMap readFromFile(File file, String libraryFileContents) => |
| 771 readFromSource(new FileBasedSource(file), libraryFileContents); | 851 readFromSource(file.createSource(), libraryFileContents); |
| 772 | 852 |
| 773 /** | 853 /** |
| 774 * Return the library map read from the given [source], given that the content | 854 * Return the library map read from the given [source], given that the content |
| 775 * of the file is already known to be [libraryFileContents]. | 855 * of the file is already known to be [libraryFileContents]. |
| 776 */ | 856 */ |
| 777 LibraryMap readFromSource(Source source, String libraryFileContents) { | 857 LibraryMap readFromSource(Source source, String libraryFileContents) { |
| 778 BooleanErrorListener errorListener = new BooleanErrorListener(); | 858 BooleanErrorListener errorListener = new BooleanErrorListener(); |
| 779 Scanner scanner = new Scanner( | 859 Scanner scanner = new Scanner( |
| 780 source, new CharSequenceReader(libraryFileContents), errorListener); | 860 source, new CharSequenceReader(libraryFileContents), errorListener); |
| 781 Parser parser = new Parser(source, errorListener); | 861 Parser parser = new Parser(source, errorListener); |
| 782 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); | 862 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); |
| 783 SdkLibrariesReader_LibraryBuilder libraryBuilder = | 863 SdkLibrariesReader_LibraryBuilder libraryBuilder = |
| 784 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); | 864 new SdkLibrariesReader_LibraryBuilder(_useDart2jsPaths); |
| 785 // If any syntactic errors were found then don't try to visit the AST | 865 // If any syntactic errors were found then don't try to visit the AST |
| 786 // structure. | 866 // structure. |
| 787 if (!errorListener.errorReported) { | 867 if (!errorListener.errorReported) { |
| 788 unit.accept(libraryBuilder); | 868 unit.accept(libraryBuilder); |
| 789 } | 869 } |
| 790 return libraryBuilder.librariesMap; | 870 return libraryBuilder.librariesMap; |
| 791 } | 871 } |
| 792 } | 872 } |
| OLD | NEW |