@@ -20,36 +20,28 @@ import '../../shared/urls.dart' as urls;
2020import 'models.dart' ;
2121import 'resolver.dart' as resolver;
2222
23- final _autoGeneratedImportSource = _AutoGeneratedImportSource ();
23+ /// Utility class for resolving and getting data for profiles.
24+ class ImportSource {
25+ final _client = Client ();
2426
25- /// Interface for resolving and getting data for profiles.
26- abstract class ImportSource {
27- /// Resolve all the package-version required for the [profile] .
28- Future <List <ResolvedVersion >> resolveVersions (TestProfile profile);
27+ /// Cached archive bytes for generated packages (keys in `<package>/<version>` format).
28+ final _archives = < String , List <int >> {};
2929
30- /// Gets the archive bytes for [package] -[version] .
31- Future <List <int >> getArchiveBytes (String package, String version);
30+ late final String pubDevArchiveCachePath;
3231
33- /// Close resources that were opened during the sourcing of data.
34- Future <void > close ();
35-
36- /// Creates a source that resolves and downloads data from pub.dev.
37- static ImportSource fromPubDev ({
38- String ? archiveCachePath,
32+ ImportSource ({
33+ String ? pubDevArchiveCachePath,
3934 }) {
40- archiveCachePath ?? = p. join ( '.dart_tool' , 'pub-test-profile' , 'archives' );
41- return _PubDevImportSource (archiveCachePath : archiveCachePath );
35+ this .pubDevArchiveCachePath = pubDevArchiveCachePath ??
36+ p. join ( '.dart_tool' , 'pub-test-profile' , 'archives' );
4237 }
4338
44- /// Creates a source that generates data based on random seed, without any
45- /// network (or file) access.
46- static ImportSource autoGenerated () => _autoGeneratedImportSource;
47- }
48-
49- abstract class _ImportSource implements ImportSource {
50- final _client = Client ();
39+ /// Close resources that were opened during the sourcing of data.
40+ Future <void > close () async {
41+ _client.close ();
42+ }
5143
52- @override
44+ /// Resolve all the package-version required for the [profile] .
5345 Future <List <ResolvedVersion >> resolveVersions (TestProfile profile) async {
5446 return < ResolvedVersion > [
5547 ...await resolver.resolveVersions (_client, profile),
@@ -91,24 +83,10 @@ abstract class _ImportSource implements ImportSource {
9183 return versions;
9284 }
9385
94- @override
95- Future <void > close () async {
96- _client.close ();
97- }
98- }
99-
100- /// Resolves and downloads data from pub.dev.
101- class _PubDevImportSource extends _ImportSource {
102- final String archiveCachePath;
103-
104- _PubDevImportSource ({
105- required this .archiveCachePath,
106- });
107-
108- @override
109- Future <List <int >> getArchiveBytes (String package, String version) async {
86+ Future <List <int >> getPubDevArchiveBytes (
87+ String package, String version) async {
11088 final archiveName = '$package -$version .tar.gz' ;
111- final file = File (p.join (archiveCachePath , archiveName));
89+ final file = File (p.join (pubDevArchiveCachePath , archiveName));
11290 // download package archive if not already in the cache
11391 if (! await file.exists ()) {
11492 // TODO: Use archive_url from version-listing, that is stable!
@@ -120,14 +98,9 @@ class _PubDevImportSource extends _ImportSource {
12098 }
12199 return await file.readAsBytes ();
122100 }
123- }
124101
125- /// Generates data based on random seed, without any network (or file) access.
126- class _AutoGeneratedImportSource extends _ImportSource {
127- final _archives = < String , List <int >> {};
128-
129- @override
130- Future <List <int >> getArchiveBytes (String package, String version) async {
102+ Future <List <int >> getGeneratedArchiveBytes (
103+ String package, String version) async {
131104 final key = '$package /$version ' ;
132105 final hasher = createHasher (key);
133106 if (_archives.containsKey (key)) {
0 commit comments