| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 system_cache; | 5 library system_cache; |
| 6 | 6 |
| 7 import 'dart:io'; | 7 import 'dart:io'; |
| 8 | 8 |
| 9 import 'git_source.dart'; |
| 10 import 'hosted_source.dart'; |
| 9 import 'io.dart'; | 11 import 'io.dart'; |
| 10 import 'io.dart' as io show createTempDir; | 12 import 'io.dart' as io show createTempDir; |
| 11 import 'package.dart'; | 13 import 'package.dart'; |
| 14 import 'sdk_source.dart'; |
| 12 import 'source.dart'; | 15 import 'source.dart'; |
| 13 import 'source_registry.dart'; | 16 import 'source_registry.dart'; |
| 14 import 'utils.dart'; | 17 import 'utils.dart'; |
| 15 import 'version.dart'; | 18 import 'version.dart'; |
| 16 | 19 |
| 17 /** | 20 /** |
| 18 * The system-wide cache of installed packages. | 21 * The system-wide cache of installed packages. |
| 19 * | 22 * |
| 20 * This cache contains all packages that are downloaded from the internet. | 23 * This cache contains all packages that are downloaded from the internet. |
| 21 * Packages that are available locally (e.g. from the SDK) don't use this cache. | 24 * Packages that are available locally (e.g. from the SDK) don't use this cache. |
| (...skipping 17 matching lines...) Expand all Loading... |
| 39 final SourceRegistry sources; | 42 final SourceRegistry sources; |
| 40 | 43 |
| 41 /** | 44 /** |
| 42 * Creates a new package cache which is backed by the given directory on the | 45 * Creates a new package cache which is backed by the given directory on the |
| 43 * user's file system. | 46 * user's file system. |
| 44 */ | 47 */ |
| 45 SystemCache(this.rootDir) | 48 SystemCache(this.rootDir) |
| 46 : _pendingInstalls = new Map<PackageId, Future<Package>>(), | 49 : _pendingInstalls = new Map<PackageId, Future<Package>>(), |
| 47 sources = new SourceRegistry(); | 50 sources = new SourceRegistry(); |
| 48 | 51 |
| 52 /// Creates a system cache and registers the standard set of sources. |
| 53 factory SystemCache.withSources(String rootDir, String sdkDir) { |
| 54 var cache = new SystemCache(rootDir); |
| 55 cache.register(new SdkSource(sdkDir)); |
| 56 cache.register(new GitSource()); |
| 57 cache.register(new HostedSource()); |
| 58 cache.sources.setDefault('hosted'); |
| 59 return cache; |
| 60 } |
| 61 |
| 49 /** | 62 /** |
| 50 * Registers a new source. This source must not have the same name as a source | 63 * Registers a new source. This source must not have the same name as a source |
| 51 * that's already been registered. | 64 * that's already been registered. |
| 52 */ | 65 */ |
| 53 void register(Source source) { | 66 void register(Source source) { |
| 54 source.bind(this); | 67 source.bind(this); |
| 55 sources.register(source); | 68 sources.register(source); |
| 56 } | 69 } |
| 57 | 70 |
| 58 /** | 71 /** |
| (...skipping 29 matching lines...) Expand all Loading... |
| 88 } | 101 } |
| 89 | 102 |
| 90 /// Delete's the system cache's internal temp directory. | 103 /// Delete's the system cache's internal temp directory. |
| 91 Future deleteTempDir() { | 104 Future deleteTempDir() { |
| 92 return dirExists(tempDir).chain((exists) { | 105 return dirExists(tempDir).chain((exists) { |
| 93 if (!exists) return new Future.immediate(null); | 106 if (!exists) return new Future.immediate(null); |
| 94 return deleteDir(tempDir); | 107 return deleteDir(tempDir); |
| 95 }); | 108 }); |
| 96 } | 109 } |
| 97 } | 110 } |
| OLD | NEW |