Common base implementations for the ShrinkWrap project enabling declarative assembly of Java archives (JAR, WAR, EAR, RAR) in code
—
The archive base classes provide foundational implementations for all ShrinkWrap archive types. These abstract classes handle core functionality including memory management, content operations, and thread safety.
Thread-safe memory-based archive storage implementation that serves as the foundation for most archive types.
public abstract class MemoryMapArchiveBase<T extends Archive<T>> extends ArchiveBase<T>Key Features:
Common Usage:
// Extend for custom archive implementations
public class CustomArchiveImpl extends MemoryMapArchiveBase<CustomArchive> {
public CustomArchiveImpl(String archiveName) {
super(archiveName, CustomArchive.class);
}
}Base implementation for archives that support type conversion through the as() method.
public abstract class AssignableBase<T extends Assignable> implements AssignableKey Methods:
public <TYPE extends Assignable> TYPE as(Class<TYPE> clazz)Usage Example:
// Convert archive to different exporter type
InputStream stream = archive.as(ZipExporter.class).exportAsInputStream();Root abstract class providing common archive operations and implementing core interfaces.
public abstract class ArchiveBase<T extends Archive<T>> implements Archive<T>, Configurable, ArchiveFormatAssociable, IdentifiableCore Operations:
Loads ShrinkWrap extensions using the Java ServiceLoader pattern.
public class ServiceExtensionLoader implements ExtensionLoaderKey Methods:
public <T> Collection<T> load(Class<T> serviceClass, ClassLoader classLoader)
public void addOverride(Class<?> serviceClass, Class<?> implementationClass)Usage:
ServiceExtensionLoader loader = new ServiceExtensionLoader();
Collection<ZipExporter> exporters = loader.load(ZipExporter.class, classLoader);Scans packages from URLs for class discovery and dynamic loading.
public class URLPackageScannerKey Methods:
public static Set<Class<?>> scanPackage(String packageName, ClassLoader classLoader)
public static Set<String> getClassNamesFromJar(URL jarUrl, String packageName)Implementation of the Archive Node interface representing archive entries.
public class NodeImpl implements NodeKey Methods:
public ArchivePath getPath()
public Asset getAsset()
public Set<Node> getChildren()
public Node getChild(ArchivePath path)Usage:
Node node = new NodeImpl(new BasicPath("/META-INF"), asset);
Set<Node> children = node.getChildren();Wrapper for extension instances providing lazy loading and caching.
public class ExtensionWrapper<T>Manages bindings between archive formats and their associated stream handlers.
public class ArchiveFormatStreamBindingsKey Methods:
public static void bind(ArchiveFormat format, Class<? extends StreamExporter> exporterClass)
public static Class<? extends StreamExporter> getExporterClass(ArchiveFormat format)Runtime exception thrown when extension loading fails.
public class ExtensionLoadingException extends RuntimeExceptionConstructors:
public ExtensionLoadingException(String message)
public ExtensionLoadingException(String message, Throwable cause)Common Scenarios:
All base classes are designed with thread safety in mind:
The base classes provide several extension points for custom implementations:
MemoryMapArchiveBase for new archive formatsServiceExtensionLoader for custom loading logicNodeImpl for specialized archive entry behaviorInstall with Tessl CLI
npx tessl i tessl/maven-org-jboss-shrinkwrap--shrinkwrap-impl-base