| 1 | // SPDX-License-Identifier: Apache-2.0 | |
| 2 | // Copyright 2026 Egothor | |
| 3 | // Copyright 2026 Accenture | |
| 4 | package org.egothor.methodatlas.receipt; | |
| 5 | ||
| 6 | import java.io.IOException; | |
| 7 | import java.io.OutputStream; | |
| 8 | import java.nio.file.Files; | |
| 9 | import java.nio.file.Path; | |
| 10 | ||
| 11 | import tools.jackson.databind.ObjectMapper; | |
| 12 | ||
| 13 | /** | |
| 14 | * Serialises a {@link ReproducibilityReceipt} to disk as pretty-printed JSON. | |
| 15 | * | |
| 16 | * <p> | |
| 17 | * The writer takes a caller-supplied {@link ObjectMapper} so the same shared | |
| 18 | * instance can be reused across an entire JVM invocation (matches the | |
| 19 | * project-wide convention of not instantiating Jackson per call). The mapper | |
| 20 | * must already be configured for indented output and {@code NON_NULL} | |
| 21 | * inclusion (see {@link ReceiptFacade}); the writer does not mutate it, so it | |
| 22 | * is safe to share concurrently. | |
| 23 | * </p> | |
| 24 | * | |
| 25 | * <p> | |
| 26 | * Package-private because nothing outside the {@code receipt} package needs | |
| 27 | * direct access; {@code MethodAtlasApp} is the sole external caller. | |
| 28 | * </p> | |
| 29 | */ | |
| 30 | final class ReceiptWriter { | |
| 31 | ||
| 32 | private ReceiptWriter() { | |
| 33 | // Utility class. | |
| 34 | } | |
| 35 | ||
| 36 | /** | |
| 37 | * Serialises {@code receipt} to {@code outputFile} using {@code mapper}. | |
| 38 | * | |
| 39 | * <p> | |
| 40 | * The mapper must already be configured for indented, {@code NON_NULL} | |
| 41 | * output (as {@link ReceiptFacade} does). The writer does not modify the | |
| 42 | * mapper. | |
| 43 | * </p> | |
| 44 | * | |
| 45 | * @param receipt receipt to serialise; must not be {@code null} | |
| 46 | * @param mapper pre-configured Jackson mapper to use; must not be | |
| 47 | * {@code null}; the caller owns its lifecycle | |
| 48 | * @param outputFile destination path; the parent directory must already | |
| 49 | * exist | |
| 50 | * @throws IOException if the target file cannot be created or written | |
| 51 | */ | |
| 52 | /* default */ static void write(ReproducibilityReceipt receipt, ObjectMapper mapper, Path outputFile) | |
| 53 | throws IOException { | |
| 54 | try (OutputStream out = Files.newOutputStream(outputFile)) { | |
| 55 |
1
1. write : removed call to tools/jackson/databind/ObjectMapper::writeValue → KILLED |
mapper.writeValue(out, receipt); |
| 56 | } | |
| 57 | } | |
| 58 | } | |
Mutations | ||
| 55 |
1.1 |