chore: add some more optional logging
ci/woodpecker/push/jfmod Pipeline was successful Details

This commit is contained in:
Johannes Frohnmeyer 2024-03-31 12:59:22 +02:00
parent 6495212095
commit 12dd3f3301
Signed by: Johannes
GPG Key ID: E76429612C2929F4
4 changed files with 33 additions and 4 deletions

View File

@ -18,15 +18,19 @@ import java.util.Set;
public class RescloneConfig implements JfCustomConfig { public class RescloneConfig implements JfCustomConfig {
public static Set<PackMetaUnloaded> packs; public static Set<PackMetaUnloaded> packs;
public static boolean pruneUnused; public static boolean pruneUnused;
public static boolean logProcessing;
private static final String ERR_DUPLICATE = "Unexpected duplicate \"%s\" in Resclone config";
private static final String PACKS = "packs"; private static final String PACKS = "packs";
private static final String PRUNE_UNUSED = "pruneUnused"; private static final String PRUNE_UNUSED = "pruneUnused";
private static final String LOG_PROCESSING = "logProcessing";
private static final Type META_SET = new TypeToken<Set<PackMetaUnloaded>>(){}.getType(); private static final Type META_SET = new TypeToken<Set<PackMetaUnloaded>>(){}.getType();
private static void load(Path path) throws IOException { private static void load(Path path) throws IOException {
if (!Files.exists(path)) { if (!Files.exists(path)) {
packs = new HashSet<>(); packs = new HashSet<>();
pruneUnused = true; pruneUnused = true;
logProcessing = false;
write(path); write(path);
return; return;
} }
@ -43,17 +47,22 @@ public class RescloneConfig implements JfCustomConfig {
reader.beginObject(); reader.beginObject();
Set<PackMetaUnloaded> packs = null; Set<PackMetaUnloaded> packs = null;
Boolean pruneUnused = null; Boolean pruneUnused = null;
Boolean logProcessing = null;
while (reader.peek() != JsonToken.END_OBJECT) { while (reader.peek() != JsonToken.END_OBJECT) {
final String name = reader.nextName(); final String name = reader.nextName();
switch (name) { switch (name) {
case PACKS -> { case PACKS -> {
if (packs != null) throw new JsonParseException("Unexpected duplicate \"" + PACKS + "\" in Resclone config"); if (packs != null) throw new JsonParseException(ERR_DUPLICATE.formatted(PACKS));
packs = GsonHolders.CONFIG.getGson().fromJson(reader, META_SET); packs = GsonHolders.CONFIG.getGson().fromJson(reader, META_SET);
} }
case PRUNE_UNUSED -> { case PRUNE_UNUSED -> {
if (pruneUnused != null) throw new JsonParseException("Unexpected duplicate \"" + PRUNE_UNUSED + "\" in Resclone config"); if (pruneUnused != null) throw new JsonParseException(ERR_DUPLICATE.formatted(PRUNE_UNUSED));
pruneUnused = reader.nextBoolean(); pruneUnused = reader.nextBoolean();
} }
case LOG_PROCESSING -> {
if (logProcessing != null) throw new JsonParseException(ERR_DUPLICATE.formatted(LOG_PROCESSING));
logProcessing = reader.nextBoolean();
}
default -> throw new JsonParseException("Unexpected element: \"" + name + "\" in Resclone config"); default -> throw new JsonParseException("Unexpected element: \"" + name + "\" in Resclone config");
} }
} }
@ -63,8 +72,13 @@ public class RescloneConfig implements JfCustomConfig {
pruneUnused = true; pruneUnused = true;
updateRequired = true; updateRequired = true;
} }
if (logProcessing == null) {
logProcessing = false;
updateRequired = true;
}
RescloneConfig.packs = packs; RescloneConfig.packs = packs;
RescloneConfig.pruneUnused = pruneUnused; RescloneConfig.pruneUnused = pruneUnused;
RescloneConfig.logProcessing = logProcessing;
} else throw new JsonParseException("Expected Resclone config to be an object or array"); } else throw new JsonParseException("Expected Resclone config to be an object or array");
} }
if (updateRequired) write(path); if (updateRequired) write(path);
@ -80,6 +94,9 @@ public class RescloneConfig implements JfCustomConfig {
writer.comment("Whether to prune unused packs from the cache") writer.comment("Whether to prune unused packs from the cache")
.name(PRUNE_UNUSED) .name(PRUNE_UNUSED)
.value(pruneUnused) .value(pruneUnused)
.comment("Whether to log processing of packs")
.name(LOG_PROCESSING)
.value(logProcessing)
.endObject(); .endObject();
} }
} }
@ -102,6 +119,7 @@ public class RescloneConfig implements JfCustomConfig {
}).setPath(path) }).setPath(path)
.<Set<PackMetaUnloaded>>value(PACKS, new HashSet<>(), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, io.gitlab.jfronny.libjf.config.api.v2.type.Type.ofClass(META_SET), 100, () -> packs, p -> packs = p) .<Set<PackMetaUnloaded>>value(PACKS, new HashSet<>(), Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY, io.gitlab.jfronny.libjf.config.api.v2.type.Type.ofClass(META_SET), 100, () -> packs, p -> packs = p)
.value(PRUNE_UNUSED, pruneUnused, () -> pruneUnused, p -> pruneUnused = p) .value(PRUNE_UNUSED, pruneUnused, () -> pruneUnused, p -> pruneUnused = p)
.value(LOG_PROCESSING, logProcessing, () -> logProcessing, p -> logProcessing = p)
).load(); ).load();
} }

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.resclone.processors; package io.gitlab.jfronny.resclone.processors;
import io.gitlab.jfronny.resclone.Resclone; import io.gitlab.jfronny.resclone.Resclone;
import io.gitlab.jfronny.resclone.RescloneConfig;
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor; import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
import net.minecraft.server.MinecraftServer; import net.minecraft.server.MinecraftServer;
import org.apache.commons.io.IOUtils; import org.apache.commons.io.IOUtils;
@ -22,7 +23,10 @@ public class PruneVanillaProcessor implements PackProcessor {
InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString()); InputStream vn = cl.getResourceAsStream(p.getPath("/").relativize(s).toString());
if (vn != null) { if (vn != null) {
try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) { try (InputStream pk = Files.newInputStream(s, StandardOpenOption.READ)) {
return IOUtils.contentEquals(vn, pk); if (IOUtils.contentEquals(vn, pk)) {
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning file unchanged from vanilla: {}", s);
return true;
}
} }
} }
} catch (Throwable e) { } catch (Throwable e) {

View File

@ -1,6 +1,7 @@
package io.gitlab.jfronny.resclone.processors; package io.gitlab.jfronny.resclone.processors;
import io.gitlab.jfronny.resclone.Resclone; import io.gitlab.jfronny.resclone.Resclone;
import io.gitlab.jfronny.resclone.RescloneConfig;
import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor; import io.gitlab.jfronny.resclone.util.io.PathPruneVisitor;
import java.io.IOException; import java.io.IOException;
@ -14,7 +15,10 @@ public class RemoveEmptyProcessor implements PackProcessor {
Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> { Files.walkFileTree(p.getPath("/assets"), new PathPruneVisitor(s -> {
if (Files.isDirectory(s)) { if (Files.isDirectory(s)) {
try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) { try (DirectoryStream<Path> paths = Files.newDirectoryStream(s)) {
return !paths.iterator().hasNext(); if (!paths.iterator().hasNext()) {
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Pruning empty directory: {}", s);
return true;
}
} catch (IOException e) { } catch (IOException e) {
Resclone.LOGGER.error("Could not check whether directory has entries", e); Resclone.LOGGER.error("Could not check whether directory has entries", e);
} }

View File

@ -1,5 +1,7 @@
package io.gitlab.jfronny.resclone.processors; package io.gitlab.jfronny.resclone.processors;
import io.gitlab.jfronny.resclone.Resclone;
import io.gitlab.jfronny.resclone.RescloneConfig;
import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor; import io.gitlab.jfronny.resclone.util.io.MoveDirVisitor;
import java.io.IOException; import java.io.IOException;
@ -14,6 +16,7 @@ public class RootPathProcessor implements PackProcessor {
try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) { try (DirectoryStream<Path> paths = Files.newDirectoryStream(root)) {
for (Path path : paths) { for (Path path : paths) {
if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) { if (Files.isDirectory(path) && Files.exists(path.resolve("pack.mcmeta"))) {
if (RescloneConfig.logProcessing) Resclone.LOGGER.info("Moving discovered root out of: {}", path);
Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING)); Files.walkFileTree(path, new MoveDirVisitor(path, root, StandardCopyOption.REPLACE_EXISTING));
} }
} }