Skip to content

Commit 1cf5f34

Browse files
authored
Support flutter in cross-links and add tests (#1680)
* Ready. * Fix case when FLUTTER_ROOT is not set * deletes throw if target does not exist * Get rid of infinite recursion in some cases for option handling * Fix grinder stream handling to not chop off error messages * Can't seem to get any information for failure, so hack travis script * reduce parallelism * Disable parallelization on travis for testing * Use numberOfProcessors * Travis has two processors and may not be detected properly by dart * print processors and adjust to two cores for travis * Fix travis parallelization once and for all. * Fix MultiFutureTracker parallelism restriction * Review comments and analyzer exclude for flutter package (ok that it doesn't analyze) * Redo flutter repo build to fix reentrancy problems * Use a Completer * dartfmt
1 parent 97a3313 commit 1cf5f34

20 files changed

+719
-280
lines changed

.travis.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,4 @@ branches:
1515
cache:
1616
directories:
1717
- $HOME/.pub-cache
18+
- $HOME/.dartdoc_grinder

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,14 @@ Unrecognized options will be ignored. Supported options:
114114
* **linkTo**: For other packages depending on this one, if this map is defined those packages
115115
will use the settings here to control how hyperlinks to the package are generated.
116116
This will override the default for packages hosted on pub.dartlang.org.
117-
* url: A string indicating the base URL for documentation of this package. The following
118-
strings will be substituted in to complete the URL:
117+
* **url**: A string indicating the base URL for documentation of this package. Ordinarily
118+
you do not need to set this in the package: consider --link-to-hosted and
119+
--link-to-sdks instead of this option if you need to build your own website with
120+
dartdoc.
121+
122+
The following strings will be substituted in to complete the URL:
123+
* `%b%`: The branch as indicated by text in the version. 2.0.0-dev.3 is branch "dev".
124+
No branch is considered to be "stable".
119125
* `%n%`: The name of this package, as defined in pubspec.yaml.
120126
* `%v%`: The version of this package as defined in pubspec.yaml.
121127

analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ analyzer:
99
- 'lib/templates/*.html'
1010
- 'pub.dartlang.org/**'
1111
- 'testing/**'
12+
- 'testing/test_package_flutter_plugin/**'
1213
linter:
1314
rules:
1415
- annotate_overrides

bin/dartdoc.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ main(List<String> arguments) async {
6969
logInfo("Generating documentation for '${config.topLevelPackageMeta}' into "
7070
"${outputDir.absolute.path}${Platform.pathSeparator}");
7171

72-
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(config, outputDir);
72+
Dartdoc dartdoc = await Dartdoc.withDefaultGenerators(config);
7373

7474
dartdoc.onCheckProgress.listen(logProgress);
7575
await Chain.capture(() async {

lib/dartdoc.dart

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -43,32 +43,30 @@ const String dartdocVersion = '0.18.1';
4343
/// directory.
4444
class Dartdoc extends PackageBuilder {
4545
final List<Generator> generators;
46-
final Directory outputDir;
4746
final Set<String> writtenFiles = new Set();
47+
Directory outputDir;
4848

4949
// Fires when the self checks make progress.
5050
final StreamController<String> _onCheckProgress =
5151
new StreamController(sync: true);
5252

53-
Dartdoc._(DartdocOptionContext config, this.generators, this.outputDir)
54-
: super(config) {
53+
Dartdoc._(DartdocOptionContext config, this.generators) : super(config) {
54+
outputDir = new Directory(config.output)..createSync(recursive: true);
5555
generators.forEach((g) => g.onFileCreated.listen(logProgress));
5656
}
5757

5858
/// An asynchronous factory method that builds Dartdoc's file writers
5959
/// and returns a Dartdoc object with them.
60-
static withDefaultGenerators(
61-
DartdocOptionContext config, Directory outputDir) async {
60+
static withDefaultGenerators(DartdocOptionContext config) async {
6261
List<Generator> generators =
6362
await initGenerators(config as GeneratorContext);
64-
return new Dartdoc._(config, generators, outputDir);
63+
return new Dartdoc._(config, generators);
6564
}
6665

6766
/// Basic synchronous factory that gives a stripped down Dartdoc that won't
6867
/// use generators. Useful for testing.
69-
factory Dartdoc.withoutGenerators(
70-
DartdocOptionContext config, Directory outputDir) {
71-
return new Dartdoc._(config, [], outputDir);
68+
factory Dartdoc.withoutGenerators(DartdocOptionContext config) {
69+
return new Dartdoc._(config, []);
7270
}
7371

7472
Stream<String> get onCheckProgress => _onCheckProgress.stream;
@@ -345,25 +343,28 @@ class Dartdoc extends PackageBuilder {
345343
// (newPathToCheck, newFullPath)
346344
Set<Tuple2<String, String>> toVisit = new Set();
347345

346+
final RegExp ignoreHyperlinks = new RegExp(r'^(https:|http:|mailto:|ftp:)');
348347
for (String href in stringLinks) {
349-
Uri uri;
350-
try {
351-
uri = Uri.parse(href);
352-
} catch (FormatError) {}
353-
354-
if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
355-
var full;
356-
if (baseHref != null) {
357-
full = '${pathLib.dirname(pathToCheck)}/$baseHref/$href';
358-
} else {
359-
full = '${pathLib.dirname(pathToCheck)}/$href';
360-
}
361-
var newPathToCheck = pathLib.normalize(full);
362-
String newFullPath = pathLib.joinAll([origin, newPathToCheck]);
363-
newFullPath = pathLib.normalize(newFullPath);
364-
if (!visited.contains(newFullPath)) {
365-
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
366-
visited.add(newFullPath);
348+
if (!href.startsWith(ignoreHyperlinks)) {
349+
Uri uri;
350+
try {
351+
uri = Uri.parse(href);
352+
} catch (FormatError) {}
353+
354+
if (uri == null || !uri.hasAuthority && !uri.hasFragment) {
355+
var full;
356+
if (baseHref != null) {
357+
full = '${pathLib.dirname(pathToCheck)}/$baseHref/$href';
358+
} else {
359+
full = '${pathLib.dirname(pathToCheck)}/$href';
360+
}
361+
var newPathToCheck = pathLib.normalize(full);
362+
String newFullPath = pathLib.joinAll([origin, newPathToCheck]);
363+
newFullPath = pathLib.normalize(newFullPath);
364+
if (!visited.contains(newFullPath)) {
365+
toVisit.add(new Tuple2(newPathToCheck, newFullPath));
366+
visited.add(newFullPath);
367+
}
367368
}
368369
}
369370
}

0 commit comments

Comments
 (0)