Skip to content

Commit 4739f32

Browse files
committed
Skip library paths that do not exist
Add ClassProvider#fromPaths
1 parent 57f1a16 commit 4739f32

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/main/java/net/minecraftforge/fart/api/ClassProvider.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,27 @@ public static Builder builder() {
4949
return new ClassProviderBuilderImpl();
5050
}
5151

52+
/**
53+
* Creates a class provider which reads class data from the provided library paths.
54+
* All queried class infos will be cached for subsequent queries.
55+
* <p>
56+
* The default supported library paths are ZIP files and directories.
57+
* Each path will be walked for all class files and stored in order.
58+
* Like a class path, entries added earlier take precedence over later entries with the same name.
59+
*
60+
* @param paths the paths to read from
61+
* @see #builder()
62+
*/
63+
static ClassProvider fromPaths(Path... paths) {
64+
Builder builder = builder().shouldCacheAll(true);
65+
66+
for (Path path : paths) {
67+
builder.addLibrary(path);
68+
}
69+
70+
return builder.build();
71+
}
72+
5273
/**
5374
* Creates a class provider which reads class data from the default classloader that loaded this class.
5475
*/

src/main/java/net/minecraftforge/fart/internal/ClassProviderBuilderImpl.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,13 @@ public ClassProvider.Builder addLibrary(Path path) {
4848
Path libraryDir;
4949
if (Files.isDirectory(path)) {
5050
libraryDir = path;
51-
} else {
51+
} else if (Files.isRegularFile(path)) {
5252
FileSystem zipFs = FileSystems.newFileSystem(path, (ClassLoader) null);
5353
this.fileSystems.add(zipFs);
5454
libraryDir = zipFs.getPath("/");
55+
} else {
56+
// We can't load it (it doesn't exist)
57+
return this;
5558
}
5659

5760
try (Stream<Path> walker = Files.walk(libraryDir)) {

0 commit comments

Comments
 (0)