public class JarBuilder extends Object implements Closeable
| Modifier and Type | Class and Description |
|---|---|
static class |
JarBuilder.DuplicateAction
Identifies an action to take when duplicate jar entries are encountered.
|
static class |
JarBuilder.DuplicateEntryException
Indicates a duplicate jar entry is being rejected.
|
static class |
JarBuilder.DuplicateHandler
Handles duplicate jar entries by selecting an appropriate action based on the entry path.
|
static class |
JarBuilder.DuplicatePolicy
Encapsulates a policy for treatment of duplicate jar entries.
|
static interface |
JarBuilder.Entry
Represents an entry to be added to a jar.
|
static class |
JarBuilder.IndexingException
Indicates a problem indexing a pre-existing jar that will be added or updated to the target
jar.
|
static class |
JarBuilder.JarBuilderException
Indicates a problem encountered when building up a jar's contents for writing out.
|
static class |
JarBuilder.JarCreationException
Indicates a problem writing out a jar.
|
static interface |
JarBuilder.Listener
An interface for those interested in the progress of writing the target jar.
|
static interface |
JarBuilder.Source
Identifies a source for jar entries.
|
| Constructor and Description |
|---|
JarBuilder(File target)
Creates a JarBuilder that will write scheduled jar additions to
target upon
write(). |
JarBuilder(File target,
JarBuilder.Listener listener)
Creates a JarBuilder that will write scheduled jar additions to
target upon
write(). |
| Modifier and Type | Method and Description |
|---|---|
JarBuilder |
add(ByteSource contents,
String jarPath)
Schedules addition of the given
contents to the entry at jarPath. |
JarBuilder |
addDirectory(File directory,
Optional<String> jarPath)
Schedules recursive addition of all files contained within
directory to the resulting
jar. |
JarBuilder |
addFile(File file,
String jarPath)
Schedules addition of the given
file's contents to the entry at jarPath. |
JarBuilder |
addJar(File file)
Schedules addition of the given jar's contents to the file at
jarPath. |
void |
close() |
JarBuilder |
useCustomManifest(CharSequence customManifest)
Registers the given Manifest to be used in the jar written out by
write(). |
JarBuilder |
useCustomManifest(File customManifest)
Registers the given Manifest to be used in the jar written out by
write(). |
JarBuilder |
useCustomManifest(org.pantsbuild.tools.jar.JarBuilder.NamedByteSource customManifest)
Registers the given Manifest to be used in the jar written out by
write(). |
JarBuilder |
useCustomManifest(Manifest customManifest)
Registers the given Manifest to be used in the jar written out by
write(). |
File |
write()
Creates a jar at the configured target path applying the scheduled additions and skipping any
duplicate entries found.
|
File |
write(boolean compress)
Creates a jar at the configured target path applying the scheduled additions and skipping any
duplicate entries found.
|
File |
write(boolean compress,
JarBuilder.DuplicateHandler duplicateHandler,
Iterable<Pattern> skipPatterns)
Creates a jar at the configured target path applying the scheduled additions per the given
duplicateHandler. |
File |
write(boolean compress,
JarBuilder.DuplicateHandler duplicateHandler,
Pattern... skipPatterns)
Creates a jar at the configured target path applying the scheduled additions per the given
duplicateHandler. |
public JarBuilder(File target)
target upon
write().
If the target exists an attempt will be made to over-write it and if it does not
exist a then a new jar will be created at its path.
target - The target jar file to write.public JarBuilder(File target, JarBuilder.Listener listener)
target upon
write().
If the target does not exist a new jar will be created at its path.
target - The target jar file to write.public void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionpublic JarBuilder add(ByteSource contents, String jarPath)
contents to the entry at jarPath. In addition,
individual parent directory entries will be created when this builder is
written in he spirit of mkdir -p.contents - The contents of the entry to add.jarPath - The path of the entry to add.public JarBuilder addDirectory(File directory, Optional<String> jarPath)
directory to the resulting
jar. The path of each file relative to directory will be used for the corresponding
jar entry path. If a jarPath is present then all subtree entries will be prefixed
with it.directory - An existing directory to add to the jar.jarPath - An optional base path to graft the directory onto.public JarBuilder addFile(File file, String jarPath)
file's contents to the entry at jarPath. In
addition, individual parent directory entries will be created when this builder is
written in the spirit of mkdir -p.file - An existing file to add to the jar.jarPath - The path of the entry to add.public JarBuilder addJar(File file)
jarPath. Even if the jar
does not contain individual parent directory entries, they will be added for each entry added.file - The path of the jar to add.public JarBuilder useCustomManifest(Manifest customManifest)
write().customManifest - The manifest to use for the built jar.public JarBuilder useCustomManifest(File customManifest)
write().customManifest - The manifest to use for the built jar.public JarBuilder useCustomManifest(CharSequence customManifest)
write().customManifest - The manifest to use for the built jar.public JarBuilder useCustomManifest(org.pantsbuild.tools.jar.JarBuilder.NamedByteSource customManifest)
write().customManifest - The manifest to use for the built jar.public File write() throws IOException
IOException - if there was a problem writing the jar file.public File write(boolean compress) throws IOException
compress - Pass true to compress all jar entries; otherwise, they will just be
stored.IOException - if there was a problem writing the jar file.public File write(boolean compress, JarBuilder.DuplicateHandler duplicateHandler, Pattern... skipPatterns) throws IOException
duplicateHandler.compress - Pass true to compress all jar entries; otherwise, they will just be
stored.duplicateHandler - A handler for dealing with duplicate entries.skipPatterns - An optional list of patterns that match entry paths that should be
excluded.IOException - if there was a problem writing the jar file.JarBuilder.DuplicateEntryException - if the the policy in effect for an entry is
JarBuilder.DuplicateAction.THROW and that entry is a duplicate.public File write(boolean compress, JarBuilder.DuplicateHandler duplicateHandler, Iterable<Pattern> skipPatterns) throws JarBuilder.DuplicateEntryException, IOException
duplicateHandler.compress - Pass true to compress all jar entries; otherwise, they will just be
stored.duplicateHandler - A handler for dealing with duplicate entries.skipPatterns - An optional sequence of patterns that match entry paths that should be
excluded.IOException - if there was a problem writing the jar file.JarBuilder.DuplicateEntryException - if the the policy in effect for an entry is
JarBuilder.DuplicateAction.THROW and that entry is a duplicate.