Skip to content

use the new Resource api #794

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 7, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
language: dart
sudo: false
dart:
dart:
- dev
- stable
# - stable
env:
- GEN_SDK_DOCS=true
- GEN_SDK_DOCS=false
Expand Down
2 changes: 1 addition & 1 deletion lib/dartdoc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class DartDoc {
if (name.startsWith(Platform.pathSeparator)) name = name.substring(1);
}
print('parsing ${name}...');
Source source = new FileBasedSource.con1(new JavaFile(filePath));
Source source = new FileBasedSource(new JavaFile(filePath));
sources.add(source);
if (context.computeKindOf(source) == SourceKind.LIBRARY) {
LibraryElement library = context.computeLibraryElement(source);
Expand Down
23 changes: 14 additions & 9 deletions lib/resource_loader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
// 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.

// TODO: Consider making this a stand-alone package, if useful.

/// Make it possible to load resources, independent of how the Dart app is run.
///
/// Future<String> getTemplateFile(String templatePath) {
Expand All @@ -14,7 +12,7 @@ library dartdoc.resource_loader;

import 'dart:async' show Future;
import 'dart:io' show Platform, File, Directory;
import 'dart:typed_data';
import 'dart:typed_data' show Uint8List;

import 'package:http/http.dart' as http;
import 'package:path/path.dart' as p;
Expand All @@ -24,20 +22,27 @@ import 'package:pub_cache/pub_cache.dart';
String packageRootPath;

/// Loads a `package:` resource as a String.
Future<String> loadAsString(String path) async {
Future<String> loadAsString(String path) {
if (!path.startsWith('package:')) {
throw new ArgumentError('path must begin with package:');
}
Uint8List bytes = await _doLoad(path);
return new String.fromCharCodes(bytes);
return new Resource(path).readAsString().catchError((_) async {
// TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
var bytes = await _doLoad(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe a note that we can remove this when a certain issue is closed?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do

return new String.fromCharCodes(bytes);
});
}

/// Loads a `package:` resource as an [Uint8List].
Future<Uint8List> loadAsBytes(String path) {
/// Loads a `package:` resource as an [List<int>].
Future<List<int>> loadAsBytes(String path) {
if (!path.startsWith('package:')) {
throw new ArgumentError('path must begin with package:');
}
return _doLoad(path);

return new Resource(path).readAsBytes().catchError((_) {
// TODO: Remove once https://github.com/dart-lang/pub/issues/22 is fixed.
return _doLoad(path);
});
}

/// Determine how to do the load. HTTP? Snapshotted? From source?
Expand Down
1 change: 0 additions & 1 deletion lib/src/model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import 'package:analyzer/src/generated/resolver.dart';
import 'package:analyzer/src/generated/utilities_dart.dart' show ParameterKind;
import 'package:quiver/core.dart';

import 'debug.dart';
import 'html_utils.dart';
import 'model_utils.dart';
import 'package_meta.dart';
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ author: Dart Team <[email protected]>
description: A documentation generator for Dart.
homepage: https://github.com/dart-lang/dartdoc
environment:
sdk: '>=1.9.0 <2.0.0' # when we go to 1.12, bump analyzer version
sdk: '>=1.12.0-dev.5.0 <2.0.0'
dependencies:
analyzer: '>=0.25.0 <0.27.0'
analyzer: '>=0.26.0 <0.27.0'
args: ^0.13.0
cli_util: ^0.0.1
html: ^0.12.1
Expand Down
2 changes: 1 addition & 1 deletion test/test_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class AnalyzerHelper {
}

Source addSource(String filePath) {
Source source = new FileBasedSource.con1(new JavaFile(filePath));
Source source = new FileBasedSource(new JavaFile(filePath));
ChangeSet changeSet = new ChangeSet();
changeSet.addedSource(source);
context.applyChanges(changeSet);
Expand Down