Skip to content

Commit

Permalink
Add utility method to quickly construct JarContent if no filters or r…
Browse files Browse the repository at this point in the history
…eplacement manifests are to be used (#65)

The most common use of JarContentBuilder is:

```java
new JarContentsBuilder().paths(path).build()
```

This allows:

```java
JarContents.of(path)

or

paths.map(JarContents::of)
```
  • Loading branch information
shartte authored Apr 10, 2024
1 parent f4a3e66 commit 5c4f4f8
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/main/java/cpw/mods/jarhandling/JarContents.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import java.net.URI;
import java.nio.file.Path;
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.Set;
Expand Down Expand Up @@ -52,4 +53,20 @@ public interface JarContents {
* Parses the {@code META-INF/services} files in the jar, and returns the list of service providers.
*/
List<SecureJar.Provider> getMetaInfServices();

/**
* Create plain jar contents from a single jar file or folder.
* For more advanced use-cases see {@link JarContentsBuilder}.
*/
static JarContents of(Path fileOrFolder) {
return new JarContentsBuilder().paths(fileOrFolder).build();
}

/**
* Create a virtual jar that consists of the contents of the given jar-files and folders.
* For more advanced use-cases see {@link JarContentsBuilder}.
*/
static JarContents of(Collection<Path> filesOrFolders) {
return new JarContentsBuilder().paths(filesOrFolders.toArray(new Path[0])).build();
}
}

0 comments on commit 5c4f4f8

Please sign in to comment.