| 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'; | |
| 13 import 'package:analyzer/src/generated/source_io.dart'; | 12 import 'package:analyzer/src/generated/source_io.dart'; |
| 13 import 'package:analyzer/src/source/source_resource.dart'; |
| 14 import 'package:analyzer/src/util/absolute_path.dart'; | 14 import 'package:analyzer/src/util/absolute_path.dart'; |
| 15 import 'package:isolate/isolate_runner.dart'; | 15 import 'package:isolate/isolate_runner.dart'; |
| 16 import 'package:path/path.dart'; | 16 import 'package:path/path.dart'; |
| 17 import 'package:watcher/watcher.dart'; | 17 import 'package:watcher/watcher.dart'; |
| 18 | 18 |
| 19 /** | 19 /** |
| 20 * Return modification times for every file path in [paths]. | 20 * Return modification times for every file path in [paths]. |
| 21 * | 21 * |
| 22 * If a path is `null`, the modification time is also `null`. | 22 * If a path is `null`, the modification time is also `null`. |
| 23 * | 23 * |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 78 } | 78 } |
| 79 | 79 |
| 80 @override | 80 @override |
| 81 Folder getFolder(String path) { | 81 Folder getFolder(String path) { |
| 82 path = normalize(path); | 82 path = normalize(path); |
| 83 return new _PhysicalFolder(new io.Directory(path)); | 83 return new _PhysicalFolder(new io.Directory(path)); |
| 84 } | 84 } |
| 85 | 85 |
| 86 @override | 86 @override |
| 87 Future<List<int>> getModificationTimes(List<Source> sources) async { | 87 Future<List<int>> getModificationTimes(List<Source> sources) async { |
| 88 List<String> paths = sources | 88 List<String> paths = sources.map((source) => source.fullName).toList(); |
| 89 .map((source) => source is FileBasedSource ? source.fullName : null) | |
| 90 .toList(); | |
| 91 IsolateRunner runner = await pathsToTimesIsolateProvider.get(); | 89 IsolateRunner runner = await pathsToTimesIsolateProvider.get(); |
| 92 return runner.run(_pathsToTimes, paths); | 90 return runner.run(_pathsToTimes, paths); |
| 93 } | 91 } |
| 94 | 92 |
| 95 @override | 93 @override |
| 96 Resource getResource(String path) { | 94 Resource getResource(String path) { |
| 97 if (io.FileSystemEntity.isDirectorySync(path)) { | 95 if (io.FileSystemEntity.isDirectorySync(path)) { |
| 98 return getFolder(path); | 96 return getFolder(path); |
| 99 } else { | 97 } else { |
| 100 return getFile(path); | 98 return getFile(path); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 133 try { | 131 try { |
| 134 io.File file = _entry as io.File; | 132 io.File file = _entry as io.File; |
| 135 return file.lastModifiedSync().millisecondsSinceEpoch; | 133 return file.lastModifiedSync().millisecondsSinceEpoch; |
| 136 } on io.FileSystemException catch (exception) { | 134 } on io.FileSystemException catch (exception) { |
| 137 throw new FileSystemException(exception.path, exception.message); | 135 throw new FileSystemException(exception.path, exception.message); |
| 138 } | 136 } |
| 139 } | 137 } |
| 140 | 138 |
| 141 @override | 139 @override |
| 142 Source createSource([Uri uri]) { | 140 Source createSource([Uri uri]) { |
| 143 io.File file = _entry as io.File; | 141 return new FileSource(this, uri ?? pathContext.toUri(path)); |
| 144 JavaFile javaFile = new JavaFile(file.absolute.path); | |
| 145 if (uri == null) { | |
| 146 uri = javaFile.toURI(); | |
| 147 } | |
| 148 return new FileBasedSource(javaFile, uri); | |
| 149 } | 142 } |
| 150 | 143 |
| 151 @override | 144 @override |
| 152 bool isOrContains(String path) { | 145 bool isOrContains(String path) { |
| 153 return path == this.path; | 146 return path == this.path; |
| 154 } | 147 } |
| 155 | 148 |
| 156 @override | 149 @override |
| 157 List<int> readAsBytesSync() { | 150 List<int> readAsBytesSync() { |
| 158 try { | 151 try { |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 String parentPath = absolutePathContext.dirname(path); | 285 String parentPath = absolutePathContext.dirname(path); |
| 293 if (parentPath == path) { | 286 if (parentPath == path) { |
| 294 return null; | 287 return null; |
| 295 } | 288 } |
| 296 return new _PhysicalFolder(new io.Directory(parentPath)); | 289 return new _PhysicalFolder(new io.Directory(parentPath)); |
| 297 } | 290 } |
| 298 | 291 |
| 299 @override | 292 @override |
| 300 String get path => _entry.absolute.path; | 293 String get path => _entry.absolute.path; |
| 301 | 294 |
| 295 /** |
| 296 * Return the path context used by this resource provider. |
| 297 */ |
| 298 Context get pathContext => io.Platform.isWindows ? windows : posix; |
| 299 |
| 302 @override | 300 @override |
| 303 String get shortName => absolutePathContext.basename(path); | 301 String get shortName => absolutePathContext.basename(path); |
| 304 | 302 |
| 305 @override | 303 @override |
| 306 bool operator ==(other) { | 304 bool operator ==(other) { |
| 307 if (runtimeType != other.runtimeType) { | 305 if (runtimeType != other.runtimeType) { |
| 308 return false; | 306 return false; |
| 309 } | 307 } |
| 310 return path == other.path; | 308 return path == other.path; |
| 311 } | 309 } |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 timer.cancel(); | 343 timer.cancel(); |
| 346 } | 344 } |
| 347 }); | 345 }); |
| 348 return completer.future; | 346 return completer.future; |
| 349 } | 347 } |
| 350 _isSpawning = true; | 348 _isSpawning = true; |
| 351 _runner = await IsolateRunner.spawn(); | 349 _runner = await IsolateRunner.spawn(); |
| 352 return _runner; | 350 return _runner; |
| 353 } | 351 } |
| 354 } | 352 } |
| OLD | NEW |