implements packer PR-09 event lane and studio adapter

This commit is contained in:
2026-03-24 13:42:42 +00:00
parent 682a0e72b5
commit 1c418a454b
16 changed files with 393 additions and 14 deletions
@@ -9,6 +9,9 @@ import p.packer.api.assets.PackerAssetSummary;
import p.packer.api.diagnostics.PackerDiagnostic;
import p.packer.api.diagnostics.PackerDiagnosticCategory;
import p.packer.api.diagnostics.PackerDiagnosticSeverity;
import p.packer.api.events.PackerEventKind;
import p.packer.api.events.PackerEventSink;
import p.packer.api.events.PackerProgress;
import p.packer.api.workspace.GetAssetDetailsRequest;
import p.packer.api.workspace.GetAssetDetailsResult;
import p.packer.api.workspace.InitWorkspaceRequest;
@@ -23,6 +26,7 @@ import p.packer.foundation.PackerRegistryEntry;
import p.packer.foundation.PackerRegistryState;
import p.packer.foundation.PackerWorkspaceFoundation;
import p.packer.foundation.PackerWorkspacePaths;
import p.packer.events.PackerOperationEventEmitter;
import java.io.IOException;
import java.nio.file.Files;
@@ -34,17 +38,26 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
private final PackerWorkspaceFoundation workspaceFoundation;
private final PackerAssetDeclarationParser parser;
private final PackerAssetDetailsService detailsService;
private final PackerEventSink eventSink;
public FileSystemPackerWorkspaceService() {
this(new PackerWorkspaceFoundation(), new PackerAssetDeclarationParser());
this(new PackerWorkspaceFoundation(), new PackerAssetDeclarationParser(), PackerEventSink.noop());
}
public FileSystemPackerWorkspaceService(
PackerWorkspaceFoundation workspaceFoundation,
PackerAssetDeclarationParser parser) {
this(workspaceFoundation, parser, PackerEventSink.noop());
}
public FileSystemPackerWorkspaceService(
PackerWorkspaceFoundation workspaceFoundation,
PackerAssetDeclarationParser parser,
PackerEventSink eventSink) {
this.workspaceFoundation = Objects.requireNonNull(workspaceFoundation, "workspaceFoundation");
this.parser = Objects.requireNonNull(parser, "parser");
this.detailsService = new PackerAssetDetailsService(workspaceFoundation, parser);
this.eventSink = Objects.requireNonNull(eventSink, "eventSink");
}
@Override
@@ -60,6 +73,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
@Override
public ListAssetsResult listAssets(ListAssetsRequest request) {
final PackerProjectContext project = Objects.requireNonNull(request, "request").project();
final PackerOperationEventEmitter events = new PackerOperationEventEmitter(project, eventSink);
final Path assetsRoot = PackerWorkspacePaths.assetsRoot(project);
final PackerRegistryState registry = workspaceFoundation.loadRegistry(project);
final Map<Path, PackerRegistryEntry> registryByRoot = new HashMap<>();
@@ -74,14 +88,23 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
if (Files.isDirectory(assetsRoot)) {
try (Stream<Path> paths = Files.find(assetsRoot, Integer.MAX_VALUE, (path, attrs) ->
attrs.isRegularFile() && path.getFileName().toString().equals("asset.json"))) {
paths.forEach(assetManifestPath -> {
final List<Path> manifests = paths.toList();
final int total = manifests.size();
for (int index = 0; index < manifests.size(); index += 1) {
final Path assetManifestPath = manifests.get(index);
final Path assetRoot = assetManifestPath.getParent().toAbsolutePath().normalize();
discoveredRoots.add(assetRoot);
final PackerRegistryEntry registryEntry = registryByRoot.get(assetRoot);
final PackerAssetDeclarationParseResult parsed = parser.parse(assetManifestPath);
diagnostics.addAll(parsed.diagnostics());
assets.add(buildSummary(assetRoot, registryEntry, parsed));
});
final PackerAssetSummary summary = buildSummary(assetRoot, registryEntry, parsed);
assets.add(summary);
events.emit(
PackerEventKind.ASSET_DISCOVERED,
"Discovered asset: " + summary.identity().assetName(),
new PackerProgress(total == 0 ? 1.0d : (index + 1) / (double) total, false),
List.of(summary.identity().assetName()));
}
} catch (IOException exception) {
diagnostics.add(new PackerDiagnostic(
PackerDiagnosticSeverity.ERROR,
@@ -110,6 +133,9 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final PackerOperationStatus status = diagnostics.stream().anyMatch(PackerDiagnostic::blocking)
? PackerOperationStatus.PARTIAL
: PackerOperationStatus.SUCCESS;
if (!diagnostics.isEmpty()) {
events.emit(PackerEventKind.DIAGNOSTICS_UPDATED, "Asset scan diagnostics updated.", List.of());
}
return new ListAssetsResult(
status,
"Packer asset snapshot ready.",