Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(490)

Side by Side Diff: pkg/analysis_server/lib/src/resource.dart

Issue 303503007: Allow physical folder resources to be watched for changes to their contents. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 resource; 5 library resource;
6 6
7 import 'dart:async';
7 import 'dart:io' as io; 8 import 'dart:io' as io;
8 9
9 import 'package:analyzer/src/generated/engine.dart' show TimestampedData; 10 import 'package:analyzer/src/generated/engine.dart' show TimestampedData;
10 import 'package:analyzer/src/generated/java_io.dart'; 11 import 'package:analyzer/src/generated/java_io.dart';
11 import 'package:analyzer/src/generated/source_io.dart'; 12 import 'package:analyzer/src/generated/source_io.dart';
12 import 'package:path/path.dart'; 13 import 'package:path/path.dart';
14 import 'package:watcher/watcher.dart';
13 15
14 16
15 /** 17 /**
16 * [File]s are leaf [Resource]s which contain data. 18 * [File]s are leaf [Resource]s which contain data.
17 */ 19 */
18 abstract class File extends Resource { 20 abstract class File extends Resource {
19 /** 21 /**
20 * Create a new [Source] instance that serves this file. 22 * Create a new [Source] instance that serves this file.
21 */ 23 */
22 Source createSource(UriKind uriKind); 24 Source createSource(UriKind uriKind);
23 } 25 }
24 26
25 27
26 /** 28 /**
27 * [Folder]s are [Resource]s which may contain files and/or other folders. 29 * [Folder]s are [Resource]s which may contain files and/or other folders.
28 */ 30 */
29 abstract class Folder extends Resource { 31 abstract class Folder extends Resource {
30 /** 32 /**
31 * Return an existing child [Resource] with the given [relPath]. 33 * Return an existing child [Resource] with the given [relPath].
32 * Return a not existing [File] if no such child exist. 34 * Return a not existing [File] if no such child exist.
33 */ 35 */
34 Resource getChild(String relPath); 36 Resource getChild(String relPath);
35 37
36 /** 38 /**
37 * Return a list of existing direct children [Resource]s (folders and files) 39 * Return a list of existing direct children [Resource]s (folders and files)
38 * in this folder, in no particular order. 40 * in this folder, in no particular order.
39 */ 41 */
40 List<Resource> getChildren(); 42 List<Resource> getChildren();
43
44 /**
45 * Watch for changes to the files inside this folder (and in any nested
46 * folders, including folders reachable via links).
47 */
48 Stream<WatchEvent> get changes;
41 } 49 }
42 50
43 51
44 /** 52 /**
45 * The abstract class [Resource] is an abstraction of file or folder. 53 * The abstract class [Resource] is an abstraction of file or folder.
46 */ 54 */
47 abstract class Resource { 55 abstract class Resource {
48 /** 56 /**
49 * Return `true` if this resource exists. 57 * Return `true` if this resource exists.
50 */ 58 */
(...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after
226 @override 234 @override
227 List<Resource> getChildren() { 235 List<Resource> getChildren() {
228 List<Resource> children = <Resource>[]; 236 List<Resource> children = <Resource>[];
229 _provider._pathToResource.forEach((path, resource) { 237 _provider._pathToResource.forEach((path, resource) {
230 if (posix.dirname(path) == _path) { 238 if (posix.dirname(path) == _path) {
231 children.add(resource); 239 children.add(resource);
232 } 240 }
233 }); 241 });
234 return children; 242 return children;
235 } 243 }
244
245 @override
246 Stream<WatchEvent> get changes {
247 // TODO(paulberry): implement.
248 return new StreamController<WatchEvent>().stream;
249 }
236 } 250 }
237 251
238 252
239 /** 253 /**
240 * An in-memory implementation of [ResourceProvider]. 254 * An in-memory implementation of [ResourceProvider].
241 * Use `/` as a path separator. 255 * Use `/` as a path separator.
242 */ 256 */
243 class MemoryResourceProvider implements ResourceProvider { 257 class MemoryResourceProvider implements ResourceProvider {
244 final Map<String, _MemoryResource> _pathToResource = <String, _MemoryResource> {}; 258 final Map<String, _MemoryResource> _pathToResource = <String, _MemoryResource> {};
245 final Map<String, String> _pathToContent = <String, String>{}; 259 final Map<String, String> _pathToContent = <String, String>{};
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 for (int i = 0; i < numEntries; i++) { 350 for (int i = 0; i < numEntries; i++) {
337 io.FileSystemEntity entity = entries[i]; 351 io.FileSystemEntity entity = entries[i];
338 if (entity is io.Directory) { 352 if (entity is io.Directory) {
339 children.add(new _PhysicalFolder(entity)); 353 children.add(new _PhysicalFolder(entity));
340 } else if (entity is io.File) { 354 } else if (entity is io.File) {
341 children.add(new _PhysicalFile(entity)); 355 children.add(new _PhysicalFile(entity));
342 } 356 }
343 } 357 }
344 return children; 358 return children;
345 } 359 }
360
361 @override
362 Stream<WatchEvent> get changes => new DirectoryWatcher(_entry.path).events;
346 } 363 }
347 364
348 365
349 /** 366 /**
350 * A `dart:io` based implementation of [Resource]. 367 * A `dart:io` based implementation of [Resource].
351 */ 368 */
352 abstract class _PhysicalResource implements Resource { 369 abstract class _PhysicalResource implements Resource {
353 final io.FileSystemEntity _entry; 370 final io.FileSystemEntity _entry;
354 371
355 _PhysicalResource(this._entry); 372 _PhysicalResource(this._entry);
(...skipping 27 matching lines...) Expand all
383 Resource getResource(String path) { 400 Resource getResource(String path) {
384 if (io.FileSystemEntity.isDirectorySync(path)) { 401 if (io.FileSystemEntity.isDirectorySync(path)) {
385 io.Directory directory = new io.Directory(path); 402 io.Directory directory = new io.Directory(path);
386 return new _PhysicalFolder(directory); 403 return new _PhysicalFolder(directory);
387 } else { 404 } else {
388 io.File file = new io.File(path); 405 io.File file = new io.File(path);
389 return new _PhysicalFile(file); 406 return new _PhysicalFile(file);
390 } 407 }
391 } 408 }
392 } 409 }
OLDNEW
« no previous file with comments | « no previous file | pkg/analysis_server/pubspec.yaml » ('j') | pkg/analysis_server/test/resource_test.dart » ('J')

Powered by Google App Engine
This is Rietveld 408576698