| OLD | NEW |
| 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2014, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 library physical_file_system; | 5 library physical_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:io' as io; | 8 import 'dart:io' as io; |
| 9 | 9 |
| 10 import 'package:analyzer/src/generated/java_io.dart'; | 10 import 'package:analyzer/src/generated/java_io.dart'; |
| 11 import 'package:analyzer/src/generated/source_io.dart'; | 11 import 'package:analyzer/src/generated/source_io.dart'; |
| 12 import 'package:path/path.dart'; | 12 import 'package:path/path.dart'; |
| 13 import 'package:watcher/watcher.dart'; | 13 import 'package:watcher/watcher.dart'; |
| 14 | 14 |
| 15 import 'file_system.dart'; | 15 import 'file_system.dart'; |
| 16 | 16 |
| 17 | |
| 18 /** | 17 /** |
| 19 * A `dart:io` based implementation of [ResourceProvider]. | 18 * A `dart:io` based implementation of [ResourceProvider]. |
| 20 */ | 19 */ |
| 21 class PhysicalResourceProvider implements ResourceProvider { | 20 class PhysicalResourceProvider implements ResourceProvider { |
| 22 | |
| 23 static final NORMALIZE_EOL_ALWAYS = | 21 static final NORMALIZE_EOL_ALWAYS = |
| 24 (String string) => string.replaceAll(new RegExp('\r\n?'), '\n'); | 22 (String string) => string.replaceAll(new RegExp('\r\n?'), '\n'); |
| 25 | 23 |
| 26 static final PhysicalResourceProvider INSTANCE = | 24 static final PhysicalResourceProvider INSTANCE = |
| 27 new PhysicalResourceProvider(null); | 25 new PhysicalResourceProvider(null); |
| 28 | 26 |
| 29 /** | 27 /** |
| 30 * The name of the directory containing plugin specific subfolders used to | 28 * The name of the directory containing plugin specific subfolders used to |
| 31 * store data across sessions. | 29 * store data across sessions. |
| 32 */ | 30 */ |
| (...skipping 30 matching lines...) Expand all Loading... |
| 63 if (home != null && io.FileSystemEntity.isDirectorySync(home)) { | 61 if (home != null && io.FileSystemEntity.isDirectorySync(home)) { |
| 64 io.Directory directory = | 62 io.Directory directory = |
| 65 new io.Directory(join(home, SERVER_DIR, pluginId)); | 63 new io.Directory(join(home, SERVER_DIR, pluginId)); |
| 66 directory.createSync(recursive: true); | 64 directory.createSync(recursive: true); |
| 67 return new _PhysicalFolder(directory); | 65 return new _PhysicalFolder(directory); |
| 68 } | 66 } |
| 69 return null; | 67 return null; |
| 70 } | 68 } |
| 71 } | 69 } |
| 72 | 70 |
| 73 | |
| 74 /** | 71 /** |
| 75 * A `dart:io` based implementation of [File]. | 72 * A `dart:io` based implementation of [File]. |
| 76 */ | 73 */ |
| 77 class _PhysicalFile extends _PhysicalResource implements File { | 74 class _PhysicalFile extends _PhysicalResource implements File { |
| 78 _PhysicalFile(io.File file) : super(file); | 75 _PhysicalFile(io.File file) : super(file); |
| 79 | 76 |
| 80 @override | 77 @override |
| 81 int get modificationStamp { | 78 int get modificationStamp { |
| 82 try { | 79 try { |
| 83 io.File file = _entry as io.File; | 80 io.File file = _entry as io.File; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 96 } | 93 } |
| 97 return new FileBasedSource.con2(uri, javaFile); | 94 return new FileBasedSource.con2(uri, javaFile); |
| 98 } | 95 } |
| 99 | 96 |
| 100 @override | 97 @override |
| 101 bool isOrContains(String path) { | 98 bool isOrContains(String path) { |
| 102 return path == this.path; | 99 return path == this.path; |
| 103 } | 100 } |
| 104 } | 101 } |
| 105 | 102 |
| 106 | |
| 107 /** | 103 /** |
| 108 * A `dart:io` based implementation of [Folder]. | 104 * A `dart:io` based implementation of [Folder]. |
| 109 */ | 105 */ |
| 110 class _PhysicalFolder extends _PhysicalResource implements Folder { | 106 class _PhysicalFolder extends _PhysicalResource implements Folder { |
| 111 _PhysicalFolder(io.Directory directory) : super(directory); | 107 _PhysicalFolder(io.Directory directory) : super(directory); |
| 112 | 108 |
| 113 @override | 109 @override |
| 114 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events; | 110 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events; |
| 115 | 111 |
| 116 @override | 112 @override |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 155 | 151 |
| 156 @override | 152 @override |
| 157 bool isOrContains(String path) { | 153 bool isOrContains(String path) { |
| 158 if (path == this.path) { | 154 if (path == this.path) { |
| 159 return true; | 155 return true; |
| 160 } | 156 } |
| 161 return contains(path); | 157 return contains(path); |
| 162 } | 158 } |
| 163 } | 159 } |
| 164 | 160 |
| 165 | |
| 166 /** | 161 /** |
| 167 * A `dart:io` based implementation of [Resource]. | 162 * A `dart:io` based implementation of [Resource]. |
| 168 */ | 163 */ |
| 169 abstract class _PhysicalResource implements Resource { | 164 abstract class _PhysicalResource implements Resource { |
| 170 final io.FileSystemEntity _entry; | 165 final io.FileSystemEntity _entry; |
| 171 | 166 |
| 172 _PhysicalResource(this._entry); | 167 _PhysicalResource(this._entry); |
| 173 | 168 |
| 174 @override | 169 @override |
| 175 bool get exists => _entry.existsSync(); | 170 bool get exists => _entry.existsSync(); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 196 bool operator ==(other) { | 191 bool operator ==(other) { |
| 197 if (runtimeType != other.runtimeType) { | 192 if (runtimeType != other.runtimeType) { |
| 198 return false; | 193 return false; |
| 199 } | 194 } |
| 200 return path == other.path; | 195 return path == other.path; |
| 201 } | 196 } |
| 202 | 197 |
| 203 @override | 198 @override |
| 204 String toString() => path; | 199 String toString() => path; |
| 205 } | 200 } |
| OLD | NEW |