Merge pull request #27 from dart-lang/2.0

support Dart 2.0
diff --git a/.gitignore b/.gitignore
index 0256a9b..96db218 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,6 +1,7 @@
 .buildlog
 .DS_Store
 .idea
+.dart_tool/
 .pub/
 .settings/
 build/
diff --git a/.travis.yml b/.travis.yml
index 9c3a39f..aaed16a 100644
--- a/.travis.yml
+++ b/.travis.yml
@@ -1,2 +1,8 @@
 language: dart
+dart:
+  - dev
 script: ./tool/travis.sh
+
+branches:
+  only:
+    - master
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7e681ff..af30e42 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Changelog
 
+## 0.2.0
+- upgraded to support Dart 2
+
 ## 0.1.1
 - fixed an issue with global_packages enumeration
 
diff --git a/README.md b/README.md
index 7111ea6..9208f60 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,6 @@
 [![pub package](http://img.shields.io/pub/v/pub_cache.svg)](https://pub.dartlang.org/packages/pub_cache)
 [![Build Status](https://travis-ci.org/dart-lang/pub_cache.svg)](https://travis-ci.org/dart-lang/pub_cache)
 [![Build status](https://ci.appveyor.com/api/projects/status/w75vsabfhgmo93hq/branch/master?svg=true)](https://ci.appveyor.com/project/devoncarew/pub-cache/branch/master)
-[![Coverage Status](https://img.shields.io/coveralls/dart-lang/pub_cache.svg)](https://coveralls.io/r/dart-lang/pub_cache?branch=master)
 
 ## How do I use it?
 
diff --git a/lib/pub_cache.dart b/lib/pub_cache.dart
index 8dd77f6..6979ae6 100644
--- a/lib/pub_cache.dart
+++ b/lib/pub_cache.dart
@@ -36,15 +36,17 @@
 
   /// Create a pubcache instance. [dir] defaults to the default platform pub
   /// cache location.
-  PubCache([Directory dir]) :
-      location = dir == null ? getSystemCacheLocation() : dir {
+  PubCache([Directory dir])
+      : location = dir == null ? getSystemCacheLocation() : dir {
     _parse();
   }
 
   /// Return the contents of `bin/` - the scripts for the activated applications.
   List<File> getBinScripts() {
     Directory dir = _getSubDir(location, 'bin');
-    return dir.existsSync() ? dir.listSync() : [];
+    return dir.existsSync()
+        ? dir.listSync().where((entity) => entity is File).cast<File>().toList()
+        : <File>[];
   }
 
   /// Return applications that have been installed via `pub global activate`.
@@ -57,7 +59,7 @@
   /// Return the list of package names (not versions) that are available in the
   /// cache.
   List<String> getCachedPackages() =>
-      new Set.from(getPackageRefs().map((p) => p.name)).toList();
+      new Set<String>.from(getPackageRefs().map((p) => p.name)).toList();
 
   /// Return all available cached versions for a given package.
   List<PackageRef> getAllPackageVersions(String packageName) =>
@@ -67,7 +69,8 @@
   /// cache. This method will prefer to return only release verions. If
   /// [includePreRelease] is true, then the very latest verision will be
   /// returned, include pre-release versions.
-  PackageRef getLatestVersion(String packageName, {bool includePreRelease: false}) {
+  PackageRef getLatestVersion(String packageName,
+      {bool includePreRelease: false}) {
     List<PackageRef> refs = getAllPackageVersions(packageName);
 
     if (refs.isEmpty) return null;
@@ -104,23 +107,25 @@
     }
 
     // Scan hosted packages - just pub.dartlang.org for now.
-    _packageRefs = [];
+    _packageRefs = <PackageRef>[];
 
-    Directory dartlangDir = new Directory(
-        path.join(location.path, 'hosted', 'pub.dartlang.org'));
+    Directory dartlangDir =
+        new Directory(path.join(location.path, 'hosted', 'pub.dartlang.org'));
     if (dartlangDir.existsSync()) {
-      _packageRefs = dartlangDir.listSync()
+      _packageRefs.addAll(dartlangDir
+          .listSync()
           .where((dir) => dir is Directory)
-          .map((dir) => new DirectoryPackageRef('hosted', dir))
-          .toList();
+          .map((dir) => new DirectoryPackageRef('hosted', dir)));
     }
 
     // Scan for git packages (ignore the git/cache directory).
     // ace-a1a140cc933e7d44d2955a6d6033308754bb9235
     Directory gitDir = new Directory(path.join(location.path, 'git'));
     if (gitDir.existsSync()) {
-      Iterable gitRefs = gitDir.listSync()
-          .where((dir) => dir is Directory && path.basename(dir.path) != 'cache')
+      Iterable<PackageRef> gitRefs = gitDir
+          .listSync()
+          .where(
+              (dir) => dir is Directory && path.basename(dir.path) != 'cache')
           .map((dir) => new GitDirectoryPackageRef(dir));
       _packageRefs.addAll(gitRefs);
     }
@@ -175,7 +180,8 @@
       Map m = packages[key];
       String source = m['source'];
       if (source == 'git') {
-        return new PackageRefImpl.git(key, m['version'], m['description'], (curRef) {
+        return new PackageRefImpl.git(key, m['version'], m['description'],
+            (curRef) {
           for (PackageRef ref in _cache.getPackageRefs()) {
             if (ref == curRef) return ref.resolve();
           }
@@ -202,8 +208,10 @@
 abstract class PackageRef {
   /// The type of the package reference. Valid types include `hosted` and `git`.
   String get sourceType;
+
   /// The name of the package.
   String get name;
+
   /// The version of the package.
   Version get version;
 
@@ -212,9 +220,9 @@
   Package resolve();
 
   bool operator ==(other) {
-    return this.sourceType == other.sourceType
-        && this.name == other.name
-        && this.version == other.version;
+    return this.sourceType == other.sourceType &&
+        this.name == other.name &&
+        this.version == other.version;
   }
 
   String toString() => '${name} ${version}';
diff --git a/lib/src/impl.dart b/lib/src/impl.dart
index 59bad03..b8e83b2 100644
--- a/lib/src/impl.dart
+++ b/lib/src/impl.dart
@@ -19,13 +19,15 @@
 
   Function _resolver;
 
-  PackageRefImpl(this.sourceType, this.name, String ver) :
-      version = new Version.parse(ver);
+  PackageRefImpl(this.sourceType, this.name, String ver)
+      : version = new Version.parse(ver);
 
-  PackageRefImpl.hosted(this.name, String ver, this._resolver) :
-    sourceType = 'hosted', version = new Version.parse(ver);
+  PackageRefImpl.hosted(this.name, String ver, this._resolver)
+      : sourceType = 'hosted',
+        version = new Version.parse(ver);
 
-  factory PackageRefImpl.git(String name, String ver, Map description, Function resolver) {
+  factory PackageRefImpl.git(
+      String name, String ver, Map description, Function resolver) {
     return new GitPackageRefImpl(name, ver, description, resolver);
   }
 
@@ -39,8 +41,9 @@
 class GitPackageRefImpl extends PackageRefImpl {
   final Map _description;
 
-  GitPackageRefImpl(String name, String ver, this._description, Function resolver) :
-      super('git', name, ver) {
+  GitPackageRefImpl(
+      String name, String ver, this._description, Function resolver)
+      : super('git', name, ver) {
     _resolver = resolver;
   }
 
@@ -56,8 +59,8 @@
 class PathPackageRefImpl extends PackageRefImpl {
   final Map _description;
 
-  PathPackageRefImpl(String name, String ver, this._description) :
-      super('path', name, ver);
+  PathPackageRefImpl(String name, String ver, this._description)
+      : super('path', name, ver);
 
   /// The path to the local package.
   String get path => _description['path'];
diff --git a/pubspec.yaml b/pubspec.yaml
index bd63774..38f4856 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,11 +1,11 @@
 name: pub_cache
-version: 0.1.1
+version: 0.2.0
 description: A library to reflect on the local pub cache.
 author: Dart Team <misc@dartlang.org>
 homepage: https://github.com/dart-lang/pub_cache
 
 environment:
-  sdk: '>=1.8.0 <2.0.0'
+  sdk: '>=2.0.0-dev.17.0 <2.0.0'
 
 dependencies:
   path: '^1.0.0'
diff --git a/test/pub_cache_test.dart b/test/pub_cache_test.dart
index d63a5c1..b6c03fa 100644
--- a/test/pub_cache_test.dart
+++ b/test/pub_cache_test.dart
@@ -18,7 +18,8 @@
   group('PubCache', () {
     tearDown(() {
       Directory cacheDir = PubCache.getSystemCacheLocation();
-      var globalDir = new Directory(path.join(cacheDir.path, "global_packages"));
+      var globalDir =
+          new Directory(path.join(cacheDir.path, "global_packages"));
       var file = new File(path.join(globalDir.path, "nonsense"));
       if (file.existsSync()) {
         file.deleteSync();
@@ -38,7 +39,8 @@
 
       // Put a file in global_packages
       Directory cacheDir = PubCache.getSystemCacheLocation();
-      var globalDir = new Directory(path.join(cacheDir.path, "global_packages"));
+      var globalDir =
+          new Directory(path.join(cacheDir.path, "global_packages"));
       var file = new File(path.join(globalDir.path, "nonsense"));
       file.writeAsStringSync("pub_cache test suite");
 
@@ -88,7 +90,8 @@
 
     test('getLatestVersion.dev', () {
       PubCache cache = new PubCache();
-      expect(cache.getLatestVersion('path', includePreRelease: true), isNotNull);
+      expect(
+          cache.getLatestVersion('path', includePreRelease: true), isNotNull);
     });
   });
 
diff --git a/tool/travis.sh b/tool/travis.sh
index 9c9c989..02f2d88 100755
--- a/tool/travis.sh
+++ b/tool/travis.sh
@@ -8,7 +8,7 @@
 set -e
 
 # Activate some packages for use while running tests.
-pub global activate dart_coveralls
+pub global activate tuneup
 pub global activate path 1.3.0
 pub global activate path
 pub global activate --source git https://github.com/dart-lang/test.git
@@ -16,18 +16,12 @@
 
 # Verify that the libraries are error free.
 dartanalyzer --fatal-warnings \
-  example/list.dart \
-  lib/pub_cache.dart \
-  test/all.dart
+  example/ \
+  lib/ \
+  test/
+
+# Ensure the example works in Dart 2.
+dart --preview-dart-2 example/list.dart
 
 # Run the tests.
-dart test/all.dart
-
-# Gather and send coverage data.
-if [ "$COVERALLS_TOKEN" ]; then
-  pub global run dart_coveralls report \
-    --token $COVERALLS_TOKEN \
-    --retry 2 \
-    --exclude-test-files \
-    test/all.dart
-fi
+dart --preview-dart-2 test/all.dart