small fixes
This commit is contained in:
parent
615c7abecd
commit
c74bbf03b4
@ -1,27 +1,18 @@
|
|||||||
package p.studio.compiler.models;
|
package p.studio.compiler.models;
|
||||||
|
|
||||||
import lombok.Getter;
|
|
||||||
import lombok.Setter;
|
|
||||||
import p.studio.compiler.messages.BuilderPipelineConfig;
|
import p.studio.compiler.messages.BuilderPipelineConfig;
|
||||||
import p.studio.utilities.logs.LogAggregator;
|
|
||||||
|
|
||||||
public class BuilderPipelineContext {
|
public class BuilderPipelineContext {
|
||||||
@Getter
|
public final BuilderPipelineConfig config;
|
||||||
private final BuilderPipelineConfig config;
|
|
||||||
@Getter
|
public ResolvedWorkspace resolvedWorkspace;
|
||||||
private final LogAggregator logs;
|
|
||||||
@Getter
|
|
||||||
@Setter
|
|
||||||
private ResolvedWorkspace resolvedWorkspace;
|
|
||||||
|
|
||||||
private BuilderPipelineContext(
|
private BuilderPipelineContext(
|
||||||
final BuilderPipelineConfig config,
|
final BuilderPipelineConfig config) {
|
||||||
final LogAggregator logs) {
|
|
||||||
this.config = config;
|
this.config = config;
|
||||||
this.logs = logs;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static BuilderPipelineContext seed(BuilderPipelineConfig config, LogAggregator logAggregator) {
|
public static BuilderPipelineContext basedOn(BuilderPipelineConfig config) {
|
||||||
return new BuilderPipelineContext(config, logAggregator);
|
return new BuilderPipelineContext(config);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -30,10 +30,10 @@ public class BuilderPipelineService {
|
|||||||
public void run(
|
public void run(
|
||||||
final BuilderPipelineConfig config,
|
final BuilderPipelineConfig config,
|
||||||
final LogAggregator logs) {
|
final LogAggregator logs) {
|
||||||
final var ctx = BuilderPipelineContext.seed(config, logs);
|
final var ctx = BuilderPipelineContext.basedOn(config);
|
||||||
|
|
||||||
for (final var builderPipelineStage : stages) {
|
for (final var builderPipelineStage : stages) {
|
||||||
final var issues = builderPipelineStage.run(ctx);
|
final var issues = builderPipelineStage.run(ctx, logs);
|
||||||
var error = false;
|
var error = false;
|
||||||
if (ReadOnlyCollection.isNotEmpty(issues)) {
|
if (ReadOnlyCollection.isNotEmpty(issues)) {
|
||||||
for (final var issue : issues) {
|
for (final var issue : issues) {
|
||||||
|
|||||||
@ -2,8 +2,9 @@ package p.studio.compiler.workspaces;
|
|||||||
|
|
||||||
import p.studio.compiler.messages.BuildingIssue;
|
import p.studio.compiler.messages.BuildingIssue;
|
||||||
import p.studio.compiler.models.BuilderPipelineContext;
|
import p.studio.compiler.models.BuilderPipelineContext;
|
||||||
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||||
|
|
||||||
public interface PipelineStage {
|
public interface PipelineStage {
|
||||||
ReadOnlyCollection<BuildingIssue> run(BuilderPipelineContext ctx);
|
ReadOnlyCollection<BuildingIssue> run(BuilderPipelineContext ctx, LogAggregator logs);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -5,33 +5,33 @@ import p.studio.compiler.messages.DependencyConfig;
|
|||||||
import p.studio.compiler.models.BuilderPipelineContext;
|
import p.studio.compiler.models.BuilderPipelineContext;
|
||||||
import p.studio.compiler.workspaces.DependencyService;
|
import p.studio.compiler.workspaces.DependencyService;
|
||||||
import p.studio.compiler.workspaces.PipelineStage;
|
import p.studio.compiler.workspaces.PipelineStage;
|
||||||
|
import p.studio.utilities.logs.LogAggregator;
|
||||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.file.Path;
|
import java.nio.file.Path;
|
||||||
import java.nio.file.Paths;
|
import java.nio.file.Paths;
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class DepsPipelineStage implements PipelineStage {
|
public class DepsPipelineStage implements PipelineStage {
|
||||||
@Override
|
@Override
|
||||||
public ReadOnlyCollection<BuildingIssue> run(final BuilderPipelineContext ctx) {
|
public ReadOnlyCollection<BuildingIssue> run(final BuilderPipelineContext ctx, LogAggregator logs) {
|
||||||
final Path rootCanonPath;
|
final Path rootCanonPath;
|
||||||
try {
|
try {
|
||||||
rootCanonPath = Paths.get(ctx.getConfig().getRootProjectPath()).toRealPath();
|
rootCanonPath = Paths.get(ctx.config.getRootProjectPath()).toRealPath();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
return ReadOnlyCollection.wrap(List.of(BuildingIssue
|
return ReadOnlyCollection.with(BuildingIssue
|
||||||
.builder()
|
.builder()
|
||||||
.error(true)
|
.error(true)
|
||||||
.message("[DEPS]: rootProjectId directory no found: " + ctx.getConfig().getRootProjectPath())
|
.message("[DEPS]: rootProjectId directory no found: " + ctx.config.getRootProjectPath())
|
||||||
.build()));
|
.build());
|
||||||
}
|
}
|
||||||
final var cfg = new DependencyConfig(false, rootCanonPath);
|
final var cfg = new DependencyConfig(false, rootCanonPath);
|
||||||
final var resolvedWorkspace = DependencyService.INSTANCE.run(cfg, ctx.getLogs());
|
final var resolvedWorkspace = DependencyService.INSTANCE.run(cfg, logs);
|
||||||
for (final var pId : resolvedWorkspace.stack().projects()) {
|
for (final var pId : resolvedWorkspace.stack().projects()) {
|
||||||
final var pd = resolvedWorkspace.graph().projectTable().get(pId);
|
final var pd = resolvedWorkspace.graph().projectTable().get(pId);
|
||||||
ctx.getLogs().info("Project [ " + pd.getName() + " ] read");
|
logs.info("Project [ " + pd.getName() + " ] read");
|
||||||
}
|
}
|
||||||
ctx.setResolvedWorkspace(resolvedWorkspace);
|
ctx.resolvedWorkspace = resolvedWorkspace;
|
||||||
return ReadOnlyCollection.empty();
|
return ReadOnlyCollection.empty();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -34,7 +34,7 @@ public final class DependencyContext {
|
|||||||
this.config = config;
|
this.config = config;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static DependencyContext seed(DependencyConfig config) {
|
public static DependencyContext basedOn(DependencyConfig config) {
|
||||||
return new DependencyContext(config);
|
return new DependencyContext(config);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -35,7 +35,7 @@ public final class DependencyService {
|
|||||||
public ResolvedWorkspace run(
|
public ResolvedWorkspace run(
|
||||||
final DependencyConfig config,
|
final DependencyConfig config,
|
||||||
final LogAggregator logs) {
|
final LogAggregator logs) {
|
||||||
final var ctx = DependencyContext.seed(config);
|
final var ctx = DependencyContext.basedOn(config);
|
||||||
|
|
||||||
for (final var dependencyPhase : phases) {
|
for (final var dependencyPhase : phases) {
|
||||||
final var issues = dependencyPhase.run(ctx);
|
final var issues = dependencyPhase.run(ctx);
|
||||||
|
|||||||
@ -90,7 +90,7 @@ public final class StackPhase implements DependencyPhase {
|
|||||||
.collect(joining("\n"));
|
.collect(joining("\n"));
|
||||||
|
|
||||||
var issue = BuildingIssue.builder().error(true).message(msg).build();
|
var issue = BuildingIssue.builder().error(true).message(msg).build();
|
||||||
return ReadOnlyCollection.wrap(List.of(issue));
|
return ReadOnlyCollection.with(issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
ctx.stack = new BuildStack(ReadOnlyList.wrap(travesalOrder));
|
ctx.stack = new BuildStack(ReadOnlyList.wrap(travesalOrder));
|
||||||
|
|||||||
@ -5,11 +5,9 @@ import p.studio.compiler.models.DependencyContext;
|
|||||||
import p.studio.compiler.workspaces.DependencyPhase;
|
import p.studio.compiler.workspaces.DependencyPhase;
|
||||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public final class ValidatePhase implements DependencyPhase {
|
public final class ValidatePhase implements DependencyPhase {
|
||||||
@Override
|
@Override
|
||||||
public ReadOnlyCollection<BuildingIssue> run(DependencyContext ctx) {
|
public ReadOnlyCollection<BuildingIssue> run(final DependencyContext ctx) {
|
||||||
// ensure rootProjectId is set
|
// ensure rootProjectId is set
|
||||||
if (ctx.rootProjectId == null) {
|
if (ctx.rootProjectId == null) {
|
||||||
final var issue = BuildingIssue
|
final var issue = BuildingIssue
|
||||||
@ -17,7 +15,7 @@ public final class ValidatePhase implements DependencyPhase {
|
|||||||
.error(true)
|
.error(true)
|
||||||
.message("[DEPS]: rootProjectId ProjectId not set")
|
.message("[DEPS]: rootProjectId ProjectId not set")
|
||||||
.build();
|
.build();
|
||||||
return ReadOnlyCollection.wrap(List.of(issue));
|
return ReadOnlyCollection.with(issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure the dependenciesByProject matches the number of projectDescriptors
|
// ensure the dependenciesByProject matches the number of projectDescriptors
|
||||||
@ -27,7 +25,7 @@ public final class ValidatePhase implements DependencyPhase {
|
|||||||
.error(true)
|
.error(true)
|
||||||
.message("[DEPS]: internal error: dependenciesByProject and projectDescriptors size mismatch")
|
.message("[DEPS]: internal error: dependenciesByProject and projectDescriptors size mismatch")
|
||||||
.build();
|
.build();
|
||||||
return ReadOnlyCollection.wrap(List.of(issue));
|
return ReadOnlyCollection.with(issue);
|
||||||
}
|
}
|
||||||
|
|
||||||
// ensure uniformity to version across the same projects (associated by name)
|
// ensure uniformity to version across the same projects (associated by name)
|
||||||
@ -40,7 +38,7 @@ public final class ValidatePhase implements DependencyPhase {
|
|||||||
.error(true)
|
.error(true)
|
||||||
.message("[DEPS]: inconsistent version for project: " + name + " (" + versions + ")")
|
.message("[DEPS]: inconsistent version for project: " + name + " (" + versions + ")")
|
||||||
.build();
|
.build();
|
||||||
return ReadOnlyCollection.wrap(List.of(issue));
|
return ReadOnlyCollection.with(issue);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,11 +1,9 @@
|
|||||||
package p.studio.utilities.structures;
|
package p.studio.utilities.structures;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.*;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Spliterator;
|
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.function.Supplier;
|
import java.util.function.Supplier;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
public class ReadOnlyCollection<T> implements Iterable<T> {
|
public class ReadOnlyCollection<T> implements Iterable<T> {
|
||||||
@ -23,6 +21,13 @@ public class ReadOnlyCollection<T> implements Iterable<T> {
|
|||||||
return new ReadOnlyCollection<>(collection);
|
return new ReadOnlyCollection<>(collection);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@SafeVarargs
|
||||||
|
public static <T> ReadOnlyCollection<T> with(final T... ts) {
|
||||||
|
if (ts == null) return ReadOnlyCollection.empty();
|
||||||
|
if (ts.length == 0) return ReadOnlyCollection.empty();
|
||||||
|
return new ReadOnlyCollection<>(Stream.of(ts).toList());
|
||||||
|
}
|
||||||
|
|
||||||
public static <T> boolean isEmpty(final ReadOnlyCollection<T> c) {
|
public static <T> boolean isEmpty(final ReadOnlyCollection<T> c) {
|
||||||
if (c == null) return true;
|
if (c == null) return true;
|
||||||
return c.isEmpty();
|
return c.isEmpty();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user