OLD | NEW |
| (Empty) |
1 // This code was auto-generated, is not intended to be edited, and is subject to | |
2 // significant change. Please see the README file for more information. | |
3 | |
4 library engine.sdk; | |
5 | |
6 import 'dart:io'; | |
7 import 'dart:uri'; | |
8 import 'java_core.dart'; | |
9 import 'java_io.dart'; | |
10 import 'java_engine.dart'; | |
11 import 'java_engine_io.dart'; | |
12 import 'package:analyzer-experimental/src/generated/source_io.dart'; | |
13 import 'package:analyzer-experimental/src/generated/error.dart'; | |
14 import 'package:analyzer-experimental/src/generated/scanner.dart'; | |
15 import 'package:analyzer-experimental/src/generated/parser.dart'; | |
16 import 'package:analyzer-experimental/src/generated/ast.dart'; | |
17 import 'package:analyzer-experimental/src/generated/engine.dart' show AnalysisEn
gine; | |
18 | |
19 /** | |
20 * Represents a single library in the SDK | |
21 */ | |
22 abstract class SdkLibrary { | |
23 /** | |
24 * Return the name of the category containing the library. | |
25 * @return the name of the category containing the library | |
26 */ | |
27 String get category; | |
28 /** | |
29 * Return the path to the file defining the library. The path is relative to t
he {@code lib}directory within the SDK. | |
30 * @return the path to the file defining the library | |
31 */ | |
32 String get path; | |
33 /** | |
34 * Return the short name of the library. This is the name used after {@code da
rt:} in a URI. | |
35 * @return the short name of the library | |
36 */ | |
37 String get shortName; | |
38 /** | |
39 * Return {@code true} if this library can be compiled to JavaScript by dart2j
s. | |
40 * @return {@code true} if this library can be compiled to JavaScript by dart2
js | |
41 */ | |
42 bool isDart2JsLibrary(); | |
43 /** | |
44 * Return {@code true} if the library is documented. | |
45 * @return {@code true} if the library is documented | |
46 */ | |
47 bool isDocumented(); | |
48 /** | |
49 * Return {@code true} if the library is an implementation library. | |
50 * @return {@code true} if the library is an implementation library | |
51 */ | |
52 bool isImplementation(); | |
53 /** | |
54 * Return {@code true} if library can be used for both client and server. | |
55 * @return {@code true} if this library can be used for both client and server
. | |
56 */ | |
57 bool isShared(); | |
58 /** | |
59 * Return {@code true} if this library can be run on the VM. | |
60 * @return {@code true} if this library can be run on the VM | |
61 */ | |
62 bool isVmLibrary(); | |
63 } | |
64 /** | |
65 * Instances of the class {@code SdkLibrary} represent the information known abo
ut a single library | |
66 * within the SDK. | |
67 * @coverage dart.engine.sdk | |
68 */ | |
69 class SdkLibraryImpl implements SdkLibrary { | |
70 /** | |
71 * The short name of the library. This is the name used after {@code dart:} in
a URI. | |
72 */ | |
73 String _shortName = null; | |
74 /** | |
75 * The path to the file defining the library. The path is relative to the {@co
de lib} directory | |
76 * within the SDK. | |
77 */ | |
78 String _path = null; | |
79 /** | |
80 * The name of the category containing the library. Unless otherwise specified
in the libraries | |
81 * file all libraries are assumed to be shared between server and client. | |
82 */ | |
83 String _category = "Shared"; | |
84 /** | |
85 * A flag indicating whether the library is documented. | |
86 */ | |
87 bool _documented = true; | |
88 /** | |
89 * A flag indicating whether the library is an implementation library. | |
90 */ | |
91 bool _implementation = false; | |
92 /** | |
93 * An encoding of which platforms this library is intended to work on. | |
94 */ | |
95 int _platforms = 0; | |
96 /** | |
97 * The bit mask used to access the bit representing the flag indicating whethe
r a library is | |
98 * intended to work on the dart2js platform. | |
99 */ | |
100 static int DART2JS_PLATFORM = 1; | |
101 /** | |
102 * The bit mask used to access the bit representing the flag indicating whethe
r a library is | |
103 * intended to work on the VM platform. | |
104 */ | |
105 static int VM_PLATFORM = 2; | |
106 /** | |
107 * Initialize a newly created library to represent the library with the given
name. | |
108 * @param name the short name of the library | |
109 */ | |
110 SdkLibraryImpl(String name) { | |
111 this._shortName = name; | |
112 } | |
113 String get category => _category; | |
114 String get path => _path; | |
115 String get shortName => _shortName; | |
116 bool isDart2JsLibrary() => (_platforms & DART2JS_PLATFORM) != 0; | |
117 bool isDocumented() => _documented; | |
118 bool isImplementation() => _implementation; | |
119 /** | |
120 * Return {@code true} if library can be used for both client and server | |
121 */ | |
122 bool isShared() => _category == "Shared"; | |
123 /** | |
124 * Return {@code true} if this library can be run on the VM. | |
125 * @return {@code true} if this library can be run on the VM | |
126 */ | |
127 bool isVmLibrary() => (_platforms & VM_PLATFORM) != 0; | |
128 /** | |
129 * Set the name of the category containing the library to the given name. | |
130 * @param category the name of the category containing the library | |
131 */ | |
132 void set category(String category2) { | |
133 this._category = category2; | |
134 } | |
135 /** | |
136 * Record that this library can be compiled to JavaScript by dart2js. | |
137 */ | |
138 void setDart2JsLibrary() { | |
139 _platforms |= DART2JS_PLATFORM; | |
140 } | |
141 /** | |
142 * Set whether the library is documented to match the given value. | |
143 * @param documented {@code true} if the library is documented | |
144 */ | |
145 void set documented(bool documented2) { | |
146 this._documented = documented2; | |
147 } | |
148 /** | |
149 * Set whether the library is an implementation library to match the given val
ue. | |
150 * @param implementation {@code true} if the library is an implementation libr
ary | |
151 */ | |
152 void set implementation(bool implementation2) { | |
153 this._implementation = implementation2; | |
154 } | |
155 /** | |
156 * Set the path to the file defining the library to the given path. The path i
s relative to the{@code lib} directory within the SDK. | |
157 * @param path the path to the file defining the library | |
158 */ | |
159 void set path(String path2) { | |
160 this._path = path2; | |
161 } | |
162 /** | |
163 * Record that this library can be run on the VM. | |
164 */ | |
165 void setVmLibrary() { | |
166 _platforms |= VM_PLATFORM; | |
167 } | |
168 } | |
169 /** | |
170 * Instances of the class {@code SdkLibrariesReader} read and parse the librarie
s file | |
171 * (dart-sdk/lib/_internal/libraries.dart) for information about the libraries i
n an SDK. The | |
172 * library information is represented as a Dart file containing a single top-lev
el variable whose | |
173 * value is a const map. The keys of the map are the names of libraries defined
in the SDK and the | |
174 * values in the map are info objects defining the library. For example, a subse
t of a typical SDK | |
175 * might have a libraries file that looks like the following: | |
176 * <pre> | |
177 * final Map<String, LibraryInfo> LIBRARIES = const <LibraryInfo> { | |
178 * // Used by VM applications | |
179 * "builtin" : const LibraryInfo( | |
180 * "builtin/builtin_runtime.dart", | |
181 * category: "Server", | |
182 * platforms: VM_PLATFORM), | |
183 * "compiler" : const LibraryInfo( | |
184 * "compiler/compiler.dart", | |
185 * category: "Tools", | |
186 * platforms: 0), | |
187 * }; | |
188 * </pre> | |
189 * @coverage dart.engine.sdk | |
190 */ | |
191 class SdkLibrariesReader { | |
192 /** | |
193 * Return the library map read from the given source. | |
194 * @return the library map read from the given source | |
195 */ | |
196 LibraryMap readFrom(JavaFile librariesFile, String libraryFileContents) { | |
197 List<bool> foundError = [false]; | |
198 AnalysisErrorListener errorListener = new AnalysisErrorListener_6(foundError
); | |
199 Source source = new FileBasedSource.con2(null, librariesFile, false); | |
200 StringScanner scanner = new StringScanner(source, libraryFileContents, error
Listener); | |
201 Parser parser = new Parser(source, errorListener); | |
202 CompilationUnit unit = parser.parseCompilationUnit(scanner.tokenize()); | |
203 SdkLibrariesReader_LibraryBuilder libraryBuilder = new SdkLibrariesReader_Li
braryBuilder(); | |
204 if (!foundError[0]) { | |
205 unit.accept(libraryBuilder); | |
206 } | |
207 return libraryBuilder.librariesMap; | |
208 } | |
209 } | |
210 class SdkLibrariesReader_LibraryBuilder extends RecursiveASTVisitor<Object> { | |
211 /** | |
212 * The prefix added to the name of a library to form the URI used in code to r
eference the | |
213 * library. | |
214 */ | |
215 static String _LIBRARY_PREFIX = "dart:"; | |
216 /** | |
217 * The name of the optional parameter used to indicate whether the library is
an implementation | |
218 * library. | |
219 */ | |
220 static String _IMPLEMENTATION = "implementation"; | |
221 /** | |
222 * The name of the optional parameter used to indicate whether the library is
documented. | |
223 */ | |
224 static String _DOCUMENTED = "documented"; | |
225 /** | |
226 * The name of the optional parameter used to specify the category of the libr
ary. | |
227 */ | |
228 static String _CATEGORY = "category"; | |
229 /** | |
230 * The name of the optional parameter used to specify the platforms on which t
he library can be | |
231 * used. | |
232 */ | |
233 static String _PLATFORMS = "platforms"; | |
234 /** | |
235 * The value of the {@link #PLATFORMS platforms} parameter used to specify tha
t the library can | |
236 * be used on the VM. | |
237 */ | |
238 static String _VM_PLATFORM = "VM_PLATFORM"; | |
239 /** | |
240 * The library map that is populated by visiting the AST structure parsed from
the contents of | |
241 * the libraries file. | |
242 */ | |
243 LibraryMap _librariesMap = new LibraryMap(); | |
244 /** | |
245 * Return the library map that was populated by visiting the AST structure par
sed from the | |
246 * contents of the libraries file. | |
247 * @return the library map describing the contents of the SDK | |
248 */ | |
249 LibraryMap get librariesMap => _librariesMap; | |
250 Object visitMapLiteralEntry(MapLiteralEntry node) { | |
251 String libraryName = null; | |
252 Expression key3 = node.key; | |
253 if (key3 is SimpleStringLiteral) { | |
254 libraryName = "${_LIBRARY_PREFIX}${((key3 as SimpleStringLiteral)).value}"
; | |
255 } | |
256 Expression value9 = node.value; | |
257 if (value9 is InstanceCreationExpression) { | |
258 SdkLibraryImpl library = new SdkLibraryImpl(libraryName); | |
259 List<Expression> arguments6 = ((value9 as InstanceCreationExpression)).arg
umentList.arguments; | |
260 for (Expression argument in arguments6) { | |
261 if (argument is SimpleStringLiteral) { | |
262 library.path = ((argument as SimpleStringLiteral)).value; | |
263 } else if (argument is NamedExpression) { | |
264 String name19 = ((argument as NamedExpression)).name.label.name; | |
265 Expression expression15 = ((argument as NamedExpression)).expression; | |
266 if (name19 == _CATEGORY) { | |
267 library.category = ((expression15 as SimpleStringLiteral)).value; | |
268 } else if (name19 == _IMPLEMENTATION) { | |
269 library.implementation = ((expression15 as BooleanLiteral)).value; | |
270 } else if (name19 == _DOCUMENTED) { | |
271 library.documented = ((expression15 as BooleanLiteral)).value; | |
272 } else if (name19 == _PLATFORMS) { | |
273 if (expression15 is SimpleIdentifier) { | |
274 String identifier = ((expression15 as SimpleIdentifier)).name; | |
275 if (identifier == _VM_PLATFORM) { | |
276 library.setVmLibrary(); | |
277 } else { | |
278 library.setDart2JsLibrary(); | |
279 } | |
280 } | |
281 } | |
282 } | |
283 } | |
284 _librariesMap.setLibrary(libraryName, library); | |
285 } | |
286 return null; | |
287 } | |
288 } | |
289 class AnalysisErrorListener_6 implements AnalysisErrorListener { | |
290 List<bool> foundError; | |
291 AnalysisErrorListener_6(this.foundError); | |
292 void onError(AnalysisError error) { | |
293 foundError[0] = true; | |
294 } | |
295 } | |
296 /** | |
297 * Instances of the class {@code LibraryMap} map Dart library URI's to the {@lin
k SdkLibraryImpllibrary}. | |
298 * @coverage dart.engine.sdk | |
299 */ | |
300 class LibraryMap { | |
301 /** | |
302 * A table mapping Dart library URI's to the library. | |
303 */ | |
304 Map<String, SdkLibraryImpl> _libraryMap = new Map<String, SdkLibraryImpl>(); | |
305 /** | |
306 * Initialize a newly created library map to be empty. | |
307 */ | |
308 LibraryMap() : super() { | |
309 } | |
310 /** | |
311 * Return the library with the given URI, or {@code null} if the URI does not
map to a library. | |
312 * @param dartUri the URI of the library to be returned | |
313 * @return the library with the given URI | |
314 */ | |
315 SdkLibrary getLibrary(String dartUri) => _libraryMap[dartUri]; | |
316 /** | |
317 * Return an array containing all the sdk libraries {@link SdkLibraryImpl} in
the mapping | |
318 * @return the sdk libraries in the mapping | |
319 */ | |
320 List<SdkLibrary> get sdkLibraries => new List.from(_libraryMap.values); | |
321 /** | |
322 * Return an array containing the library URI's for which a mapping is availab
le. | |
323 * @return the library URI's for which a mapping is available | |
324 */ | |
325 List<String> get uris => new List.from(_libraryMap.keys.toSet()); | |
326 /** | |
327 * Return the library with the given URI, or {@code null} if the URI does not
map to a library. | |
328 * @param dartUri the URI of the library to be returned | |
329 * @param library the library with the given URI | |
330 */ | |
331 void setLibrary(String dartUri, SdkLibraryImpl library) { | |
332 _libraryMap[dartUri] = library; | |
333 } | |
334 /** | |
335 * Return the number of library URI's for which a mapping is available. | |
336 * @return the number of library URI's for which a mapping is available | |
337 */ | |
338 int size() => _libraryMap.length; | |
339 } | |
340 /** | |
341 * Instances of the class {@code DartSdk} represent a Dart SDK installed in a sp
ecified location. | |
342 * @coverage dart.engine.sdk | |
343 */ | |
344 class DartSdk { | |
345 /** | |
346 * The short name of the dart SDK core library. | |
347 */ | |
348 static String DART_CORE = "dart:core"; | |
349 /** | |
350 * The short name of the dart SDK html library. | |
351 */ | |
352 static String DART_HTML = "dart:html"; | |
353 /** | |
354 * The directory containing the SDK. | |
355 */ | |
356 JavaFile _sdkDirectory; | |
357 /** | |
358 * The revision number of this SDK, or {@code "0"} if the revision number cann
ot be discovered. | |
359 */ | |
360 String _sdkVersion; | |
361 /** | |
362 * The file containing the Dartium executable. | |
363 */ | |
364 JavaFile _dartiumExecutable; | |
365 /** | |
366 * The file containing the VM executable. | |
367 */ | |
368 JavaFile _vmExecutable; | |
369 /** | |
370 * A mapping from Dart library URI's to the library represented by that URI. | |
371 */ | |
372 LibraryMap _libraryMap; | |
373 /** | |
374 * The name of the directory within the SDK directory that contains executable
s. | |
375 */ | |
376 static String _BIN_DIRECTORY_NAME = "bin"; | |
377 /** | |
378 * The name of the directory within the SDK directory that contains Chromium. | |
379 */ | |
380 static String _CHROMIUM_DIRECTORY_NAME = "chromium"; | |
381 /** | |
382 * The name of the environment variable whose value is the path to the default
Dart SDK directory. | |
383 */ | |
384 static String _DART_SDK_ENVIRONMENT_VARIABLE_NAME = "DART_SDK"; | |
385 /** | |
386 * The name of the file containing the Dartium executable on Linux. | |
387 */ | |
388 static String _DARTIUM_EXECUTABLE_NAME_LINUX = "chromium/chrome"; | |
389 /** | |
390 * The name of the file containing the Dartium executable on Macintosh. | |
391 */ | |
392 static String _DARTIUM_EXECUTABLE_NAME_MAC = "Chromium.app/Contents/MacOS/Chro
mium"; | |
393 /** | |
394 * The name of the file containing the Dartium executable on Windows. | |
395 */ | |
396 static String _DARTIUM_EXECUTABLE_NAME_WIN = "chromium/Chrome.exe"; | |
397 /** | |
398 * The name of the {@link System} property whose value is the path to the defa
ult Dart SDK | |
399 * directory. | |
400 */ | |
401 static String _DEFAULT_DIRECTORY_PROPERTY_NAME = "com.google.dart.sdk"; | |
402 /** | |
403 * The version number that is returned when the real version number could not
be determined. | |
404 */ | |
405 static String _DEFAULT_VERSION = "0"; | |
406 /** | |
407 * The name of the directory within the SDK directory that contains documentat
ion for the | |
408 * libraries. | |
409 */ | |
410 static String _DOCS_DIRECTORY_NAME = "docs"; | |
411 /** | |
412 * The suffix added to the name of a library to derive the name of the file co
ntaining the | |
413 * documentation for that library. | |
414 */ | |
415 static String _DOC_FILE_SUFFIX = "_api.json"; | |
416 /** | |
417 * The name of the directory within the SDK directory that contains the librar
ies file. | |
418 */ | |
419 static String _INTERNAL_DIR = "_internal"; | |
420 /** | |
421 * The name of the directory within the SDK directory that contains the librar
ies. | |
422 */ | |
423 static String _LIB_DIRECTORY_NAME = "lib"; | |
424 /** | |
425 * The name of the libraries file. | |
426 */ | |
427 static String _LIBRARIES_FILE = "libraries.dart"; | |
428 /** | |
429 * The name of the directory within the SDK directory that contains the packag
es. | |
430 */ | |
431 static String _PKG_DIRECTORY_NAME = "pkg"; | |
432 /** | |
433 * The name of the file within the SDK directory that contains the revision nu
mber of the SDK. | |
434 */ | |
435 static String _REVISION_FILE_NAME = "revision"; | |
436 /** | |
437 * The name of the file containing the VM executable on the Windows operating
system. | |
438 */ | |
439 static String _VM_EXECUTABLE_NAME_WIN = "dart.exe"; | |
440 /** | |
441 * The name of the file containing the VM executable on non-Windows operating
systems. | |
442 */ | |
443 static String _VM_EXECUTABLE_NAME = "dart"; | |
444 /** | |
445 * Return the default Dart SDK, or {@code null} if the directory containing th
e default SDK cannot | |
446 * be determined (or does not exist). | |
447 * @return the default Dart SDK | |
448 */ | |
449 static DartSdk get defaultSdk { | |
450 JavaFile sdkDirectory = defaultSdkDirectory; | |
451 if (sdkDirectory == null) { | |
452 return null; | |
453 } | |
454 return new DartSdk(sdkDirectory); | |
455 } | |
456 /** | |
457 * Return the default directory for the Dart SDK, or {@code null} if the direc
tory cannot be | |
458 * determined (or does not exist). The default directory is provided by a {@li
nk System} property | |
459 * named {@code com.google.dart.sdk}, or, if the property is not defined, an e
nvironment variable | |
460 * named {@code DART_SDK}. | |
461 * @return the default directory for the Dart SDK | |
462 */ | |
463 static JavaFile get defaultSdkDirectory { | |
464 String sdkProperty = JavaSystemIO.getProperty(_DEFAULT_DIRECTORY_PROPERTY_NA
ME); | |
465 if (sdkProperty == null) { | |
466 sdkProperty = JavaSystemIO.getenv(_DART_SDK_ENVIRONMENT_VARIABLE_NAME); | |
467 if (sdkProperty == null) { | |
468 return null; | |
469 } | |
470 } | |
471 JavaFile sdkDirectory = new JavaFile(sdkProperty); | |
472 if (!sdkDirectory.exists()) { | |
473 return null; | |
474 } | |
475 return sdkDirectory; | |
476 } | |
477 /** | |
478 * Initialize a newly created SDK to represent the Dart SDK installed in the g
iven directory. | |
479 * @param sdkDirectory the directory containing the SDK | |
480 */ | |
481 DartSdk(JavaFile sdkDirectory) { | |
482 this._sdkDirectory = sdkDirectory.getAbsoluteFile(); | |
483 initializeSdk(); | |
484 initializeLibraryMap(); | |
485 } | |
486 /** | |
487 * Return the file containing the Dartium executable, or {@code null} if it do
es not exist. | |
488 * @return the file containing the Dartium executable | |
489 */ | |
490 JavaFile get dartiumExecutable { | |
491 { | |
492 if (_dartiumExecutable == null) { | |
493 JavaFile file = new JavaFile.relative(_sdkDirectory, dartiumBinaryName); | |
494 if (file.exists()) { | |
495 _dartiumExecutable = file; | |
496 } | |
497 } | |
498 } | |
499 return _dartiumExecutable; | |
500 } | |
501 /** | |
502 * Return the directory where dartium can be found in the Dart SDK (the direct
ory that will be the | |
503 * working directory is Dartium is invoked without changing the default). | |
504 * @return the directory where dartium can be found | |
505 */ | |
506 JavaFile get dartiumWorkingDirectory { | |
507 if (OSUtilities.isWindows() || OSUtilities.isMac()) { | |
508 return _sdkDirectory; | |
509 } else { | |
510 return new JavaFile.relative(_sdkDirectory, _CHROMIUM_DIRECTORY_NAME); | |
511 } | |
512 } | |
513 /** | |
514 * Return the directory containing the SDK. | |
515 * @return the directory containing the SDK | |
516 */ | |
517 JavaFile get directory => _sdkDirectory; | |
518 /** | |
519 * Return the directory containing documentation for the SDK. | |
520 * @return the SDK's documentation directory | |
521 */ | |
522 JavaFile get docDirectory => new JavaFile.relative(_sdkDirectory, _DOCS_DIRECT
ORY_NAME); | |
523 /** | |
524 * Return the auxiliary documentation file for the given library, or {@code nu
ll} if no such file | |
525 * exists. | |
526 * @param libraryName the name of the library associated with the documentatio
n file to be | |
527 * returned | |
528 * @return the auxiliary documentation file for the library | |
529 */ | |
530 JavaFile getDocFileFor(String libraryName) { | |
531 JavaFile dir = docDirectory; | |
532 if (!dir.exists()) { | |
533 return null; | |
534 } | |
535 JavaFile libDir = new JavaFile.relative(dir, libraryName); | |
536 JavaFile docFile = new JavaFile.relative(libDir, "${libraryName}${_DOC_FILE_
SUFFIX}"); | |
537 if (docFile.exists()) { | |
538 return docFile; | |
539 } | |
540 return null; | |
541 } | |
542 /** | |
543 * Return the directory within the SDK directory that contains the libraries. | |
544 * @return the directory that contains the libraries | |
545 */ | |
546 JavaFile get libraryDirectory => new JavaFile.relative(_sdkDirectory, _LIB_DIR
ECTORY_NAME); | |
547 /** | |
548 * Return the directory within the SDK directory that contains the packages. | |
549 * @return the directory that contains the packages | |
550 */ | |
551 JavaFile get packageDirectory => new JavaFile.relative(directory, _PKG_DIRECTO
RY_NAME); | |
552 /** | |
553 * Return an array containing all of the libraries defined in this SDK. | |
554 * @return the libraries defined in this SDK | |
555 */ | |
556 List<SdkLibrary> get sdkLibraries => _libraryMap.sdkLibraries; | |
557 /** | |
558 * Return the revision number of this SDK, or {@code "0"} if the revision numb
er cannot be | |
559 * discovered. | |
560 * @return the revision number of this SDK | |
561 */ | |
562 String get sdkVersion { | |
563 { | |
564 if (_sdkVersion == null) { | |
565 _sdkVersion = _DEFAULT_VERSION; | |
566 JavaFile revisionFile = new JavaFile.relative(_sdkDirectory, _REVISION_F
ILE_NAME); | |
567 try { | |
568 String revision = revisionFile.readAsStringSync(); | |
569 if (revision != null) { | |
570 _sdkVersion = revision; | |
571 } | |
572 } on IOException catch (exception) { | |
573 } | |
574 } | |
575 } | |
576 return _sdkVersion; | |
577 } | |
578 /** | |
579 * Return an array containing the library URI's for the libraries defined in t
his SDK. | |
580 * @return the library URI's for the libraries defined in this SDK | |
581 */ | |
582 List<String> get uris => _libraryMap.uris; | |
583 /** | |
584 * Return the file containing the VM executable, or {@code null} if it does no
t exist. | |
585 * @return the file containing the VM executable | |
586 */ | |
587 JavaFile get vmExecutable { | |
588 { | |
589 if (_vmExecutable == null) { | |
590 JavaFile file = new JavaFile.relative(new JavaFile.relative(_sdkDirector
y, _BIN_DIRECTORY_NAME), binaryName); | |
591 if (file.exists()) { | |
592 _vmExecutable = file; | |
593 } | |
594 } | |
595 } | |
596 return _vmExecutable; | |
597 } | |
598 /** | |
599 * Return {@code true} if this SDK includes documentation. | |
600 * @return {@code true} if this installation of the SDK has documentation | |
601 */ | |
602 bool hasDocumentation() => docDirectory.exists(); | |
603 /** | |
604 * Return {@code true} if the Dartium binary is available. | |
605 * @return {@code true} if the Dartium binary is available | |
606 */ | |
607 bool isDartiumInstalled() => dartiumExecutable != null; | |
608 /** | |
609 * Return the file representing the library with the given {@code dart:} URI,
or {@code null} if | |
610 * the given URI does not denote a library in this SDK. | |
611 * @param dartUri the URI of the library to be returned | |
612 * @return the file representing the specified library | |
613 */ | |
614 JavaFile mapDartUri(String dartUri) { | |
615 SdkLibrary library = _libraryMap.getLibrary(dartUri); | |
616 if (library == null) { | |
617 return null; | |
618 } | |
619 return new JavaFile.relative(libraryDirectory, library.path); | |
620 } | |
621 /** | |
622 * Ensure that the dart VM is executable. If it is not, make it executable and
log that it was | |
623 * necessary for us to do so. | |
624 */ | |
625 void ensureVmIsExecutable() { | |
626 } | |
627 /** | |
628 * Return the name of the file containing the VM executable. | |
629 * @return the name of the file containing the VM executable | |
630 */ | |
631 String get binaryName { | |
632 if (OSUtilities.isWindows()) { | |
633 return _VM_EXECUTABLE_NAME_WIN; | |
634 } else { | |
635 return _VM_EXECUTABLE_NAME; | |
636 } | |
637 } | |
638 /** | |
639 * Return the name of the file containing the Dartium executable. | |
640 * @return the name of the file containing the Dartium executable | |
641 */ | |
642 String get dartiumBinaryName { | |
643 if (OSUtilities.isWindows()) { | |
644 return _DARTIUM_EXECUTABLE_NAME_WIN; | |
645 } else if (OSUtilities.isMac()) { | |
646 return _DARTIUM_EXECUTABLE_NAME_MAC; | |
647 } else { | |
648 return _DARTIUM_EXECUTABLE_NAME_LINUX; | |
649 } | |
650 } | |
651 /** | |
652 * Read all of the configuration files to initialize the library maps. | |
653 */ | |
654 void initializeLibraryMap() { | |
655 try { | |
656 JavaFile librariesFile = new JavaFile.relative(new JavaFile.relative(libra
ryDirectory, _INTERNAL_DIR), _LIBRARIES_FILE); | |
657 String contents = librariesFile.readAsStringSync(); | |
658 _libraryMap = new SdkLibrariesReader().readFrom(librariesFile, contents); | |
659 } on JavaException catch (exception) { | |
660 AnalysisEngine.instance.logger.logError3(exception); | |
661 _libraryMap = new LibraryMap(); | |
662 } | |
663 } | |
664 /** | |
665 * Initialize the state of the SDK. | |
666 */ | |
667 void initializeSdk() { | |
668 if (!OSUtilities.isWindows()) { | |
669 ensureVmIsExecutable(); | |
670 } | |
671 } | |
672 } | |
OLD | NEW |