| 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 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 331 } | 331 } |
| 332 } else { | 332 } else { |
| 333 libraries.addAll(_findFilesToDocumentInPackage(arg)); | 333 libraries.addAll(_findFilesToDocumentInPackage(arg)); |
| 334 } | 334 } |
| 335 } | 335 } |
| 336 return libraries; | 336 return libraries; |
| 337 } | 337 } |
| 338 | 338 |
| 339 /// Given a package name, explore the directory and pull out all top level | 339 /// Given a package name, explore the directory and pull out all top level |
| 340 /// library files in the "lib" directory to document. | 340 /// library files in the "lib" directory to document. |
| 341 List<Uri> _findFilesToDocumentInPackage(String packageName) { | 341 List<Uri> _findFilesToDocumentInPackage(String packageDir) { |
| 342 var libraries = []; | 342 var libraries = []; |
| 343 // To avoid anaylzing package files twice, only files with paths not | 343 // To avoid anaylzing package files twice, only files with paths not |
| 344 // containing '/packages' will be added. The only exception is if the file | 344 // containing '/packages' will be added. The only exception is if the file |
| 345 // to analyze already has a '/package' in its path. | 345 // to analyze already has a '/package' in its path. |
| 346 var files = listDir(packageName, recursive: true, listDir: _packageDirList) | 346 var files = listDir(packageDir, recursive: true, listDir: _packageDirList) |
| 347 .where((f) => f.endsWith('.dart') && | 347 .where((f) => f.endsWith('.dart') && |
| 348 (!f.contains('${path.separator}packages') || | 348 (!f.contains('${path.separator}packages') || |
| 349 packageName.contains('${path.separator}packages'))) | 349 packageDir.contains('${path.separator}packages'))) |
| 350 .toList(); | 350 .toList(); |
| 351 | 351 |
| 352 var packageLibDir = path.join(packageDir, 'lib'); |
| 353 var packageLibSrcDir = path.join(packageLibDir, 'src'); |
| 354 |
| 352 files.forEach((String lib) { | 355 files.forEach((String lib) { |
| 353 // Only include libraries at the top level of "lib" | 356 // Only include libraries within the lib dir that are not in lib/src |
| 354 if (path.basename(path.dirname(lib)) == 'lib') { | 357 if (path.isWithin(packageLibDir, lib) && |
| 358 !path.isWithin(packageLibSrcDir, lib)) { |
| 355 // Only add the file if it does not contain 'part of' | 359 // Only add the file if it does not contain 'part of' |
| 356 // TODO(janicejl): Remove when Issue(12406) is resolved. | 360 // TODO(janicejl): Remove when Issue(12406) is resolved. |
| 357 var contents = new File(lib).readAsStringSync(); | 361 var contents = new File(lib).readAsStringSync(); |
| 358 if (!(contents.contains(new RegExp('\npart of ')) || | 362 |
| 359 contents.startsWith(new RegExp('part of ')))) { | 363 |
| 364 if (contents.contains(new RegExp('\npart of ')) || |
| 365 contents.startsWith(new RegExp('part of '))) { |
| 366 logger.warning('Skipping part "$lib". ' |
| 367 'Part files should be in "lib/src".'); |
| 368 } else { |
| 360 libraries.add(new Uri.file(path.normalize(path.absolute(lib)))); | 369 libraries.add(new Uri.file(path.normalize(path.absolute(lib)))); |
| 361 logger.info('Added to libraries: $lib'); | 370 logger.info('Added to libraries: $lib'); |
| 362 } | 371 } |
| 363 } | 372 } |
| 364 }); | 373 }); |
| 365 return libraries; | 374 return libraries; |
| 366 } | 375 } |
| 367 | 376 |
| 368 /// If [dir] contains both a `lib` directory and a `pubspec.yaml` file treat | 377 /// If [dir] contains both a `lib` directory and a `pubspec.yaml` file treat |
| 369 /// it like a package and only return the `lib` dir. | 378 /// it like a package and only return the `lib` dir. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 465 * [Samples](http://www.dartlang.org/samples/) | 474 * [Samples](http://www.dartlang.org/samples/) |
| 466 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) | 475 * [A Tour of the Dart Libraries](http://www.dartlang.org/docs/dart-up-and-runn
ing/contents/ch03.html) |
| 467 | 476 |
| 468 This API reference is automatically generated from the source code in the | 477 This API reference is automatically generated from the source code in the |
| 469 [Dart project](https://code.google.com/p/dart/). | 478 [Dart project](https://code.google.com/p/dart/). |
| 470 If you'd like to contribute to this documentation, see | 479 If you'd like to contribute to this documentation, see |
| 471 [Contributing](https://code.google.com/p/dart/wiki/Contributing) | 480 [Contributing](https://code.google.com/p/dart/wiki/Contributing) |
| 472 and | 481 and |
| 473 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). | 482 [Writing API Documentation](https://code.google.com/p/dart/wiki/WritingApiDocume
ntation). |
| 474 """; | 483 """; |
| OLD | NEW |