Skip to content

Commit

Permalink
Replace resources storage callback with output directory option. (#1325)
Browse files Browse the repository at this point in the history
isoos authored Feb 1, 2024
1 parent 38a35cf commit 3cef95d
Showing 2 changed files with 29 additions and 15 deletions.
19 changes: 12 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
## 0.22.0

- `ToolEnvironment.create()` takes `configHomeDir` to specify config the home
directory used for the analysis (helps switching different analyzer SDKs).
- `ToolEnvironment.create()` takes `pubHostedUrl` as `PackageAnalyzer.create()`
was removed.
- `InspectOptions.totalTimeBudget` to allow the dynamic reduction of `dartdocTimeout`.
- `ToolEnvironment`:
- `.create()` takes `configHomeDir` to specify config the home
directory used for the analysis (helps switching different analyzer SDKs).
- `create()` takes `pubHostedUrl` as `PackageAnalyzer.create()` was removed.
- `InspectOptions`:
- `totalTimeBudget` to allow the dynamic reduction of `dartdocTimeout`.
- `resourcesOutputDir` to store the resources files (without the previous callback).


**BREAKING CHANGES**

- Renamed `runProc` -> `runConstrained`.
- Removed:
- deprecated APIs
- `InspectOptions.checkRemoteRepository` - repositories are verified by default
- `PackageAnalyzer.create()`
- `PackageAnalyzer.inspectVersions()`
- `PackageAnalyzer`:
- `create()`
- `inspectVersions()`
- `storeResource` callback in `inspectPackage()`, use `InspectOptions.resourcesOutputDir` instead
- `ProcessOutput.asBytes`
- `Report.joinSection()`
- `ToolEnvironment`:
25 changes: 17 additions & 8 deletions lib/src/package_analyzer.dart
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:io';
import 'dart:typed_data';

import 'package:collection/collection.dart';
@@ -33,6 +34,10 @@ class InspectOptions {
/// the generated docs will be discarded.
final String? dartdocOutputDir;

/// The output directory to store the extracted/derived resources like screenshots.
/// When not specified, the resources will be discarded.
final String? resourcesOutputDir;

/// The total time budget allocated for the full analysis. `pana` may not be
/// able to finish the analysis within this time, but some parts will be
/// running with reduced timeouts in the attempt to complete the analysis
@@ -51,6 +56,7 @@ class InspectOptions {
InspectOptions({
this.pubHostedUrl,
this.dartdocOutputDir,
this.resourcesOutputDir,
this.totalTimeBudget,
this.dartdocTimeout = const Duration(minutes: 5),
this.lineLength,
@@ -69,7 +75,6 @@ class PackageAnalyzer {
String? version,
InspectOptions? options,
Logger? logger,
Future<void> Function(String filename, Uint8List data)? storeResource,
}) async {
final sharedContext = _createSharedContext(options: options);
return withLogger(() async {
@@ -80,8 +85,7 @@ class PackageAnalyzer {
destination: tempDir,
pubHostedUrl: options?.pubHostedUrl,
);
return await _inspect(sharedContext, tempDir,
storeResource: storeResource);
return await _inspect(sharedContext, tempDir);
});
}, logger: logger);
}
@@ -106,10 +110,7 @@ class PackageAnalyzer {
);

Future<Summary> _inspect(
SharedAnalysisContext sharedContext,
String pkgDir, {
Future<void> Function(String filename, Uint8List data)? storeResource,
}) async {
SharedAnalysisContext sharedContext, String pkgDir) async {
final tags = <String>{};
final context = PackageContext(
sharedContext: sharedContext,
@@ -199,7 +200,15 @@ class PackageAnalyzer {
final processedScreenshot = r.processedScreenshot!;
processedScreenshots.add(processedScreenshot);

if (storeResource != null) {
final resourcesOutputDir = context.options.resourcesOutputDir;
if (resourcesOutputDir != null) {
Future<void> storeResource(
String resourcePath, Uint8List bytes) async {
final f = File(path.join(resourcesOutputDir, resourcePath));
await f.parent.create(recursive: true);
await f.writeAsBytes(bytes);
}

await storeResource(processedScreenshot.webpImage, r.webpImageBytes!);
await storeResource(
processedScreenshot.webp100Thumbnail, r.webp100ThumbnailBytes!);

0 comments on commit 3cef95d

Please sign in to comment.