asset details (WIP)
This commit is contained in:
-3
@@ -3,7 +3,6 @@ package p.packer.dtos;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -16,7 +15,6 @@ public record PackerAssetDetailsDTO(
|
||||
Map<OutputCodecCatalog, List<PackerCodecConfigurationFieldDTO>> codecConfigurationFieldsByCodec,
|
||||
List<PackerCodecConfigurationFieldDTO> metadataFields,
|
||||
PackerBankCompositionDetailsDTO bankComposition,
|
||||
Map<String, List<Path>> inputsByRole,
|
||||
List<PackerDiagnosticDTO> diagnostics) {
|
||||
|
||||
public PackerAssetDetailsDTO {
|
||||
@@ -27,7 +25,6 @@ public record PackerAssetDetailsDTO(
|
||||
codecConfigurationFieldsByCodec = Map.copyOf(Objects.requireNonNull(codecConfigurationFieldsByCodec, "codecConfigurationFieldsByCodec"));
|
||||
metadataFields = List.copyOf(Objects.requireNonNull(metadataFields, "metadataFields"));
|
||||
bankComposition = Objects.requireNonNull(bankComposition, "bankComposition");
|
||||
inputsByRole = Map.copyOf(Objects.requireNonNull(inputsByRole, "inputsByRole"));
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
}
|
||||
}
|
||||
|
||||
-2
@@ -14,7 +14,6 @@ public record PackerAssetDeclaration(
|
||||
String assetUuid,
|
||||
String name,
|
||||
AssetFamilyCatalog assetFamily,
|
||||
Map<String, List<String>> inputsByRole,
|
||||
List<PackerAssetArtifactSelection> artifacts,
|
||||
OutputFormatCatalog outputFormat,
|
||||
OutputCodecCatalog outputCodec,
|
||||
@@ -28,7 +27,6 @@ public record PackerAssetDeclaration(
|
||||
assetUuid = Objects.requireNonNull(assetUuid, "assetUuid").trim();
|
||||
name = Objects.requireNonNull(name, "name").trim();
|
||||
assetFamily = Objects.requireNonNull(assetFamily, "assetFamily");
|
||||
inputsByRole = Map.copyOf(Objects.requireNonNull(inputsByRole, "inputsByRole"));
|
||||
artifacts = List.copyOf(Objects.requireNonNull(artifacts, "artifacts"));
|
||||
outputFormat = Objects.requireNonNull(outputFormat, "outputFormat");
|
||||
outputCodec = Objects.requireNonNull(outputCodec, "outputCodec");
|
||||
|
||||
-3
@@ -3,7 +3,6 @@ package p.packer.models;
|
||||
import p.packer.messages.assets.OutputCodecCatalog;
|
||||
import p.packer.messages.assets.OutputFormatCatalog;
|
||||
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
@@ -16,7 +15,6 @@ public record PackerAssetDetails(
|
||||
Map<OutputCodecCatalog, List<PackerCodecConfigurationField>> codecConfigurationFieldsByCodec,
|
||||
List<PackerCodecConfigurationField> metadataFields,
|
||||
PackerBankCompositionDetails bankComposition,
|
||||
Map<String, List<Path>> inputsByRole,
|
||||
List<PackerDiagnostic> diagnostics) {
|
||||
|
||||
public PackerAssetDetails {
|
||||
@@ -27,7 +25,6 @@ public record PackerAssetDetails(
|
||||
codecConfigurationFieldsByCodec = Map.copyOf(Objects.requireNonNull(codecConfigurationFieldsByCodec, "codecConfigurationFieldsByCodec"));
|
||||
metadataFields = List.copyOf(Objects.requireNonNull(metadataFields, "metadataFields"));
|
||||
bankComposition = Objects.requireNonNull(bankComposition, "bankComposition");
|
||||
inputsByRole = Map.copyOf(Objects.requireNonNull(inputsByRole, "inputsByRole"));
|
||||
diagnostics = List.copyOf(Objects.requireNonNull(diagnostics, "diagnostics"));
|
||||
}
|
||||
}
|
||||
|
||||
+2
-5
@@ -480,7 +480,6 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
manifest.put("asset_uuid", assetUuid);
|
||||
manifest.put("name", request.assetName());
|
||||
manifest.put("type", request.assetFamily().manifestType());
|
||||
manifest.put("inputs", Map.of());
|
||||
manifest.put("output", Map.of(
|
||||
"format", request.outputFormat().manifestValue(),
|
||||
"codec", request.outputCodec().manifestValue()));
|
||||
@@ -760,8 +759,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
private void patchManifestArtifacts(ObjectNode manifest, ApplyBankCompositionRequest request) {
|
||||
final ObjectNode inputsNode = mutableObject(manifest, "inputs");
|
||||
inputsNode.removeAll();
|
||||
manifest.remove("inputs");
|
||||
|
||||
final var artifactsNode = manifest.putArray("artifacts");
|
||||
for (int index = 0; index < request.selectedFiles().size(); index += 1) {
|
||||
@@ -799,8 +797,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
}
|
||||
|
||||
private void clearManifestBankComposition(ObjectNode manifest) {
|
||||
final ObjectNode inputsNode = mutableObject(manifest, "inputs");
|
||||
inputsNode.removeAll();
|
||||
manifest.remove("inputs");
|
||||
manifest.putArray("artifacts");
|
||||
}
|
||||
|
||||
|
||||
+10
-44
@@ -45,7 +45,7 @@ public final class PackerAssetDeclarationParser {
|
||||
final var assetUuid = requiredText(root, "asset_uuid", diagnostics, manifestPath);
|
||||
final var name = requiredText(root, "name", diagnostics, manifestPath);
|
||||
final var assetFamily = requiredAssetFamily(root, diagnostics, manifestPath);
|
||||
final var inputsByRole = requiredInputs(root.path("inputs"), diagnostics, manifestPath);
|
||||
rejectLegacyInputs(root.path("inputs"), diagnostics, manifestPath);
|
||||
final var artifacts = optionalArtifacts(root.path("artifacts"), diagnostics, manifestPath);
|
||||
final var outputFormat = requiredOutputFormat(root.path("output"), diagnostics, manifestPath);
|
||||
final var outputCodec = requiredOutputCodec(root.path("output"), diagnostics, manifestPath);
|
||||
@@ -71,7 +71,6 @@ public final class PackerAssetDeclarationParser {
|
||||
assetUuid,
|
||||
name,
|
||||
assetFamily,
|
||||
inputsByRole,
|
||||
artifacts,
|
||||
outputFormat,
|
||||
outputCodec,
|
||||
@@ -229,52 +228,19 @@ public final class PackerAssetDeclarationParser {
|
||||
return Map.copyOf(metadata);
|
||||
}
|
||||
|
||||
private Map<String, List<String>> requiredInputs(
|
||||
private void rejectLegacyInputs(
|
||||
final JsonNode node,
|
||||
final List<PackerDiagnostic> diagnostics,
|
||||
final Path manifestPath) {
|
||||
if (!node.isObject()) {
|
||||
diagnostics.add(missingOrInvalid("inputs", "object of input roles", manifestPath));
|
||||
return Map.of();
|
||||
if (node.isMissingNode() || node.isNull()) {
|
||||
return;
|
||||
}
|
||||
|
||||
final Map<String, List<String>> result = new LinkedHashMap<>();
|
||||
node.fields().forEachRemaining(entry -> {
|
||||
if (!entry.getValue().isArray()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Input role '" + entry.getKey() + "' must be an array of relative paths.",
|
||||
manifestPath,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
final List<String> values = new ArrayList<>();
|
||||
entry.getValue().forEach(value -> {
|
||||
if (!value.isTextual() || value.asText().isBlank()) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Input role '" + entry.getKey() + "' must contain only non-blank path strings.",
|
||||
manifestPath,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
final String relativePath = value.asText().trim();
|
||||
if (!isTrustedRelativePath(relativePath)) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Input role '" + entry.getKey() + "' contains an untrusted path outside the asset root.",
|
||||
manifestPath,
|
||||
true));
|
||||
return;
|
||||
}
|
||||
values.add(relativePath);
|
||||
});
|
||||
result.put(entry.getKey(), List.copyOf(values));
|
||||
});
|
||||
return Map.copyOf(result);
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.STRUCTURAL,
|
||||
"Field 'inputs' is no longer supported; use 'artifacts' instead.",
|
||||
manifestPath,
|
||||
true));
|
||||
}
|
||||
|
||||
private List<PackerAssetArtifactSelection> optionalArtifacts(
|
||||
|
||||
+4
-21
@@ -80,7 +80,6 @@ public final class PackerAssetDetailsService {
|
||||
outputContract.codecConfigurationFieldsByCodec(),
|
||||
metadataFields(outputContract.metadataFields(), declaration.outputMetadata()),
|
||||
resolveBankCompositionDetails(runtimeAsset, declaration),
|
||||
resolveInputs(resolved.assetRoot(), declaration.inputsByRole()),
|
||||
diagnostics);
|
||||
return new GetAssetDetailsResult(
|
||||
diagnostics.stream().anyMatch(PackerDiagnostic::blocking) ? PackerOperationStatus.PARTIAL : PackerOperationStatus.SUCCESS,
|
||||
@@ -120,7 +119,6 @@ public final class PackerAssetDetailsService {
|
||||
Map.of(OutputCodecCatalog.NONE, List.of()),
|
||||
List.of(),
|
||||
PackerBankCompositionDetails.EMPTY,
|
||||
Map.of(),
|
||||
diagnostics);
|
||||
return new GetAssetDetailsResult(
|
||||
PackerOperationStatus.FAILED,
|
||||
@@ -129,16 +127,6 @@ public final class PackerAssetDetailsService {
|
||||
PackerReadMessageMapper.toDiagnosticDTOs(diagnostics));
|
||||
}
|
||||
|
||||
private Map<String, List<Path>> resolveInputs(
|
||||
final Path assetRoot,
|
||||
final Map<String, List<String>> inputsByRole) {
|
||||
final Map<String, List<Path>> resolved = new LinkedHashMap<>();
|
||||
inputsByRole.forEach((role, inputs) -> resolved.put(
|
||||
role,
|
||||
inputs.stream().map(input -> assetRoot.resolve(input).toAbsolutePath().normalize()).toList()));
|
||||
return Map.copyOf(resolved);
|
||||
}
|
||||
|
||||
private PackerBankCompositionDetails resolveBankCompositionDetails(
|
||||
final PackerRuntimeAsset runtimeAsset,
|
||||
final PackerAssetDeclaration declaration) {
|
||||
@@ -163,15 +151,10 @@ public final class PackerAssetDetailsService {
|
||||
}
|
||||
|
||||
private List<String> selectedPathsFor(PackerAssetDeclaration declaration) {
|
||||
if (!declaration.artifacts().isEmpty()) {
|
||||
return declaration.artifacts().stream()
|
||||
.sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index))
|
||||
.map(PackerAssetArtifactSelection::file)
|
||||
.toList();
|
||||
}
|
||||
final List<String> selected = new ArrayList<>();
|
||||
declaration.inputsByRole().values().forEach(selected::addAll);
|
||||
return List.copyOf(selected);
|
||||
return declaration.artifacts().stream()
|
||||
.sorted(Comparator.comparingInt(PackerAssetArtifactSelection::index))
|
||||
.map(PackerAssetArtifactSelection::file)
|
||||
.toList();
|
||||
}
|
||||
|
||||
private Optional<PackerBankCompositionFile> resolveSelectedBankFile(
|
||||
|
||||
-1
@@ -32,7 +32,6 @@ public final class PackerReadMessageMapper {
|
||||
toCodecConfigurationFieldsByCodecDTO(details.codecConfigurationFieldsByCodec()),
|
||||
toCodecConfigurationFieldDTOs(details.metadataFields()),
|
||||
toBankCompositionDetailsDTO(details.bankComposition()),
|
||||
details.inputsByRole(),
|
||||
toDiagnosticDTOs(details.diagnostics()));
|
||||
}
|
||||
|
||||
|
||||
-1
@@ -73,7 +73,6 @@ final class PackerRuntimeAssetMaterializerTest {
|
||||
"uuid",
|
||||
"asset",
|
||||
AssetFamilyCatalog.TILE_BANK,
|
||||
Map.of(),
|
||||
List.of(),
|
||||
OutputFormatCatalog.TILES_INDEXED_V1,
|
||||
OutputCodecCatalog.NONE,
|
||||
|
||||
+2
-6
@@ -271,8 +271,7 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertTrue(updateResult.success());
|
||||
|
||||
final var manifest = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
assertTrue(manifest.path("inputs").isObject());
|
||||
assertTrue(manifest.path("inputs").isEmpty());
|
||||
assertTrue(manifest.path("inputs").isMissingNode());
|
||||
assertTrue(manifest.path("artifacts").isArray());
|
||||
assertTrue(manifest.path("artifacts").isEmpty());
|
||||
|
||||
@@ -304,8 +303,7 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
assertEquals(1, loader.loadCount());
|
||||
|
||||
final var manifest = MAPPER.readTree(assetRoot.resolve("asset.json").toFile());
|
||||
assertTrue(manifest.path("inputs").isObject());
|
||||
assertTrue(manifest.path("inputs").isEmpty());
|
||||
assertTrue(manifest.path("inputs").isMissingNode());
|
||||
assertEquals("cancel.png", manifest.path("artifacts").get(0).path("file").asText());
|
||||
assertEquals(0, manifest.path("artifacts").get(0).path("index").asInt());
|
||||
assertEquals("confirm.png", manifest.path("artifacts").get(1).path("file").asText());
|
||||
@@ -497,7 +495,6 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
"asset_uuid": "shared-uuid",
|
||||
"name": "ui_atlas",
|
||||
"type": "IMAGE/bank",
|
||||
"inputs": {},
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "none"
|
||||
@@ -513,7 +510,6 @@ final class FileSystemPackerWorkspaceServiceTest {
|
||||
"asset_uuid": "shared-uuid",
|
||||
"name": "ui_clone",
|
||||
"type": "IMAGE/bank",
|
||||
"inputs": {},
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "none"
|
||||
|
||||
+2
-3
@@ -62,7 +62,7 @@ final class PackerAssetDeclarationParserTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsUntrustedInputPaths() throws Exception {
|
||||
void rejectsLegacyInputsField() throws Exception {
|
||||
final Path manifest = tempDir.resolve("asset.json");
|
||||
Files.writeString(manifest, """
|
||||
{
|
||||
@@ -79,7 +79,7 @@ final class PackerAssetDeclarationParserTest {
|
||||
final var result = parser.parse(manifest);
|
||||
|
||||
assertFalse(result.valid());
|
||||
assertTrue(result.diagnostics().stream().anyMatch(diagnostic -> diagnostic.message().contains("untrusted path")));
|
||||
assertTrue(result.diagnostics().stream().anyMatch(diagnostic -> diagnostic.message().contains("no longer supported")));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,7 +91,6 @@ final class PackerAssetDeclarationParserTest {
|
||||
"asset_uuid": "uuid-video",
|
||||
"name": "bad_asset",
|
||||
"type": "video_bank",
|
||||
"inputs": { "sprites": ["atlas.png"] },
|
||||
"output": { "format": "TILES/indexed_v1", "codec": "NONE" },
|
||||
"preload": { "enabled": true }
|
||||
}
|
||||
|
||||
+3
-5
@@ -64,8 +64,8 @@ final class PackerAssetDetailsServiceTest {
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final ObjectNode manifest = (ObjectNode) mapper.readTree(manifestPath.toFile());
|
||||
final ObjectNode inputs = manifest.putObject("inputs");
|
||||
inputs.putArray("sprites").add("confirm.png");
|
||||
final var artifacts = manifest.putArray("artifacts");
|
||||
artifacts.addObject().put("file", "confirm.png").put("index", 0);
|
||||
mapper.writerWithDefaultPrettyPrinter().writeValue(manifestPath.toFile(), manifest);
|
||||
|
||||
final PackerAssetDetailsService service = service();
|
||||
@@ -81,7 +81,7 @@ final class PackerAssetDetailsServiceTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
void prefersArtifactsSelectionOrderOverLegacyInputs() throws Exception {
|
||||
void prefersArtifactsSelectionOrder() throws Exception {
|
||||
final Path projectRoot = copyFixture("workspaces/managed-basic", tempDir.resolve("managed-artifacts-order"));
|
||||
final Path assetRoot = projectRoot.resolve("assets/ui/atlas");
|
||||
final BufferedImage tile = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
|
||||
@@ -91,8 +91,6 @@ final class PackerAssetDetailsServiceTest {
|
||||
|
||||
final ObjectMapper mapper = new ObjectMapper();
|
||||
final ObjectNode manifest = (ObjectNode) mapper.readTree(manifestPath.toFile());
|
||||
final ObjectNode inputs = manifest.putObject("inputs");
|
||||
inputs.putArray("sprites").add("a.png");
|
||||
final var artifacts = manifest.putArray("artifacts");
|
||||
artifacts.addObject().put("file", "b.png").put("index", 0);
|
||||
artifacts.addObject().put("file", "a.png").put("index", 1);
|
||||
|
||||
-1
@@ -54,7 +54,6 @@ final class PackerRuntimeRegistryTest {
|
||||
"asset_uuid": "runtime-refresh-uuid",
|
||||
"name": "ui_sounds",
|
||||
"type": "audio.bank",
|
||||
"inputs": {},
|
||||
"output": {
|
||||
"format": "SOUND/bank_v1",
|
||||
"codec": "none"
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
"asset_uuid": "future-uuid-1",
|
||||
"name": "future_asset",
|
||||
"type": "tile_bank",
|
||||
"inputs": {
|
||||
"sprites": ["future.png"]
|
||||
},
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "NONE"
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
"asset_uuid": "fixture-uuid-1",
|
||||
"name": "ui_atlas",
|
||||
"type": "tile_bank",
|
||||
"inputs": {
|
||||
"sprites": ["sprites/confirm.png"]
|
||||
},
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "NONE"
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
"asset_uuid": "orphan-uuid-1",
|
||||
"name": "ui_sounds",
|
||||
"type": "sound_bank",
|
||||
"inputs": {
|
||||
"sources": ["confirm.wav"]
|
||||
},
|
||||
"output": {
|
||||
"format": "SOUND/bank_v1",
|
||||
"codec": "NONE"
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
"asset_uuid": "orphan-uuid-2",
|
||||
"name": "ui_sounds",
|
||||
"type": "sound_bank",
|
||||
"inputs": {
|
||||
"sources": ["confirm.wav"]
|
||||
},
|
||||
"output": {
|
||||
"format": "SOUND/bank_v1",
|
||||
"codec": "NONE"
|
||||
|
||||
-3
@@ -3,9 +3,6 @@
|
||||
"asset_uuid": "uuid-1",
|
||||
"name": "ui_atlas",
|
||||
"type": "tile_bank",
|
||||
"inputs": {
|
||||
"sprites": ["sprites/confirm.png"]
|
||||
},
|
||||
"output": {
|
||||
"format": "TILES/indexed_v1",
|
||||
"codec": "NONE"
|
||||
|
||||
Reference in New Issue
Block a user