Skip to content
Snippets Groups Projects
Commit 72ec5063 authored by nweiz@google.com's avatar nweiz@google.com
Browse files

Add a pub validator for compiled dartdoc output.

BUG=7045

Review URL: https://codereview.chromium.org//12089076

git-svn-id: https://dart.googlecode.com/svn/branches/bleeding_edge@17943 260f80e4-7a28-3924-810f-c04153c831b5
parent af1e8fc2
No related branches found
No related tags found
No related merge requests found
......@@ -118,6 +118,18 @@ void chainToCompleter(Future future, Completer completer) {
onError: (e) => completer.completeError(e.error, e.stackTrace));
}
/// Like [Iterable.where], but allows [test] to return [Future]s and uses the
/// results of those [Future]s as the test.
Future<Iterable> futureWhere(Iterable iter, test(value)) {
return Future.wait(iter.mappedBy((e) {
var result = test(e);
if (result is! Future) result = new Future.immediate(result);
return result.then((result) => new Pair(e, result));
}))
.then((pairs) => pairs.where((pair) => pair.last))
.then((pairs) => pairs.mappedBy((pair) => pair.first));
}
// TODO(nweiz): unify the following functions with the utility functions in
// pkg/http.
......
......@@ -11,6 +11,7 @@ import 'log.dart' as log;
import 'io.dart';
import 'system_cache.dart';
import 'utils.dart';
import 'validator/compiled_dartdoc.dart';
import 'validator/dependency.dart';
import 'validator/directory.dart';
import 'validator/lib.dart';
......@@ -50,7 +51,8 @@ abstract class Validator {
new NameValidator(entrypoint),
new PubspecFieldValidator(entrypoint),
new DependencyValidator(entrypoint),
new DirectoryValidator(entrypoint)
new DirectoryValidator(entrypoint),
new CompiledDartdocValidator(entrypoint)
];
return Future.wait(validators.map((validator) => validator.validate()))
......
// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
library compiled_dartdoc_validator;
import 'dart:async';
import '../../../pkg/path/lib/path.dart' as path;
import '../entrypoint.dart';
import '../io.dart';
import '../utils.dart';
import '../validator.dart';
/// Validates that a package doesn't contain compiled Dartdoc
/// output.
class CompiledDartdocValidator extends Validator {
CompiledDartdocValidator(Entrypoint entrypoint)
: super(entrypoint);
Future validate() {
return listDir(entrypoint.root.dir, recursive: true).then((entries) {
return futureWhere(entries, (entry) {
if (basename(entry) != "nav.json") return false;
var dir = dirname(entry);
// Look for tell-tale Dartdoc output files all in the same directory.
return Future.wait([
fileExists(entry),
fileExists(join(dir, "index.html")),
fileExists(join(dir, "styles.css")),
fileExists(join(dir, "dart-logo-small.png")),
fileExists(join(dir, "client-live-nav.js"))
]).then((results) => results.every((val) => val));
}).then((files) {
for (var dartdocDir in files.mappedBy(dirname)) {
var relativePath = path.relative(dartdocDir);
warnings.add("Avoid putting generated documentation in "
"$relativePath.\n"
"Generated documentation bloats the package with redundant "
"data.");
}
});
});
}
}
......@@ -15,6 +15,7 @@ import '../../../pkg/http/lib/testing.dart';
import '../../pub/entrypoint.dart';
import '../../pub/io.dart';
import '../../pub/validator.dart';
import '../../pub/validator/compiled_dartdoc.dart';
import '../../pub/validator/dependency.dart';
import '../../pub/validator/directory.dart';
import '../../pub/validator/lib.dart';
......@@ -34,6 +35,9 @@ void expectValidationWarning(ValidatorCreator fn) {
expectLater(schedulePackageValidation(fn), pairOf(isEmpty, isNot(isEmpty)));
}
Validator compiledDartdoc(Entrypoint entrypoint) =>
new CompiledDartdocValidator(entrypoint);
Validator dependency(Entrypoint entrypoint) =>
new DependencyValidator(entrypoint);
......@@ -125,6 +129,18 @@ main() {
]).scheduleCreate();
expectNoValidationError(directory);
});
integration('has most but not all files from compiling dartdoc', () {
dir(appPath, [
dir("doc-out", [
file("nav.json", ""),
file("index.html", ""),
file("styles.css", ""),
file("dart-logo-small.png", "")
])
]).scheduleCreate();
expectNoValidationError(compiledDartdoc);
});
});
group('should consider a package invalid if it', () {
......@@ -520,5 +536,19 @@ main() {
});
}
});
test('contains compiled dartdoc', () {
dir(appPath, [
dir('doc-out', [
file('nav.json', ''),
file('index.html', ''),
file('styles.css', ''),
file('dart-logo-small.png', ''),
file('client-live-nav.js', '')
])
]).scheduleCreate();
expectValidationWarning(compiledDartdoc);
});
});
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment