Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(28)

Unified Diff: utils/pub/entrypoint.dart

Issue 12090081: Add a Pub validator for READMEs that are invalid utf-8. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Actually use the validator. Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: utils/pub/entrypoint.dart
diff --git a/utils/pub/entrypoint.dart b/utils/pub/entrypoint.dart
index 30bfeb1650a37f6af89274ae9180f255b30578eb..c830dd7bbd2965741df16dfa852279319f877312 100644
--- a/utils/pub/entrypoint.dart
+++ b/utils/pub/entrypoint.dart
@@ -14,6 +14,8 @@ import 'utils.dart';
import 'version.dart';
import 'version_solver.dart';
+final _README_REGEXP = new RegExp(r"^README($|\.)", caseSensitive: false);
+
/// Pub operates over a directed graph of dependencies that starts at a root
/// "entrypoint" package. This is typically the package where the current
/// working directory is located. An entrypoint knows the [root] package it is
@@ -54,6 +56,26 @@ class Entrypoint {
/// The path to this "packages" directory.
String get path => join(root.dir, 'packages');
+ /// Returns the path to the README file at the root of the entrypoint, or null
+ /// if no README file is found. If multiple READMEs are found, this uses the
+ /// same conventions as pub.dartlang.org for choosing the primary one: the
+ /// README with the fewest extensions that is lexically ordered first is
+ /// chosen.
Bob Nystrom 2013/01/31 19:08:29 How about moving this to Package? It's not specifi
nweiz 2013/01/31 21:39:10 Done.
+ Future<String> get readmePath {
+ return listDir(root.dir).then((entries) {
+ var readmes = entries.where((entry) => entry.contains(_README_REGEXP));
+ if (readmes.isEmpty) return;
+
+ return readmes.min((readme1, readme2) {
+ var extensions1 = ".".allMatches(readme1).length;
+ var extensions2 = ".".allMatches(readme2).length;
+ var comparison = extensions1.compareTo(extensions2);
+ if (comparison != 0) return comparison;
+ return readme1.compareTo(readme2);
+ });
+ });
+ }
+
/// Ensures that the package identified by [id] is installed to the directory.
/// Returns the resolved [PackageId].
///
« no previous file with comments | « no previous file | utils/pub/io.dart » ('j') | utils/pub/io.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698