@Beta
public class ArchiveBuilder
extends java.lang.Object
Supports creating temporary archives that will be deleted on exit, if no name is
specified. The created file must be a Java archive type, with the extension .zip
,
.jar
, .war
or .ear
.
Example:
File zip = ArchiveBuilder.archive("data/archive.zip") .addAt(new File("./pom.xml"), "") .addDirContentsAt(new File("./src"), "src/") .addAt(new File("/tmp/Extra.java"), "src/main/java/") .addDirContentsAt(new File("/tmp/overlay/"), "") .create();
Modifier and Type | Method and Description |
---|---|
ArchiveBuilder |
add(java.io.File file)
Deprecated.
since 0.7.0 use one of the other add methods which makes the strategy explicit
|
ArchiveBuilder |
add(java.lang.Iterable<java.lang.String> files)
Deprecated.
since 0.7.0 use one of the other add methods if keeping this file's path was not intended
|
ArchiveBuilder |
add(java.lang.String filePath)
Deprecated.
since 0.7.0 use one of the other add methods which makes the strategy explicit
|
ArchiveBuilder |
add(java.lang.String baseDir,
java.lang.Iterable<java.lang.String> files)
Deprecated.
since 0.7.0 use one of the other add methods if keeping this file's path was not intended
|
ArchiveBuilder |
add(java.lang.String baseDir,
java.lang.String fileSubPath)
Deprecated.
since 0.7.0 use
addFromLocalBaseDir(File, String) , or
one of the other add methods if adding relative to baseDir was not intended |
ArchiveBuilder |
addAt(java.io.File file,
java.lang.String archiveParentDir)
adds the given file to the archive, preserving its name but putting under the given directory in the archive (may be
"" or "./" ) |
ArchiveBuilder |
addDir(java.io.File dir)
Deprecated.
since 0.7.0 use {@link #addDirContentsAt(File, String)
to clarify API, argument types, and be explicit about where it should be installed,
because JARs seem to require
"" |
ArchiveBuilder |
addDir(java.lang.String dirName)
Deprecated.
since 0.7.0 use {@link #addDirContentsAt(File, String)
|
ArchiveBuilder |
addDirContentsAt(java.io.File dir,
java.lang.String archiveParentDir)
Add the contents of the directory
dir to the archive. |
ArchiveBuilder |
addFromLocalBaseDir(java.io.File baseDir,
java.lang.String fileSubPath)
Add the file located at the
fileSubPath , relative to the baseDir on the local system,
to the archive. |
ArchiveBuilder |
addFromLocalBaseDir(java.lang.String baseDir,
java.lang.String fileSubPath)
Deprecated.
since 0.7.0 use
addFromLocalBaseDir(File, String) , or
one of the other add methods if adding relative to baseDir was not intended |
static ArchiveBuilder |
archive(java.lang.String archive)
Create an
ArchiveBuilder for an archive with the given name. |
java.io.File |
create()
Generates the archive.
|
java.io.File |
create(java.lang.String archiveFile)
Generates the archive, saving it with the given name.
|
ArchiveBuilder |
entries(java.util.Map<java.lang.String,java.io.File> entries)
Add a
Map of entries to the archive. |
ArchiveBuilder |
entry(java.lang.String entryPath,
java.io.File file)
Add the
file to the archive with the path entryPath . |
ArchiveBuilder |
entry(java.lang.String entryPath,
java.lang.String filePath)
Add the
file to the archive with the path entryPath . |
static ArchiveBuilder |
jar()
Create an
ArchiveBuilder for a Jar format archive. |
ArchiveBuilder |
manifest(java.lang.Object key,
java.lang.Object value)
Add a manifest entry with the given
key and value . |
ArchiveBuilder |
named(java.io.File file) |
ArchiveBuilder |
named(java.lang.String name)
Set the location of the generated archive file.
|
void |
stream(java.io.OutputStream output)
Generates the archive and outputs it to the given stream, ignoring any file name.
|
static ArchiveBuilder |
zip()
Create an
ArchiveBuilder for a Zip format archive. |
public static ArchiveBuilder archive(java.lang.String archive)
ArchiveBuilder
for an archive with the given name.public static ArchiveBuilder zip()
ArchiveBuilder
for a Zip
format archive.public static ArchiveBuilder jar()
ArchiveBuilder
for a Jar
format archive.public ArchiveBuilder named(java.lang.String name)
public ArchiveBuilder named(java.io.File file)
named(String)
public ArchiveBuilder manifest(java.lang.Object key, java.lang.Object value)
key
and value
.@Deprecated public ArchiveBuilder add(java.lang.String filePath)
filePath
to the archive,
with some complicated base-name strategies.@Deprecated public ArchiveBuilder add(java.io.File file)
file
to the archive.
If the file path is absolute, or points to a file above the current directory,
the file is added to the archive as a top-level entry, using the file name only.
For relative filePath
s below the current directory, the file is added
using the path given and is assumed to be located relative to the current
working directory.
No checks for file existence are made at this stage.
entry(String, File)
public ArchiveBuilder addFromLocalBaseDir(java.io.File baseDir, java.lang.String fileSubPath)
fileSubPath
, relative to the baseDir
on the local system,
to the archive.
Uses the fileSubPath
as the name of the file in the archive. Note that the
file is found by concatenating the two path components using Os.mergePaths(String...)
,
thus fileSubPath
should not be absolute or point to a location above the current directory.
Use entry(String, String)
directly or entries(Map)
for complete
control over file locations and names in the archive.
entry(String, String)
@Deprecated public ArchiveBuilder addFromLocalBaseDir(java.lang.String baseDir, java.lang.String fileSubPath)
addFromLocalBaseDir(File, String)
, or
one of the other add methods if adding relative to baseDir was not intended@Deprecated public ArchiveBuilder add(java.lang.String baseDir, java.lang.String fileSubPath)
addFromLocalBaseDir(File, String)
, or
one of the other add methods if adding relative to baseDir was not intendedpublic ArchiveBuilder addAt(java.io.File file, java.lang.String archiveParentDir)
""
or "./"
)@Deprecated public ArchiveBuilder addDir(java.lang.String dirName)
dirName
to the archive.addDir(File)
public ArchiveBuilder addDirContentsAt(java.io.File dir, java.lang.String archiveParentDir)
dir
to the archive.
The directory's name is not included; use #addAtRoot(File)
if you want that behaviour.
Uses . as the parent directory name for the contents.
entry(String, File)
@Deprecated public ArchiveBuilder addDir(java.io.File dir)
"" whereas ZIPs might want "./"
.
addDirContentsAt(File, String)
,
using . as the parent directory name for the contents.@Deprecated public ArchiveBuilder add(java.lang.Iterable<java.lang.String> files)
files
to the archive.add(String)
@Deprecated public ArchiveBuilder add(java.lang.String baseDir, java.lang.Iterable<java.lang.String> files)
files
, relative to the baseDir
, to
the archive.add(String, String)
public ArchiveBuilder entry(java.lang.String entryPath, java.lang.String filePath)
file
to the archive with the path entryPath
.entry(String, File)
public ArchiveBuilder entry(java.lang.String entryPath, java.io.File file)
file
to the archive with the path entryPath
.public ArchiveBuilder entries(java.util.Map<java.lang.String,java.io.File> entries)
Map
of entries to the archive.
The keys should be the names of the file entries to be added to the archive and
the value should point to the actual File
to be added.
This allows complete control over the directory structure of the eventual archive, as the entry names do not need to bear any relationship to the name or location of the files on the filesystem.
public void stream(java.io.OutputStream output)
This will add a manifest file if the type is a Jar archive.
public java.io.File create(java.lang.String archiveFile)
public java.io.File create()
If no name has been specified, the archive will be created as a temporary file with a unique name, that is deleted on exit. Otherwise, the given name will be used.