added asset workspace working with packer
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
package p.packer.api.assets;
|
||||
|
||||
public enum PackerAssetState {
|
||||
MANAGED,
|
||||
ORPHAN,
|
||||
INVALID
|
||||
REGISTERED,
|
||||
UNREGISTERED
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import java.util.Objects;
|
||||
public record PackerAssetSummary(
|
||||
PackerAssetIdentity identity,
|
||||
PackerAssetState state,
|
||||
PackerBuildParticipation buildParticipation,
|
||||
String assetFamily,
|
||||
boolean preloadEnabled,
|
||||
boolean hasDiagnostics) {
|
||||
@@ -12,9 +13,16 @@ public record PackerAssetSummary(
|
||||
public PackerAssetSummary {
|
||||
Objects.requireNonNull(identity, "identity");
|
||||
Objects.requireNonNull(state, "state");
|
||||
Objects.requireNonNull(buildParticipation, "buildParticipation");
|
||||
assetFamily = Objects.requireNonNullElse(assetFamily, "unknown").trim();
|
||||
if (assetFamily.isBlank()) {
|
||||
assetFamily = "unknown";
|
||||
}
|
||||
if (state == PackerAssetState.REGISTERED && identity.assetId() == null) {
|
||||
throw new IllegalArgumentException("registered asset must expose assetId");
|
||||
}
|
||||
if (state == PackerAssetState.UNREGISTERED && buildParticipation != PackerBuildParticipation.EXCLUDED) {
|
||||
throw new IllegalArgumentException("unregistered asset must stay excluded from build participation");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,6 @@
|
||||
package p.packer.api.assets;
|
||||
|
||||
public enum PackerBuildParticipation {
|
||||
INCLUDED,
|
||||
EXCLUDED
|
||||
}
|
||||
@@ -2,9 +2,8 @@ package p.packer.api.mutations;
|
||||
|
||||
public enum PackerMutationType {
|
||||
REGISTER_ASSET,
|
||||
ADOPT_ASSET,
|
||||
FORGET_ASSET,
|
||||
INCLUDE_ASSET_IN_BUILD,
|
||||
EXCLUDE_ASSET_FROM_BUILD,
|
||||
REMOVE_ASSET,
|
||||
QUARANTINE_ASSET,
|
||||
RELOCATE_ASSET
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package p.packer.building;
|
||||
|
||||
import p.packer.api.PackerOperationStatus;
|
||||
import p.packer.api.PackerProjectContext;
|
||||
import p.packer.api.assets.PackerBuildParticipation;
|
||||
import p.packer.api.assets.PackerAssetState;
|
||||
import p.packer.api.diagnostics.PackerDiagnostic;
|
||||
import p.packer.api.diagnostics.PackerDiagnosticCategory;
|
||||
@@ -45,16 +46,17 @@ public final class PackerBuildPlanner {
|
||||
final List<PackerPlannedAsset> plannedAssets = new ArrayList<>();
|
||||
|
||||
snapshot.assets().stream()
|
||||
.filter(asset -> asset.state() == PackerAssetState.MANAGED)
|
||||
.filter(asset -> asset.buildParticipation() == PackerBuildParticipation.INCLUDED)
|
||||
.sorted(Comparator.comparingInt(asset -> asset.identity().assetId()))
|
||||
.forEach(asset -> {
|
||||
final var detailsResult = detailsService.getAssetDetails(new GetAssetDetailsRequest(project, Integer.toString(asset.identity().assetId())));
|
||||
diagnostics.addAll(detailsResult.diagnostics());
|
||||
if (detailsResult.details().summary().state() != PackerAssetState.MANAGED) {
|
||||
if (detailsResult.details().summary().state() != PackerAssetState.REGISTERED
|
||||
|| detailsResult.details().summary().buildParticipation() != PackerBuildParticipation.INCLUDED) {
|
||||
diagnostics.add(new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.ERROR,
|
||||
PackerDiagnosticCategory.BUILD,
|
||||
"Managed asset is not build-eligible: " + asset.identity().assetName(),
|
||||
"Registered asset is not build-eligible: " + asset.identity().assetName(),
|
||||
asset.identity().assetRoot(),
|
||||
true));
|
||||
return;
|
||||
@@ -115,7 +117,7 @@ public final class PackerBuildPlanner {
|
||||
"inputs", plannedAssets.stream().map(this::cacheKeyView).toList())));
|
||||
return new PackerBuildPlanResult(
|
||||
diagnostics.isEmpty() ? PackerOperationStatus.SUCCESS : PackerOperationStatus.PARTIAL,
|
||||
"Build plan ready for " + plannedAssets.size() + " managed assets.",
|
||||
"Build plan ready for " + plannedAssets.size() + " included assets.",
|
||||
new PackerBuildPlan(cacheKey, plannedAssets, assetTableJson, preloadJson),
|
||||
List.copyOf(diagnostics));
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import p.packer.api.assets.PackerAssetDetails;
|
||||
import p.packer.api.assets.PackerAssetIdentity;
|
||||
import p.packer.api.assets.PackerAssetState;
|
||||
import p.packer.api.assets.PackerAssetSummary;
|
||||
import p.packer.api.assets.PackerBuildParticipation;
|
||||
import p.packer.api.diagnostics.PackerDiagnostic;
|
||||
import p.packer.api.diagnostics.PackerDiagnosticCategory;
|
||||
import p.packer.api.diagnostics.PackerDiagnosticSeverity;
|
||||
@@ -65,13 +66,19 @@ public final class PackerAssetDetailsService {
|
||||
}
|
||||
|
||||
final PackerAssetDeclaration declaration = parsed.declaration();
|
||||
final PackerAssetState state = resolved.registryEntry().isPresent()
|
||||
? PackerAssetState.REGISTERED
|
||||
: PackerAssetState.UNREGISTERED;
|
||||
final PackerAssetSummary summary = new PackerAssetSummary(
|
||||
new PackerAssetIdentity(
|
||||
resolved.registryEntry().map(PackerRegistryEntry::assetId).orElse(null),
|
||||
resolved.registryEntry().map(PackerRegistryEntry::assetUuid).orElse(null),
|
||||
declaration.name(),
|
||||
resolved.assetRoot()),
|
||||
resolved.registryEntry().isPresent() ? PackerAssetState.MANAGED : PackerAssetState.ORPHAN,
|
||||
state,
|
||||
resolved.registryEntry().map(entry -> entry.includedInBuild()
|
||||
? PackerBuildParticipation.INCLUDED
|
||||
: PackerBuildParticipation.EXCLUDED).orElse(PackerBuildParticipation.EXCLUDED),
|
||||
declaration.type(),
|
||||
declaration.preloadEnabled(),
|
||||
!diagnostics.isEmpty());
|
||||
@@ -89,13 +96,19 @@ public final class PackerAssetDetailsService {
|
||||
}
|
||||
|
||||
private GetAssetDetailsResult failureResult(ResolvedAssetReference resolved, List<PackerDiagnostic> diagnostics) {
|
||||
final PackerAssetState state = resolved.registryEntry().isPresent()
|
||||
? PackerAssetState.REGISTERED
|
||||
: PackerAssetState.UNREGISTERED;
|
||||
final PackerAssetSummary summary = new PackerAssetSummary(
|
||||
new PackerAssetIdentity(
|
||||
resolved.registryEntry().map(PackerRegistryEntry::assetId).orElse(null),
|
||||
resolved.registryEntry().map(PackerRegistryEntry::assetUuid).orElse(null),
|
||||
resolved.assetRoot().getFileName().toString(),
|
||||
resolved.assetRoot()),
|
||||
PackerAssetState.INVALID,
|
||||
state,
|
||||
resolved.registryEntry().map(entry -> entry.includedInBuild()
|
||||
? PackerBuildParticipation.INCLUDED
|
||||
: PackerBuildParticipation.EXCLUDED).orElse(PackerBuildParticipation.EXCLUDED),
|
||||
"unknown",
|
||||
false,
|
||||
true);
|
||||
|
||||
@@ -86,38 +86,29 @@ public final class FileSystemPackerDoctorService implements PackerDoctorService
|
||||
addDiagnostic(diagnostics, seenDiagnostics, diagnostic);
|
||||
}
|
||||
|
||||
if (doctorRequest.mode() == PackerDoctorMode.EXPANDED_WORKSPACE && asset.state() == PackerAssetState.ORPHAN) {
|
||||
if (doctorRequest.mode() == PackerDoctorMode.EXPANDED_WORKSPACE && asset.state() == PackerAssetState.UNREGISTERED) {
|
||||
addDiagnostic(diagnostics, seenDiagnostics, new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.WARNING,
|
||||
PackerDiagnosticCategory.HYGIENE,
|
||||
"Orphan asset is valid but not registered in the managed build set: " + relativeAssetRoot(project, asset.identity().assetRoot()),
|
||||
"Asset is present in assets/ but not registered, so it stays excluded from builds: " + relativeAssetRoot(project, asset.identity().assetRoot()),
|
||||
asset.identity().assetRoot(),
|
||||
false));
|
||||
if (doctorRequest.includeSafeFixes() && details.summary().state() != PackerAssetState.INVALID) {
|
||||
if (doctorRequest.includeSafeFixes() && details.diagnostics().stream().noneMatch(PackerDiagnostic::blocking)) {
|
||||
safeFixes.add("register_asset " + relativeAssetRoot(project, asset.identity().assetRoot()));
|
||||
}
|
||||
}
|
||||
|
||||
if (doctorRequest.mode() == PackerDoctorMode.EXPANDED_WORKSPACE && isInsideQuarantine(project, asset.identity().assetRoot())) {
|
||||
addDiagnostic(diagnostics, seenDiagnostics, new PackerDiagnostic(
|
||||
PackerDiagnosticSeverity.INFO,
|
||||
PackerDiagnosticCategory.HYGIENE,
|
||||
"Asset root is currently quarantined and excluded from the active workspace surface.",
|
||||
asset.identity().assetRoot(),
|
||||
false));
|
||||
}
|
||||
|
||||
details.inputsByRole().forEach((role, inputs) -> inputs.forEach(input -> {
|
||||
if (Files.isRegularFile(input)) {
|
||||
return;
|
||||
}
|
||||
final boolean managed = asset.state() == PackerAssetState.MANAGED;
|
||||
final boolean registered = asset.state() == PackerAssetState.REGISTERED;
|
||||
addDiagnostic(diagnostics, seenDiagnostics, new PackerDiagnostic(
|
||||
managed ? PackerDiagnosticSeverity.ERROR : PackerDiagnosticSeverity.WARNING,
|
||||
managed ? PackerDiagnosticCategory.STRUCTURAL : PackerDiagnosticCategory.HYGIENE,
|
||||
registered ? PackerDiagnosticSeverity.ERROR : PackerDiagnosticSeverity.WARNING,
|
||||
registered ? PackerDiagnosticCategory.STRUCTURAL : PackerDiagnosticCategory.HYGIENE,
|
||||
"Declared input is missing for role '" + role + "': " + relativeEvidence(project, input),
|
||||
input,
|
||||
managed));
|
||||
registered));
|
||||
}));
|
||||
events.emit(
|
||||
PackerEventKind.PROGRESS_UPDATED,
|
||||
@@ -143,7 +134,7 @@ public final class FileSystemPackerDoctorService implements PackerDoctorService
|
||||
if (mode == PackerDoctorMode.EXPANDED_WORKSPACE) {
|
||||
return true;
|
||||
}
|
||||
return state == PackerAssetState.MANAGED || state == PackerAssetState.INVALID;
|
||||
return state == PackerAssetState.REGISTERED;
|
||||
}
|
||||
|
||||
private void addDiagnostic(List<PackerDiagnostic> diagnostics, Set<String> seenDiagnostics, PackerDiagnostic diagnostic) {
|
||||
@@ -153,11 +144,6 @@ public final class FileSystemPackerDoctorService implements PackerDoctorService
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isInsideQuarantine(PackerProjectContext project, Path assetRoot) {
|
||||
return assetRoot.toAbsolutePath().normalize()
|
||||
.startsWith(project.rootPath().resolve("assets/.prometeu/quarantine").toAbsolutePath().normalize());
|
||||
}
|
||||
|
||||
private String relativeAssetRoot(PackerProjectContext project, Path assetRoot) {
|
||||
return project.rootPath().resolve("assets").toAbsolutePath().normalize()
|
||||
.relativize(assetRoot.toAbsolutePath().normalize())
|
||||
|
||||
+12
-3
@@ -37,7 +37,11 @@ public final class FileSystemPackerRegistryRepository implements PackerRegistryR
|
||||
if (asset == null) {
|
||||
continue;
|
||||
}
|
||||
entries.add(new PackerRegistryEntry(asset.assetId, asset.assetUuid, normalizeRoot(asset.root)));
|
||||
entries.add(new PackerRegistryEntry(
|
||||
asset.assetId,
|
||||
asset.assetUuid,
|
||||
normalizeRoot(asset.root),
|
||||
asset.includedInBuild == null || asset.includedInBuild));
|
||||
}
|
||||
}
|
||||
validateEntries(entries);
|
||||
@@ -64,7 +68,11 @@ public final class FileSystemPackerRegistryRepository implements PackerRegistryR
|
||||
document.schemaVersion = state.schemaVersion();
|
||||
document.nextAssetId = state.nextAssetId();
|
||||
document.assets = state.assets().stream()
|
||||
.map(entry -> new RegistryAssetDocument(entry.assetId(), entry.assetUuid(), entry.root()))
|
||||
.map(entry -> new RegistryAssetDocument(
|
||||
entry.assetId(),
|
||||
entry.assetUuid(),
|
||||
entry.root(),
|
||||
entry.includedInBuild()))
|
||||
.toList();
|
||||
MAPPER.writerWithDefaultPrettyPrinter().writeValue(registryPath.toFile(), document);
|
||||
} catch (IOException exception) {
|
||||
@@ -121,6 +129,7 @@ public final class FileSystemPackerRegistryRepository implements PackerRegistryR
|
||||
private record RegistryAssetDocument(
|
||||
@JsonProperty("asset_id") int assetId,
|
||||
@JsonProperty("asset_uuid") String assetUuid,
|
||||
@JsonProperty("root") String root) {
|
||||
@JsonProperty("root") String root,
|
||||
@JsonProperty("included_in_build") Boolean includedInBuild) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,12 @@ import java.util.Objects;
|
||||
public record PackerRegistryEntry(
|
||||
int assetId,
|
||||
String assetUuid,
|
||||
String root) {
|
||||
String root,
|
||||
boolean includedInBuild) {
|
||||
|
||||
public PackerRegistryEntry(int assetId, String assetUuid, String root) {
|
||||
this(assetId, assetUuid, root, true);
|
||||
}
|
||||
|
||||
public PackerRegistryEntry {
|
||||
assetUuid = Objects.requireNonNull(assetUuid, "assetUuid").trim();
|
||||
|
||||
+41
-64
@@ -36,9 +36,6 @@ import java.util.UUID;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public final class FileSystemPackerMutationService implements PackerMutationService {
|
||||
private static final String RECOVERED_DIR = "recovered";
|
||||
private static final String QUARANTINE_DIR = "quarantine";
|
||||
|
||||
private final PackerWorkspaceFoundation workspaceFoundation;
|
||||
private final PackerAssetDetailsService detailsService;
|
||||
private final PackerProjectWriteCoordinator writeCoordinator;
|
||||
@@ -97,10 +94,10 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
final Path assetRoot = context.assetDetails().summary().identity().assetRoot();
|
||||
|
||||
return switch (preview.request().type()) {
|
||||
case REGISTER_ASSET, ADOPT_ASSET -> applyRegister(project, registry, assetRoot, preview);
|
||||
case FORGET_ASSET -> applyForget(project, registry, assetRoot, preview);
|
||||
case REGISTER_ASSET -> applyRegister(project, registry, assetRoot, preview);
|
||||
case INCLUDE_ASSET_IN_BUILD -> applyBuildParticipationChange(project, registry, assetRoot, preview, true);
|
||||
case EXCLUDE_ASSET_FROM_BUILD -> applyBuildParticipationChange(project, registry, assetRoot, preview, false);
|
||||
case REMOVE_ASSET -> applyRemove(project, registry, assetRoot, preview);
|
||||
case QUARANTINE_ASSET -> applyQuarantine(project, registry, assetRoot, preview);
|
||||
case RELOCATE_ASSET -> applyRelocate(project, registry, assetRoot, preview);
|
||||
};
|
||||
}
|
||||
@@ -131,18 +128,26 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
List.of());
|
||||
}
|
||||
|
||||
private PackerMutationResult applyForget(
|
||||
private PackerMutationResult applyBuildParticipationChange(
|
||||
PackerProjectContext project,
|
||||
PackerRegistryState registry,
|
||||
Path assetRoot,
|
||||
PackerMutationPreview preview) {
|
||||
PackerMutationPreview preview,
|
||||
boolean includedInBuild) {
|
||||
final PackerRegistryState updated = registry.withAssets(
|
||||
registry.assets().stream()
|
||||
.filter(entry -> !PackerWorkspacePaths.assetRoot(project, entry.root()).equals(assetRoot))
|
||||
.map(entry -> PackerWorkspacePaths.assetRoot(project, entry.root()).equals(assetRoot)
|
||||
? new PackerRegistryEntry(entry.assetId(), entry.assetUuid(), entry.root(), includedInBuild)
|
||||
: entry)
|
||||
.toList(),
|
||||
registry.nextAssetId());
|
||||
workspaceFoundation.saveRegistry(project, updated);
|
||||
return new PackerMutationResult(PackerOperationStatus.SUCCESS, "Asset forgotten.", preview.operationId(), preview.proposedActions(), List.of());
|
||||
return new PackerMutationResult(
|
||||
PackerOperationStatus.SUCCESS,
|
||||
includedInBuild ? "Asset included in builds." : "Asset excluded from builds.",
|
||||
preview.operationId(),
|
||||
preview.proposedActions(),
|
||||
List.of());
|
||||
}
|
||||
|
||||
private PackerMutationResult applyRemove(
|
||||
@@ -160,21 +165,6 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
return new PackerMutationResult(PackerOperationStatus.SUCCESS, "Asset removed from workspace.", preview.operationId(), preview.proposedActions(), List.of());
|
||||
}
|
||||
|
||||
private PackerMutationResult applyQuarantine(
|
||||
PackerProjectContext project,
|
||||
PackerRegistryState registry,
|
||||
Path assetRoot,
|
||||
PackerMutationPreview preview) {
|
||||
final PackerRegistryState updated = registry.withAssets(
|
||||
registry.assets().stream()
|
||||
.filter(entry -> !PackerWorkspacePaths.assetRoot(project, entry.root()).equals(assetRoot))
|
||||
.toList(),
|
||||
registry.nextAssetId());
|
||||
workspaceFoundation.saveRegistry(project, updated);
|
||||
moveAssetRoot(assetRoot, requireTarget(preview));
|
||||
return new PackerMutationResult(PackerOperationStatus.SUCCESS, "Asset moved to quarantine.", preview.operationId(), preview.proposedActions(), List.of());
|
||||
}
|
||||
|
||||
private PackerMutationResult applyRelocate(
|
||||
PackerProjectContext project,
|
||||
PackerRegistryState registry,
|
||||
@@ -184,7 +174,11 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
final PackerRegistryState updated = registry.withAssets(
|
||||
registry.assets().stream()
|
||||
.map(entry -> PackerWorkspacePaths.assetRoot(project, entry.root()).equals(assetRoot)
|
||||
? new PackerRegistryEntry(entry.assetId(), entry.assetUuid(), PackerWorkspacePaths.relativeAssetRoot(project, targetRoot))
|
||||
? new PackerRegistryEntry(
|
||||
entry.assetId(),
|
||||
entry.assetUuid(),
|
||||
PackerWorkspacePaths.relativeAssetRoot(project, targetRoot),
|
||||
entry.includedInBuild())
|
||||
: entry)
|
||||
.toList(),
|
||||
registry.nextAssetId());
|
||||
@@ -206,11 +200,11 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
Path targetAssetRoot = null;
|
||||
|
||||
switch (request.type()) {
|
||||
case REGISTER_ASSET, ADOPT_ASSET -> {
|
||||
case REGISTER_ASSET -> {
|
||||
if (managed) {
|
||||
blockers.add("Asset is already managed.");
|
||||
blockers.add("Asset is already registered.");
|
||||
}
|
||||
if (assetDetails.summary().state() == PackerAssetState.INVALID) {
|
||||
if (assetDetails.diagnostics().stream().anyMatch(PackerDiagnostic::blocking)) {
|
||||
blockers.add("Asset declaration must be valid before registration.");
|
||||
}
|
||||
if (!blockers.isEmpty()) {
|
||||
@@ -221,12 +215,24 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
warnings.add("Asset currently reports diagnostics and will still be registered.");
|
||||
}
|
||||
}
|
||||
case FORGET_ASSET -> {
|
||||
case INCLUDE_ASSET_IN_BUILD -> {
|
||||
if (!managed) {
|
||||
blockers.add("Only managed assets can be forgotten.");
|
||||
blockers.add("Only registered assets can be included in builds.");
|
||||
} else if (assetDetails.summary().buildParticipation() == p.packer.api.assets.PackerBuildParticipation.INCLUDED) {
|
||||
blockers.add("Asset is already included in builds.");
|
||||
} else {
|
||||
actions.add(new PackerProposedAction(PackerOperationClass.REGISTRY_MUTATION, "REMOVE", relativeRoot));
|
||||
warnings.add("The asset will leave the managed build set.");
|
||||
actions.add(new PackerProposedAction(PackerOperationClass.REGISTRY_MUTATION, "UPDATE", relativeRoot));
|
||||
warnings.add("The asset will remain registered and return to the build set.");
|
||||
}
|
||||
}
|
||||
case EXCLUDE_ASSET_FROM_BUILD -> {
|
||||
if (!managed) {
|
||||
blockers.add("Only registered assets can be excluded from builds.");
|
||||
} else if (assetDetails.summary().buildParticipation() == p.packer.api.assets.PackerBuildParticipation.EXCLUDED) {
|
||||
blockers.add("Asset is already excluded from builds.");
|
||||
} else {
|
||||
actions.add(new PackerProposedAction(PackerOperationClass.REGISTRY_MUTATION, "UPDATE", relativeRoot));
|
||||
warnings.add("The asset will remain registered but leave the build set.");
|
||||
}
|
||||
}
|
||||
case REMOVE_ASSET -> {
|
||||
@@ -236,24 +242,6 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
actions.add(new PackerProposedAction(PackerOperationClass.WORKSPACE_MUTATION, "DELETE", relativeRoot));
|
||||
warnings.add("Physical files inside the asset root will be deleted.");
|
||||
}
|
||||
case QUARANTINE_ASSET -> {
|
||||
if (isInsideQuarantine(context.project(), assetRoot)) {
|
||||
blockers.add("Asset is already inside quarantine.");
|
||||
} else {
|
||||
targetAssetRoot = request.targetRoot() != null
|
||||
? request.targetRoot()
|
||||
: nextAvailablePath(quarantineRoot(context.project()), sanitizeSegment(assetDetails.summary().identity().assetName()));
|
||||
if (managed) {
|
||||
actions.add(new PackerProposedAction(PackerOperationClass.REGISTRY_MUTATION, "REMOVE", relativeRoot));
|
||||
warnings.add("Quarantining a managed asset removes it from the active registry.");
|
||||
}
|
||||
actions.add(new PackerProposedAction(
|
||||
PackerOperationClass.WORKSPACE_MUTATION,
|
||||
"MOVE",
|
||||
relativeRoot + " -> " + PackerWorkspacePaths.relativeAssetRoot(context.project(), targetAssetRoot)));
|
||||
warnings.add("Quarantine is explicit and reversible, but the asset will leave its current workspace location.");
|
||||
}
|
||||
}
|
||||
case RELOCATE_ASSET -> {
|
||||
targetAssetRoot = request.targetRoot() != null
|
||||
? request.targetRoot()
|
||||
@@ -291,26 +279,15 @@ public final class FileSystemPackerMutationService implements PackerMutationServ
|
||||
final List<String> initialBlockers = assetDetails.diagnostics().stream()
|
||||
.filter(PackerDiagnostic::blocking)
|
||||
.map(PackerDiagnostic::message)
|
||||
.filter(message -> request.type() != PackerMutationType.FORGET_ASSET
|
||||
.filter(message -> request.type() != PackerMutationType.INCLUDE_ASSET_IN_BUILD
|
||||
&& request.type() != PackerMutationType.EXCLUDE_ASSET_FROM_BUILD
|
||||
&& request.type() != PackerMutationType.REMOVE_ASSET
|
||||
&& request.type() != PackerMutationType.QUARANTINE_ASSET
|
||||
&& request.type() != PackerMutationType.RELOCATE_ASSET)
|
||||
.toList();
|
||||
return new ResolvedMutationContext(request.project(), request, assetDetails, initialBlockers);
|
||||
}
|
||||
|
||||
private Path quarantineRoot(PackerProjectContext project) {
|
||||
return PackerWorkspacePaths.registryDirectory(project).resolve(QUARANTINE_DIR).toAbsolutePath().normalize();
|
||||
}
|
||||
|
||||
private boolean isInsideQuarantine(PackerProjectContext project, Path assetRoot) {
|
||||
return assetRoot.toAbsolutePath().normalize().startsWith(quarantineRoot(project));
|
||||
}
|
||||
|
||||
private Path relocationTarget(PackerProjectContext project, Path assetRoot, String assetName) {
|
||||
if (isInsideQuarantine(project, assetRoot)) {
|
||||
return nextAvailablePath(PackerWorkspacePaths.assetsRoot(project).resolve(RECOVERED_DIR), sanitizeSegment(assetName));
|
||||
}
|
||||
final Path siblingParent = assetRoot.getParent() == null ? PackerWorkspacePaths.assetsRoot(project) : assetRoot.getParent();
|
||||
return nextAvailablePath(siblingParent, assetRoot.getFileName().toString() + "-relocated");
|
||||
}
|
||||
|
||||
+8
-3
@@ -6,6 +6,7 @@ import p.packer.api.PackerProjectContext;
|
||||
import p.packer.api.assets.PackerAssetIdentity;
|
||||
import p.packer.api.assets.PackerAssetState;
|
||||
import p.packer.api.assets.PackerAssetSummary;
|
||||
import p.packer.api.assets.PackerBuildParticipation;
|
||||
import p.packer.api.diagnostics.PackerDiagnostic;
|
||||
import p.packer.api.diagnostics.PackerDiagnosticCategory;
|
||||
import p.packer.api.diagnostics.PackerDiagnosticSeverity;
|
||||
@@ -160,9 +161,12 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
: "unknown";
|
||||
final boolean preload = parsed.declaration() != null && parsed.declaration().preloadEnabled();
|
||||
final boolean hasDiagnostics = !parsed.diagnostics().isEmpty();
|
||||
final PackerAssetState state = parsed.valid()
|
||||
? (registryEntry == null ? PackerAssetState.ORPHAN : PackerAssetState.MANAGED)
|
||||
: PackerAssetState.INVALID;
|
||||
final PackerAssetState state = registryEntry == null
|
||||
? PackerAssetState.UNREGISTERED
|
||||
: PackerAssetState.REGISTERED;
|
||||
final PackerBuildParticipation buildParticipation = state == PackerAssetState.REGISTERED
|
||||
? (registryEntry.includedInBuild() ? PackerBuildParticipation.INCLUDED : PackerBuildParticipation.EXCLUDED)
|
||||
: PackerBuildParticipation.EXCLUDED;
|
||||
return new PackerAssetSummary(
|
||||
new PackerAssetIdentity(
|
||||
registryEntry == null ? null : registryEntry.assetId(),
|
||||
@@ -170,6 +174,7 @@ public final class FileSystemPackerWorkspaceService implements PackerWorkspaceSe
|
||||
assetName,
|
||||
assetRoot),
|
||||
state,
|
||||
buildParticipation,
|
||||
assetFamily,
|
||||
preload,
|
||||
hasDiagnostics);
|
||||
|
||||
Reference in New Issue
Block a user