Index: pkg/analyzer/lib/src/dart/sdk/sdk.dart |
diff --git a/pkg/analyzer/lib/src/generated/sdk_io.dart b/pkg/analyzer/lib/src/dart/sdk/sdk.dart |
similarity index 60% |
copy from pkg/analyzer/lib/src/generated/sdk_io.dart |
copy to pkg/analyzer/lib/src/dart/sdk/sdk.dart |
index 50cb9d066fb7cf512c51c2c6c888ef6499a923f4..bbde2ed279e5f28b4e410a17fb88f0ca2cb049cc 100644 |
--- a/pkg/analyzer/lib/src/generated/sdk_io.dart |
+++ b/pkg/analyzer/lib/src/dart/sdk/sdk.dart |
@@ -1,13 +1,14 @@ |
-// Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
+// Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file |
// for details. All rights reserved. Use of this source code is governed by a |
// BSD-style license that can be found in the LICENSE file. |
-library analyzer.src.generated.sdk_io; |
+library analyzer.src.generated.sdk2; |
import 'dart:collection'; |
-import 'dart:io'; |
+import 'dart:io' as io; |
import 'package:analyzer/dart/ast/ast.dart'; |
+import 'package:analyzer/file_system/file_system.dart'; |
import 'package:analyzer/src/context/context.dart'; |
import 'package:analyzer/src/dart/scanner/reader.dart'; |
import 'package:analyzer/src/dart/scanner/scanner.dart'; |
@@ -16,13 +17,13 @@ import 'package:analyzer/src/generated/error.dart'; |
import 'package:analyzer/src/generated/java_core.dart'; |
import 'package:analyzer/src/generated/java_engine.dart'; |
import 'package:analyzer/src/generated/java_engine_io.dart'; |
-import 'package:analyzer/src/generated/java_io.dart'; |
import 'package:analyzer/src/generated/parser.dart'; |
import 'package:analyzer/src/generated/sdk.dart'; |
import 'package:analyzer/src/generated/source_io.dart'; |
import 'package:analyzer/src/summary/idl.dart' show PackageBundle; |
import 'package:analyzer/src/summary/summary_sdk.dart'; |
import 'package:path/path.dart' as pathos; |
+import 'package:yaml/yaml.dart'; |
/** |
* An abstract implementation of a Dart SDK in which the available libraries are |
@@ -31,6 +32,11 @@ import 'package:path/path.dart' as pathos; |
*/ |
abstract class AbstractDartSdk implements DartSdk { |
/** |
+ * The resource provider used to access the file system. |
+ */ |
+ ResourceProvider resourceProvider; |
+ |
+ /** |
* A mapping from Dart library URI's to the library represented by that URI. |
*/ |
LibraryMap libraryMap = new LibraryMap(); |
@@ -108,30 +114,16 @@ abstract class AbstractDartSdk implements DartSdk { |
_useSummary = use; |
} |
- /** |
- * Add the extensions from one or more sdk extension files to this sdk. The |
- * [extensions] should be a table mapping the names of extensions to the paths |
- * where those extensions can be found. |
- */ |
- void addExtensions(Map<String, String> extensions) { |
- extensions.forEach((String uri, String path) { |
- String shortName = uri.substring(uri.indexOf(':') + 1); |
- SdkLibraryImpl library = new SdkLibraryImpl(shortName); |
- library.path = path; |
- libraryMap.setLibrary(uri, library); |
- }); |
- } |
- |
@override |
Source fromFileUri(Uri uri) { |
- JavaFile file = new JavaFile.fromUri(uri); |
+ File file = resourceProvider.getFile(uri.toFilePath(windows: false)); |
String path = _getPath(file); |
if (path == null) { |
return null; |
} |
try { |
- return new FileBasedSource(file, parseUriWithException(path)); |
+ return file.createSource(parseUriWithException(path)); |
} on URISyntaxException catch (exception, stackTrace) { |
AnalysisEngine.instance.logger.logInformation( |
"Failed to create URI: $path", |
@@ -140,7 +132,7 @@ abstract class AbstractDartSdk implements DartSdk { |
return null; |
} |
- String getRelativePathFromFile(JavaFile file); |
+ String getRelativePathFromFile(File file); |
@override |
SdkLibrary getSdkLibrary(String dartUri) => libraryMap.getLibrary(dartUri); |
@@ -152,7 +144,7 @@ abstract class AbstractDartSdk implements DartSdk { |
*/ |
PackageBundle getSummarySdkBundle(bool strongMode); |
- FileBasedSource internalMapDartUri(String dartUri) { |
+ Source internalMapDartUri(String dartUri) { |
// TODO(brianwilkerson) Figure out how to unify the implementations in the |
// two subclasses. |
String libraryName; |
@@ -174,7 +166,7 @@ abstract class AbstractDartSdk implements DartSdk { |
srcPath = library.path; |
} else { |
String libraryPath = library.path; |
- int index = libraryPath.lastIndexOf(JavaFile.separator); |
+ int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator); |
if (index == -1) { |
index = libraryPath.lastIndexOf('/'); |
if (index == -1) { |
@@ -184,10 +176,10 @@ abstract class AbstractDartSdk implements DartSdk { |
String prefix = libraryPath.substring(0, index + 1); |
srcPath = '$prefix$relativePath'; |
} |
- String filePath = srcPath.replaceAll('/', JavaFile.separator); |
+ String filePath = srcPath.replaceAll('/', resourceProvider.pathContext.separator); |
try { |
- JavaFile file = new JavaFile(filePath); |
- return new FileBasedSource(file, parseUriWithException(dartUri)); |
+ File file = resourceProvider.getFile(filePath); |
+ return file.createSource(parseUriWithException(dartUri)); |
} on URISyntaxException { |
return null; |
} |
@@ -203,7 +195,7 @@ abstract class AbstractDartSdk implements DartSdk { |
return source; |
} |
- String _getPath(JavaFile file) { |
+ String _getPath(File file) { |
List<SdkLibrary> libraries = libraryMap.sdkLibraries; |
int length = libraries.length; |
List<String> paths = new List(length); |
@@ -213,7 +205,7 @@ abstract class AbstractDartSdk implements DartSdk { |
} |
for (int i = 0; i < length; i++) { |
SdkLibrary library = libraries[i]; |
- String libraryPath = library.path.replaceAll('/', JavaFile.separator); |
+ String libraryPath = library.path.replaceAll('/', resourceProvider.pathContext.separator); |
if (filePath == libraryPath) { |
return library.shortName; |
} |
@@ -222,13 +214,13 @@ abstract class AbstractDartSdk implements DartSdk { |
for (int i = 0; i < length; i++) { |
SdkLibrary library = libraries[i]; |
String libraryPath = paths[i]; |
- int index = libraryPath.lastIndexOf(JavaFile.separator); |
+ int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator); |
if (index >= 0) { |
String prefix = libraryPath.substring(0, index + 1); |
if (filePath.startsWith(prefix)) { |
String relPath = filePath |
.substring(prefix.length) |
- .replaceAll(JavaFile.separator, '/'); |
+ .replaceAll(resourceProvider.pathContext.separator, '/'); |
return '${library.shortName}/$relPath'; |
} |
} |
@@ -238,6 +230,111 @@ abstract class AbstractDartSdk implements DartSdk { |
} |
/** |
+ * An SDK backed by URI mappings derived from an `_embedder.yaml` file. |
+ */ |
+class EmbedderSdk extends AbstractDartSdk { |
+ static const String _DART_COLON_PREFIX = 'dart:'; |
+ |
+ static const String _EMBEDDED_LIB_MAP_KEY = 'embedded_libs'; |
+ final Map<String, String> _urlMappings = new HashMap<String, String>(); |
+ |
+ EmbedderSdk( |
+ ResourceProvider resourceProvider, Map<Folder, YamlMap> embedderYamls) { |
+ this.resourceProvider = resourceProvider; |
+ embedderYamls?.forEach(_processEmbedderYaml); |
+ } |
+ |
+ @override |
+ // TODO(danrubel) Determine SDK version |
+ String get sdkVersion => '0'; |
+ |
+ /** |
+ * The url mappings for this SDK. |
+ */ |
+ Map<String, String> get urlMappings => _urlMappings; |
+ |
+ @override |
+ String getRelativePathFromFile(File file) => file.path; |
+ |
+ @override |
+ PackageBundle getSummarySdkBundle(bool strongMode) => null; |
+ |
+ @override |
+ Source internalMapDartUri(String dartUri) { |
+ String libraryName; |
+ String relativePath; |
+ int index = dartUri.indexOf('/'); |
+ if (index >= 0) { |
+ libraryName = dartUri.substring(0, index); |
+ relativePath = dartUri.substring(index + 1); |
+ } else { |
+ libraryName = dartUri; |
+ relativePath = ""; |
+ } |
+ SdkLibrary library = getSdkLibrary(libraryName); |
+ if (library == null) { |
+ return null; |
+ } |
+ String srcPath; |
+ if (relativePath.isEmpty) { |
+ srcPath = library.path; |
+ } else { |
+ String libraryPath = library.path; |
+ int index = libraryPath.lastIndexOf(resourceProvider.pathContext.separator); |
+ if (index == -1) { |
+ index = libraryPath.lastIndexOf('/'); |
+ if (index == -1) { |
+ return null; |
+ } |
+ } |
+ String prefix = libraryPath.substring(0, index + 1); |
+ srcPath = '$prefix$relativePath'; |
+ } |
+ String filePath = srcPath.replaceAll('/', resourceProvider.pathContext.separator); |
+ try { |
+ File file = resourceProvider.getFile(filePath); |
+ return file.createSource(parseUriWithException(dartUri)); |
+ } on URISyntaxException { |
+ return null; |
+ } |
+ } |
+ |
+ /** |
+ * Install the mapping from [name] to [libDir]/[file]. |
+ */ |
+ void _processEmbeddedLibs(String name, String file, Folder libDir) { |
+ if (!name.startsWith(_DART_COLON_PREFIX)) { |
+ // SDK libraries must begin with 'dart:'. |
+ return; |
+ } |
+ String libPath = libDir.canonicalizePath(file); |
+ _urlMappings[name] = libPath; |
+ SdkLibraryImpl library = new SdkLibraryImpl(name); |
+ library.path = libPath; |
+ libraryMap.setLibrary(name, library); |
+ } |
+ |
+ /** |
+ * Given the 'embedderYamls' from [EmbedderYamlLocator] check each one for the |
+ * top level key 'embedded_libs'. Under the 'embedded_libs' key are key value |
+ * pairs. Each key is a 'dart:' library uri and each value is a path |
+ * (relative to the directory containing `_embedder.yaml`) to a dart script |
+ * for the given library. For example: |
+ * |
+ * embedded_libs: |
+ * 'dart:io': '../../sdk/io/io.dart' |
+ * |
+ * If a key doesn't begin with `dart:` it is ignored. |
+ */ |
+ void _processEmbedderYaml(Folder libDir, YamlMap map) { |
+ YamlNode embedded_libs = map[_EMBEDDED_LIB_MAP_KEY]; |
+ if (embedded_libs is YamlMap) { |
+ embedded_libs.forEach((k, v) => _processEmbeddedLibs(k, v, libDir)); |
+ } |
+ } |
+} |
+ |
+/** |
* A Dart SDK installed in a specified directory. Typical Dart SDK layout is |
* something like... |
* |
@@ -253,13 +350,7 @@ abstract class AbstractDartSdk implements DartSdk { |
* ... Dart utilities ... |
* Chromium/ <-- Dartium typically exists in a sibling directory |
*/ |
-class DirectoryBasedDartSdk extends AbstractDartSdk { |
- /** |
- * The default SDK, or `null` if the default SDK either has not yet been |
- * created or cannot be created for some reason. |
- */ |
- static DirectoryBasedDartSdk _DEFAULT_SDK; |
- |
+class FolderBasedDartSdk extends AbstractDartSdk { |
/** |
* The name of the directory within the SDK directory that contains |
* executables. |
@@ -267,55 +358,12 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
static String _BIN_DIRECTORY_NAME = "bin"; |
/** |
- * The name of the directory on non-Mac that contains dartium. |
- */ |
- static String _DARTIUM_DIRECTORY_NAME = "chromium"; |
- |
- /** |
- * The name of the dart2js executable on non-windows operating systems. |
- */ |
- static String _DART2JS_EXECUTABLE_NAME = "dart2js"; |
- |
- /** |
- * The name of the file containing the dart2js executable on Windows. |
- */ |
- static String _DART2JS_EXECUTABLE_NAME_WIN = "dart2js.bat"; |
- |
- /** |
- * The name of the file containing the Dartium executable on Linux. |
- */ |
- static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome"; |
- |
- /** |
- * The name of the file containing the Dartium executable on Macintosh. |
- */ |
- static String _DARTIUM_EXECUTABLE_NAME_MAC = |
- "Chromium.app/Contents/MacOS/Chromium"; |
- |
- /** |
- * The name of the file containing the Dartium executable on Windows. |
- */ |
- static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe"; |
- |
- /** |
- * The name of the [System] property whose value is the path to the default |
- * Dart SDK directory. |
- */ |
- static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; |
- |
- /** |
* The name of the directory within the SDK directory that contains |
* documentation for the libraries. |
*/ |
static String _DOCS_DIRECTORY_NAME = "docs"; |
/** |
- * The suffix added to the name of a library to derive the name of the file |
- * containing the documentation for that library. |
- */ |
- static String _DOC_FILE_SUFFIX = "_api.json"; |
- |
- /** |
* The name of the directory within the SDK directory that contains the |
* sdk_library_metadata directory. |
*/ |
@@ -361,59 +409,14 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
static String _VERSION_FILE_NAME = "version"; |
/** |
- * The name of the file containing the VM executable on the Windows operating |
- * system. |
- */ |
- static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; |
- |
- /** |
- * The name of the file containing the VM executable on non-Windows operating |
- * systems. |
- */ |
- static String _VM_EXECUTABLE_NAME = "dart"; |
- |
- /** |
- * Return the default Dart SDK, or `null` if the directory containing the |
- * default SDK cannot be determined (or does not exist). |
- */ |
- static DirectoryBasedDartSdk get defaultSdk { |
- if (_DEFAULT_SDK == null) { |
- JavaFile sdkDirectory = defaultSdkDirectory; |
- if (sdkDirectory == null) { |
- return null; |
- } |
- _DEFAULT_SDK = new DirectoryBasedDartSdk(sdkDirectory); |
- } |
- return _DEFAULT_SDK; |
- } |
- |
- /** |
- * Return the default directory for the Dart SDK, or `null` if the directory |
- * cannot be determined (or does not exist). The default directory is provided |
- * by a system property named `com.google.dart.sdk`. |
- */ |
- static JavaFile get defaultSdkDirectory { |
- String sdkProperty = |
- JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NAME); |
- if (sdkProperty == null) { |
- return null; |
- } |
- JavaFile sdkDirectory = new JavaFile(sdkProperty); |
- if (!sdkDirectory.exists()) { |
- return null; |
- } |
- return sdkDirectory; |
- } |
- |
- /** |
* The directory containing the SDK. |
*/ |
- JavaFile _sdkDirectory; |
+ Folder _sdkDirectory; |
/** |
* The directory within the SDK directory that contains the libraries. |
*/ |
- JavaFile _libraryDirectory; |
+ Folder _libraryDirectory; |
/** |
* The revision number of this SDK, or `"0"` if the revision number cannot be |
@@ -422,110 +425,39 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
String _sdkVersion; |
/** |
- * The file containing the dart2js executable. |
- */ |
- JavaFile _dart2jsExecutable; |
- |
- /** |
- * The file containing the Dartium executable. |
- */ |
- JavaFile _dartiumExecutable; |
- |
- /** |
* The file containing the pub executable. |
*/ |
- JavaFile _pubExecutable; |
- |
- /** |
- * The file containing the VM executable. |
- */ |
- JavaFile _vmExecutable; |
+ File _pubExecutable; |
/** |
* Initialize a newly created SDK to represent the Dart SDK installed in the |
* [sdkDirectory]. The flag [useDart2jsPaths] is `true` if the dart2js path |
* should be used when it is available |
*/ |
- DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) { |
- this._sdkDirectory = sdkDirectory.getAbsoluteFile(); |
+ FolderBasedDartSdk(ResourceProvider resourceProvider, this._sdkDirectory, |
+ [bool useDart2jsPaths = false]) { |
+ this.resourceProvider = resourceProvider; |
libraryMap = initialLibraryMap(useDart2jsPaths); |
} |
/** |
- * Return the file containing the dart2js executable, or `null` if it does not |
- * exist. |
- */ |
- JavaFile get dart2JsExecutable { |
- if (_dart2jsExecutable == null) { |
- _dart2jsExecutable = _verifyExecutable(new JavaFile.relative( |
- new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
- OSUtilities.isWindows() |
- ? _DART2JS_EXECUTABLE_NAME_WIN |
- : _DART2JS_EXECUTABLE_NAME)); |
- } |
- return _dart2jsExecutable; |
- } |
- |
- /** |
- * Return the name of the file containing the Dartium executable. |
- */ |
- String get dartiumBinaryName { |
- if (OSUtilities.isWindows()) { |
- return _DARTIUM_EXECUTABLE_NAME_WIN; |
- } else if (OSUtilities.isMac()) { |
- return _DARTIUM_EXECUTABLE_NAME_MAC; |
- } else { |
- return _DARTIUM_EXECUTABLE_NAME_LINUX; |
- } |
- } |
- |
- /** |
- * Return the file containing the Dartium executable, or `null` if it does not |
- * exist. |
- */ |
- JavaFile get dartiumExecutable { |
- if (_dartiumExecutable == null) { |
- _dartiumExecutable = _verifyExecutable( |
- new JavaFile.relative(dartiumWorkingDirectory, dartiumBinaryName)); |
- } |
- return _dartiumExecutable; |
- } |
- |
- /** |
- * Return the directory where dartium can be found (the directory that will be |
- * the working directory is Dartium is invoked without changing the default). |
- */ |
- JavaFile get dartiumWorkingDirectory => |
- getDartiumWorkingDirectory(_sdkDirectory.getParentFile()); |
- |
- /** |
* Return the directory containing the SDK. |
*/ |
- JavaFile get directory => _sdkDirectory; |
+ Folder get directory => _sdkDirectory; |
/** |
* Return the directory containing documentation for the SDK. |
*/ |
- JavaFile get docDirectory => |
- new JavaFile.relative(_sdkDirectory, _DOCS_DIRECTORY_NAME); |
- |
- /** |
- * Return `true` if this SDK includes documentation. |
- */ |
- bool get hasDocumentation => docDirectory.exists(); |
- |
- /** |
- * Return `true` if the Dartium binary is available. |
- */ |
- bool get isDartiumInstalled => dartiumExecutable != null; |
+ Folder get docDirectory => |
+ _sdkDirectory.getChildAssumingFolder(_DOCS_DIRECTORY_NAME); |
/** |
* Return the directory within the SDK directory that contains the libraries. |
*/ |
- JavaFile get libraryDirectory { |
+ Folder get libraryDirectory { |
if (_libraryDirectory == null) { |
_libraryDirectory = |
- new JavaFile.relative(_sdkDirectory, _LIB_DIRECTORY_NAME); |
+ _sdkDirectory.getChildAssumingFolder(_LIB_DIRECTORY_NAME); |
} |
return _libraryDirectory; |
} |
@@ -533,13 +465,13 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
/** |
* Return the file containing the Pub executable, or `null` if it does not exist. |
*/ |
- JavaFile get pubExecutable { |
+ File get pubExecutable { |
if (_pubExecutable == null) { |
- _pubExecutable = _verifyExecutable(new JavaFile.relative( |
- new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
- OSUtilities.isWindows() |
+ _pubExecutable = _sdkDirectory |
+ .getChildAssumingFolder(_BIN_DIRECTORY_NAME) |
+ .getChildAssumingFile(OSUtilities.isWindows() |
? _PUB_EXECUTABLE_NAME_WIN |
- : _PUB_EXECUTABLE_NAME)); |
+ : _PUB_EXECUTABLE_NAME); |
} |
return _pubExecutable; |
} |
@@ -552,8 +484,8 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
String get sdkVersion { |
if (_sdkVersion == null) { |
_sdkVersion = DartSdk.DEFAULT_VERSION; |
- JavaFile revisionFile = |
- new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME); |
+ File revisionFile = |
+ _sdkDirectory.getChildAssumingFile(_VERSION_FILE_NAME); |
try { |
String revision = revisionFile.readAsStringSync(); |
if (revision != null) { |
@@ -567,76 +499,24 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
} |
/** |
- * Return the name of the file containing the VM executable. |
- */ |
- String get vmBinaryName { |
- if (OSUtilities.isWindows()) { |
- return _VM_EXECUTABLE_NAME_WIN; |
- } else { |
- return _VM_EXECUTABLE_NAME; |
- } |
- } |
- |
- /** |
- * Return the file containing the VM executable, or `null` if it does not |
- * exist. |
- */ |
- JavaFile get vmExecutable { |
- if (_vmExecutable == null) { |
- _vmExecutable = _verifyExecutable(new JavaFile.relative( |
- new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), |
- vmBinaryName)); |
- } |
- return _vmExecutable; |
- } |
- |
- /** |
* Determine the search order for trying to locate the [_LIBRARIES_FILE]. |
*/ |
- Iterable<JavaFile> get _libraryMapLocations sync* { |
- yield new JavaFile.relative( |
- new JavaFile.relative( |
- new JavaFile.relative( |
- new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
- _SDK_LIBRARY_METADATA_DIR), |
- _SDK_LIBRARY_METADATA_LIB_DIR), |
- _LIBRARIES_FILE); |
- yield new JavaFile.relative( |
- new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), |
- _LIBRARIES_FILE); |
- } |
- |
- /** |
- * Return the directory where dartium can be found (the directory that will be |
- * the working directory if Dartium is invoked without changing the default), |
- * assuming that the Editor was installed in the [installDir]. |
- */ |
- JavaFile getDartiumWorkingDirectory(JavaFile installDir) => |
- new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME); |
- |
- /** |
- * Return the auxiliary documentation file for the library with the given |
- * [libraryName], or `null` if no such file exists. |
- */ |
- JavaFile getDocFileFor(String libraryName) { |
- JavaFile dir = docDirectory; |
- if (!dir.exists()) { |
- return null; |
- } |
- JavaFile libDir = new JavaFile.relative(dir, libraryName); |
- JavaFile docFile = |
- new JavaFile.relative(libDir, "$libraryName$_DOC_FILE_SUFFIX"); |
- if (docFile.exists()) { |
- return docFile; |
- } |
- return null; |
+ Iterable<File> get _libraryMapLocations sync* { |
+ yield libraryDirectory |
+ .getChildAssumingFolder(_INTERNAL_DIR) |
+ .getChildAssumingFolder(_SDK_LIBRARY_METADATA_DIR) |
+ .getChildAssumingFolder(_SDK_LIBRARY_METADATA_LIB_DIR) |
+ .getChildAssumingFile(_LIBRARIES_FILE); |
+ yield libraryDirectory |
+ .getChildAssumingFolder(_INTERNAL_DIR) |
+ .getChildAssumingFile(_LIBRARIES_FILE); |
} |
@override |
- String getRelativePathFromFile(JavaFile file) { |
- String filePath = file.getAbsolutePath(); |
- String libPath = libraryDirectory.getAbsolutePath(); |
- if (!filePath.startsWith("$libPath${JavaFile.separator}")) { |
+ String getRelativePathFromFile(File file) { |
+ String filePath = file.path; |
+ String libPath = libraryDirectory.path; |
+ if (!filePath.startsWith("$libPath${resourceProvider.pathContext.separator}")) { |
return null; |
} |
return filePath.substring(libPath.length + 1); |
@@ -648,12 +528,12 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
* packages. |
*/ |
PackageBundle getSummarySdkBundle(bool strongMode) { |
- String rootPath = directory.getAbsolutePath(); |
+ String rootPath = directory.path; |
String name = strongMode ? 'strong.sum' : 'spec.sum'; |
- String path = pathos.join(rootPath, 'lib', '_internal', name); |
+ String path = resourceProvider.pathContext.join(rootPath, 'lib', '_internal', name); |
try { |
- File file = new File(path); |
- if (file.existsSync()) { |
+ File file = resourceProvider.getFile(path); |
+ if (file.exists) { |
List<int> bytes = file.readAsBytesSync(); |
return new PackageBundle.fromBuffer(bytes); |
} |
@@ -674,13 +554,13 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
List<String> searchedPaths = <String>[]; |
var lastStackTrace = null; |
var lastException = null; |
- for (JavaFile librariesFile in _libraryMapLocations) { |
+ for (File librariesFile in _libraryMapLocations) { |
try { |
String contents = librariesFile.readAsStringSync(); |
return new SdkLibrariesReader(useDart2jsPaths) |
.readFromFile(librariesFile, contents); |
} catch (exception, stackTrace) { |
- searchedPaths.add(librariesFile.getAbsolutePath()); |
+ searchedPaths.add(librariesFile.path); |
lastException = exception; |
lastStackTrace = stackTrace; |
} |
@@ -692,7 +572,7 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
} |
@override |
- FileBasedSource internalMapDartUri(String dartUri) { |
+ Source internalMapDartUri(String dartUri) { |
String libraryName; |
String relativePath; |
int index = dartUri.indexOf('/'); |
@@ -708,23 +588,51 @@ class DirectoryBasedDartSdk extends AbstractDartSdk { |
return null; |
} |
try { |
- JavaFile file = new JavaFile.relative(libraryDirectory, library.path); |
+ File file = libraryDirectory.getChildAssumingFile(library.path); |
if (!relativePath.isEmpty) { |
- file = file.getParentFile(); |
- file = new JavaFile.relative(file, relativePath); |
+ file = file.parent.getChildAssumingFile(relativePath); |
} |
- return new FileBasedSource(file, parseUriWithException(dartUri)); |
+ return file.createSource(parseUriWithException(dartUri)); |
} on URISyntaxException { |
return null; |
} |
} |
/** |
- * Return the given [file] if it exists and is executable, or `null` if it |
- * does not exist or is not executable. |
+ * Return the default directory for the Dart SDK, or `null` if the directory |
+ * cannot be determined (or does not exist). The default directory is provided |
+ * by a system property named `com.google.dart.sdk`. |
*/ |
- JavaFile _verifyExecutable(JavaFile file) => |
- file.isExecutable() ? file : null; |
+ static Folder defaultSdkDirectory(ResourceProvider resourceProvider) { |
+ // TODO(brianwilkerson) This is currently only being used in the analysis |
+ // server's Driver class to find the default SDK. The command-line analyzer |
+ // uses cli_utils to find the SDK. Not sure why they're different. |
+ String sdkProperty = getSdkProperty(resourceProvider); |
+ if (sdkProperty == null) { |
+ return null; |
+ } |
+ Folder sdkDirectory = resourceProvider.getFolder(sdkProperty); |
+ if (!sdkDirectory.exists) { |
+ return null; |
+ } |
+ return sdkDirectory; |
+ } |
+ |
+ static String getSdkProperty(ResourceProvider resourceProvider) { |
+ String exec = io.Platform.executable; |
+ if (exec.length == 0) { |
+ return null; |
+ } |
+ pathos.Context pathContext = resourceProvider.pathContext; |
+ // Might be "xcodebuild/ReleaseIA32/dart" with "sdk" sibling |
+ String outDir = pathContext.dirname(pathContext.dirname(exec)); |
+ String sdkPath = pathContext.join(pathContext.dirname(outDir), "sdk"); |
+ if (resourceProvider.getFolder(sdkPath).exists) { |
+ return sdkPath; |
+ } |
+ // probably be "dart-sdk/bin/dart" |
+ return pathContext.dirname(pathContext.dirname(exec)); |
+ } |
} |
/** |
@@ -767,8 +675,8 @@ class SdkLibrariesReader { |
* Return the library map read from the given [file], given that the content |
* of the file is already known to be [libraryFileContents]. |
*/ |
- LibraryMap readFromFile(JavaFile file, String libraryFileContents) => |
- readFromSource(new FileBasedSource(file), libraryFileContents); |
+ LibraryMap readFromFile(File file, String libraryFileContents) => |
+ readFromSource(file.createSource(), libraryFileContents); |
/** |
* Return the library map read from the given [source], given that the content |