Skip to content

Commit

Permalink
fix.
Browse files Browse the repository at this point in the history
  • Loading branch information
portlek committed Jun 24, 2024
1 parent edfb382 commit b333868
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
24 changes: 24 additions & 0 deletions generator/src/main/java/net/infumia/pack/PackReadFilters.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package net.infumia.pack;

import java.nio.file.Path;
import java.util.function.Predicate;

/**
* Utility class for creating read filters for pack reading.
*/
public final class PackReadFilters {

/**
* Creates a predicate that filters paths by the specified file extension.
*
* @param extension the file extension to filter by. Cannot be null.
* @return a predicate that returns true for paths with the specified extension.
*/
public static Predicate<Path> withExtension(final String extension) {
return path -> path.getFileName().toString().endsWith(extension);
}

private PackReadFilters() {
throw new IllegalStateException("Utility class");
}
}
3 changes: 3 additions & 0 deletions generator/src/main/java/net/infumia/pack/PackReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ PackGeneratorContext read() throws IOException {
private PackGeneratorContext read0(@NotNull final Stream<Path> walking) throws IOException {
final PackReferenceMeta packReference = this.packReader.readValue(this.packReferenceFile);
final Collection<PackReferencePart> packPartReferences = walking
.filter(Files::isRegularFile)
.filter(this.settings.readFilter())
.map(Path::toFile)
.filter(file -> !this.packReferenceFile.equals(file))
.map(file -> {
try (
final MappingIterator<PackReferencePart> iterator =
Expand Down
29 changes: 28 additions & 1 deletion generator/src/main/java/net/infumia/pack/PackReaderSettings.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@

import com.fasterxml.jackson.databind.ObjectMapper;
import java.nio.file.FileVisitOption;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.StringJoiner;
import java.util.function.Predicate;
import net.kyori.adventure.text.serializer.ComponentSerializer;

/**
Expand All @@ -18,6 +20,7 @@ public final class PackReaderSettings {
private final Path outputDirectory;
private final Path outputFile;
private final ObjectMapper mapper;
private final Predicate<Path> readFilter;
private final ComponentSerializer<?, ?, String> serializer;

/**
Expand All @@ -29,6 +32,7 @@ public final class PackReaderSettings {
* @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.
*/
public PackReaderSettings(
Expand All @@ -38,6 +42,7 @@ public PackReaderSettings(
final Path outputDirectory,
final Path outputFile,
final ObjectMapper mapper,
final Predicate<Path> readFilter,
final ComponentSerializer<?, ?, String> serializer
) {
this.root = root;
Expand All @@ -46,6 +51,7 @@ public PackReaderSettings(
this.outputDirectory = outputDirectory;
this.outputFile = outputFile;
this.mapper = mapper;
this.readFilter = readFilter;
this.serializer = serializer;
}

Expand All @@ -57,16 +63,27 @@ public PackReaderSettings(
* @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<Path> readFilter,
final ComponentSerializer<?, ?, String> serializer
) {
this(root, null, packReferenceFileName, outputDirectory, outputFile, mapper, serializer);
this(
root,
null,
packReferenceFileName,
outputDirectory,
outputFile,
mapper,
readFilter,
serializer
);
}

/**
Expand Down Expand Up @@ -123,6 +140,15 @@ public ObjectMapper mapper() {
return this.mapper;
}

/**
* Returns the read filter.
*
* @return the read filter.
*/
public Predicate<Path> readFilter() {
return this.readFilter;
}

/**
* Returns the component serializer.
*
Expand All @@ -141,6 +167,7 @@ public String toString() {
.add("outputDirectory=" + this.outputDirectory)
.add("outputFile=" + this.outputFile)
.add("mapper=" + this.mapper)
.add("readFilter=" + this.readFilter)
.add("serializer=" + this.serializer)
.toString();
}
Expand Down

0 comments on commit b333868

Please sign in to comment.