Skip to content

Commit

Permalink
Add SecureModuleFinder.of(Iterable) allows for passing in a collect…
Browse files Browse the repository at this point in the history
…ion rather then an array (#5)
  • Loading branch information
PaintNinja authored Nov 26, 2024
1 parent e7f217d commit 9d783ab
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/main/java/cpw/mods/jarhandling/impl/Jar.java
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,7 @@ private Set<String> gatherPackages() {
var ret = new HashSet<String>();
for (var file : files) {
int idx = file.lastIndexOf('/');
if (!file.endsWith(".class") || idx == -1)
if (idx == -1 || !file.endsWith(".class"))
continue;
ret.add(file.substring(0, idx).replace('/', '.'));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
public class SecureModuleFinder implements ModuleFinder {
private final Map<String, ModuleReference> references = new HashMap<>();

protected SecureModuleFinder(final SecureJar... jars) {
protected SecureModuleFinder(final Iterable<SecureJar> jars) {
for (var jar : jars) {
var data = jar.moduleDataProvider();
if (references.containsKey(data.name()))
Expand All @@ -34,6 +34,10 @@ protected SecureModuleFinder(final SecureJar... jars) {
}
}

protected SecureModuleFinder(final SecureJar... jars) {
this(Arrays.asList(jars));
}

@Override
public Optional<ModuleReference> find(final String name) {
return Optional.ofNullable(references.get(name));
Expand All @@ -48,6 +52,10 @@ public static SecureModuleFinder of(SecureJar... jars) {
return new SecureModuleFinder(jars);
}

public static SecureModuleFinder of(Iterable<SecureJar> jars) {
return new SecureModuleFinder(jars);
}

private static class Reference extends SecureModuleReference {
private final SecureJar.ModuleDataProvider jar;
private final Manifest manifest;
Expand Down

0 comments on commit 9d783ab

Please sign in to comment.