Class LibraryGenerator
java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.core.AbstractGenerator
org.jdrupes.builder.java.JarGenerator
org.jdrupes.builder.java.LibraryGenerator
- All Implemented Interfaces:
Generator, ResourceProvider, ResourceRetriever
- Direct Known Subclasses:
UberJarGenerator
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.
Instead of explicitly adding resources, this generator also supports
resource retrieval from added providers. The providers will be used
to retrieve resources of type ClassTree and JavaResourceTree in
addition to the explicitly added resources.
The standard pattern for creating a library is simply:
generator(LibraryGenerator::new).from(providers(Supply));
-
Field Summary
Fields inherited from class AbstractProvider
log -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected 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 byAbstractProvider.provide(ResourceRequest)after checking if the invocation is allowed.from(Stream<ResourceProvider> providers) Additionally uses the given providers for obtaining contents for the jar.from(ResourceProvider... providers) Additionally uses the given providers for obtaining contents for the jar.Returns the main class.Sets the main class.protected StreamCollector<ResourceProvider> return the cached providers.Methods inherited from class JarGenerator
add, add, addEntries, addTrees, attributes, attributes, buildJar, collect, destination, destination, destination, jarName, jarName, jarName, resolveDuplicatesMethods inherited from class AbstractGenerator
cleanup, name, name, newResource, project, toStringMethods inherited from class AbstractProvider
provideMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
provide
-
Constructor Details
-
LibraryGenerator
Instantiates a new library generator.- Parameters:
project- the project
-
-
Method Details
-
mainClass
-
mainClass
Sets the main class.- Parameters:
mainClass- the new main class- Returns:
- the jar generator for method chaining
-
from
Additionally uses the given providers for obtaining contents for the jar.- Specified by:
fromin interfaceResourceRetriever- Parameters:
providers- the providers- Returns:
- the jar generator
-
from
Additionally uses the given providers for obtaining contents for the jar.- Specified by:
fromin interfaceResourceRetriever- Parameters:
providers- the providers- Returns:
- the jar generator
-
providers
return the cached providers.- Returns:
- the cached stream
-
collectContents
Description copied from class:JarGeneratorAdd 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 classJarGenerator- 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 byAbstractProvider.provide(ResourceRequest)after checking if the invocation is allowed.- Overrides:
doProvidein classJarGenerator- Type Parameters:
T- the generic type- Parameters:
requested- the requested- Returns:
- the stream
-