Remove deprecated Resource class from dart:core.

BUG=
R=floitsch@google.com, mit@google.com

Review URL: https://codereview.chromium.org/2272373002 .
This commit is contained in:
Lasse Nielsen 2016-08-26 10:31:08 +02:00
parent d63577da67
commit f61143153a
10 changed files with 3 additions and 293 deletions

View file

@ -1,6 +1,8 @@
## 1.20.0
### Core library changes
* `dart:core`: Remove deprecated `Resource` class.
Use the class in `package:resource` instead.
* `dart:async`
* `Future.wait` now catches synchronous errors and returns them in the
returned Future.

View file

@ -1 +0,0 @@
Sample text file.

View file

@ -1,7 +0,0 @@
name: package_test_data
version: 0.0.1
author: "Dart Team <misc@dartlang.org>"
publish_to: "none"
description: >
Contains data used by platform tests using package: URIs.
Should *not* be published.

View file

@ -157,9 +157,8 @@ import "dart:_internal" hide Symbol;
import "dart:_internal" as internal show Symbol;
import "dart:convert" show
Encoding, ASCII, LATIN1, UTF8,
BASE64, StringConversionSink, ChunkedConversionSink;
BASE64, StringConversionSink;
import "dart:math" show Random; // Used by List.shuffle.
import "dart:async" show Stream, Future; // Used by Resource.
import "dart:typed_data" show Uint8List;
part "annotations.dart";
@ -185,7 +184,6 @@ part "object.dart";
part "pattern.dart";
part "print.dart";
part "regexp.dart";
part "resource.dart";
part "set.dart";
part "sink.dart";
part "stacktrace.dart";

View file

@ -29,7 +29,6 @@
'pattern.dart',
'print.dart',
'regexp.dart',
'resource.dart',
'set.dart',
'sink.dart',
'stacktrace.dart',

View file

@ -1,57 +0,0 @@
// Copyright (c) 2015, 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.
part of dart.core;
/**
* DEPRECATED. A resource that can be read into the program.
*
* WARNING: This API is _deprecated_,
* and it will be removed in 1.14. Please use
* https://pub.dartlang.org/packages/resource instead.
*
* A resource is data that can be located using a URI and read into
* the program at runtime.
* The URI may use the `package` scheme to read resources provided
* along with package sources.
*/
@Deprecated('1.14')
abstract class Resource {
/**
* Creates a resource object with the given [uri] as location.
*
* The `uri` is a string containing a valid URI.
* If the string is not a valid URI, using any of the functions on
* the resource object will fail.
*
* The URI may be relative, in which case it will be resolved
* against [Uri.base] before being used.
*
* The URI may use the `package` scheme, which is always supported.
* Other schemes may also be supported where possible.
*/
external const factory Resource(String uri);
/**
* The location `uri` of this resource.
*
* This is a [Uri] of the `uri` parameter given to the constructor.
* If the parameter was not a valid URI, reading `uri` may fail.
*/
Uri get uri;
/** Read the resource content as a stream of bytes. */
Stream<List<int>> openRead();
/** Read the resource content. */
Future<List<int>> readAsBytes();
/**
* Read the resource content as a string.
*
* The content is decoded into a string using an [Encoding].
* If no other encoding is provided, it defaults to UTF-8.
*/
Future<String> readAsString({Encoding encoding});
}

View file

@ -1,51 +0,0 @@
// Copyright (c) 2015, 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.
const sampleText = "Sample text file.";
main() async {
var uriEncoded = sampleText.replaceAll(' ', '%20');
await testUri("data:application/dart;charset=utf-8,$uriEncoded");
// TODO: Support other data: URI formats too.
// See: https://github.com/dart-lang/sdk/issues/24030
// await testUri("data:text/plain;charset=utf-8,$uriEncoded");
var base64Encoded = "U2FtcGxlIHRleHQgZmlsZS4=";
// await testUri("data:application/dart;charset=utf-8;base64,$base64Encoded");
// await testUri("data:text/plain;charset=utf-8;base64,$base64Encoded");
}
testUri(uriText) async {
var resource = new Resource(uriText);
if (resource.uri != Uri.parse(uriText)) {
throw "uriText: Incorrect URI: ${resource.uri}";
}
var text = await resource.readAsString();
if (text != sampleText) {
throw "uriText: Incorrect reading of text file: $text";
}
var bytes = await resource.readAsBytes();
if (!compareBytes(bytes, sampleText.codeUnits)) {
throw "uriText: Incorrect reading of bytes: $bytes";
}
var streamBytes = [];
await for (var byteSlice in resource.openRead()) {
streamBytes.addAll(byteSlice);
}
if (!compareBytes(streamBytes, sampleText.codeUnits)) {
throw "uriText: Incorrect reading of bytes: $bytes";
}
}
/// Checks that [bytes] and [expectedBytes] have the same contents.
bool compareBytes(bytes, expectedBytes) {
if (bytes.length != expectedBytes.length) return false;
for (int i = 0; i < expectedBytes.length; i++) {
if (bytes[i] != expectedBytes[i]) return false;
}
return true;
}

View file

@ -1,63 +0,0 @@
// Copyright (c) 2015, 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.
import "dart:io";
const sampleText = "Sample text file.";
main() async {
var file = await createFile();
var uri = new Uri.file(file.path);
var resource = new Resource(uri.toString());
if (resource.uri != uri) {
throw "Incorrect URI: ${resource.uri}";
}
var text = await resource.readAsString();
if (text != sampleText) {
throw "Incorrect reading of text file: $text";
}
var bytes = await resource.readAsBytes();
if (!compareBytes(bytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
var streamBytes = [];
await for (var byteSlice in resource.openRead()) {
streamBytes.addAll(byteSlice);
}
if (!compareBytes(streamBytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
await deleteFile(file);
}
/// Checks that [bytes] and [expectedBytes] have the same contents.
bool compareBytes(bytes, expectedBytes) {
if (bytes.length != expectedBytes.length) return false;
for (int i = 0; i < expectedBytes.length; i++) {
if (bytes[i] != expectedBytes[i]) return false;
}
return true;
}
createFile() async {
var tempDir = await Directory.systemTemp.createTemp("sample");
var filePath = tempDir.path + Platform.pathSeparator + "sample.txt";
var file = new File(filePath);
await file.create();
await file.writeAsString(sampleText);
return file;
}
deleteFile(File file) async {
// Removes the file and the temporary directory it's in.
var parentDir = new Directory(file.path.substring(0,
file.path.lastIndexOf(Platform.pathSeparator)));
await parentDir.delete(recursive: true);
}

View file

@ -1,62 +0,0 @@
// Copyright (c) 2015, 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.
import "dart:io";
const sampleText = "Sample text file.";
main() async {
var server = await startServer();
var uriText = "http://localhost:${server.port}/sample.txt?query#fragment";
var resource = new Resource(uriText);
if (resource.uri != Uri.parse(uriText)) {
throw "Incorrect URI: ${resource.uri}";
}
var text = await resource.readAsString();
if (text != sampleText) {
throw "Incorrect reading of text file: $text";
}
var bytes = await resource.readAsBytes();
if (!compareBytes(bytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
var streamBytes = [];
await for (var byteSlice in resource.openRead()) {
streamBytes.addAll(byteSlice);
}
if (!compareBytes(streamBytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
await server.close();
}
/// Checks that [bytes] and [expectedBytes] have the same contents.
bool compareBytes(bytes, expectedBytes) {
if (bytes.length != expectedBytes.length) return false;
for (int i = 0; i < expectedBytes.length; i++) {
if (bytes[i] != expectedBytes[i]) return false;
}
return true;
}
startServer() async {
var server = await HttpServer.bind(InternetAddress.LOOPBACK_IP_V4, 0);
var expectedUri = new Uri(path: "/sample.txt", query: "query");
server.forEach((request) async {
await request.drain();
var response = request.response;
if (request.uri == expectedUri) {
response.write(sampleText);
} else {
response.write("INCORRECT PATH!: ${request.uri}");
}
response.close();
});
return server;
}

View file

@ -1,48 +0,0 @@
// Copyright (c) 2015, 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.
const sampleText = "Sample text file.";
main() async {
const uriText = "package:package_test_data/resources/sample.txt";
const resource = const Resource(uriText);
if (resource.uri != Uri.parse(uriText)) {
throw "Incorrect URI: ${resource.uri}";
}
var text = await resource.readAsString();
if (!text.startsWith("Sample text file.")) {
throw "Incorrect reading of text file: $text";
}
var bytes = await resource.readAsBytes();
if (!compareBytes(bytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
var streamBytes = [];
await for (var byteSlice in resource.openRead()) {
streamBytes.addAll(byteSlice);
}
if (!compareBytes(streamBytes, sampleText.codeUnits)) {
throw "Incorrect reading of bytes: $bytes";
}
if (!compareBytes(streamBytes, bytes)) {
throw "Inconsistent reading of bytes: $bytes / $streamBytes";
}
}
/// Checks that [bytes] starts with [expectedBytes].
///
/// The bytes may be longer (because the test file is a text file and its
/// terminating line ending may be mangled on some platforms).
bool compareBytes(bytes, expectedBytes) {
if (bytes.length < expectedBytes.length) return false;
for (int i = 0; i < expectedBytes.length; i++) {
if (bytes[i] != expectedBytes[i]) return false;
}
return true;
}