package com.ankurm.boot42up; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.List; /** * Collects lines and writes output/NN-name.txt (or NN-name-on-4.1.2.txt when run against the * 4.1 baseline). The test asserts the same values it writes, so every figure quoted in the * article is an assertion that fails the build when it stops being true. */ final class Transcript { static final String LABEL = System.getProperty("boot.label", "4.2.0"); static boolean is42() { return LABEL.startsWith("4.2"); } private final List lines = new ArrayList<>(); private final Path file; Transcript(String name) { String suffix = is42() ? "" : "-on-" + LABEL; this.file = Path.of("output", name + suffix + ".txt"); line("# " + name + " (Spring Boot " + LABEL + ", JDK " + Runtime.version().feature() + ")"); } Transcript line(String s) { lines.add(s); return this; } void write() { try { Files.createDirectories(file.getParent()); Files.write(file, lines); } catch (IOException ex) { throw new IllegalStateException(ex); } } }