packer (WIP)

This commit is contained in:
2026-03-24 13:42:56 +00:00
parent 31621303d1
commit 3fbcb30dff
4 changed files with 907 additions and 753 deletions
@@ -156,7 +156,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final PackerProjectContext project = Objects.requireNonNull(request, "request").project();
final PackerRuntimeSnapshot snapshot = runtimeRegistry.getOrLoad(project).snapshot();
final List<PackerPackSummaryAssetDTO> assets = snapshot.assets().stream()
.filter(runtimeAsset -> runtimeAsset.registryEntry().isPresent() && runtimeAsset.registryEntry().get().includedInBuild())
.filter(this::isEffectivelyIncludedInPackSet)
.sorted(Comparator.comparingInt(runtimeAsset -> runtimeAsset.registryEntry().get().assetId()))
.map(this::toPackSummaryAssetDTO)
.toList();
@@ -171,7 +171,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final PackerProjectContext project = Objects.requireNonNull(request, "request").project();
final PackerRuntimeSnapshot snapshot = runtimeRegistry.getOrLoad(project).snapshot();
final List<PackerPackValidationAssetDTO> blockedAssets = snapshot.assets().stream()
.filter(runtimeAsset -> runtimeAsset.registryEntry().isPresent() && runtimeAsset.registryEntry().get().includedInBuild())
.filter(this::isEffectivelyIncludedInPackSet)
.map(this::toPackValidationAssetDTO)
.filter(PackerPackValidationAssetDTO::blocked)
.toList();
@@ -321,7 +321,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final PackerRuntimeSnapshot refreshedSnapshot = runtimeRegistry.refresh(project).snapshot();
final PackerRuntimeSnapshot frozenSnapshot = createFrozenPackingSnapshot(refreshedSnapshot);
final List<PackerPackValidationAssetDTO> blockedAssets = frozenSnapshot.assets().stream()
.filter(runtimeAsset -> runtimeAsset.registryEntry().isPresent() && runtimeAsset.registryEntry().get().includedInBuild())
.filter(this::isEffectivelyIncludedInPackSet)
.map(this::toPackValidationAssetDTO)
.filter(PackerPackValidationAssetDTO::blocked)
.toList();
@@ -778,7 +778,8 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
final List<PackerDiagnostic> blockingDiagnostics = Stream.of(
parsed.diagnostics(),
runtimeAsset.walkDiagnostics(),
collectWalkFileDiagnostics(runtimeAsset),
collectPackRelevantWalkFileDiagnostics(runtimeAsset),
packExecutionSupportDiagnostics(parsed.declaration(), runtimeAsset.manifestPath()),
identityMismatchDiagnostics(registryEntry, parsed, runtimeAsset.manifestPath()))
.flatMap(Collection::stream)
.filter(PackerDiagnostic::blocking)
@@ -791,14 +792,39 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
PackerReadMessageMapper.toDiagnosticDTOs(blockingDiagnostics));
}
private List<PackerDiagnostic> collectWalkFileDiagnostics(PackerRuntimeAsset runtimeAsset) {
private List<PackerDiagnostic> collectPackRelevantWalkFileDiagnostics(PackerRuntimeAsset runtimeAsset) {
final List<PackerDiagnostic> diagnostics = new ArrayList<>();
final Set<String> selectedPaths = runtimeAsset.parsedDeclaration().declaration() == null
? Set.of()
: runtimeAsset.parsedDeclaration().declaration().artifacts().stream()
.map(PackerAssetArtifactSelection::file)
.collect(java.util.stream.Collectors.toSet());
for (PackerRuntimeWalkFile file : runtimeAsset.walkProjection().buildCandidateFiles()) {
if (!selectedPaths.isEmpty() && !selectedPaths.contains(file.relativePath())) {
continue;
}
diagnostics.addAll(file.diagnostics());
}
return diagnostics;
}
private List<PackerDiagnostic> packExecutionSupportDiagnostics(
PackerAssetDeclaration declaration,
Path manifestPath) {
if (declaration == null) {
return List.of();
}
if (declaration.assetFamily() == AssetFamilyCatalog.TILE_BANK) {
return List.of();
}
return List.of(new PackerDiagnostic(
PackerDiagnosticSeverity.ERROR,
PackerDiagnosticCategory.STRUCTURAL,
"Pack execution is not implemented yet for asset family " + declaration.assetFamily().manifestType() + ".",
manifestPath,
true));
}
private void saveRuntimeCache(PackerProjectContext project, PackerRuntimeSnapshot snapshot) {
cacheRepository.save(project, snapshot.cacheState());
}
@@ -815,7 +841,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
PackerRuntimeSnapshot snapshot,
PackerRuntimeAsset asset,
PackerRuntimeAssetMaterializer materializer) {
if (asset.registryEntry().isEmpty() || !asset.registryEntry().get().includedInBuild() || !asset.parsedDeclaration().valid()) {
if (!isEffectivelyIncludedInPackSet(asset) || !asset.parsedDeclaration().valid()) {
return asset;
}
return materializer.materialize(
@@ -829,7 +855,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
private PackedWorkspaceArtifacts buildPackedWorkspaceArtifacts(PackerRuntimeSnapshot snapshot) throws IOException {
final List<PackedAsset> packedAssets = snapshot.assets().stream()
.filter(asset -> asset.registryEntry().isPresent() && asset.registryEntry().get().includedInBuild())
.filter(this::isEffectivelyIncludedInPackSet)
.sorted(Comparator.comparingInt(asset -> asset.registryEntry().get().assetId()))
.map(this::packRuntimeAsset)
.toList();
@@ -882,6 +908,14 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return packTileBank(runtimeAsset, declaration);
}
private boolean isEffectivelyIncludedInPackSet(PackerRuntimeAsset runtimeAsset) {
if (runtimeAsset.registryEntry().isEmpty() || !runtimeAsset.registryEntry().get().includedInBuild()) {
return false;
}
final PackerAssetDeclaration declaration = runtimeAsset.parsedDeclaration().declaration();
return declaration == null || !declaration.artifacts().isEmpty();
}
private PackedAsset packTileBank(PackerRuntimeAsset runtimeAsset, PackerAssetDeclaration declaration) {
final int tileSize = parseTileSize(declaration.outputMetadata().get("tile_size"));
final int width = 256;
@@ -924,8 +958,9 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
metadata.put("width", width);
metadata.put("height", height);
metadata.put("palette_count", 64);
metadata.put("palette_authored", countAuthoredTileBankPalettes(declaration));
metadata.put("codec", Map.of());
metadata.put("pipeline", PackerReadMessageMapper.normalizeMetadata(declaration.outputPipelineMetadata()));
metadata.put("pipeline", normalizeTileBankRuntimePipelineMetadata(declaration));
declaration.outputMetadata().forEach((key, value) -> {
if (!"tile_size".equals(key)) {
metadata.putIfAbsent(key, value);
@@ -994,6 +1029,18 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
return bytes;
}
private int countAuthoredTileBankPalettes(PackerAssetDeclaration declaration) {
final JsonNode palettesNode = declaration.outputPipelineMetadata().get("palettes");
return palettesNode instanceof ArrayNode palettesArray ? palettesArray.size() : 0;
}
private Map<String, Object> normalizeTileBankRuntimePipelineMetadata(PackerAssetDeclaration declaration) {
final LinkedHashMap<String, Object> pipeline = new LinkedHashMap<>(
PackerReadMessageMapper.normalizeMetadata(declaration.outputPipelineMetadata()));
pipeline.remove("palettes");
return pipeline;
}
private byte[] buildPrelude(int headerLength) {
final int preludeLength = 24;
final ByteBuffer buffer = ByteBuffer.allocate(preludeLength).order(ByteOrder.LITTLE_ENDIAN);