resolved workspace adjustments for topological order
This commit is contained in:
parent
c74bbf03b4
commit
efa8063b57
@ -22,15 +22,12 @@ public class DepsPipelineStage implements PipelineStage {
|
||||
return ReadOnlyCollection.with(BuildingIssue
|
||||
.builder()
|
||||
.error(true)
|
||||
.message("[DEPS]: rootProjectId directory no found: " + ctx.config.getRootProjectPath())
|
||||
.message("[BUILD]: root project directory no found: " + ctx.config.getRootProjectPath())
|
||||
.build());
|
||||
}
|
||||
final var cfg = new DependencyConfig(false, rootCanonPath);
|
||||
final var resolvedWorkspace = DependencyService.INSTANCE.run(cfg, logs);
|
||||
for (final var pId : resolvedWorkspace.stack().projects()) {
|
||||
final var pd = resolvedWorkspace.graph().projectTable().get(pId);
|
||||
logs.info("Project [ " + pd.getName() + " ] read");
|
||||
}
|
||||
resolvedWorkspace.topologicalOrder().forEach(pd -> logs.info("Project [ " + pd.getName() + " ] read"));
|
||||
ctx.resolvedWorkspace = resolvedWorkspace;
|
||||
return ReadOnlyCollection.empty();
|
||||
}
|
||||
|
||||
@ -3,5 +3,12 @@ package p.studio.compiler.models;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
public record BuildStack(ReadOnlyList<ProjectId> projects) {
|
||||
public class BuildStack {
|
||||
public final ReadOnlyList<ProjectId> topologicalOrder;
|
||||
public final ReadOnlyList<ProjectId> reverseTopologicalOrder;
|
||||
|
||||
public BuildStack(ReadOnlyList<ProjectId> topologicalOrder) {
|
||||
this.topologicalOrder = topologicalOrder;
|
||||
this.reverseTopologicalOrder = topologicalOrder.invert();
|
||||
}
|
||||
}
|
||||
|
||||
@ -3,7 +3,6 @@ package p.studio.compiler.models;
|
||||
import p.studio.compiler.exceptions.BuildException;
|
||||
import p.studio.compiler.messages.DependencyConfig;
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.source.tables.FileTable;
|
||||
import p.studio.compiler.source.tables.ProjectTable;
|
||||
import p.studio.utilities.structures.ReadOnlyList;
|
||||
|
||||
@ -28,7 +27,6 @@ public final class DependencyContext {
|
||||
|
||||
public ProjectId rootProjectId;
|
||||
public BuildStack stack;
|
||||
public FileTable fileTable;
|
||||
|
||||
private DependencyContext(DependencyConfig config) {
|
||||
this.config = config;
|
||||
@ -56,7 +54,7 @@ public final class DependencyContext {
|
||||
}
|
||||
final var dependenciesByProject = buildDependenciesByProject();
|
||||
final var workspaceGraph = new WorkspaceGraph(projectTable, dependenciesByProject);
|
||||
return new ResolvedWorkspace(rootProjectId, workspaceGraph, stack, fileTable);
|
||||
return new ResolvedWorkspace(rootProjectId, workspaceGraph, stack);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -1,11 +1,22 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import p.studio.compiler.source.identifiers.ProjectId;
|
||||
import p.studio.compiler.source.tables.FileTable;
|
||||
|
||||
import java.util.stream.Stream;
|
||||
|
||||
public record ResolvedWorkspace(
|
||||
ProjectId projectId,
|
||||
WorkspaceGraph graph,
|
||||
BuildStack stack,
|
||||
FileTable fileTable) {
|
||||
BuildStack stack) {
|
||||
public ProjectDescriptor getMainProjectDescriptor() {
|
||||
return graph.getProjectDescriptor(projectId);
|
||||
}
|
||||
|
||||
public Stream<ProjectDescriptor> topologicalOrder() {
|
||||
return stack.topologicalOrder.stream().map(graph::getProjectDescriptor);
|
||||
}
|
||||
|
||||
public Stream<ProjectDescriptor> reverseTopologicalOrder() {
|
||||
return stack.reverseTopologicalOrder.stream().map(graph::getProjectDescriptor);
|
||||
}
|
||||
}
|
||||
|
||||
@ -6,10 +6,12 @@ import p.studio.compiler.dtos.PrometeuManifestDTO;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
|
||||
public final class PrometeuManifestMapper {
|
||||
private static final ObjectMapper mapper = new ObjectMapper();
|
||||
public final class PrometeuManifestUtils {
|
||||
public static final PrometeuManifestUtils INSTANCE = new PrometeuManifestUtils();
|
||||
|
||||
public static PrometeuManifestDTO read(Path manifestPath) {
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
|
||||
public PrometeuManifestDTO read(Path manifestPath) {
|
||||
try {
|
||||
return mapper.readValue(manifestPath.toFile(), PrometeuManifestDTO.class);
|
||||
} catch (IOException e) {
|
||||
@ -9,7 +9,7 @@ import p.studio.compiler.models.DependencyContext;
|
||||
import p.studio.compiler.models.ProjectInfo;
|
||||
import p.studio.compiler.models.ProjectInfoId;
|
||||
import p.studio.compiler.models.PrometeuManifest;
|
||||
import p.studio.compiler.utilities.PrometeuManifestMapper;
|
||||
import p.studio.compiler.utilities.PrometeuManifestUtils;
|
||||
import p.studio.compiler.workspaces.DependencyPhase;
|
||||
import p.studio.compiler.workspaces.DependencyReference;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
@ -56,7 +56,7 @@ public class DiscoverPhase implements DependencyPhase {
|
||||
continue;
|
||||
}
|
||||
|
||||
final var prometeuManifestDTO = PrometeuManifestMapper.read(manifestPathCanon);
|
||||
final var prometeuManifestDTO = PrometeuManifestUtils.INSTANCE.read(manifestPathCanon);
|
||||
final var manifestMaybe = map(rootPathCanon, prometeuManifestDTO, issues);
|
||||
|
||||
if (manifestMaybe.isEmpty()) {
|
||||
|
||||
@ -28,7 +28,7 @@ public final class ValidatePhase implements DependencyPhase {
|
||||
return ReadOnlyCollection.with(issue);
|
||||
}
|
||||
|
||||
// ensure uniformity to version across the same projects (associated by name)
|
||||
// ensure uniformity to version across the same projectIds (associated by name)
|
||||
for (final var entry : ctx.projectNameAndVersions.entrySet()) {
|
||||
final var name = entry.getKey();
|
||||
final var versions = entry.getValue();
|
||||
|
||||
@ -43,7 +43,7 @@ public final class WireProjectsPhase implements DependencyPhase {
|
||||
return ReadOnlyCollection.wrap(issues);
|
||||
}
|
||||
|
||||
// since it is not ordered, we have to iterate it over again, but now associating dependencies with projects
|
||||
// since it is not ordered, we have to iterate it over again, but now associating dependencies with projectIds
|
||||
for (int i = 0; i < ctx.projectInfoTable.size(); i++) {
|
||||
final var projectInfo = ctx.projectInfoTable.get(new ProjectInfoId(i));
|
||||
final var dependencies = new ArrayList<ProjectId>();
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package p.studio.utilities.structures;
|
||||
|
||||
import org.apache.commons.collections4.ListUtils;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
@ -83,4 +85,10 @@ public class ReadOnlyList<T> extends ReadOnlyCollection<T> {
|
||||
}
|
||||
return ReadOnlyList.wrap(s.toList());
|
||||
}
|
||||
|
||||
public ReadOnlyList<T> invert() {
|
||||
final var inverted = new ArrayList<>(collection);
|
||||
java.util.Collections.reverse(inverted);
|
||||
return ReadOnlyList.wrap(inverted);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user