Class JarBuilder
java.lang.Object
org.jdrupes.builder.core.AbstractProvider
org.jdrupes.builder.core.AbstractGenerator
org.jdrupes.builder.java.JarBuilder
- All Implemented Interfaces:
Generator, Renamable, ResourceProvider
- Direct Known Subclasses:
JavadocJarGenerator, LibraryBuilder, SourcesJarGenerator
A general purpose generator for jars. All contents must be added
explicitly using one of the
add* methods.-
Constructor Summary
ConstructorsConstructorDescriptionJarBuilder(Project project, ResourceType<? extends JarFile> jarType) Initializes a new library generator. -
Method Summary
Modifier and TypeMethodDescriptionFor each file tree, add its entries with the given prefix.Adds the file tree with the given prefix for each entry.add(Path path, IOResource resource) Convenience method for adding a single entry, seeaddEntries(Stream).Convenience method for adding entries, seeaddTrees(Stream).addAttributeValues(Stream<Map.Entry<Attributes.Name, String>> attributes) Add the given attributes to the manifest.addEntries(Stream<? extends Map.Entry<Path, ? extends IOResource>> entries) Adds single resources to the jar.addManifestAttributes(Stream<ManifestAttributes> attributes) Add the given attributes to the manifest.Adds the givenFileTrees.final JarBuilderattributes(Map.Entry<Attributes.Name, String>... attributes) Add the given attributes to the manifest.protected voidBuilds the jar.protected voidAdds the resources from the given file tree to the given contents.protected voidcollectContents(Map<Path, Resources<IOResource>> contents) Add the contents from the added streams as preliminary jar entries.Returns the destination directory.destination(Path destination) Sets the destination directory.destination(Supplier<Path> destination) Sets the destination directory.doProvide(ResourceRequest<T> requested) Invoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.jarName()Returns the name of the generated jar file.Sets the name of the generated jar file.Sets the supplier for obtaining the name of the generated jar file inResourceProviderSpi.provide(ResourceRequest).Set the new name.protected voidresolveDuplicates(Map<Path, Resources<IOResource>> entries) Resolve duplicates.Methods inherited from class AbstractGenerator
cleanup, newResource, project, toStringMethods inherited from class AbstractProvider
context, name, of, rename, vavrStream
-
Constructor Details
-
JarBuilder
Initializes a new library generator.- Parameters:
project- the projectjarType- the type of jar that the generator generates
-
-
Method Details
-
name
Description copied from interface:RenamableSet the new name.- Specified by:
namein interfaceRenamable- Overrides:
namein classAbstractGenerator- Parameters:
name- the name- Returns:
- the renamable
-
destination
Returns the destination directory. Defaults to sub directorylibsin the project's build directory (seeProject.buildDirectory()).- Returns:
- the destination
-
destination
Sets the destination directory. ThePathis resolved against the project's build directory (seeProject.buildDirectory()).- Parameters:
destination- the new destination- Returns:
- the jar generator
-
destination
Sets the destination directory.- Parameters:
destination- the new destination- Returns:
- the jar generator
-
jarName
-
jarName
Sets the supplier for obtaining the name of the generated jar file inResourceProviderSpi.provide(ResourceRequest).- Parameters:
jarName- the jar name- Returns:
- the jar generator
-
jarName
Sets the name of the generated jar file.- Parameters:
jarName- the jar name- Returns:
- the jar generator
-
addAttributeValues
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the library generator
-
addManifestAttributes
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the library generator
-
attributes
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the library generator
-
addEntries
Adds single resources to the jar. Each entry is added to the jar as entry with the name passed in the key attribute of theMap.Entrywith the content from theIOResourcein the value attribute.- Parameters:
entries- the entries- Returns:
- the jar generator
-
addTrees
Adds the givenFileTrees. Each file in the tree will be added as an entry using its relative path in the tree as name.- Parameters:
trees- the trees- Returns:
- the jar generator
-
add
Convenience method for adding entries, seeaddTrees(Stream).- Parameters:
trees- the trees- Returns:
- the jar generator
-
add
Adds the file tree with the given prefix for each entry.- Parameters:
prefix- the prefixtree- the tree- Returns:
- the jar builder
-
add
For each file tree, add its entries with the given prefix.- Parameters:
prefix- the prefixtrees- the trees- Returns:
- the jar builder
-
add
Convenience method for adding a single entry, seeaddEntries(Stream).- Parameters:
path- the pathresource- the resource- Returns:
- the jar generator
-
buildJar
-
collectContents
Add 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(...).- Parameters:
contents- the preliminary contents
-
collect
-
resolveDuplicates
Resolve duplicates. The default implementation outputs a warning and skips the duplicate entry.- Parameters:
entries- the entries
-
doProvide
Description copied from class:AbstractProviderInvoked byResourceProviderSpi.provide(ResourceRequest)after checking if the invocation is allowed.- Specified by:
doProvidein classAbstractProvider- Type Parameters:
T- the generic type- Parameters:
requested- the requested- Returns:
- the stream
-