| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 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 | 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 docgen.generator; | 5 library docgen.generator; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:collection'; | 8 import 'dart:collection'; |
| 9 import 'dart:convert'; | 9 import 'dart:convert'; |
| 10 import 'dart:io'; | 10 import 'dart:io'; |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 54 /// also be documented. | 54 /// also be documented. |
| 55 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. | 55 /// If [parseSdk] is `true`, then all Dart SDK libraries will be documented. |
| 56 /// This option is useful when only the SDK libraries are needed. | 56 /// This option is useful when only the SDK libraries are needed. |
| 57 /// | 57 /// |
| 58 /// Returned Future completes with true if document generation is successful. | 58 /// Returned Future completes with true if document generation is successful. |
| 59 Future<bool> generateDocumentation(List<String> files, {String packageRoot, | 59 Future<bool> generateDocumentation(List<String> files, {String packageRoot, |
| 60 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, | 60 bool outputToYaml: true, bool includePrivate: false, bool includeSdk: false, |
| 61 bool parseSdk: false, String introFileName: '', | 61 bool parseSdk: false, String introFileName: '', |
| 62 out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries: const [], bool | 62 out: DEFAULT_OUTPUT_DIRECTORY, List<String> excludeLibraries: const [], bool |
| 63 includeDependentPackages: false, String startPage, String dartBinaryValue, | 63 includeDependentPackages: false, String startPage, String dartBinaryValue, |
| 64 String pubScriptValue, bool indentJSON: false}) { | 64 String pubScriptValue, bool indentJSON: false, String sdk}) { |
| 65 _excluded = excludeLibraries; | 65 _excluded = excludeLibraries; |
| 66 dartBinary = dartBinaryValue; | 66 dartBinary = dartBinaryValue; |
| 67 pubScript = pubScriptValue; | 67 pubScript = pubScriptValue; |
| 68 | 68 |
| 69 logger.onRecord.listen((record) => print(record.message)); | 69 logger.onRecord.listen((record) => print(record.message)); |
| 70 | 70 |
| 71 _ensureOutputDirectory(out); | 71 _ensureOutputDirectory(out); |
| 72 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); | 72 var updatedPackageRoot = _obtainPackageRoot(packageRoot, parseSdk, files); |
| 73 | 73 |
| 74 var requestedLibraries = _findLibrariesToDocument(files, | 74 var requestedLibraries = _findLibrariesToDocument(files, |
| 75 includeDependentPackages); | 75 includeDependentPackages); |
| 76 | 76 |
| 77 var allLibraries = []..addAll(requestedLibraries); | 77 var allLibraries = []..addAll(requestedLibraries); |
| 78 if (includeSdk) { | 78 if (includeSdk) { |
| 79 allLibraries.addAll(_listSdk()); | 79 allLibraries.addAll(_listSdk()); |
| 80 } | 80 } |
| 81 | 81 |
| 82 return getMirrorSystem(allLibraries, includePrivate, | 82 return getMirrorSystem(allLibraries, includePrivate, |
| 83 packageRoot: updatedPackageRoot, parseSdk: parseSdk) | 83 packageRoot: updatedPackageRoot, parseSdk: parseSdk, sdkRoot: sdk) |
| 84 .then((MirrorSystem mirrorSystem) { | 84 .then((MirrorSystem mirrorSystem) { |
| 85 if (mirrorSystem.libraries.isEmpty) { | 85 if (mirrorSystem.libraries.isEmpty) { |
| 86 throw new StateError('No library mirrors were created.'); | 86 throw new StateError('No library mirrors were created.'); |
| 87 } | 87 } |
| 88 initializeTopLevelLibraries(mirrorSystem); | 88 initializeTopLevelLibraries(mirrorSystem); |
| 89 | 89 |
| 90 var availableLibraries = mirrorSystem.libraries.values | 90 var availableLibraries = mirrorSystem.libraries.values |
| 91 .where((each) => each.uri.scheme == 'file'); | 91 .where((each) => each.uri.scheme == 'file'); |
| 92 var availableLibrariesByPath = | 92 var availableLibrariesByPath = |
| 93 new Map.fromIterables(availableLibraries.map((each) => each.uri), | 93 new Map.fromIterables(availableLibraries.map((each) => each.uri), |
| 94 availableLibraries); | 94 availableLibraries); |
| 95 var librariesToDocument = requestedLibraries | 95 var librariesToDocument = requestedLibraries |
| 96 .map((each) { | 96 .map((each) { |
| 97 return availableLibrariesByPath | 97 return availableLibrariesByPath |
| 98 .putIfAbsent(each, () => throw "Missing library $each"); | 98 .putIfAbsent(each, () => throw "Missing library $each"); |
| 99 }).toList(); | 99 }).toList(); |
| 100 librariesToDocument.addAll((includeSdk || parseSdk) ? sdkLibraries : []); | 100 librariesToDocument.addAll((includeSdk || parseSdk) ? sdkLibraries : []); |
| 101 librariesToDocument.removeWhere((x) => _excluded.contains( | 101 librariesToDocument.removeWhere((x) => _excluded.contains( |
| 102 dart2js_util.nameOf(x))); | 102 dart2js_util.nameOf(x))); |
| 103 _documentLibraries(librariesToDocument, includeSdk, parseSdk, introFileName, | 103 _documentLibraries(librariesToDocument, includeSdk, parseSdk, introFileName, |
| 104 startPage, indentJSON); | 104 startPage, indentJSON); |
| 105 return true; | 105 return true; |
| 106 }); | 106 }); |
| 107 } | 107 } |
| 108 | 108 |
| 109 | 109 |
| 110 /// Analyzes set of libraries by getting a mirror system and triggers the | 110 /// Analyzes set of libraries by getting a mirror system and triggers the |
| 111 /// documentation of the libraries. | 111 /// documentation of the libraries. |
| 112 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, | 112 Future<MirrorSystem> getMirrorSystem(List<Uri> libraries, |
| 113 bool includePrivate, {String packageRoot, bool parseSdk: false}) { | 113 bool includePrivate, {String packageRoot, bool parseSdk: false, |
| 114 String sdkRoot}) { |
| 114 if (libraries.isEmpty) throw new StateError('No Libraries.'); | 115 if (libraries.isEmpty) throw new StateError('No Libraries.'); |
| 115 | 116 |
| 116 includePrivateMembers = includePrivate; | 117 includePrivateMembers = includePrivate; |
| 117 | 118 |
| 118 // Finds the root of SDK library based off the location of docgen. | 119 // Finds the root of SDK library based off the location of docgen. |
| 119 // We have two different places to look, depending if we're in a development | 120 // We have two different places to look, depending if we're in a development |
| 120 // repo or in a built SDK, either sdk or dart-sdk respectively | 121 // repo or in a built SDK, either sdk or dart-sdk respectively |
| 121 var root = rootDirectory; | 122 if (sdkRoot == null) { |
| 122 var sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk'))); | 123 var root = rootDirectory; |
| 123 if (!new Directory(sdkRoot).existsSync()) { | 124 sdkRoot = path.normalize(path.absolute(path.join(root, 'sdk'))); |
| 124 sdkRoot = path.normalize(path.absolute(path.join(root, 'dart-sdk'))); | 125 if (!new Directory(sdkRoot).existsSync()) { |
| 126 sdkRoot = path.normalize(path.absolute(path.join(root, 'dart-sdk'))); |
| 127 } |
| 125 } | 128 } |
| 126 logger.info('SDK Root: ${sdkRoot}'); | 129 logger.info('SDK Root: ${sdkRoot}'); |
| 127 return analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); | 130 return analyzeLibraries(libraries, sdkRoot, packageRoot: packageRoot); |
| 128 } | 131 } |
| 129 | 132 |
| 130 /// Writes [text] to a file in the output directory. | 133 /// Writes [text] to a file in the output directory. |
| 131 void _writeToFile(String text, String filename) { | 134 void _writeToFile(String text, String filename) { |
| 132 if (text == null) return; | 135 if (text == null) return; |
| 133 | 136 |
| 134 var filePath = path.join(_outputDirectory, filename); | 137 var filePath = path.join(_outputDirectory, filename); |
| (...skipping 339 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 474 * [Samples](http://www.dartlang.org/samples/) | 477 * [Samples](http://www.dartlang.org/samples/) |
| 475 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) | 478 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) |
| 476 | 479 |
| 477 This API reference is automatically generated from the source code in the | 480 This API reference is automatically generated from the source code in the |
| 478 [Dart project](https://code.google.com/p/dart/). | 481 [Dart project](https://code.google.com/p/dart/). |
| 479 If you'd like to contribute to this documentation, see | 482 If you'd like to contribute to this documentation, see |
| 480 [Contributing](https://code.google.com/p/dart/wiki/Contributing) | 483 [Contributing](https://code.google.com/p/dart/wiki/Contributing) |
| 481 and | 484 and |
| 482 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). | 485 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). |
| 483 """; | 486 """; |
| OLD | NEW |