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

Side by Side Diff: observatory_pub_packages/analyzer/src/generated/sdk_io.dart

Issue 816693004: Add observatory_pub_packages snapshot to third_party (Closed) Base URL: http://dart.googlecode.com/svn/third_party/
Patch Set: Created 6 years 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
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
3 // BSD-style license that can be found in the LICENSE file.
4
5 // This code was auto-generated, is not intended to be edited, and is subject to
6 // significant change. Please see the README file for more information.
7
8 library engine.sdk.io;
9
10 import 'java_core.dart';
11 import 'java_io.dart';
12 import 'java_engine_io.dart';
13 import 'source_io.dart';
14 import 'error.dart';
15 import 'scanner.dart';
16 import 'ast.dart';
17 import 'parser.dart';
18 import 'sdk.dart';
19 import 'engine.dart';
20
21 /**
22 * Instances of the class `DirectoryBasedDartSdk` represent a Dart SDK installed in a
23 * specified directory. Typical Dart SDK layout is something like...
24 *
25 * <pre>
26 * dart-sdk/
27 * bin/
28 * dart[.exe] <-- VM
29 * lib/
30 * core/
31 * core.dart
32 * ... other core library files ...
33 * ... other libraries ...
34 * util/
35 * ... Dart utilities ...
36 * Chromium/ <-- Dartium typically exists in a sibling directory
37 * </pre>
38 */
39 class DirectoryBasedDartSdk implements DartSdk {
40 /**
41 * The [AnalysisContext] which is used for all of the sources in this [DartSdk ].
42 */
43 InternalAnalysisContext _analysisContext;
44
45 /**
46 * The directory containing the SDK.
47 */
48 JavaFile _sdkDirectory;
49
50 /**
51 * The revision number of this SDK, or `"0"` if the revision number cannot be discovered.
52 */
53 String _sdkVersion;
54
55 /**
56 * The file containing the dart2js executable.
57 */
58 JavaFile _dart2jsExecutable;
59
60 /**
61 * The file containing the dart formatter executable.
62 */
63 JavaFile _dartFmtExecutable;
64
65 /**
66 * The file containing the Dartium executable.
67 */
68 JavaFile _dartiumExecutable;
69
70 /**
71 * The file containing the pub executable.
72 */
73 JavaFile _pubExecutable;
74
75 /**
76 * The file containing the VM executable.
77 */
78 JavaFile _vmExecutable;
79
80 /**
81 * A mapping from Dart library URI's to the library represented by that URI.
82 */
83 LibraryMap _libraryMap;
84
85 /**
86 * The name of the directory within the SDK directory that contains executable s.
87 */
88 static String _BIN_DIRECTORY_NAME = "bin";
89
90 /**
91 * The name of the directory on non-Mac that contains dartium.
92 */
93 static String _DARTIUM_DIRECTORY_NAME = "chromium";
94
95 /**
96 * The name of the dart2js executable on non-windows operating systems.
97 */
98 static String _DART2JS_EXECUTABLE_NAME = "dart2js";
99
100 /**
101 * The name of the file containing the dart2js executable on Windows.
102 */
103 static String _DART2JS_EXECUTABLE_NAME_WIN = "dart2js.bat";
104
105 /**
106 * The name of the dart formatter executable on non-windows operating systems.
107 */
108 static String _DARTFMT_EXECUTABLE_NAME = "dartfmt";
109
110 /**
111 * The name of the dart formatter executable on windows operating systems.
112 */
113 static String _DARTFMT_EXECUTABLE_NAME_WIN = "dartfmt.bat";
114
115 /**
116 * The name of the file containing the Dartium executable on Linux.
117 */
118 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chrome";
119
120 /**
121 * The name of the file containing the Dartium executable on Macintosh.
122 */
123 static String _DARTIUM_EXECUTABLE_NAME_MAC = "Chromium.app/Contents/MacOS/Chro mium";
124
125 /**
126 * The name of the file containing the Dartium executable on Windows.
127 */
128 static String _DARTIUM_EXECUTABLE_NAME_WIN = "Chrome.exe";
129
130 /**
131 * The name of the [System] property whose value is the path to the default Da rt SDK
132 * directory.
133 */
134 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk";
135
136 /**
137 * The name of the directory within the SDK directory that contains documentat ion for the
138 * libraries.
139 */
140 static String _DOCS_DIRECTORY_NAME = "docs";
141
142 /**
143 * The suffix added to the name of a library to derive the name of the file co ntaining the
144 * documentation for that library.
145 */
146 static String _DOC_FILE_SUFFIX = "_api.json";
147
148 /**
149 * The name of the directory within the SDK directory that contains the librar ies file.
150 */
151 static String _INTERNAL_DIR = "_internal";
152
153 /**
154 * The name of the directory within the SDK directory that contains the librar ies.
155 */
156 static String _LIB_DIRECTORY_NAME = "lib";
157
158 /**
159 * The name of the libraries file.
160 */
161 static String _LIBRARIES_FILE = "libraries.dart";
162
163 /**
164 * The name of the pub executable on windows.
165 */
166 static String _PUB_EXECUTABLE_NAME_WIN = "pub.bat";
167
168 /**
169 * The name of the pub executable on non-windows operating systems.
170 */
171 static String _PUB_EXECUTABLE_NAME = "pub";
172
173 /**
174 * The name of the file within the SDK directory that contains the version num ber of the SDK.
175 */
176 static String _VERSION_FILE_NAME = "version";
177
178 /**
179 * The name of the file containing the VM executable on the Windows operating system.
180 */
181 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe";
182
183 /**
184 * The name of the file containing the VM executable on non-Windows operating systems.
185 */
186 static String _VM_EXECUTABLE_NAME = "dart";
187
188 /**
189 * Return the default Dart SDK, or `null` if the directory containing the defa ult SDK cannot
190 * be determined (or does not exist).
191 *
192 * @return the default Dart SDK
193 */
194 static DirectoryBasedDartSdk get defaultSdk {
195 JavaFile sdkDirectory = defaultSdkDirectory;
196 if (sdkDirectory == null) {
197 return null;
198 }
199 return new DirectoryBasedDartSdk(sdkDirectory);
200 }
201
202 /**
203 * Return the default directory for the Dart SDK, or `null` if the directory c annot be
204 * determined (or does not exist). The default directory is provided by a [Sys tem] property
205 * named `com.google.dart.sdk`.
206 *
207 * @return the default directory for the Dart SDK
208 */
209 static JavaFile get defaultSdkDirectory {
210 String sdkProperty = JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NA ME);
211 if (sdkProperty == null) {
212 return null;
213 }
214 JavaFile sdkDirectory = new JavaFile(sdkProperty);
215 if (!sdkDirectory.exists()) {
216 return null;
217 }
218 return sdkDirectory;
219 }
220
221 /**
222 * Initialize a newly created SDK to represent the Dart SDK installed in the g iven directory.
223 *
224 * @param sdkDirectory the directory containing the SDK
225 * @param useDart2jsPaths `true` if the dart2js path should be used when it is available
226 */
227 DirectoryBasedDartSdk(JavaFile sdkDirectory, [bool useDart2jsPaths = false]) {
228 this._sdkDirectory = sdkDirectory.getAbsoluteFile();
229 _libraryMap = initialLibraryMap(useDart2jsPaths);
230 }
231
232 @override
233 Source fromFileUri(Uri uri) {
234 JavaFile file = new JavaFile.fromUri(uri);
235 String filePath = file.getAbsolutePath();
236 String libPath = libraryDirectory.getAbsolutePath();
237 if (!filePath.startsWith("${libPath}${JavaFile.separator}")) {
238 return null;
239 }
240 filePath = filePath.substring(libPath.length + 1);
241 for (SdkLibrary library in _libraryMap.sdkLibraries) {
242 String libraryPath = library.path;
243 if (filePath.replaceAll('\\', '/') == libraryPath) {
244 String path = library.shortName;
245 try {
246 return new FileBasedSource.con2(parseUriWithException(path), file);
247 } on URISyntaxException catch (exception) {
248 AnalysisEngine.instance.logger.logInformation2("Failed to create URI: ${path}", exception);
249 return null;
250 }
251 }
252 libraryPath = new JavaFile(libraryPath).getParent();
253 if (filePath.startsWith("${libraryPath}${JavaFile.separator}")) {
254 String path = "${library.shortName}/${filePath.substring(libraryPath.len gth + 1)}";
255 try {
256 return new FileBasedSource.con2(parseUriWithException(path), file);
257 } on URISyntaxException catch (exception) {
258 AnalysisEngine.instance.logger.logInformation2("Failed to create URI: ${path}", exception);
259 return null;
260 }
261 }
262 }
263 return null;
264 }
265
266 @override
267 AnalysisContext get context {
268 if (_analysisContext == null) {
269 _analysisContext = new SdkAnalysisContext();
270 SourceFactory factory = new SourceFactory([new DartUriResolver(this)]);
271 _analysisContext.sourceFactory = factory;
272 List<String> uris = this.uris;
273 ChangeSet changeSet = new ChangeSet();
274 for (String uri in uris) {
275 changeSet.addedSource(factory.forUri(uri));
276 }
277 _analysisContext.applyChanges(changeSet);
278 }
279 return _analysisContext;
280 }
281
282 /**
283 * Return the file containing the dart2js executable, or `null` if it does not exist.
284 *
285 * @return the file containing the dart2js executable
286 */
287 JavaFile get dart2JsExecutable {
288 if (_dart2jsExecutable == null) {
289 _dart2jsExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile. relative(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities.isWindows() ? _DART2JS _EXECUTABLE_NAME_WIN : _DART2JS_EXECUTABLE_NAME));
290 }
291 return _dart2jsExecutable;
292 }
293
294 /**
295 * Return the file containing the dart formatter executable, or `null` if it d oes not exist.
296 *
297 * @return the file containing the dart formatter executable
298 */
299 JavaFile get dartFmtExecutable {
300 if (_dartFmtExecutable == null) {
301 _dartFmtExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile. relative(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities.isWindows() ? _DARTFMT _EXECUTABLE_NAME_WIN : _DARTFMT_EXECUTABLE_NAME));
302 }
303 return _dartFmtExecutable;
304 }
305
306 /**
307 * Return the file containing the Dartium executable, or `null` if it does not exist.
308 *
309 * @return the file containing the Dartium executable
310 */
311 JavaFile get dartiumExecutable {
312 if (_dartiumExecutable == null) {
313 _dartiumExecutable = _verifyExecutable(new JavaFile.relative(dartiumWorkin gDirectory, dartiumBinaryName));
314 }
315 return _dartiumExecutable;
316 }
317
318 /**
319 * Return the directory where dartium can be found (the directory that will be the working
320 * directory is Dartium is invoked without changing the default).
321 *
322 * @return the directory where dartium can be found
323 */
324 JavaFile get dartiumWorkingDirectory => getDartiumWorkingDirectory(_sdkDirecto ry.getParentFile());
325
326 /**
327 * Return the directory where dartium can be found (the directory that will be the working
328 * directory is Dartium is invoked without changing the default).
329 *
330 * @param installDir the installation directory
331 * @return the directory where dartium can be found
332 */
333 JavaFile getDartiumWorkingDirectory(JavaFile installDir) => new JavaFile.relat ive(installDir, _DARTIUM_DIRECTORY_NAME);
334
335 /**
336 * Return the directory containing the SDK.
337 *
338 * @return the directory containing the SDK
339 */
340 JavaFile get directory => _sdkDirectory;
341
342 /**
343 * Return the directory containing documentation for the SDK.
344 *
345 * @return the SDK's documentation directory
346 */
347 JavaFile get docDirectory => new JavaFile.relative(_sdkDirectory, _DOCS_DIRECT ORY_NAME);
348
349 /**
350 * Return the auxiliary documentation file for the given library, or `null` if no such file
351 * exists.
352 *
353 * @param libraryName the name of the library associated with the documentatio n file to be
354 * returned
355 * @return the auxiliary documentation file for the library
356 */
357 JavaFile getDocFileFor(String libraryName) {
358 JavaFile dir = docDirectory;
359 if (!dir.exists()) {
360 return null;
361 }
362 JavaFile libDir = new JavaFile.relative(dir, libraryName);
363 JavaFile docFile = new JavaFile.relative(libDir, "${libraryName}${_DOC_FILE_ SUFFIX}");
364 if (docFile.exists()) {
365 return docFile;
366 }
367 return null;
368 }
369
370 /**
371 * Return the directory within the SDK directory that contains the libraries.
372 *
373 * @return the directory that contains the libraries
374 */
375 JavaFile get libraryDirectory => new JavaFile.relative(_sdkDirectory, _LIB_DIR ECTORY_NAME);
376
377 /**
378 * Return the file containing the Pub executable, or `null` if it does not exi st.
379 *
380 * @return the file containing the Pub executable
381 */
382 JavaFile get pubExecutable {
383 if (_pubExecutable == null) {
384 _pubExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile.rela tive(_sdkDirectory, _BIN_DIRECTORY_NAME), OSUtilities.isWindows() ? _PUB_EXECUTA BLE_NAME_WIN : _PUB_EXECUTABLE_NAME));
385 }
386 return _pubExecutable;
387 }
388
389 @override
390 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries;
391
392 @override
393 SdkLibrary getSdkLibrary(String dartUri) => _libraryMap.getLibrary(dartUri);
394
395 /**
396 * Return the revision number of this SDK, or `"0"` if the revision number can not be
397 * discovered.
398 *
399 * @return the revision number of this SDK
400 */
401 @override
402 String get sdkVersion {
403 if (_sdkVersion == null) {
404 _sdkVersion = DartSdk.DEFAULT_VERSION;
405 JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _VERSION_FILE _NAME);
406 try {
407 String revision = revisionFile.readAsStringSync();
408 if (revision != null) {
409 _sdkVersion = revision.trim();
410 }
411 } on JavaIOException catch (exception) {
412 }
413 }
414 return _sdkVersion;
415 }
416
417 /**
418 * Return an array containing the library URI's for the libraries defined in t his SDK.
419 *
420 * @return the library URI's for the libraries defined in this SDK
421 */
422 @override
423 List<String> get uris => _libraryMap.uris;
424
425 /**
426 * Return the file containing the VM executable, or `null` if it does not exis t.
427 *
428 * @return the file containing the VM executable
429 */
430 JavaFile get vmExecutable {
431 if (_vmExecutable == null) {
432 _vmExecutable = _verifyExecutable(new JavaFile.relative(new JavaFile.relat ive(_sdkDirectory, _BIN_DIRECTORY_NAME), vmBinaryName));
433 }
434 return _vmExecutable;
435 }
436
437 /**
438 * Return `true` if this SDK includes documentation.
439 *
440 * @return `true` if this installation of the SDK has documentation
441 */
442 bool get hasDocumentation => docDirectory.exists();
443
444 /**
445 * Return `true` if the Dartium binary is available.
446 *
447 * @return `true` if the Dartium binary is available
448 */
449 bool get isDartiumInstalled => dartiumExecutable != null;
450
451 @override
452 Source mapDartUri(String dartUri) {
453 String libraryName;
454 String relativePath;
455 int index = dartUri.indexOf('/');
456 if (index >= 0) {
457 libraryName = dartUri.substring(0, index);
458 relativePath = dartUri.substring(index + 1);
459 } else {
460 libraryName = dartUri;
461 relativePath = "";
462 }
463 SdkLibrary library = getSdkLibrary(libraryName);
464 if (library == null) {
465 return null;
466 }
467 try {
468 JavaFile file = new JavaFile.relative(libraryDirectory, library.path);
469 if (!relativePath.isEmpty) {
470 file = file.getParentFile();
471 file = new JavaFile.relative(file, relativePath);
472 }
473 return new FileBasedSource.con2(parseUriWithException(dartUri), file);
474 } on URISyntaxException catch (exception) {
475 return null;
476 }
477 }
478
479 /**
480 * Read all of the configuration files to initialize the library maps.
481 *
482 * @param useDart2jsPaths `true` if the dart2js path should be used when it is available
483 * @return the initialized library map
484 */
485 LibraryMap initialLibraryMap(bool useDart2jsPaths) {
486 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(library Directory, _INTERNAL_DIR), _LIBRARIES_FILE);
487 try {
488 String contents = librariesFile.readAsStringSync();
489 return new SdkLibrariesReader(useDart2jsPaths).readFromFile(librariesFile, contents);
490 } catch (exception) {
491 AnalysisEngine.instance.logger.logError2("Could not initialize the library map from ${librariesFile.getAbsolutePath()}", exception);
492 return new LibraryMap();
493 }
494 }
495
496 /**
497 * Ensure that the dart VM is executable. If it is not, make it executable and log that it was
498 * necessary for us to do so.
499 */
500 void _ensureVmIsExecutable() {
501 }
502
503 /**
504 * Return the name of the file containing the Dartium executable.
505 *
506 * @return the name of the file containing the Dartium executable
507 */
508 String get dartiumBinaryName {
509 if (OSUtilities.isWindows()) {
510 return _DARTIUM_EXECUTABLE_NAME_WIN;
511 } else if (OSUtilities.isMac()) {
512 return _DARTIUM_EXECUTABLE_NAME_MAC;
513 } else {
514 return _DARTIUM_EXECUTABLE_NAME_LINUX;
515 }
516 }
517
518 /**
519 * Return the name of the file containing the VM executable.
520 *
521 * @return the name of the file containing the VM executable
522 */
523 String get vmBinaryName {
524 if (OSUtilities.isWindows()) {
525 return _VM_EXECUTABLE_NAME_WIN;
526 } else {
527 return _VM_EXECUTABLE_NAME;
528 }
529 }
530
531 /**
532 * Verify that the given executable file exists and is executable.
533 *
534 * @param file the binary file
535 * @return the file if it exists and is executable, else `null`
536 */
537 JavaFile _verifyExecutable(JavaFile file) => file.isExecutable() ? file : null ;
538 }
539
540 /**
541 * Instances of the class `SdkLibrariesReader` read and parse the libraries file
542 * (dart-sdk/lib/_internal/libraries.dart) for information about the libraries i n an SDK. The
543 * library information is represented as a Dart file containing a single top-lev el variable whose
544 * value is a const map. The keys of the map are the names of libraries defined in the SDK and the
545 * values in the map are info objects defining the library. For example, a subse t of a typical SDK
546 * might have a libraries file that looks like the following:
547 *
548 * <pre>
549 * final Map&lt;String, LibraryInfo&gt; LIBRARIES = const &lt;LibraryInfo&gt; {
550 * // Used by VM applications
551 * "builtin" : const LibraryInfo(
552 * "builtin/builtin_runtime.dart",
553 * category: "Server",
554 * platforms: VM_PLATFORM),
555 *
556 * "compiler" : const LibraryInfo(
557 * "compiler/compiler.dart",
558 * category: "Tools",
559 * platforms: 0),
560 * };
561 * </pre>
562 */
563 class SdkLibrariesReader {
564 /**
565 * A flag indicating whether the dart2js path should be used when it is availa ble.
566 */
567 final bool _useDart2jsPaths;
568
569 /**
570 * Initialize a newly created library reader to use the dart2js path if the gi ven value is
571 * `true`.
572 *
573 * @param useDart2jsPaths `true` if the dart2js path should be used when it is available
574 */
575 SdkLibrariesReader(this._useDart2jsPaths);
576
577 /**
578 * Return the library map read from the given source.
579 *
580 * @param file the [File] of the library file
581 * @param libraryFileContents the contents from the library file
582 * @return the library map read from the given source
583 */
584 LibraryMap readFromFile(JavaFile file, String libraryFileContents) => readFrom Source(new FileBasedSource.con1(file), libraryFileContents);
585
586 /**
587 * Return the library map read from the given source.
588 *
589 * @param source the source of the library file
590 * @param libraryFileContents the contents from the library file
591 * @return the library map read from the given source
592 */
593 LibraryMap readFromSource(Source source, String libraryFileContents) {
594 BooleanErrorListener errorListener = new BooleanErrorListener();
595 Scanner scanner = new Scanner(source, new CharSequenceReader(libraryFileCont ents), errorListener);
596 Parser parser = new Parser(source, errorListener);
597 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize());
598 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li braryBuilder(_useDart2jsPaths);
599 // If any syntactic errors were found then don't try to visit the AST struct ure.
600 if (!errorListener.errorReported) {
601 unit.accept(libraryBuilder);
602 }
603 return libraryBuilder.librariesMap;
604 }
605 }
OLDNEW
« no previous file with comments | « observatory_pub_packages/analyzer/src/generated/sdk.dart ('k') | observatory_pub_packages/analyzer/src/generated/source.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698