Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(19)

Unified Diff: pkg/analyzer/lib/src/generated/sdk_io.dart

Issue 229653004: New analyzer snapshot with MapIterator. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « pkg/analyzer/lib/src/generated/scanner.dart ('k') | pkg/analyzer/lib/src/generated/source.dart » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/analyzer/lib/src/generated/sdk_io.dart
diff --git a/pkg/analyzer/lib/src/generated/sdk_io.dart b/pkg/analyzer/lib/src/generated/sdk_io.dart
index eedc729506f5034e2e28eb7d04721e592b226cd1..d09350b0dcc7af017daee675e5b56f66b09781c0 100644
--- a/pkg/analyzer/lib/src/generated/sdk_io.dart
+++ b/pkg/analyzer/lib/src/generated/sdk_io.dart
@@ -20,7 +20,21 @@ import 'engine.dart';
/**
* Instances of the class `DirectoryBasedDartSdk` represent a Dart SDK installed in a
- * specified directory.
+ * specified directory. Typical Dart SDK layout is something like...
+ *
+ * <pre>
+ * dart-sdk/
+ * bin/
+ * dart[.exe] <-- VM
+ * lib/
+ * core/
+ * core.dart
+ * ... other core library files ...
+ * ... other libraries ...
+ * util/
+ * ... Dart utilities ...
+ * Chromium/ <-- Dartium typically exists in a sibling directory
+ * </pre>
*/
class DirectoryBasedDartSdk implements DartSdk {
/**
@@ -39,11 +53,26 @@ class DirectoryBasedDartSdk implements DartSdk {
String _sdkVersion;
/**
+ * The file containing the dart2js executable.
+ */
+ JavaFile _dart2jsExecutable;
+
+ /**
+ * The file containing the dart formatter executable.
+ */
+ JavaFile _dartFmtExecutable;
+
+ /**
* The file containing the Dartium executable.
*/
JavaFile _dartiumExecutable;
/**
+ * The file containing the pub executable.
+ */
+ JavaFile _pubExecutable;
+
+ /**
* The file containing the VM executable.
*/
JavaFile _vmExecutable;
@@ -59,9 +88,34 @@ class DirectoryBasedDartSdk implements DartSdk {
static String _BIN_DIRECTORY_NAME = "bin";
/**
- * The name of the directory within the SDK directory that contains Chromium.
+ * The name of the directory on Mac that contains dartium.
+ */
+ static String _DARTIUM_DIRECTORY_NAME_MAC = "Chromium.app";
+
+ /**
+ * The name of the directory on non-Mac that contains dartium.
*/
- static String _CHROMIUM_DIRECTORY_NAME = "chromium";
+ 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 dart formatter executable on non-windows operating systems.
+ */
+ static String _DARTFMT_EXECUTABLE_NAME = "dartfmt";
+
+ /**
+ * The name of the dart formatter executable on windows operating systems.
+ */
+ static String _DARTFMT_EXECUTABLE_NAME_WIN = "dartfmt.bat";
/**
* The name of the file containing the Dartium executable on Linux.
@@ -122,9 +176,9 @@ class DirectoryBasedDartSdk implements DartSdk {
static String _PUB_EXECUTABLE_NAME = "pub";
/**
- * The name of the file within the SDK directory that contains the revision number of the SDK.
+ * The name of the file within the SDK directory that contains the version number of the SDK.
*/
- static String _REVISION_FILE_NAME = "revision";
+ static String _VERSION_FILE_NAME = "version";
/**
* The name of the file containing the VM executable on the Windows operating system.
@@ -177,8 +231,7 @@ class DirectoryBasedDartSdk implements DartSdk {
*/
DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) {
this._sdkDirectory = sdkDirectory.getAbsoluteFile();
- _initializeSdk();
- _initializeLibraryMap(useDart2jsPaths);
+ _libraryMap = initialLibraryMap(useDart2jsPaths);
_analysisContext = new AnalysisContextImpl();
_analysisContext.sourceFactory = new SourceFactory([new DartUriResolver(this)]);
List<String> uris = this.uris;
@@ -196,27 +249,57 @@ class DirectoryBasedDartSdk implements DartSdk {
AnalysisContext get context => _analysisContext;
/**
+ * Return the file containing the dart2js executable, or `null` if it does not exist.
+ *
+ * @return the file containing the dart2js executable
+ */
+ 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 file containing the dart formatter executable, or `null` if it does not exist.
+ *
+ * @return the file containing the dart formatter executable
+ */
+ JavaFile get dartFmtExecutable {
+ if (_dartFmtExecutable == null) {
+ _dartFmtExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities.isWindows() ? _DARTFMT_EXECUTABLE_NAME_WIN : _DARTFMT_EXECUTABLE_NAME));
+ }
+ return _dartFmtExecutable;
+ }
+
+ /**
* Return the file containing the Dartium executable, or `null` if it does not exist.
*
* @return the file containing the Dartium executable
*/
JavaFile get dartiumExecutable {
if (_dartiumExecutable == null) {
- JavaFile file = new JavaFile.relative(dartiumWorkingDirectory, dartiumBinaryName);
- if (file.exists()) {
- _dartiumExecutable = file;
- }
+ _dartiumExecutable = _verifyExecutable(new JavaFile.relative(dartiumWorkingDirectory, dartiumBinaryName));
}
return _dartiumExecutable;
}
/**
- * Return the directory where dartium can be found in the Dart SDK (the directory that will be the
- * working directory is Dartium is invoked without changing the default).
+ * Return the directory where dartium can be found (the directory that will be the working
+ * directory is Dartium is invoked without changing the default).
+ *
+ * @return the directory where dartium can be found
+ */
+ JavaFile get dartiumWorkingDirectory => getDartiumWorkingDirectory(_sdkDirectory.getParentFile());
+
+ /**
+ * Return the directory where dartium can be found (the directory that will be the working
+ * directory is Dartium is invoked without changing the default).
*
+ * @param installDir the installation directory
* @return the directory where dartium can be found
*/
- JavaFile get dartiumWorkingDirectory => new JavaFile.relative(_sdkDirectory.getParentFile(), _CHROMIUM_DIRECTORY_NAME);
+ JavaFile getDartiumWorkingDirectory(JavaFile installDir) => new JavaFile.relative(installDir, _DARTIUM_DIRECTORY_NAME);
/**
* Return the directory containing the SDK.
@@ -266,9 +349,10 @@ class DirectoryBasedDartSdk implements DartSdk {
* @return the file containing the Pub executable
*/
JavaFile get pubExecutable {
- String pubBinaryName = OSUtilities.isWindows() ? _PUB_EXECUTABLE_NAME_WIN : _PUB_EXECUTABLE_NAME;
- JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), pubBinaryName);
- return file.exists() ? file : null;
+ if (_pubExecutable == null) {
+ _pubExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities.isWindows() ? _PUB_EXECUTABLE_NAME_WIN : _PUB_EXECUTABLE_NAME));
+ }
+ return _pubExecutable;
}
@override
@@ -287,11 +371,11 @@ class DirectoryBasedDartSdk implements DartSdk {
String get sdkVersion {
if (_sdkVersion == null) {
_sdkVersion = DartSdk.DEFAULT_VERSION;
- JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _REVISION_FILE_NAME);
+ JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _VERSION_FILE_NAME);
try {
String revision = revisionFile.readAsStringSync();
if (revision != null) {
- _sdkVersion = revision;
+ _sdkVersion = revision.trim();
}
} on JavaIOException catch (exception) {
}
@@ -314,10 +398,7 @@ class DirectoryBasedDartSdk implements DartSdk {
*/
JavaFile get vmExecutable {
if (_vmExecutable == null) {
- JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), vmBinaryName);
- if (file.exists()) {
- _vmExecutable = file;
- }
+ _vmExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile.relative(_sdkDirectory, _BIN_DIRECTORY_NAME), vmBinaryName));
}
return _vmExecutable;
}
@@ -346,6 +427,23 @@ class DirectoryBasedDartSdk implements DartSdk {
}
/**
+ * Read all of the configuration files to initialize the library maps.
+ *
+ * @param useDart2jsPaths `true` if the dart2js path should be used when it is available
+ * @return the initialized library map
+ */
+ LibraryMap initialLibraryMap(bool useDart2jsPaths) {
+ JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE);
+ try {
+ String contents = librariesFile.readAsStringSync();
+ return new SdkLibrariesReader(useDart2jsPaths).readFromFile(librariesFile, contents);
+ } on JavaException catch (exception) {
+ AnalysisEngine.instance.logger.logError2("Could not initialize the library map from ${librariesFile.getAbsolutePath()}", exception);
+ return new LibraryMap();
+ }
+ }
+
+ /**
* Ensure that the dart VM is executable. If it is not, make it executable and log that it was
* necessary for us to do so.
*/
@@ -381,29 +479,12 @@ class DirectoryBasedDartSdk implements DartSdk {
}
/**
- * Read all of the configuration files to initialize the library maps.
+ * Verify that the given executable file exists and is executable.
*
- * @param useDart2jsPaths `true` if the dart2js path should be used when it is available
- */
- void _initializeLibraryMap(bool useDart2jsPaths) {
- JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libraryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE);
- try {
- String contents = librariesFile.readAsStringSync();
- _libraryMap = new SdkLibrariesReader(useDart2jsPaths).readFromFile(librariesFile, contents);
- } on JavaException catch (exception) {
- AnalysisEngine.instance.logger.logError2("Could not initialize the library map from ${librariesFile.getAbsolutePath()}", exception);
- _libraryMap = new LibraryMap();
- }
- }
-
- /**
- * Initialize the state of the SDK.
+ * @param file the binary file
+ * @return the file if it exists and is executable, else `null`
*/
- void _initializeSdk() {
- if (!OSUtilities.isWindows()) {
- _ensureVmIsExecutable();
- }
- }
+ JavaFile _verifyExecutable(JavaFile file) => file.isExecutable() ? file : null;
}
/**
« no previous file with comments | « pkg/analyzer/lib/src/generated/scanner.dart ('k') | pkg/analyzer/lib/src/generated/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698