basic for analyse
This commit is contained in:
+21
-5
@@ -57,7 +57,7 @@ public class BuilderPipelineService {
|
||||
public AnalysisSnapshot analyze(
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var diagnostics = run(ctx, logs, analyses, new ArrayList<>());
|
||||
final var diagnostics = run(ctx, logs, analyses, new ArrayList<>(), false);
|
||||
return new AnalysisSnapshot(
|
||||
ctx.resolvedWorkspace.frontendSpec(),
|
||||
diagnostics,
|
||||
@@ -70,7 +70,10 @@ public class BuilderPipelineService {
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var analysisSnapshot = this.analyze(ctx, logs);
|
||||
final var diagnostics = run(ctx, logs, compile, new ArrayList<>(analysisSnapshot.diagnostics()));
|
||||
if (hasErrors(analysisSnapshot.diagnostics())) {
|
||||
throw new BuildException("issues found on pipeline stage: analyze");
|
||||
}
|
||||
final var diagnostics = run(ctx, logs, compile, new ArrayList<>(analysisSnapshot.diagnostics()), true);
|
||||
return new CompileResult(
|
||||
analysisSnapshot,
|
||||
diagnostics,
|
||||
@@ -84,7 +87,7 @@ public class BuilderPipelineService {
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs) {
|
||||
final var compileResult = this.compile(ctx, logs);
|
||||
final var diagnostics = run(ctx, logs, build, new ArrayList<>(compileResult.diagnostics()));
|
||||
final var diagnostics = run(ctx, logs, build, new ArrayList<>(compileResult.diagnostics()), true);
|
||||
return new BuildResult(
|
||||
compileResult,
|
||||
diagnostics,
|
||||
@@ -95,19 +98,32 @@ public class BuilderPipelineService {
|
||||
final BuilderPipelineContext ctx,
|
||||
final LogAggregator logs,
|
||||
final List<PipelineStage> stages,
|
||||
final List<BuildingIssue> diagnostics) {
|
||||
final List<BuildingIssue> diagnostics,
|
||||
final boolean failFast) {
|
||||
for (final var builderPipelineStage : stages) {
|
||||
final var issues = builderPipelineStage.run(ctx, logs);
|
||||
diagnostics.addAll(issues.asCollection());
|
||||
printIssues(issues, logs);
|
||||
if (issues.hasErrors()) {
|
||||
throw new BuildException("issues found on pipeline stage: " + builderPipelineStage.getClass().getSimpleName());
|
||||
if (failFast) {
|
||||
throw new BuildException("issues found on pipeline stage: " + builderPipelineStage.getClass().getSimpleName());
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
logs.using(log).info("builder pipeline completed successfully");
|
||||
return List.copyOf(diagnostics);
|
||||
}
|
||||
|
||||
private boolean hasErrors(final List<BuildingIssue> diagnostics) {
|
||||
for (final var diagnostic : diagnostics) {
|
||||
if (diagnostic.isError()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private void printIssues(
|
||||
final ReadOnlyCollection<BuildingIssue> issues,
|
||||
final LogAggregator logs) {
|
||||
|
||||
+9
@@ -48,6 +48,11 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
final var span = diagnostic.getSpan();
|
||||
issues.report(builder -> builder
|
||||
.error(diagnostic.getSeverity().isError())
|
||||
.phase(diagnostic.getPhase().id())
|
||||
.code(diagnostic.getCode())
|
||||
.fileId(span.getFileId().isNone() ? null : span.getFileId().getId())
|
||||
.start(safeToInt(span.getStart()))
|
||||
.end(safeToInt(span.getEnd()))
|
||||
.message("[BUILD] %s :: %s @ %s:[%d,%d)".formatted(
|
||||
diagnostic.getCode(),
|
||||
diagnostic.getMessage(),
|
||||
@@ -56,4 +61,8 @@ public class FrontendPhasePipelineStage implements PipelineStage {
|
||||
span.getEnd())));
|
||||
}
|
||||
}
|
||||
|
||||
private int safeToInt(final long value) {
|
||||
return value > Integer.MAX_VALUE ? Integer.MAX_VALUE : (int) Math.max(0L, value);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user