From c1992fa5d71c298fd2d4fcb16454123c2cadd836 Mon Sep 17 00:00:00 2001 From: danrubel Date: Mon, 31 Aug 2015 14:53:16 -0400 Subject: [PATCH] modify MemoryResourceProvider to support windows pathContext for testing #24000 R=paulberry@google.com Review URL: https://codereview.chromium.org//1318813007 . --- .gitignore | 3 +- .../lib/file_system/memory_file_system.dart | 43 ++++++++++--------- pkg/analyzer/pubspec.yaml | 2 +- 3 files changed, 25 insertions(+), 23 deletions(-) diff --git a/.gitignore b/.gitignore index d8b8eb808df..116adeeca9b 100644 --- a/.gitignore +++ b/.gitignore @@ -34,9 +34,10 @@ *.xcodeproj *.intermediate -# Dart Editor config files - also in all subdirectories. +# Eclipse config files - also in all subdirectories. .children .project +.settings # IntelliJ project files *.iml diff --git a/pkg/analyzer/lib/file_system/memory_file_system.dart b/pkg/analyzer/lib/file_system/memory_file_system.dart index cfc3aa2d5d8..1684fe96991 100644 --- a/pkg/analyzer/lib/file_system/memory_file_system.dart +++ b/pkg/analyzer/lib/file_system/memory_file_system.dart @@ -72,7 +72,7 @@ class MemoryResourceProvider implements ResourceProvider { @override Resource getResource(String path) { - path = posix.normalize(path); + path = pathContext.normalize(path); Resource resource = _pathToResource[path]; if (resource == null) { resource = new _MemoryFile(this, path); @@ -97,8 +97,8 @@ class MemoryResourceProvider implements ResourceProvider { * appears in its parent directory, but whose `exists` property is false) */ File newDummyLink(String path) { - path = posix.normalize(path); - newFolder(posix.dirname(path)); + path = pathContext.normalize(path); + newFolder(pathContext.dirname(path)); _MemoryDummyLink link = new _MemoryDummyLink(this, path); _pathToResource[path] = link; _pathToTimestamp[path] = nextStamp++; @@ -107,10 +107,10 @@ class MemoryResourceProvider implements ResourceProvider { } File newFile(String path, String content, [int stamp]) { - path = posix.normalize(path); - _MemoryResource folder = _pathToResource[posix.dirname(path)]; + path = pathContext.normalize(path); + _MemoryResource folder = _pathToResource[pathContext.dirname(path)]; if (folder == null) { - newFolder(posix.dirname(path)); + newFolder(pathContext.dirname(path)); } else if (folder is! Folder) { throw new ArgumentError('Cannot create file ($path) as child of file'); } @@ -123,13 +123,14 @@ class MemoryResourceProvider implements ResourceProvider { } Folder newFolder(String path) { - path = posix.normalize(path); - if (!path.startsWith('/')) { - throw new ArgumentError("Path must start with '/'"); + path = pathContext.normalize(path); + if (!path.startsWith(pathContext.separator)) { + throw new ArgumentError( + "Path must start with '${pathContext.separator}' : $path"); } _MemoryResource resource = _pathToResource[path]; if (resource == null) { - String parentPath = posix.dirname(path); + String parentPath = pathContext.dirname(path); if (parentPath != path) { newFolder(parentPath); } @@ -149,8 +150,8 @@ class MemoryResourceProvider implements ResourceProvider { } File updateFile(String path, String content, [int stamp]) { - path = posix.normalize(path); - newFolder(posix.dirname(path)); + path = pathContext.normalize(path); + newFolder(pathContext.dirname(path)); _MemoryFile file = new _MemoryFile(this, path); _pathToResource[path] = file; _pathToContent[path] = content; @@ -178,7 +179,7 @@ class MemoryResourceProvider implements ResourceProvider { void _notifyWatchers(String path, ChangeType changeType) { _pathToWatchers.forEach((String watcherPath, List> streamControllers) { - if (watcherPath == path || posix.isWithin(watcherPath, path)) { + if (watcherPath == path || pathContext.isWithin(watcherPath, path)) { for (StreamController streamController in streamControllers) { streamController.add(new WatchEvent(changeType, path)); @@ -261,7 +262,7 @@ class _MemoryFile extends _MemoryResource implements File { @override Source createSource([Uri uri]) { if (uri == null) { - uri = posix.toUri(path); + uri = _provider.pathContext.toUri(path); } return new _MemoryFileSource(this, uri); } @@ -381,15 +382,15 @@ class _MemoryFolder extends _MemoryResource implements Folder { @override String canonicalizePath(String relPath) { - relPath = posix.normalize(relPath); - String childPath = posix.join(path, relPath); - childPath = posix.normalize(childPath); + relPath = _provider.pathContext.normalize(relPath); + String childPath = _provider.pathContext.join(path, relPath); + childPath = _provider.pathContext.normalize(childPath); return childPath; } @override bool contains(String path) { - return posix.isWithin(this.path, path); + return _provider.pathContext.isWithin(this.path, path); } @override @@ -419,7 +420,7 @@ class _MemoryFolder extends _MemoryResource implements Folder { } List children = []; _provider._pathToResource.forEach((resourcePath, resource) { - if (posix.dirname(resourcePath) == path) { + if (_provider.pathContext.dirname(resourcePath) == path) { children.add(resource); } }); @@ -465,7 +466,7 @@ abstract class _MemoryResource implements Resource { @override Folder get parent { - String parentPath = posix.dirname(path); + String parentPath = _provider.pathContext.dirname(path); if (parentPath == path) { return null; } @@ -473,7 +474,7 @@ abstract class _MemoryResource implements Resource { } @override - String get shortName => posix.basename(path); + String get shortName => _provider.pathContext.basename(path); @override bool operator ==(other) { diff --git a/pkg/analyzer/pubspec.yaml b/pkg/analyzer/pubspec.yaml index 2413e129fb8..27dd8fed104 100644 --- a/pkg/analyzer/pubspec.yaml +++ b/pkg/analyzer/pubspec.yaml @@ -1,5 +1,5 @@ name: analyzer -version: 0.26.1+2 +version: 0.26.1+3 author: Dart Team description: Static analyzer for Dart. homepage: http://www.dartlang.org