Class 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
LibraryJarFile. 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) Adds the given providers as sources for resources.addFrom(ResourceProvider... providers) Adds the given provider(s) as source for resources.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.protected StreamCollector<ResourceProvider> return the cached providers.doProvide(ResourceRequest<T> request) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.Returns the main class.Sets the main class.Set the new name.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, 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
Description copied from interface:ResourceRetrieverAdds the given provider(s) as source for resources.- Specified by:
addFromin interfaceResourceRetriever- Parameters:
providers- the provider to add- Returns:
- the resource retriever
-
addFrom
Description copied from interface:ResourceRetrieverAdds the given providers as sources for resources. The stream must not be terminated before the generators' provide method is invoked.- Specified by:
addFromin interfaceResourceRetriever- Parameters:
providers- the providers to retrieve resources from- Returns:
- the resource retriever
-
contentProviders
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:
request- the request for resources- Returns:
- the stream
-