mirror of
https://github.com/VolmitSoftware/Iris.git
synced 2026-11-27 08:14:45 +00:00
Color boot reports in the console
- Keep legacy colors on Bukkit warning and error lines - Stop stripping colors from ChatReport console output - Render unknown pack fields as a themed report once logging is bound - Label epoch snapshots by their dimension key - Show clean pack validation with the success tone
This commit is contained in:
1 parent
7b2e28d439
commit
2f82ad34a3
5 files changed
+91
-41
No files matched your search
@@ -598,14 +598,13 @@ public final class IrisRuntime implements IrisPluginRuntime {
|
||||
}
|
||||
|
||||
private static void diagnostic(Level level, String message) {
|
||||
String line = IrisLogging.clean(message);
|
||||
Iris plugin = Iris.instance;
|
||||
ComponentLog.log(
|
||||
ComponentLog.logLegacy(
|
||||
plugin,
|
||||
Logger.getLogger("Iris"),
|
||||
logPrefix(plugin),
|
||||
level,
|
||||
ComponentText.literal(line),
|
||||
message,
|
||||
null);
|
||||
}
|
||||
|
||||
|
||||
@@ -130,8 +130,7 @@ public final class ChatReport {
|
||||
}
|
||||
}
|
||||
|
||||
private void logLine(String styledText) {
|
||||
String text = IrisLogging.clean(styledText);
|
||||
private void logLine(String text) {
|
||||
switch (tone) {
|
||||
case ERROR -> IrisLogging.error(text);
|
||||
case WARNING -> IrisLogging.warn(text);
|
||||
|
||||
@@ -2,7 +2,6 @@ package art.arcane.iris.pack;
|
||||
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import art.arcane.iris.pack.validation.PackCompatReport;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -32,7 +31,7 @@ public final class PackBootReporter {
|
||||
return;
|
||||
}
|
||||
if (announceClean || !compatSummary.isEmpty()) {
|
||||
IrisLogging.info("Pack '" + pack + "' validated." + compatSuffix);
|
||||
ChatReport.of(ChatReport.Tone.SUCCESS, "Pack '" + pack + "' validated." + compatSuffix).build().log();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,14 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import art.arcane.iris.localization.C;
|
||||
import art.arcane.iris.spi.IrisLogging;
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import art.arcane.iris.spi.IrisPlatforms;
|
||||
import art.arcane.iris.world.history.GenerationHistoryPaths;
|
||||
import art.arcane.volmlib.util.json.JSONObject;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -20,7 +24,9 @@ import java.util.concurrent.TimeUnit;
|
||||
final class UnknownFieldReport {
|
||||
private static final long QUIET_PERIOD_BEFORE_FLUSH_MS = 1_500L;
|
||||
private static final String FLUSH_THREAD_NAME = "Iris Unknown Field Report";
|
||||
private static final String EPOCH_METADATA_FILE_NAME = "epoch.json";
|
||||
private static final Set<String> REPORTED = ConcurrentHashMap.newKeySet();
|
||||
private static final Map<Path, String> PACK_LABELS = new ConcurrentHashMap<>();
|
||||
private static final List<UnknownField> PENDING = new ArrayList<>();
|
||||
private static final ScheduledExecutorService FLUSHER = Executors.newSingleThreadScheduledExecutor(runnable -> {
|
||||
Thread thread = new Thread(runnable, FLUSH_THREAD_NAME);
|
||||
@@ -46,18 +52,24 @@ final class UnknownFieldReport {
|
||||
}
|
||||
|
||||
static void flush() {
|
||||
drainReportLines().forEach(line -> IrisLogging.warn("%s", line));
|
||||
if (!IrisPlatforms.isBound()) {
|
||||
synchronized (PENDING) {
|
||||
rescheduleFlush();
|
||||
}
|
||||
return;
|
||||
}
|
||||
drainReports().forEach(ChatReport::log);
|
||||
}
|
||||
|
||||
static List<String> drainReportLines() {
|
||||
static List<ChatReport> drainReports() {
|
||||
List<UnknownField> batch;
|
||||
synchronized (PENDING) {
|
||||
batch = new ArrayList<>(PENDING);
|
||||
PENDING.clear();
|
||||
}
|
||||
List<String> lines = new ArrayList<>();
|
||||
groupByPack(batch).forEach((pack, fields) -> appendPackLines(lines, pack, fields));
|
||||
return lines;
|
||||
List<ChatReport> reports = new ArrayList<>();
|
||||
groupByPack(batch).forEach((pack, fields) -> reports.add(packReport(pack, fields)));
|
||||
return reports;
|
||||
}
|
||||
|
||||
static void resetForTests() {
|
||||
@@ -65,6 +77,7 @@ final class UnknownFieldReport {
|
||||
PENDING.clear();
|
||||
}
|
||||
REPORTED.clear();
|
||||
PACK_LABELS.clear();
|
||||
}
|
||||
|
||||
private static void rescheduleFlush() {
|
||||
@@ -84,21 +97,24 @@ final class UnknownFieldReport {
|
||||
return packs;
|
||||
}
|
||||
|
||||
private static void appendPackLines(List<String> lines, String pack, Map<String, List<UnknownField>> fields) {
|
||||
lines.add(pack + ": unknown fields, ignored");
|
||||
private static ChatReport packReport(String pack, Map<String, List<UnknownField>> fields) {
|
||||
String title = "Pack '" + pack + "': " + fields.size() + (fields.size() == 1 ? " unknown field" : " unknown fields") + ", ignored";
|
||||
ChatReport.Builder report = ChatReport.of(ChatReport.Tone.WARNING, title);
|
||||
int labelWidth = fields.keySet().stream().mapToInt(String::length).max().orElse(0);
|
||||
fields.forEach((typeAndField, occurrences) -> lines.add(describeField(typeAndField, occurrences, labelWidth)));
|
||||
fields.forEach((typeAndField, occurrences) -> report.styledItem(describeField(typeAndField, occurrences, labelWidth)));
|
||||
return report.build();
|
||||
}
|
||||
|
||||
private static String describeField(String typeAndField, List<UnknownField> occurrences, int labelWidth) {
|
||||
UnknownField first = occurrences.getFirst();
|
||||
int count = occurrences.size();
|
||||
StringBuilder out = new StringBuilder(" ")
|
||||
.append(C.WHITE).append(padRight(typeAndField, labelWidth)).append(C.YELLOW)
|
||||
.append(" ").append(count).append(count == 1 ? " file " : " files")
|
||||
.append(" ").append(count == 1 ? "" : "e.g. ").append(first.location());
|
||||
StringBuilder out = new StringBuilder()
|
||||
.append(C.WHITE).append(padRight(typeAndField, labelWidth))
|
||||
.append(C.DARK_GRAY).append(" ").append(count).append(count == 1 ? " file " : " files")
|
||||
.append(" ").append(C.GRAY).append(count == 1 ? "" : "e.g. ")
|
||||
.append(C.AQUA).append(first.location());
|
||||
if (first.suggestion() != null) {
|
||||
out.append(" (did you mean ").append(C.WHITE).append('"').append(first.suggestion()).append('"').append(C.YELLOW).append("?)");
|
||||
out.append(C.GRAY).append(" did you mean ").append(C.WHITE).append('\'').append(first.suggestion()).append('\'').append(C.GRAY).append('?');
|
||||
}
|
||||
return out.toString();
|
||||
}
|
||||
@@ -111,17 +127,29 @@ final class UnknownFieldReport {
|
||||
if (dataFolder == null) {
|
||||
return "pack";
|
||||
}
|
||||
Path epochDimension = epochDimensionRoot(dataFolder.toPath().toAbsolutePath().normalize());
|
||||
return epochDimension != null ? epochDimension.getFileName().toString() : dataFolder.getName();
|
||||
Path folder = dataFolder.toPath().toAbsolutePath().normalize();
|
||||
return PACK_LABELS.computeIfAbsent(folder, UnknownFieldReport::resolvePackLabel);
|
||||
}
|
||||
|
||||
private static Path epochDimensionRoot(Path dataFolder) {
|
||||
private static String resolvePackLabel(Path dataFolder) {
|
||||
Path epochs = ancestor(dataFolder, 2);
|
||||
if (!GenerationHistoryPaths.LEGACY_PACK_DIRECTORY_NAME.equals(name(dataFolder))
|
||||
|| !GenerationHistoryPaths.EPOCHS_DIRECTORY_NAME.equals(name(epochs))) {
|
||||
boolean epochSnapshot = GenerationHistoryPaths.LEGACY_PACK_DIRECTORY_NAME.equals(name(dataFolder))
|
||||
&& GenerationHistoryPaths.EPOCHS_DIRECTORY_NAME.equals(name(epochs));
|
||||
if (!epochSnapshot) {
|
||||
return name(dataFolder);
|
||||
}
|
||||
String dimensionKey = epochDimensionKey(dataFolder.getParent().resolve(EPOCH_METADATA_FILE_NAME));
|
||||
return dimensionKey != null ? dimensionKey : name(ancestor(epochs, 3));
|
||||
}
|
||||
|
||||
private static String epochDimensionKey(Path epochMetadata) {
|
||||
try {
|
||||
JSONObject contract = new JSONObject(Files.readString(epochMetadata)).optJSONObject("dimensionContract");
|
||||
String dimensionKey = contract == null ? "" : contract.optString("dimensionKey", "");
|
||||
return dimensionKey.isBlank() ? null : dimensionKey;
|
||||
} catch (IOException | RuntimeException unreadable) {
|
||||
return null;
|
||||
}
|
||||
return ancestor(epochs, 3);
|
||||
}
|
||||
|
||||
private static Path ancestor(Path path, int levels) {
|
||||
@@ -150,7 +178,7 @@ final class UnknownFieldReport {
|
||||
|
||||
private record UnknownField(String pack, String resourceTypeName, String field, String location, String suggestion) {
|
||||
String typeAndField() {
|
||||
return resourceTypeName + " \"" + field + "\"";
|
||||
return resourceTypeName + " '" + field + "'";
|
||||
}
|
||||
|
||||
String identity() {
|
||||
|
||||
@@ -1,16 +1,24 @@
|
||||
package art.arcane.iris.pack.loading;
|
||||
|
||||
import art.arcane.iris.localization.ChatReport;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.util.List;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
public class UnknownFieldReportTest {
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
private static final File SOURCE_PACK = new File("/server/plugins/Iris/packs/cavetest");
|
||||
private static final File EPOCH_PACK = new File("/server/world/dimensions/iris/cavetest/iris/generation/epochs/"
|
||||
+ "ba9f3038756c38bc3f3a3174f3e7c575b766f76f422a129d6e8eb98380c33b8b/pack");
|
||||
@@ -31,11 +39,11 @@ public class UnknownFieldReportTest {
|
||||
recordBiomeCaves(EPOCH_PACK, "biomes/carving/volcanic.json", 144);
|
||||
recordBiomeCaves(SOURCE_PACK, "biomes/carving/volcanic.json", 144);
|
||||
|
||||
List<String> lines = plain(UnknownFieldReport.drainReportLines());
|
||||
List<String> lines = plain(UnknownFieldReport.drainReports());
|
||||
|
||||
assertEquals(List.of(
|
||||
"cavetest: unknown fields, ignored",
|
||||
" Biome \"caves\" 1 file biomes/carving/volcanic.json:144"
|
||||
"Pack 'cavetest': 1 unknown field, ignored",
|
||||
" » Biome 'caves' 1 file biomes/carving/volcanic.json:144"
|
||||
), lines);
|
||||
}
|
||||
|
||||
@@ -46,12 +54,12 @@ public class UnknownFieldReportTest {
|
||||
recordBiomeCaves(SOURCE_PACK, "biomes/carving/volcanic.json", 144);
|
||||
UnknownFieldReport.record(SOURCE_PACK, new File(SOURCE_PACK, "dimensions/cavetest.json"), "Dimension", "caves", 856, null);
|
||||
|
||||
List<String> lines = plain(UnknownFieldReport.drainReportLines());
|
||||
List<String> lines = plain(UnknownFieldReport.drainReports());
|
||||
|
||||
assertEquals(List.of(
|
||||
"cavetest: unknown fields, ignored",
|
||||
" Biome \"caves\" 3 files e.g. biomes/carving/deep-ravine.json:157",
|
||||
" Dimension \"caves\" 1 file dimensions/cavetest.json:856"
|
||||
"Pack 'cavetest': 2 unknown fields, ignored",
|
||||
" » Biome 'caves' 3 files e.g. biomes/carving/deep-ravine.json:157",
|
||||
" » Dimension 'caves' 1 file dimensions/cavetest.json:856"
|
||||
), lines);
|
||||
}
|
||||
|
||||
@@ -59,26 +67,43 @@ public class UnknownFieldReportTest {
|
||||
public void typoKeepsItsSuggestion() {
|
||||
UnknownFieldReport.record(SOURCE_PACK, new File(SOURCE_PACK, "biomes/x.json"), "Biome", "carvng", 12, "carving");
|
||||
|
||||
List<String> lines = plain(UnknownFieldReport.drainReportLines());
|
||||
List<String> lines = plain(UnknownFieldReport.drainReports());
|
||||
|
||||
assertTrue(lines.get(1).endsWith("biomes/x.json:12 (did you mean \"carving\"?)"));
|
||||
assertTrue(lines.get(1).endsWith("biomes/x.json:12 did you mean 'carving'?"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void alreadyReportedFieldsStayQuietInLaterBatches() {
|
||||
recordBiomeCaves(SOURCE_PACK, "biomes/carving/volcanic.json", 144);
|
||||
UnknownFieldReport.drainReportLines();
|
||||
UnknownFieldReport.drainReports();
|
||||
|
||||
recordBiomeCaves(EPOCH_PACK, "biomes/carving/volcanic.json", 144);
|
||||
|
||||
assertEquals(List.of(), UnknownFieldReport.drainReportLines());
|
||||
assertEquals(List.of(), UnknownFieldReport.drainReports());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void studioEpochIsLabelledByItsDimensionNotItsWorldFolder() throws Exception {
|
||||
Path epoch = temporaryFolder.getRoot().toPath()
|
||||
.resolve("world/dimensions/iris/iris-d4521eb8/iris/generation/epochs/d826fe90");
|
||||
Files.createDirectories(epoch.resolve("pack"));
|
||||
Files.writeString(epoch.resolve("epoch.json"), "{\"dimensionContract\":{\"dimensionKey\":\"cavetest\"}}");
|
||||
File studioPack = epoch.resolve("pack").toFile();
|
||||
|
||||
recordBiomeCaves(SOURCE_PACK, "biomes/carving/volcanic.json", 144);
|
||||
recordBiomeCaves(studioPack, "biomes/carving/volcanic.json", 144);
|
||||
|
||||
assertEquals(2, plain(UnknownFieldReport.drainReports()).size());
|
||||
}
|
||||
|
||||
private static void recordBiomeCaves(File pack, String relativePath, int line) {
|
||||
UnknownFieldReport.record(pack, new File(pack, relativePath), "Biome", "caves", line, null);
|
||||
}
|
||||
|
||||
private static List<String> plain(List<String> lines) {
|
||||
return lines.stream().map(line -> line.replaceAll("(?i)\u00a7[0-9a-fk-orx]|<[^>]+>", "")).toList();
|
||||
private static List<String> plain(List<ChatReport> reports) {
|
||||
return reports.stream()
|
||||
.flatMap(report -> report.lines().stream())
|
||||
.map(line -> line.text().replaceAll("(?i)\u00a7[0-9a-fk-orx]|<[^>]+>", ""))
|
||||
.toList();
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user