Package org.jboss.shrinkwrap.api
Interface Archive<T extends Archive<T>>
- All Superinterfaces:
Assignable
- All Known Subinterfaces:
EnterpriseArchive
,GenericArchive
,JavaArchive
,MemoryMapArchive
,ResourceAdapterArchive
,WebArchive
- All Known Implementing Classes:
ArchiveBase
,ContainerBase
,EnterpriseArchiveImpl
,EnterpriseContainerBase
,GenericArchiveImpl
,JavaArchiveImpl
,MemoryMapArchiveBase
,MemoryMapArchiveImpl
,ResourceAdapterArchiveImpl
,ResourceAdapterContainerBase
,WebArchiveImpl
,WebContainerBase
Represents a collection of resources which may be constructed programmatically. In effect this represents a virtual
filesystem.
All
Because
All
Archive
types support the addition of Node
s under a designated ArchivePath
(context). The
contents of a Node
are either a directory or Asset
.
Archive
s are generally created via an ArchiveFactory
or via the default configuration shortcut
ShrinkWrap
utility class.
Because
Archive
s are Assignable
, they may be wrapped in another user "view" used to perform
operations like adding JavaEE Spec-specific resources or exporting in ZIP format.- Version:
- $Revision: $
-
Method Summary
Modifier and TypeMethodDescriptionadd
(Archive<?> archive, String path, Class<? extends StreamExporter> exporter) Add an archive under a specific context and maintain the archive name as context path.add
(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter) Add an archive under a specific context and maintain the archive name as context path.Adds the specified resource under the context denoted by the specified targetAdds the specified asset under the specified target (directory) using the specified name.add
(Asset asset, ArchivePath target) Adds the specified asset under the specified path into the target contextadd
(Asset asset, ArchivePath target, String name) Adds the specified asset under the specified target (directory) using the specified name.add
(NamedAsset namedAsset) Adds the asset encapsulated within the specifiedNamedAsset
under the encapsulated name and target (directory)addAsDirectories
(String... paths) Adds the specified directories.addAsDirectories
(ArchivePath... paths) Adds the specified directories.addAsDirectory
(String path) Adds the specified directory.addAsDirectory
(ArchivePath path) Adds the specified directory.addHandlers
(ArchiveEventHandler... handlers) Add an array of listeners for call back based.boolean
Denotes whether this archive contains a resource at the specified pathboolean
contains
(ArchivePath path) Denotes whether this archive contains a resource at the specified pathdelete
(ArchivePath path) filter
(Filter<ArchivePath> filter) Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).Obtains theNode
located at the specified pathget
(ArchivePath path) Obtains theNode
located at the specified path<X extends Archive<X>>
XGet a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
XgetAsType
(Class<X> type, String path, ArchiveFormat archiveFormat) Get a nestedArchive
as a specific type using the specifyArchiveFormat
<X extends Archive<X>>
XgetAsType
(Class<X> type, ArchivePath path) Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
XgetAsType
(Class<X> type, ArchivePath path, ArchiveFormat archiveFormat) <X extends Archive<X>>
Collection<X> getAsType
(Class<X> type, Filter<ArchivePath> filter) Get all nestedArchive
matching the filter as a specific type.
The found Archives must have been added as a Archive, no import is performed.<X extends Archive<X>>
Collection<X> getAsType
(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat) Get all nestedArchive
matching the filter as a specific type using the specifyArchiveFormat
.Obtains all assets in this archive, along with their respective paths.getContent
(Filter<ArchivePath> filter) Obtains all assets matching given filter in this archive, along with its respective Path.getId()
Obtains a globally-unique identifier for thisArchive
getName()
Obtains the name of this archive (ie.Merge the contents from an existing archive without maintaining the archive name in the context path.Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge
(Archive<?> source, String path, Filter<ArchivePath> filter) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge
(Archive<?> source, ArchivePath path) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge
(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge
(Archive<?> source, Filter<ArchivePath> filter) Merge the contents from an existing archive without maintaining the archive name in the context path.Moves the asset under the source path to the target path.move
(ArchivePath source, ArchivePath target) Moves the asset under the source path to the target path.Creates a shallow copy of thisArchive
.shallowCopy
(Filter<ArchivePath> filter) Creates a shallow copy of thisArchive
based on given filter.Assets from this archive are made available under the same paths.toString()
Acts as a shorthand fortoString(Formatter)
where theFormatters.SIMPLE
is leveraged.toString
(boolean verbose) If "true" is specified, acts as a shorthand fortoString(Formatter)
where theFormatters.VERBOSE
is leveraged.void
writeTo
(OutputStream outputStream, Formatter formatter) Prints the content of thisArchive
to the specifiedOutputStream
on the format defined by the specifiedFormatter
.Methods inherited from interface org.jboss.shrinkwrap.api.Assignable
as
-
Method Details
-
getName
String getName()Obtains the name of this archive (ie. myLibrary.jar) -
getId
String getId()Obtains a globally-unique identifier for thisArchive
- Returns:
-
add
Adds the specified asset under the specified path into the target context- Parameters:
asset
-target
- The context under which to add the assets- Returns:
- Throws:
IllegalArgumentException
- If no target or assets were specifiedIllegalArchivePathException
- If the target is invalid.
-
add
Adds the specified asset under the specified target (directory) using the specified name. The resultant path will be treating the specified path as a prefix namespace, then appending the name.- Parameters:
asset
-target
- The context directory under which to add the assetname
- The name to assign the assent under the target namespace- Returns:
- Throws:
IllegalArgumentException
- If the target, name, or asset was not specifiedIllegalArchivePathException
- If the target is invalid.
-
add
Adds the specified asset under the specified target (directory) using the specified name. The resultant path will be treating the specified path as a prefix namespace, then appending the name.- Parameters:
asset
-target
- The context directory under which to add the assetname
- The name to assign the assent under the target namespace- Returns:
- Throws:
IllegalArgumentException
- If the target, name, or asset was not specifiedIllegalArchivePathException
- If the target is invalid.
-
add
Adds the asset encapsulated within the specifiedNamedAsset
under the encapsulated name and target (directory)- Parameters:
namedAsset
-- Returns:
- Throws:
IllegalArgumentException
- If either the target or asset is not specifiedIllegalArchivePathException
- If the target is invalid.
-
add
Adds the specified resource under the context denoted by the specified target- Parameters:
asset
-target
-- Returns:
- Throws:
IllegalArgumentException
- If either the target or asset is not specifiedIllegalArchivePathException
- If the target is invalid.
-
addAsDirectory
Adds the specified directory.- Parameters:
path
- The path to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no path was specifiedIllegalArchivePathException
- If the path is invalid.
-
addAsDirectories
Adds the specified directories.- Parameters:
paths
- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no paths were specifiedIllegalArchivePathException
- If at least one path is invalid.
-
addAsDirectory
Adds the specified directory.- Parameters:
path
- The path to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no path was specifiedIllegalArchivePathException
- If the path is invalid.
-
addAsDirectories
Adds the specified directories.- Parameters:
paths
- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException
- If no paths were specifiedIllegalArchivePathException
- If at least one path is invalid.
-
addHandlers
Add an array of listeners for call back based.- Parameters:
listener
- CallBack on add- Returns:
- This archive
-
get
Obtains theNode
located at the specified path- Parameters:
path
-- Returns:
- The
Node
, or null if nothing is found at the specified path - Throws:
IllegalArgumentException
- If the path is not specified
-
get
Obtains theNode
located at the specified path- Parameters:
path
-- Returns:
- The
Node
, or null if nothing is found at the Path - Throws:
IllegalArgumentException
- If the path is not specified
-
getAsType
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.- Type Parameters:
X
-- Parameters:
type
- The Type to return the Archive aspath
- The location of the Archive- Returns:
- The found Archive as given type or null if none found at given path
- Throws:
IllegalArgumentException
- if foundAsset
is not pointing to aArchive
- See Also:
-
getAsType
Get a nestedArchive
as a specific type.
The found Archives must have been added as a Archive, no import is performed.- Type Parameters:
X
-- Parameters:
type
- The Type to return the Archive aspath
- The location of the Archive- Returns:
- The found Archive as given type or null if none found at given
ArchivePath
- Throws:
IllegalArgumentException
- if foundAsset
is not pointing to aArchive
- See Also:
-
getAsType
Get all nestedArchive
matching the filter as a specific type.
The found Archives must have been added as a Archive, no import is performed.- Type Parameters:
X
-- Parameters:
type
- The Type to return the Archive asfilter
- Filter to match result- Returns:
- A
Collection
of found Archives matching given filter or emptyCollection
if non found. - Throws:
IllegalArgumentException
- if foundAsset
is not pointing to aArchive
- See Also:
-
getAsType
Get a nestedArchive
as a specific type using the specifyArchiveFormat
- Parameters:
type
- The Type to return the Archive aspath
- The location of the ArchivearchiveFormat
- The archive format- Returns:
- The found Archive as given type or null if none found at the given path
- See Also:
-
getAsType
- Parameters:
type
- The Type to return the Archive aspath
- The location of the ArchivearchiveFormat
- The archive format- Returns:
- The found Archive as given type or null if none found at given
ArchivePath
- See Also:
-
getAsType
<X extends Archive<X>> Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat) Get all nestedArchive
matching the filter as a specific type using the specifyArchiveFormat
.- Type Parameters:
X
-- Parameters:
type
- The Type to return the Archive asfilter
- Filter to match resultarchiveFormat
- The archive format- Returns:
- A
Collection
of found Archives matching given filter or emptyCollection
if non found. - See Also:
-
contains
Denotes whether this archive contains a resource at the specified path- Parameters:
path
-- Returns:
- Throws:
IllegalArgumentException
- If the path is not specified
-
contains
Denotes whether this archive contains a resource at the specified path- Parameters:
path
-- Returns:
- Throws:
IllegalArgumentException
- If the path is not specified
-
delete
Removes theNode
in theArchive
at the specifiedArchivePath
. If the path is a directory, recursively removes all contents. If the path does not exist, return null.- Parameters:
path
-- Returns:
- The Node removed
- Throws:
IllegalArgumentException
-
delete
Removes theNode
in theArchive
at theArchivePath
indicated by the specified String archivePath. If the path is a directory, recursively removes all contents. If the path does not exist, return null.- Parameters:
archivePath
-- Returns:
- The Node removed
- Throws:
IllegalArgumentException
- See Also:
-
getContent
Map<ArchivePath,Node> getContent()Obtains all assets in this archive, along with their respective paths. The returned Map will be an immutable view.- Returns:
-
getContent
Obtains all assets matching given filter in this archive, along with its respective Path. The returned Map will be an immutable view.- Returns:
-
filter
Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).- Parameters:
filter
-- Returns:
- See Also:
-
add
T add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter) throws IllegalArgumentException Add an archive under a specific context and maintain the archive name as context path.- Parameters:
archive
- to addpath
- to useexporter
- Exporter type to use in fulfilling theAsset.openStream()
contract for the added (nested) archive.- Returns:
- Throws:
IllegalArgumentException
- If any argument is not specified
-
add
T add(Archive<?> archive, String path, Class<? extends StreamExporter> exporter) throws IllegalArgumentException Add an archive under a specific context and maintain the archive name as context path.- Parameters:
archive
- to addpath
- to useexporter
- Exporter type to use in fulfilling theAsset.openStream()
contract for the added (nested) archive.- Returns:
- Throws:
IllegalArgumentException
- If the path or archive are not specified
-
merge
Merge the contents from an existing archive without maintaining the archive name in the context path.- Parameters:
source
- Archive to add contents from- Returns:
- Throws:
IllegalArgumentException
- If the existing archive is not specified
-
merge
Merge the contents from an existing archive without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Parameters:
source
- Archive to add contents from- Returns:
- Throws:
IllegalArgumentException
- If the existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Parameters:
source
- Archive to add contents frompath
- Path to add contents to- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Parameters:
source
- Archive to add contents frompath
- Path to add contents to- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified
-
merge
T merge(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter) throws IllegalArgumentException Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Parameters:
source
- Archive to add contents frompath
- Path to add contents tofilter
- Filter to use for includingAsset
s in the merge.- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter control whichArchivePath
s to include form the sourceArchive
.- Parameters:
source
- Archive to add contents frompath
- Path to add contents tofilter
- Filter to use for includingAsset
s in the merge.- Returns:
- Throws:
IllegalArgumentException
- If the path or existing archive is not specified
-
move
T move(ArchivePath source, ArchivePath target) throws IllegalArgumentException, IllegalArchivePathException Moves the asset under the source path to the target path.- Parameters:
source
- The context under which to remove the assetstarget
- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException
- If any of the paths is not specifiedIllegalArchivePathException
- If the source path is invalid.
-
move
Moves the asset under the source path to the target path.- Parameters:
source
- The context under which to remove the assetstarget
- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException
- If any of the paths is not specifiedIllegalArchivePathException
- If the source path is invalid.
-
toString
String toString()Acts as a shorthand fortoString(Formatter)
where theFormatters.SIMPLE
is leveraged. -
toString
If "true" is specified, acts as a shorthand fortoString(Formatter)
where theFormatters.VERBOSE
is leveraged. Otherwise theFormatters.SIMPLE
will be used (equivalent totoString()
).- Returns:
-
toString
Returns a view of thisArchive
as returned from the specifiedFormatter
. Common options may be to use the predefined formatters located inFormatters
- Parameters:
formatter
-- Returns:
- Throws:
IllegalArgumentException
- If the formatter is not specified
-
writeTo
Prints the content of thisArchive
to the specifiedOutputStream
on the format defined by the specifiedFormatter
. The caller is responsible for opening, flushing and eventually closing the stream.- Parameters:
outputStream
- the stream to print the archive contents toformatter
- the output format- Throws:
IllegalArgumentException
- if an exceptions occur when writing the archive contents.
-
shallowCopy
Creates a shallow copy of thisArchive
. Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive.- Returns:
- a new archive with a copy of the pointers to the assets
-
shallowCopy
Creates a shallow copy of thisArchive
based on given filter.Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive.- Returns:
- a new archive with a copy of the pointers to the assets
-