diff --git a/CHANGELOG.md b/CHANGELOG.md index 3dcc731d..6856db15 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ - Updated dependency: `tar: ^2.0.0`. - New text logging format. +- *Breaking change:* Removed `ToolEnvironment.panaCache` field (not intended for public API). ## 0.22.7 diff --git a/bin/pana.dart b/bin/pana.dart index fc706591..2fd812d2 100755 --- a/bin/pana.dart +++ b/bin/pana.dart @@ -171,7 +171,6 @@ Future main(List args) async { final pubHostedUrl = result['hosted-url'] as String?; final analyzer = PackageAnalyzer(await ToolEnvironment.create( pubCacheDir: pubCacheDir, - panaCacheDir: Platform.environment['PANA_CACHE'], dartSdkConfig: SdkConfig( rootPath: result['dart-sdk'] as String?, configHomePath: result['dart-config-home'] as String?, @@ -185,6 +184,7 @@ Future main(List args) async { )); final options = InspectOptions( pubHostedUrl: pubHostedUrl, + panaCacheDir: Platform.environment['PANA_CACHE'], lineLength: int.tryParse(result['line-length'] as String? ?? ''), dartdocOutputDir: runDartdoc ? dartdocOutputDir : null, resourcesOutputDir: resourcesOutputDir, diff --git a/lib/src/package_analyzer.dart b/lib/src/package_analyzer.dart index b9d65c4d..f0007dbf 100644 --- a/lib/src/package_analyzer.dart +++ b/lib/src/package_analyzer.dart @@ -29,6 +29,9 @@ class InspectOptions { /// The PUB_HOSTED_URL to use for the package download and dependency analysis. final String? pubHostedUrl; + /// The cache directory for cross-analysis (shared) pana results. + final String? panaCacheDir; + /// The output directory to copy the generated docs. When not specified, /// the generated docs will be discarded. final String? dartdocOutputDir; @@ -54,6 +57,7 @@ class InspectOptions { InspectOptions({ this.pubHostedUrl, + this.panaCacheDir, this.dartdocOutputDir, this.resourcesOutputDir, this.totalTimeout, diff --git a/lib/src/package_context.dart b/lib/src/package_context.dart index f7870162..bb2a4382 100644 --- a/lib/src/package_context.dart +++ b/lib/src/package_context.dart @@ -17,6 +17,7 @@ import 'license.dart'; import 'logging.dart'; import 'messages.dart' as messages; import 'package_analyzer.dart' show InspectOptions; +import 'pana_cache.dart'; import 'pkg_resolution.dart'; import 'pubspec.dart'; import 'pubspec_io.dart'; @@ -32,28 +33,29 @@ import 'utils.dart' show listFocusDirs; /// External systems that may be independent of the archive content may be /// stored here, e.g. repository and URL verification. class SharedAnalysisContext { + final PanaCache panaCache; final ToolEnvironment toolEnvironment; final InspectOptions options; final UrlChecker _urlChecker; SharedAnalysisContext({ + PanaCache? panaCache, required this.toolEnvironment, InspectOptions? options, UrlChecker? urlChecker, - }) : options = options ?? InspectOptions(), + }) : panaCache = panaCache ?? PanaCache(), + options = options ?? InspectOptions(), _urlChecker = urlChecker ?? UrlChecker(); Future checkUrlStatus(String url) async { final cacheType = 'url'; final cacheKey = url; - final cachedData = - await toolEnvironment.panaCache.readData(cacheType, cacheKey); + final cachedData = await panaCache.readData(cacheType, cacheKey); if (cachedData != null) { return UrlStatus.fromJson(cachedData); } final status = await _urlChecker.checkStatus(url); - await toolEnvironment.panaCache - .writeData(cacheType, cacheKey, status.toJson()); + await panaCache.writeData(cacheType, cacheKey, status.toJson()); return status; } @@ -66,8 +68,7 @@ class SharedAnalysisContext { } final cacheType = 'repository'; final cacheKey = '$package/$repositoryOrHomepage'; - final cachedData = - await toolEnvironment.panaCache.readData(cacheType, cacheKey); + final cachedData = await panaCache.readData(cacheType, cacheKey); if (cachedData != null) { return VerifiedRepository.fromJson(cachedData); } @@ -77,8 +78,7 @@ class SharedAnalysisContext { sourceUrl: repositoryOrHomepage, ); if (repository != null) { - await toolEnvironment.panaCache - .writeData(cacheType, cacheKey, repository.toJson()); + await panaCache.writeData(cacheType, cacheKey, repository.toJson()); } return repository; } diff --git a/lib/src/sdk_env.dart b/lib/src/sdk_env.dart index 048005a7..d34ad164 100644 --- a/lib/src/sdk_env.dart +++ b/lib/src/sdk_env.dart @@ -15,7 +15,6 @@ import 'internal_model.dart'; import 'logging.dart'; import 'model.dart' show PanaRuntimeInfo; import 'package_analyzer.dart' show InspectOptions; -import 'pana_cache.dart'; import 'tool/flutter_tool.dart'; import 'tool/run_constrained.dart'; import 'utils.dart'; @@ -75,7 +74,6 @@ class SdkConfig { class ToolEnvironment { final String? pubCacheDir; - final PanaCache panaCache; final _DartSdk _dartSdk; final _FlutterSdk _flutterSdk; PanaRuntimeInfo? _runtimeInfo; @@ -85,7 +83,6 @@ class ToolEnvironment { ToolEnvironment._( this.pubCacheDir, - this.panaCache, this._dartSdk, this._flutterSdk, this._dartdocVersion, @@ -93,11 +90,9 @@ class ToolEnvironment { ToolEnvironment.fake({ this.pubCacheDir, - PanaCache? panaCache, Map environment = const {}, required PanaRuntimeInfo runtimeInfo, - }) : panaCache = panaCache ?? PanaCache(), - _dartSdk = _DartSdk._(SdkConfig(environment: environment)), + }) : _dartSdk = _DartSdk._(SdkConfig(environment: environment)), _flutterSdk = _FlutterSdk._(SdkConfig(environment: environment), _DartSdk._(SdkConfig(environment: environment))), _dartdocVersion = null, @@ -129,7 +124,7 @@ class ToolEnvironment { SdkConfig? dartSdkConfig, SdkConfig? flutterSdkConfig, String? pubCacheDir, - String? panaCacheDir, + @Deprecated('parameter no longer used') String? panaCacheDir, String? pubHostedUrl, /// When specified, this version of `dartdoc` will be initialized @@ -142,7 +137,6 @@ class ToolEnvironment { dartSdkConfig ??= SdkConfig(rootPath: cli.getSdkPath()); flutterSdkConfig ??= SdkConfig(); final resolvedPubCache = await _resolve(pubCacheDir); - final resolvedPanaCache = await _resolve(panaCacheDir); final origPubEnvValue = Platform.environment[_pubEnvironmentKey] ?? ''; final origPubEnvValues = origPubEnvValue @@ -170,7 +164,6 @@ class ToolEnvironment { final toolEnv = ToolEnvironment._( resolvedPubCache, - PanaCache(path: resolvedPanaCache), await _DartSdk.detect(dartSdkConfig, env), flutterSdk, dartdocVersion, diff --git a/test/end2end_test.dart b/test/end2end_test.dart index 788d148d..4979f4eb 100644 --- a/test/end2end_test.dart +++ b/test/end2end_test.dart @@ -53,7 +53,6 @@ void main() { dartSdkConfig: SdkConfig(configHomePath: dartConfigDir), flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir), pubCacheDir: pubCacheDir, - panaCacheDir: panaCacheDir, pubHostedUrl: 'http://127.0.0.1:${httpServer.port}', dartdocVersion: 'any', )); @@ -66,6 +65,7 @@ void main() { version: version, options: InspectOptions( pubHostedUrl: 'http://127.0.0.1:${httpServer.port}', + panaCacheDir: panaCacheDir, dartdocOutputDir: skipDartdoc ? null : dartdocOutputDir, ), );