From 1dea1b098d85cd715e4b6c1c415d42474677b1b2 Mon Sep 17 00:00:00 2001 From: piexel Date: Tue, 10 Nov 2026 13:57:59 +0100 Subject: [PATCH] Move the pack weight converter's command line out of production code Core production code may not write to the process streams; the entry point now lives in the test sources. --- .../iris/core/pack/PackWeightConverter.java | 31 +--------- .../core/pack/PackWeightConverterCli.java | 62 +++++++++++++++++++ 2 files changed, 63 insertions(+), 30 deletions(-) create mode 100644 core/src/test/java/art/arcane/iris/core/pack/PackWeightConverterCli.java diff --git a/core/src/main/java/art/arcane/iris/core/pack/PackWeightConverter.java b/core/src/main/java/art/arcane/iris/core/pack/PackWeightConverter.java index fe6c0719f..e774c65c9 100644 --- a/core/src/main/java/art/arcane/iris/core/pack/PackWeightConverter.java +++ b/core/src/main/java/art/arcane/iris/core/pack/PackWeightConverter.java @@ -55,7 +55,7 @@ import java.util.stream.Stream; * a weight above {@link Weighted#MAX_WEIGHT} stops the conversion. A pack with lists already converted and lists not yet * converted cannot be told apart from rarity 1 and is refused. *

- * Usage: {@code PackWeightConverter [--dry-run] ...} + * {@code PackWeightConverterCli} in the test sources runs it from the command line. */ public final class PackWeightConverter { private static final String INDENT_STEP = " "; @@ -118,35 +118,6 @@ public final class PackWeightConverter { return new Result(changed, List.copyOf(converter.warnings)); } - public static void main(String[] arguments) throws IOException { - boolean dryRun = false; - List packs = new ArrayList<>(); - for (String argument : arguments) { - if (argument.equals("--dry-run")) { - dryRun = true; - } else { - packs.add(Path.of(argument)); - } - } - - if (packs.isEmpty()) { - System.err.println("Usage: PackWeightConverter [--dry-run] ..."); - System.exit(2); - } - - for (Path folder : packs) { - try { - Result result = convert(folder, dryRun); - result.changedFiles().forEach(System.out::println); - result.warnings().forEach(warning -> System.out.println("warning: " + warning)); - System.out.println(folder + ": " + result.changedFiles().size() + " files " + (dryRun ? "would change" : "changed")); - } catch (ConversionException refusal) { - System.err.println(folder + ": " + refusal.getMessage()); - System.exit(1); - } - } - } - /** The converted text of the file; null when nothing in it changes. */ private String convertFile(String folder, Path file) throws IOException { currentFile = relative(pack, file); diff --git a/core/src/test/java/art/arcane/iris/core/pack/PackWeightConverterCli.java b/core/src/test/java/art/arcane/iris/core/pack/PackWeightConverterCli.java new file mode 100644 index 000000000..b94530beb --- /dev/null +++ b/core/src/test/java/art/arcane/iris/core/pack/PackWeightConverterCli.java @@ -0,0 +1,62 @@ +/* + * Iris is a World Generator for Minecraft Servers + * Copyright (c) 2026 Arcane Arts (Volmit Software) + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package art.arcane.iris.core.pack; + +import java.io.IOException; +import java.nio.file.Path; +import java.util.ArrayList; +import java.util.List; + +/** Usage: {@code PackWeightConverterCli [--dry-run] ...} */ +public final class PackWeightConverterCli { + private static final int EXIT_USAGE = 2; + private static final int EXIT_REFUSED = 1; + + private PackWeightConverterCli() { + } + + public static void main(String[] arguments) throws IOException { + boolean dryRun = false; + List packs = new ArrayList<>(); + for (String argument : arguments) { + if (argument.equals("--dry-run")) { + dryRun = true; + } else { + packs.add(Path.of(argument)); + } + } + + if (packs.isEmpty()) { + System.err.println("Usage: PackWeightConverterCli [--dry-run] ..."); + System.exit(EXIT_USAGE); + } + + for (Path folder : packs) { + try { + PackWeightConverter.Result result = PackWeightConverter.convert(folder, dryRun); + result.changedFiles().forEach(System.out::println); + result.warnings().forEach(warning -> System.out.println("warning: " + warning)); + System.out.println(folder + ": " + result.changedFiles().size() + " files " + (dryRun ? "would change" : "changed")); + } catch (PackWeightConverter.ConversionException refusal) { + System.err.println(folder + ": " + refusal.getMessage()); + System.exit(EXIT_REFUSED); + } + } + } +}