prepare first attempt on the builder pipeline
This commit is contained in:
+10
@@ -0,0 +1,10 @@
|
||||
package p.studio.compiler.messages;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Getter
|
||||
@Setter
|
||||
public class BuilderPipelineConfig {
|
||||
private String rootProjectPath;
|
||||
}
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package p.studio.compiler.models;
|
||||
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import p.studio.compiler.messages.BuilderPipelineConfig;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
|
||||
public class BuilderPipelineContext {
|
||||
@Getter
|
||||
private final BuilderPipelineConfig config;
|
||||
@Getter
|
||||
private final LogAggregator logs;
|
||||
@Getter
|
||||
@Setter
|
||||
private ResolvedWorkspace resolvedWorkspace;
|
||||
|
||||
private BuilderPipelineContext(
|
||||
final BuilderPipelineConfig config,
|
||||
final LogAggregator logs) {
|
||||
this.config = config;
|
||||
this.logs = logs;
|
||||
}
|
||||
|
||||
public static BuilderPipelineContext seed(BuilderPipelineConfig config, LogAggregator logAggregator) {
|
||||
return new BuilderPipelineContext(config, logAggregator);
|
||||
}
|
||||
}
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package p.studio.compiler.workspaces;
|
||||
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import p.studio.compiler.exceptions.BuildException;
|
||||
import p.studio.compiler.messages.BuilderPipelineConfig;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.workspaces.stages.DepsPipelineStage;
|
||||
import p.studio.utilities.logs.LogAggregator;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@Slf4j
|
||||
public class BuilderPipelineService {
|
||||
public final static BuilderPipelineService INSTANCE;
|
||||
|
||||
static {
|
||||
final var stages = List.<PipelineStage>of(
|
||||
new DepsPipelineStage()
|
||||
);
|
||||
INSTANCE = new BuilderPipelineService(stages);
|
||||
}
|
||||
|
||||
private final List<PipelineStage> stages;
|
||||
|
||||
BuilderPipelineService(List<PipelineStage> stages) {
|
||||
this.stages = stages;
|
||||
}
|
||||
|
||||
public void run(
|
||||
final BuilderPipelineConfig config,
|
||||
final LogAggregator logs) {
|
||||
final var ctx = BuilderPipelineContext.seed(config, logs);
|
||||
|
||||
for (final var builderPipelineStage : stages) {
|
||||
final var issues = builderPipelineStage.run(ctx);
|
||||
var error = false;
|
||||
if (ReadOnlyCollection.isNotEmpty(issues)) {
|
||||
for (final var issue : issues) {
|
||||
if (issue.isError()) {
|
||||
error = true;
|
||||
logs.using(log).error(issue.getMessage(), issue.getException());
|
||||
continue;
|
||||
}
|
||||
logs.using(log).warn(issue.getMessage());
|
||||
}
|
||||
}
|
||||
if (error) {
|
||||
throw new BuildException("issues found on pipeline stage: " + builderPipelineStage.getClass().getSimpleName());
|
||||
}
|
||||
}
|
||||
|
||||
logs.using(log).info("builder pipeline completed successfully");
|
||||
}
|
||||
}
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
package p.studio.compiler.workspaces;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
public interface PipelineStage {
|
||||
ReadOnlyCollection<BuildingIssue> run(BuilderPipelineContext ctx);
|
||||
}
|
||||
+37
@@ -0,0 +1,37 @@
|
||||
package p.studio.compiler.workspaces.stages;
|
||||
|
||||
import p.studio.compiler.messages.BuildingIssue;
|
||||
import p.studio.compiler.messages.DependencyConfig;
|
||||
import p.studio.compiler.models.BuilderPipelineContext;
|
||||
import p.studio.compiler.workspaces.DependencyService;
|
||||
import p.studio.compiler.workspaces.PipelineStage;
|
||||
import p.studio.utilities.structures.ReadOnlyCollection;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
|
||||
public class DepsPipelineStage implements PipelineStage {
|
||||
@Override
|
||||
public ReadOnlyCollection<BuildingIssue> run(final BuilderPipelineContext ctx) {
|
||||
final Path rootCanonPath;
|
||||
try {
|
||||
rootCanonPath = Paths.get(ctx.getConfig().getRootProjectPath()).toRealPath();
|
||||
} catch (IOException e) {
|
||||
return ReadOnlyCollection.wrap(List.of(BuildingIssue
|
||||
.builder()
|
||||
.error(true)
|
||||
.message("[DEPS]: root directory no found: " + ctx.getConfig().getRootProjectPath())
|
||||
.build()));
|
||||
}
|
||||
final var cfg = new DependencyConfig(false, rootCanonPath);
|
||||
final var resolvedWorkspace = DependencyService.INSTANCE.run(cfg, ctx.getLogs());
|
||||
for (final var pId : resolvedWorkspace.stack().projects()) {
|
||||
final var pd = resolvedWorkspace.graph().projects().get(pId.getIndex());
|
||||
ctx.getLogs().info("Project [ " + pd.getName() + " ] read");
|
||||
}
|
||||
ctx.setResolvedWorkspace(resolvedWorkspace);
|
||||
return ReadOnlyCollection.empty();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user