Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.nio.charset.StandardCharsets;
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
Expand All @@ -23,27 +22,24 @@

import io.quarkus.builder.item.BuildItem;

import static java.nio.charset.StandardCharsets.UTF_8;

/**
* A build chain builder.
*
* @author <a href="mailto:[email protected]">David M. Lloyd</a>
*/
public final class BuildChainBuilder {

private static final String GRAPH_OUTPUT = System.getProperty("quarkus.builder.graph-output");
static final boolean LOG_CONFLICT_CAUSING = Boolean.getBoolean("quarkus.builder.log-conflict-cause");
private static final String GRAPH_OUTPUT = System.getProperty("quarkus.builder.graph-output");

private final BuildStepBuilder finalStep;
private final List<BuildProvider> providers = new ArrayList<>();
private final Map<BuildStepBuilder, StackTraceElement[]> steps = new HashMap<BuildStepBuilder, StackTraceElement[]>();
private final Map<BuildStepBuilder, StackTraceElement[]> steps = new HashMap<>();
private final Set<ItemId> initialIds = new HashSet<>();
private final Set<ItemId> finalIds = new HashSet<>();
private ClassLoader classLoader = BuildChainBuilder.class.getClassLoader();

BuildChainBuilder() {
finalStep = addBuildStep(new FinalStep());
}

/**
* Add a build step to the chain. The configuration in the build step builder at the time that the chain is built is
* the configuration that will apply to the build step in the final chain. Any subsequent changes will be ignored.
Expand Down Expand Up @@ -109,26 +105,23 @@ public BuildChainBuilder addInitial(Class<? extends BuildItem> type) {
return this;
}

public BuildChainBuilder loadProviders(ClassLoader classLoader) throws ChainBuildException {
public void loadProviders(ClassLoader classLoader) throws ChainBuildException {
final ServiceLoader<BuildProvider> serviceLoader = ServiceLoader.load(BuildProvider.class, classLoader);
for (final BuildProvider provider : serviceLoader) {
provider.installInto(this);
}
return this;
}

/**
* Declare a final item that will be consumable after the build step chain completes. This may be any item
* that is produced in the chain.
*
* @param type the item type (must not be {@code null})
* @return this builder
* @throws IllegalArgumentException if the item type is {@code null}
*/
public BuildChainBuilder addFinal(Class<? extends BuildItem> type) {
public void addFinal(Class<? extends BuildItem> type) {
Assert.checkNotNullParam("type", type);
finalIds.add(new ItemId(type));
return this;
}

ClassLoader getClassLoader() {
Expand Down Expand Up @@ -463,42 +456,39 @@ Set<ItemId> getFinalIds() {
}

private static void outputGraph(Set<StepInfo> startSteps, Set<StepInfo> endSteps) {
if (GRAPH_OUTPUT != null && !GRAPH_OUTPUT.isEmpty()) {
try (FileOutputStream fos = new FileOutputStream(GRAPH_OUTPUT)) {
try (OutputStreamWriter osw = new OutputStreamWriter(fos, StandardCharsets.UTF_8)) {
try (BufferedWriter writer = new BufferedWriter(osw)) {
writer.write("digraph {");
writer.newLine();
writer.write(" node [shape=rectangle];");
writer.newLine();
writer.write(" rankdir=LR;");
writer.newLine();
writer.newLine();
writer.write(" { rank = same; ");
for (StepInfo startStep : startSteps) {
writer.write(quoteString(startStep.getBuildStep().getId()));
writer.write("; ");
}
writer.write("};");
writer.newLine();
writer.write(" { rank = same; ");
for (StepInfo endStep : endSteps) {
if (!startSteps.contains(endStep)) {
writer.write(quoteString(endStep.getBuildStep().getId()));
writer.write("; ");
}
}
writer.write("};");
writer.newLine();
writer.newLine();
final HashSet<StepInfo> printed = new HashSet<>();
for (StepInfo step : startSteps) {
writeStep(writer, printed, step);
}
writer.write("}");
writer.newLine();
if (GRAPH_OUTPUT != null && !GRAPH_OUTPUT.isBlank()) {
try (BufferedWriter writer =
new BufferedWriter(new OutputStreamWriter(new FileOutputStream(GRAPH_OUTPUT), UTF_8))) {
writer.write("digraph {");
writer.newLine();
writer.write(" node [shape=rectangle];");
writer.newLine();
writer.write(" rankdir=LR;");
writer.newLine();
writer.newLine();
writer.write(" { rank = same; ");
for (StepInfo startStep : startSteps) {
writer.write(quoteString(startStep.getBuildStep().getId()));
writer.write("; ");
}
writer.write("};");
writer.newLine();
writer.write(" { rank = same; ");
for (StepInfo endStep : endSteps) {
if (!startSteps.contains(endStep)) {
writer.write(quoteString(endStep.getBuildStep().getId()));
writer.write("; ");
}
}
writer.write("};");
writer.newLine();
writer.newLine();
final HashSet<StepInfo> printed = new HashSet<>();
for (StepInfo step : startSteps) {
writeStep(writer, printed, step);
}
writer.write("}");
writer.newLine();
} catch (IOException ioe) {
throw new RuntimeException("Failed to write debug graph output", ioe);
}
Expand Down