From a59a820f9aae7ba222dfc3532a69d75611eb09cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Hasan=20Demirta=C5=9F?= Date: Sat, 13 Jul 2024 00:12:20 +0300 Subject: [PATCH] Move output directory/file from PackGeneratorContext to PackWriterSettings --- .../infumia/pack/PackGeneratorContext.java | 28 ------------ .../java/net/infumia/pack/PackReader.java | 2 - .../net/infumia/pack/PackReaderSettings.java | 43 +------------------ .../java/net/infumia/pack/PackWriter.java | 4 +- .../net/infumia/pack/PackWriterSettings.java | 31 ++++++++++++- 5 files changed, 33 insertions(+), 75 deletions(-) diff --git a/generator/src/main/java/net/infumia/pack/PackGeneratorContext.java b/generator/src/main/java/net/infumia/pack/PackGeneratorContext.java index 6a1698e..c29fb65 100644 --- a/generator/src/main/java/net/infumia/pack/PackGeneratorContext.java +++ b/generator/src/main/java/net/infumia/pack/PackGeneratorContext.java @@ -17,8 +17,6 @@ public final class PackGeneratorContext { private final PackReferenceMeta packReference; private final Collection packPartReferences; private final Path rootDirectory; - private final Path outputDirectory; - private final Path outputFile; private final ComponentSerializer serializer; /** @@ -29,8 +27,6 @@ public final class PackGeneratorContext { * @param packReference the pack file reference. Cannot be null. * @param packPartReferences the pack part references. Cannot be null. * @param rootDirectory the root directory of the pack. Cannot be null. - * @param outputDirectory the output directory. Can be null. - * @param outputFile the output file. Can be null. * @param serializer the serializer to serialize components when needed. Cannot be null. */ PackGeneratorContext( @@ -39,8 +35,6 @@ public final class PackGeneratorContext { final PackReferenceMeta packReference, final Collection packPartReferences, final Path rootDirectory, - final Path outputDirectory, - final Path outputFile, final ComponentSerializer serializer ) { this.resourcePack = resourcePack; @@ -48,8 +42,6 @@ public final class PackGeneratorContext { this.packReference = packReference; this.packPartReferences = Collections.unmodifiableCollection(packPartReferences); this.rootDirectory = rootDirectory; - this.outputDirectory = outputDirectory; - this.outputFile = outputFile; this.serializer = serializer; } @@ -98,24 +90,6 @@ public Path rootDirectory() { return this.rootDirectory; } - /** - * Returns the output directory. - * - * @return the output directory. Can be null. - */ - public Path outputDirectory() { - return this.outputDirectory; - } - - /** - * Returns the output file. - * - * @return the output file. Can be null. - */ - public Path outputFile() { - return this.outputFile; - } - /** * Returns the component serializer. * @@ -132,8 +106,6 @@ public String toString() { .add("pack=" + this.pack) .add("packReference=" + this.packReference) .add("packPartReferences=" + this.packPartReferences) - .add("outputDirectory=" + this.outputDirectory) - .add("outputFile=" + this.outputFile) .add("serializer=" + this.serializer) .toString(); } diff --git a/generator/src/main/java/net/infumia/pack/PackReader.java b/generator/src/main/java/net/infumia/pack/PackReader.java index d328856..c59ab6a 100644 --- a/generator/src/main/java/net/infumia/pack/PackReader.java +++ b/generator/src/main/java/net/infumia/pack/PackReader.java @@ -75,8 +75,6 @@ private PackGeneratorContext read0(@NotNull final Stream walking) throws I packReference, packPartReferences, this.settings.root(), - this.settings.outputDirectory(), - this.settings.outputFile(), this.settings.serializer() ); } diff --git a/generator/src/main/java/net/infumia/pack/PackReaderSettings.java b/generator/src/main/java/net/infumia/pack/PackReaderSettings.java index f0f4f22..c5e0e8b 100644 --- a/generator/src/main/java/net/infumia/pack/PackReaderSettings.java +++ b/generator/src/main/java/net/infumia/pack/PackReaderSettings.java @@ -17,8 +17,6 @@ public final class PackReaderSettings { private final Path root; private final FileVisitOption[] visitOptions; private final String packReferenceFileName; - private final Path outputDirectory; - private final Path outputFile; private final ObjectMapper mapper; private final Predicate readFilter; private final ComponentSerializer serializer; @@ -29,8 +27,6 @@ public final class PackReaderSettings { * @param root the root path. * @param visitOptions the visit options. Can be null. * @param packReferenceFileName the pack reference file name. Cannot be null. - * @param outputDirectory the directory name. Can be null. - * @param outputFile the zip file name. Can be null. * @param mapper the object mapper to read pack and pack part reference files. Cannot be null. * @param readFilter the read filter for {@link Files#walk(Path, FileVisitOption...)}. * @param serializer the serializer to serialize components when needed. Cannot be null. @@ -39,8 +35,6 @@ public PackReaderSettings( final Path root, final FileVisitOption[] visitOptions, final String packReferenceFileName, - final Path outputDirectory, - final Path outputFile, final ObjectMapper mapper, final Predicate readFilter, final ComponentSerializer serializer @@ -48,8 +42,6 @@ public PackReaderSettings( this.root = root; this.visitOptions = visitOptions; this.packReferenceFileName = packReferenceFileName; - this.outputDirectory = outputDirectory; - this.outputFile = outputFile; this.mapper = mapper; this.readFilter = readFilter; this.serializer = serializer; @@ -60,30 +52,17 @@ public PackReaderSettings( * * @param root the root path. * @param packReferenceFileName the pack reference file name. Cannot be null. - * @param outputDirectory the directory name. Can be null. - * @param outputFile the zip file name. Can be null. * @param mapper the object mapper to read pack and pack part reference files. Cannot be null. * @param readFilter the read filter for {@link Files#walk(Path, FileVisitOption...)}. */ public PackReaderSettings( final Path root, final String packReferenceFileName, - final Path outputDirectory, - final Path outputFile, final ObjectMapper mapper, final Predicate readFilter, final ComponentSerializer serializer ) { - this( - root, - null, - packReferenceFileName, - outputDirectory, - outputFile, - mapper, - readFilter, - serializer - ); + this(root, null, packReferenceFileName, mapper, readFilter, serializer); } /** @@ -113,24 +92,6 @@ public String packReferenceFileName() { return this.packReferenceFileName; } - /** - * Returns the output directory. - * - * @return the directory output. Can be null. - */ - public Path outputDirectory() { - return this.outputDirectory; - } - - /** - * Returns the zip file. - * - * @return the zip file. Can be null. - */ - public Path outputFile() { - return this.outputFile; - } - /** * Returns the object mapper. * @@ -164,8 +125,6 @@ public String toString() { .add("root=" + this.root) .add("visitOptions=" + Arrays.toString(this.visitOptions)) .add("packReferenceFileName='" + this.packReferenceFileName + "'") - .add("outputDirectory=" + this.outputDirectory) - .add("outputFile=" + this.outputFile) .add("mapper=" + this.mapper) .add("readFilter=" + this.readFilter) .add("serializer=" + this.serializer) diff --git a/generator/src/main/java/net/infumia/pack/PackWriter.java b/generator/src/main/java/net/infumia/pack/PackWriter.java index d16f7a0..9b39eba 100644 --- a/generator/src/main/java/net/infumia/pack/PackWriter.java +++ b/generator/src/main/java/net/infumia/pack/PackWriter.java @@ -14,12 +14,12 @@ final class PackWriter { PackGeneratedContext write(final PackGeneratorContext context) { final MinecraftResourcePackWriter writer = this.settings.writer(); - final Path outputDirectory = context.outputDirectory(); + final Path outputDirectory = this.settings.outputDirectory(); final ResourcePack resourcePack = context.resourcePack(); if (outputDirectory != null) { writer.writeToDirectory(outputDirectory.toFile(), resourcePack); } - final Path outputFile = context.outputFile(); + final Path outputFile = this.settings.outputFile(); if (outputFile != null) { writer.writeToZipFile(outputFile, resourcePack); } diff --git a/generator/src/main/java/net/infumia/pack/PackWriterSettings.java b/generator/src/main/java/net/infumia/pack/PackWriterSettings.java index f3f3d1f..9b489a6 100644 --- a/generator/src/main/java/net/infumia/pack/PackWriterSettings.java +++ b/generator/src/main/java/net/infumia/pack/PackWriterSettings.java @@ -1,5 +1,6 @@ package net.infumia.pack; +import java.nio.file.Path; import java.util.StringJoiner; import team.unnamed.creative.serialize.minecraft.MinecraftResourcePackWriter; @@ -9,14 +10,24 @@ public final class PackWriterSettings { private final MinecraftResourcePackWriter writer; + private final Path outputDirectory; + private final Path outputFile; /** * Ctor. * * @param writer the resource pack writer. Cannot be null. + * @param outputDirectory the output directory. Can be null. + * @param outputFile the output file. Can be null. */ - public PackWriterSettings(final MinecraftResourcePackWriter writer) { + public PackWriterSettings( + final MinecraftResourcePackWriter writer, + final Path outputDirectory, + final Path outputFile + ) { this.writer = writer; + this.outputDirectory = outputDirectory; + this.outputFile = outputFile; } /** @@ -28,6 +39,24 @@ public MinecraftResourcePackWriter writer() { return this.writer; } + /** + * Returns the output directory. + * + * @return the output directory. Can be null. + */ + public Path outputDirectory() { + return this.outputDirectory; + } + + /** + * Returns the output file. + * + * @return the output file. Can be null. + */ + public Path outputFile() { + return this.outputFile; + } + @Override public String toString() { return new StringJoiner(", ", PackWriterSettings.class.getSimpleName() + "[", "]")