| 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 analyzer.file_system.physical_file_system; | 5 library analyzer.file_system.physical_file_system; |
| 6 | 6 |
| 7 import 'dart:async'; | 7 import 'dart:async'; |
| 8 import 'dart:core' hide Resource; | 8 import 'dart:core' hide Resource; |
| 9 import 'dart:io' as io; | 9 import 'dart:io' as io; |
| 10 | 10 |
| 11 import 'package:analyzer/file_system/file_system.dart'; | 11 import 'package:analyzer/file_system/file_system.dart'; |
| 12 import 'package:analyzer/src/generated/java_io.dart'; | 12 import 'package:analyzer/src/generated/java_io.dart'; |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 13 import 'package:analyzer/src/generated/source_io.dart'; |
| 14 import 'package:analyzer/src/util/absolute_path.dart'; | 14 import 'package:analyzer/src/util/absolute_path.dart'; |
| 15 import 'package:path/path.dart'; | 15 import 'package:path/path.dart'; |
| 16 import 'package:watcher/watcher.dart'; | 16 import 'package:watcher/watcher.dart'; |
| 17 | 17 |
| 18 /** | 18 /** |
| 19 * A `dart:io` based implementation of [ResourceProvider]. | 19 * A `dart:io` based implementation of [ResourceProvider]. |
| 20 */ | 20 */ |
| 21 class PhysicalResourceProvider implements ResourceProvider { | 21 class PhysicalResourceProvider implements ResourceProvider { |
| 22 static final NORMALIZE_EOL_ALWAYS = (String string) => | 22 static final NORMALIZE_EOL_ALWAYS = |
| 23 string.replaceAll(new RegExp('\r\n?'), '\n'); | 23 (String string) => string.replaceAll(new RegExp('\r\n?'), '\n'); |
| 24 | 24 |
| 25 static final PhysicalResourceProvider INSTANCE = | 25 static final PhysicalResourceProvider INSTANCE = |
| 26 new PhysicalResourceProvider(null); | 26 new PhysicalResourceProvider(null); |
| 27 | 27 |
| 28 /** | 28 /** |
| 29 * The name of the directory containing plugin specific subfolders used to | 29 * The name of the directory containing plugin specific subfolders used to |
| 30 * store data across sessions. | 30 * store data across sessions. |
| 31 */ | 31 */ |
| 32 static final String SERVER_DIR = ".dartServer"; | 32 static final String SERVER_DIR = ".dartServer"; |
| 33 | 33 |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 105 } | 105 } |
| 106 return new FileBasedSource(javaFile, uri); | 106 return new FileBasedSource(javaFile, uri); |
| 107 } | 107 } |
| 108 | 108 |
| 109 @override | 109 @override |
| 110 bool isOrContains(String path) { | 110 bool isOrContains(String path) { |
| 111 return path == this.path; | 111 return path == this.path; |
| 112 } | 112 } |
| 113 | 113 |
| 114 @override | 114 @override |
| 115 List<int> readAsBytesSync() { |
| 116 try { |
| 117 io.File file = _entry as io.File; |
| 118 return file.readAsBytesSync(); |
| 119 } on io.FileSystemException catch (exception) { |
| 120 throw new FileSystemException(exception.path, exception.message); |
| 121 } |
| 122 } |
| 123 |
| 124 @override |
| 115 String readAsStringSync() { | 125 String readAsStringSync() { |
| 116 try { | 126 try { |
| 117 io.File file = _entry as io.File; | 127 io.File file = _entry as io.File; |
| 118 return FileBasedSource.fileReadMode(file.readAsStringSync()); | 128 return FileBasedSource.fileReadMode(file.readAsStringSync()); |
| 119 } on io.FileSystemException catch (exception) { | 129 } on io.FileSystemException catch (exception) { |
| 120 throw new FileSystemException(exception.path, exception.message); | 130 throw new FileSystemException(exception.path, exception.message); |
| 121 } | 131 } |
| 122 } | 132 } |
| 133 |
| 134 @override |
| 135 void writeAsBytesSync(List<int> bytes) { |
| 136 try { |
| 137 io.File file = _entry as io.File; |
| 138 file.writeAsBytesSync(bytes); |
| 139 } on io.FileSystemException catch (exception) { |
| 140 throw new FileSystemException(exception.path, exception.message); |
| 141 } |
| 142 } |
| 123 } | 143 } |
| 124 | 144 |
| 125 /** | 145 /** |
| 126 * A `dart:io` based implementation of [Folder]. | 146 * A `dart:io` based implementation of [Folder]. |
| 127 */ | 147 */ |
| 128 class _PhysicalFolder extends _PhysicalResource implements Folder { | 148 class _PhysicalFolder extends _PhysicalResource implements Folder { |
| 129 _PhysicalFolder(io.Directory directory) : super(directory); | 149 _PhysicalFolder(io.Directory directory) : super(directory); |
| 130 | 150 |
| 131 @override | 151 @override |
| 132 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events; | 152 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events; |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 220 bool operator ==(other) { | 240 bool operator ==(other) { |
| 221 if (runtimeType != other.runtimeType) { | 241 if (runtimeType != other.runtimeType) { |
| 222 return false; | 242 return false; |
| 223 } | 243 } |
| 224 return path == other.path; | 244 return path == other.path; |
| 225 } | 245 } |
| 226 | 246 |
| 227 @override | 247 @override |
| 228 String toString() => path; | 248 String toString() => path; |
| 229 } | 249 } |
| OLD | NEW |