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:
JavadocJarBuilder, LibraryBuilder, SourcesJarBuilder
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 JAR file 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, InputResource 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 InputResource>> 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<InputResource>> 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.protected <T extends Resource>
Collection<T> 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<InputResource>> entries) Resolve duplicates.Methods inherited from class AbstractGenerator
cleanup, project, toStringMethods inherited from class AbstractProvider
context, name, of, rename, vavrStreamMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface ResourceProvider
context, name, of, resources
-
Constructor Details
-
JarBuilder
Initializes a new JAR file 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 builder
-
destination
Sets the destination directory.- Parameters:
destination- the new destination- Returns:
- the JAR builder
-
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 builder
-
jarName
Sets the name of the generated JAR file.- Parameters:
jarName- the JAR name- Returns:
- the JAR builder
-
addAttributeValues
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the JAR builder
-
addManifestAttributes
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the JAR builder
-
attributes
Add the given attributes to the manifest.- Parameters:
attributes- the attributes- Returns:
- the JAR builder
-
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 builder
-
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 builder
-
add
Convenience method for adding entries, seeaddTrees(Stream).- Parameters:
trees- the trees- Returns:
- the JAR builder
-
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 builder
-
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.collectContents(...).- Parameters:
contents- the preliminary contents
-
collect
Adds the resources from the given file tree to the given contents. May be used by derived classes while collecting contents for the jar.- Parameters:
collected- the preliminary contentsfileTree- the file tree
-
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 request for resources- Returns:
- the stream
-