diff --git a/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java b/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java index 7d72d220502cc..8599df9c97914 100644 --- a/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java +++ b/core/builder/src/main/java/io/quarkus/builder/BuildChainBuilder.java @@ -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; @@ -23,6 +22,8 @@ import io.quarkus.builder.item.BuildItem; +import static java.nio.charset.StandardCharsets.UTF_8; + /** * A build chain builder. * @@ -30,20 +31,15 @@ */ 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 providers = new ArrayList<>(); - private final Map steps = new HashMap(); + private final Map steps = new HashMap<>(); private final Set initialIds = new HashSet<>(); private final Set 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. @@ -109,12 +105,11 @@ public BuildChainBuilder addInitial(Class type) { return this; } - public BuildChainBuilder loadProviders(ClassLoader classLoader) throws ChainBuildException { + public void loadProviders(ClassLoader classLoader) throws ChainBuildException { final ServiceLoader serviceLoader = ServiceLoader.load(BuildProvider.class, classLoader); for (final BuildProvider provider : serviceLoader) { provider.installInto(this); } - return this; } /** @@ -122,13 +117,11 @@ public BuildChainBuilder loadProviders(ClassLoader classLoader) throws ChainBuil * 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 type) { + public void addFinal(Class type) { Assert.checkNotNullParam("type", type); finalIds.add(new ItemId(type)); - return this; } ClassLoader getClassLoader() { @@ -463,42 +456,39 @@ Set getFinalIds() { } private static void outputGraph(Set startSteps, Set 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 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 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); }