Skip to content

Commit 0498b23

Browse files
authoredJul 5, 2024··
Move PanaCache out of ToolEnvironment (also from public API), add option in InspectOptions. (#1384)
1 parent 5146beb commit 0498b23

6 files changed

+18
-20
lines changed
 

‎CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
- Updated dependency: `tar: ^2.0.0`.
44
- New text logging format.
5+
- *Breaking change:* Removed `ToolEnvironment.panaCache` field (not intended for public API).
56

67
## 0.22.7
78

‎bin/pana.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,6 @@ Future<void> main(List<String> args) async {
171171
final pubHostedUrl = result['hosted-url'] as String?;
172172
final analyzer = PackageAnalyzer(await ToolEnvironment.create(
173173
pubCacheDir: pubCacheDir,
174-
panaCacheDir: Platform.environment['PANA_CACHE'],
175174
dartSdkConfig: SdkConfig(
176175
rootPath: result['dart-sdk'] as String?,
177176
configHomePath: result['dart-config-home'] as String?,
@@ -185,6 +184,7 @@ Future<void> main(List<String> args) async {
185184
));
186185
final options = InspectOptions(
187186
pubHostedUrl: pubHostedUrl,
187+
panaCacheDir: Platform.environment['PANA_CACHE'],
188188
lineLength: int.tryParse(result['line-length'] as String? ?? ''),
189189
dartdocOutputDir: runDartdoc ? dartdocOutputDir : null,
190190
resourcesOutputDir: resourcesOutputDir,

‎lib/src/package_analyzer.dart

+4
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ class InspectOptions {
2929
/// The PUB_HOSTED_URL to use for the package download and dependency analysis.
3030
final String? pubHostedUrl;
3131

32+
/// The cache directory for cross-analysis (shared) pana results.
33+
final String? panaCacheDir;
34+
3235
/// The output directory to copy the generated docs. When not specified,
3336
/// the generated docs will be discarded.
3437
final String? dartdocOutputDir;
@@ -54,6 +57,7 @@ class InspectOptions {
5457

5558
InspectOptions({
5659
this.pubHostedUrl,
60+
this.panaCacheDir,
5761
this.dartdocOutputDir,
5862
this.resourcesOutputDir,
5963
this.totalTimeout,

‎lib/src/package_context.dart

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import 'license.dart';
1717
import 'logging.dart';
1818
import 'messages.dart' as messages;
1919
import 'package_analyzer.dart' show InspectOptions;
20+
import 'pana_cache.dart';
2021
import 'pkg_resolution.dart';
2122
import 'pubspec.dart';
2223
import 'pubspec_io.dart';
@@ -32,28 +33,29 @@ import 'utils.dart' show listFocusDirs;
3233
/// External systems that may be independent of the archive content may be
3334
/// stored here, e.g. repository and URL verification.
3435
class SharedAnalysisContext {
36+
final PanaCache panaCache;
3537
final ToolEnvironment toolEnvironment;
3638
final InspectOptions options;
3739
final UrlChecker _urlChecker;
3840

3941
SharedAnalysisContext({
42+
PanaCache? panaCache,
4043
required this.toolEnvironment,
4144
InspectOptions? options,
4245
UrlChecker? urlChecker,
43-
}) : options = options ?? InspectOptions(),
46+
}) : panaCache = panaCache ?? PanaCache(),
47+
options = options ?? InspectOptions(),
4448
_urlChecker = urlChecker ?? UrlChecker();
4549

4650
Future<UrlStatus> checkUrlStatus(String url) async {
4751
final cacheType = 'url';
4852
final cacheKey = url;
49-
final cachedData =
50-
await toolEnvironment.panaCache.readData(cacheType, cacheKey);
53+
final cachedData = await panaCache.readData(cacheType, cacheKey);
5154
if (cachedData != null) {
5255
return UrlStatus.fromJson(cachedData);
5356
}
5457
final status = await _urlChecker.checkStatus(url);
55-
await toolEnvironment.panaCache
56-
.writeData(cacheType, cacheKey, status.toJson());
58+
await panaCache.writeData(cacheType, cacheKey, status.toJson());
5759
return status;
5860
}
5961

@@ -66,8 +68,7 @@ class SharedAnalysisContext {
6668
}
6769
final cacheType = 'repository';
6870
final cacheKey = '$package/$repositoryOrHomepage';
69-
final cachedData =
70-
await toolEnvironment.panaCache.readData(cacheType, cacheKey);
71+
final cachedData = await panaCache.readData(cacheType, cacheKey);
7172
if (cachedData != null) {
7273
return VerifiedRepository.fromJson(cachedData);
7374
}
@@ -77,8 +78,7 @@ class SharedAnalysisContext {
7778
sourceUrl: repositoryOrHomepage,
7879
);
7980
if (repository != null) {
80-
await toolEnvironment.panaCache
81-
.writeData(cacheType, cacheKey, repository.toJson());
81+
await panaCache.writeData(cacheType, cacheKey, repository.toJson());
8282
}
8383
return repository;
8484
}

‎lib/src/sdk_env.dart

+2-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import 'internal_model.dart';
1515
import 'logging.dart';
1616
import 'model.dart' show PanaRuntimeInfo;
1717
import 'package_analyzer.dart' show InspectOptions;
18-
import 'pana_cache.dart';
1918
import 'tool/flutter_tool.dart';
2019
import 'tool/run_constrained.dart';
2120
import 'utils.dart';
@@ -75,7 +74,6 @@ class SdkConfig {
7574

7675
class ToolEnvironment {
7776
final String? pubCacheDir;
78-
final PanaCache panaCache;
7977
final _DartSdk _dartSdk;
8078
final _FlutterSdk _flutterSdk;
8179
PanaRuntimeInfo? _runtimeInfo;
@@ -85,19 +83,16 @@ class ToolEnvironment {
8583

8684
ToolEnvironment._(
8785
this.pubCacheDir,
88-
this.panaCache,
8986
this._dartSdk,
9087
this._flutterSdk,
9188
this._dartdocVersion,
9289
);
9390

9491
ToolEnvironment.fake({
9592
this.pubCacheDir,
96-
PanaCache? panaCache,
9793
Map<String, String> environment = const <String, String>{},
9894
required PanaRuntimeInfo runtimeInfo,
99-
}) : panaCache = panaCache ?? PanaCache(),
100-
_dartSdk = _DartSdk._(SdkConfig(environment: environment)),
95+
}) : _dartSdk = _DartSdk._(SdkConfig(environment: environment)),
10196
_flutterSdk = _FlutterSdk._(SdkConfig(environment: environment),
10297
_DartSdk._(SdkConfig(environment: environment))),
10398
_dartdocVersion = null,
@@ -129,7 +124,7 @@ class ToolEnvironment {
129124
SdkConfig? dartSdkConfig,
130125
SdkConfig? flutterSdkConfig,
131126
String? pubCacheDir,
132-
String? panaCacheDir,
127+
@Deprecated('parameter no longer used') String? panaCacheDir,
133128
String? pubHostedUrl,
134129

135130
/// When specified, this version of `dartdoc` will be initialized
@@ -142,7 +137,6 @@ class ToolEnvironment {
142137
dartSdkConfig ??= SdkConfig(rootPath: cli.getSdkPath());
143138
flutterSdkConfig ??= SdkConfig();
144139
final resolvedPubCache = await _resolve(pubCacheDir);
145-
final resolvedPanaCache = await _resolve(panaCacheDir);
146140

147141
final origPubEnvValue = Platform.environment[_pubEnvironmentKey] ?? '';
148142
final origPubEnvValues = origPubEnvValue
@@ -170,7 +164,6 @@ class ToolEnvironment {
170164

171165
final toolEnv = ToolEnvironment._(
172166
resolvedPubCache,
173-
PanaCache(path: resolvedPanaCache),
174167
await _DartSdk.detect(dartSdkConfig, env),
175168
flutterSdk,
176169
dartdocVersion,

‎test/end2end_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ void main() {
5353
dartSdkConfig: SdkConfig(configHomePath: dartConfigDir),
5454
flutterSdkConfig: SdkConfig(configHomePath: flutterConfigDir),
5555
pubCacheDir: pubCacheDir,
56-
panaCacheDir: panaCacheDir,
5756
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
5857
dartdocVersion: 'any',
5958
));
@@ -66,6 +65,7 @@ void main() {
6665
version: version,
6766
options: InspectOptions(
6867
pubHostedUrl: 'http://127.0.0.1:${httpServer.port}',
68+
panaCacheDir: panaCacheDir,
6969
dartdocOutputDir: skipDartdoc ? null : dartdocOutputDir,
7070
),
7171
);

0 commit comments

Comments
 (0)
Please sign in to comment.