Class LibraryBuilder
java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.core.AbstractGenerator
org.jdrupes.builder.java.JarBuilder
org.jdrupes.builder.java.LibraryBuilder
- All Implemented Interfaces:
Generator, Renamable, ResourceProvider, ResourceRetriever
- Direct Known Subclasses:
UberJarBuilder
A Generator for Java libraries packaged as jars. A library jar
is expected to contain class files and supporting resources together
with additional information in META-INF/.
The generator provides two types of resources.
-
A
JarFile. This type of resource is also returned if a more generalResourceTypesuch asClasspathElementis requested. -
An
AppJarFile. When requesting this special jar type, the generator checks if a main class is specified.
In addition to explicitly adding resources, this generator supports
resource retrieval from added providers. The resources of type ClassTree
and JavaResourceTree that the providers supply will be used in
addition to the explicitly added resources.
The standard pattern for creating a library is simply:
generator(LibraryGenerator::new).from(this);
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionaddFrom(Stream<ResourceProvider> providers) Additionally uses the given providers for obtaining contents for the jar.addFrom(ResourceProvider... providers) Additionally uses the given providers for obtaining contents for the jar.protected voidcollectContents(Map<Path, Resources<IOResource>> contents) Add the contents from the added streams as preliminary jar entries.protected voidcollectFromProviders(Map<Path, Resources<IOResource>> contents) Collects the contents from the providers.doProvide(ResourceRequest<T> requested) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.Returns the main class.Sets the main class.Set the new name.protected StreamCollector<ResourceProvider> return the cached providers.Methods inherited from class JarBuilder
add, add, add, add, addAttributeValues, addEntries, addManifestAttributes, addTrees, attributes, buildJar, collect, destination, destination, destination, jarName, jarName, jarName, resolveDuplicatesMethods inherited from class AbstractGenerator
cleanup, newResource, project, toStringMethods inherited from class AbstractProvider
context, name, of, rename, vavrStream
-
Constructor Details
-
LibraryBuilder
Instantiates a new library generator.- Parameters:
project- the project
-
-
Method Details
-
name
Description copied from interface:RenamableSet the new name.- Specified by:
namein interfaceRenamable- Overrides:
namein classJarBuilder- Parameters:
name- the name- Returns:
- the renamable
-
mainClass
-
mainClass
Sets the main class.- Parameters:
mainClass- the new main class- Returns:
- the jar generator for method chaining
-
addFrom
Additionally uses the given providers for obtaining contents for the jar.- Specified by:
addFromin interfaceResourceRetriever- Parameters:
providers- the providers- Returns:
- the jar generator
-
addFrom
Additionally uses the given providers for obtaining contents for the jar.- Specified by:
addFromin interfaceResourceRetriever- Parameters:
providers- the providers- Returns:
- the jar generator
-
providers
return the cached providers.- Returns:
- the cached stream
-
collectContents
Description copied from class:JarBuilderAdd the contents from the added streams as preliminary jar entries. Must be overridden by derived classes that define additional ways to provide contents. The overriding method must invokesuper.collectEntries(...).- Overrides:
collectContentsin classJarBuilder- Parameters:
contents- the preliminary contents
-
collectFromProviders
Collects the contents from the providers. This implementation requestsClassTrees andJavaResourceTrees.- Parameters:
contents- the contents
-
doProvide
Description copied from class:AbstractProviderInvoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.- Overrides:
doProvidein classJarBuilder- Type Parameters:
T- the generic type- Parameters:
requested- the requested- Returns:
- the stream
-