mirror of
https://github.com/dart-lang/sdk
synced 2024-10-14 20:19:23 +00:00
modify MemoryResourceProvider to support windows pathContext for testing #24000
R=paulberry@google.com Review URL: https://codereview.chromium.org//1318813007 .
This commit is contained in:
parent
1463fb3ff2
commit
c1992fa5d7
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -34,9 +34,10 @@
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
*.intermediate
|
*.intermediate
|
||||||
|
|
||||||
# Dart Editor config files - also in all subdirectories.
|
# Eclipse config files - also in all subdirectories.
|
||||||
.children
|
.children
|
||||||
.project
|
.project
|
||||||
|
.settings
|
||||||
|
|
||||||
# IntelliJ project files
|
# IntelliJ project files
|
||||||
*.iml
|
*.iml
|
||||||
|
|
|
@ -72,7 +72,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Resource getResource(String path) {
|
Resource getResource(String path) {
|
||||||
path = posix.normalize(path);
|
path = pathContext.normalize(path);
|
||||||
Resource resource = _pathToResource[path];
|
Resource resource = _pathToResource[path];
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
resource = new _MemoryFile(this, path);
|
resource = new _MemoryFile(this, path);
|
||||||
|
@ -97,8 +97,8 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
* appears in its parent directory, but whose `exists` property is false)
|
* appears in its parent directory, but whose `exists` property is false)
|
||||||
*/
|
*/
|
||||||
File newDummyLink(String path) {
|
File newDummyLink(String path) {
|
||||||
path = posix.normalize(path);
|
path = pathContext.normalize(path);
|
||||||
newFolder(posix.dirname(path));
|
newFolder(pathContext.dirname(path));
|
||||||
_MemoryDummyLink link = new _MemoryDummyLink(this, path);
|
_MemoryDummyLink link = new _MemoryDummyLink(this, path);
|
||||||
_pathToResource[path] = link;
|
_pathToResource[path] = link;
|
||||||
_pathToTimestamp[path] = nextStamp++;
|
_pathToTimestamp[path] = nextStamp++;
|
||||||
|
@ -107,10 +107,10 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
File newFile(String path, String content, [int stamp]) {
|
File newFile(String path, String content, [int stamp]) {
|
||||||
path = posix.normalize(path);
|
path = pathContext.normalize(path);
|
||||||
_MemoryResource folder = _pathToResource[posix.dirname(path)];
|
_MemoryResource folder = _pathToResource[pathContext.dirname(path)];
|
||||||
if (folder == null) {
|
if (folder == null) {
|
||||||
newFolder(posix.dirname(path));
|
newFolder(pathContext.dirname(path));
|
||||||
} else if (folder is! Folder) {
|
} else if (folder is! Folder) {
|
||||||
throw new ArgumentError('Cannot create file ($path) as child of file');
|
throw new ArgumentError('Cannot create file ($path) as child of file');
|
||||||
}
|
}
|
||||||
|
@ -123,13 +123,14 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
Folder newFolder(String path) {
|
Folder newFolder(String path) {
|
||||||
path = posix.normalize(path);
|
path = pathContext.normalize(path);
|
||||||
if (!path.startsWith('/')) {
|
if (!path.startsWith(pathContext.separator)) {
|
||||||
throw new ArgumentError("Path must start with '/'");
|
throw new ArgumentError(
|
||||||
|
"Path must start with '${pathContext.separator}' : $path");
|
||||||
}
|
}
|
||||||
_MemoryResource resource = _pathToResource[path];
|
_MemoryResource resource = _pathToResource[path];
|
||||||
if (resource == null) {
|
if (resource == null) {
|
||||||
String parentPath = posix.dirname(path);
|
String parentPath = pathContext.dirname(path);
|
||||||
if (parentPath != path) {
|
if (parentPath != path) {
|
||||||
newFolder(parentPath);
|
newFolder(parentPath);
|
||||||
}
|
}
|
||||||
|
@ -149,8 +150,8 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
File updateFile(String path, String content, [int stamp]) {
|
File updateFile(String path, String content, [int stamp]) {
|
||||||
path = posix.normalize(path);
|
path = pathContext.normalize(path);
|
||||||
newFolder(posix.dirname(path));
|
newFolder(pathContext.dirname(path));
|
||||||
_MemoryFile file = new _MemoryFile(this, path);
|
_MemoryFile file = new _MemoryFile(this, path);
|
||||||
_pathToResource[path] = file;
|
_pathToResource[path] = file;
|
||||||
_pathToContent[path] = content;
|
_pathToContent[path] = content;
|
||||||
|
@ -178,7 +179,7 @@ class MemoryResourceProvider implements ResourceProvider {
|
||||||
void _notifyWatchers(String path, ChangeType changeType) {
|
void _notifyWatchers(String path, ChangeType changeType) {
|
||||||
_pathToWatchers.forEach((String watcherPath,
|
_pathToWatchers.forEach((String watcherPath,
|
||||||
List<StreamController<WatchEvent>> streamControllers) {
|
List<StreamController<WatchEvent>> streamControllers) {
|
||||||
if (watcherPath == path || posix.isWithin(watcherPath, path)) {
|
if (watcherPath == path || pathContext.isWithin(watcherPath, path)) {
|
||||||
for (StreamController<WatchEvent> streamController
|
for (StreamController<WatchEvent> streamController
|
||||||
in streamControllers) {
|
in streamControllers) {
|
||||||
streamController.add(new WatchEvent(changeType, path));
|
streamController.add(new WatchEvent(changeType, path));
|
||||||
|
@ -261,7 +262,7 @@ class _MemoryFile extends _MemoryResource implements File {
|
||||||
@override
|
@override
|
||||||
Source createSource([Uri uri]) {
|
Source createSource([Uri uri]) {
|
||||||
if (uri == null) {
|
if (uri == null) {
|
||||||
uri = posix.toUri(path);
|
uri = _provider.pathContext.toUri(path);
|
||||||
}
|
}
|
||||||
return new _MemoryFileSource(this, uri);
|
return new _MemoryFileSource(this, uri);
|
||||||
}
|
}
|
||||||
|
@ -381,15 +382,15 @@ class _MemoryFolder extends _MemoryResource implements Folder {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String canonicalizePath(String relPath) {
|
String canonicalizePath(String relPath) {
|
||||||
relPath = posix.normalize(relPath);
|
relPath = _provider.pathContext.normalize(relPath);
|
||||||
String childPath = posix.join(path, relPath);
|
String childPath = _provider.pathContext.join(path, relPath);
|
||||||
childPath = posix.normalize(childPath);
|
childPath = _provider.pathContext.normalize(childPath);
|
||||||
return childPath;
|
return childPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool contains(String path) {
|
bool contains(String path) {
|
||||||
return posix.isWithin(this.path, path);
|
return _provider.pathContext.isWithin(this.path, path);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
@ -419,7 +420,7 @@ class _MemoryFolder extends _MemoryResource implements Folder {
|
||||||
}
|
}
|
||||||
List<Resource> children = <Resource>[];
|
List<Resource> children = <Resource>[];
|
||||||
_provider._pathToResource.forEach((resourcePath, resource) {
|
_provider._pathToResource.forEach((resourcePath, resource) {
|
||||||
if (posix.dirname(resourcePath) == path) {
|
if (_provider.pathContext.dirname(resourcePath) == path) {
|
||||||
children.add(resource);
|
children.add(resource);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
@ -465,7 +466,7 @@ abstract class _MemoryResource implements Resource {
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Folder get parent {
|
Folder get parent {
|
||||||
String parentPath = posix.dirname(path);
|
String parentPath = _provider.pathContext.dirname(path);
|
||||||
if (parentPath == path) {
|
if (parentPath == path) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
@ -473,7 +474,7 @@ abstract class _MemoryResource implements Resource {
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String get shortName => posix.basename(path);
|
String get shortName => _provider.pathContext.basename(path);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool operator ==(other) {
|
bool operator ==(other) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
name: analyzer
|
name: analyzer
|
||||||
version: 0.26.1+2
|
version: 0.26.1+3
|
||||||
author: Dart Team <misc@dartlang.org>
|
author: Dart Team <misc@dartlang.org>
|
||||||
description: Static analyzer for Dart.
|
description: Static analyzer for Dart.
|
||||||
homepage: http://www.dartlang.org
|
homepage: http://www.dartlang.org
|
||||||
|
|
Loading…
Reference in a new issue