Class ModuleBuilder
- java.lang.Object
-
- org.wildfly.testing.tools.modules.ModuleBuilder
-
public class ModuleBuilder extends Object
A simple utility to create a module.This will create a JAR based on the classes and generate a module.xml file.
- Author:
- James R. Perkins
-
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description ModuleBuilderaddAsset(org.jboss.shrinkwrap.api.asset.Asset asset, String target)Adds an asset to the module library.ModuleBuilderaddClass(Class<?> c)Adds a class to the module to be generated.ModuleBuilderaddClasses(Class<?>... classes)Adds the classes to the module to be generated.ModuleBuilderaddDependencies(String... dependencies)Adds the dependencies for the module.xml file.ModuleBuilderaddDependencies(Collection<ModuleDependency> dependencies)Adds the dependencies for the module.xml file.ModuleBuilderaddDependencies(ModuleDependency... dependencies)Adds the dependencies for the module.xml file.ModuleBuilderaddDependency(String dependency)Adds a dependency for the module.xml file.ModuleBuilderaddDependency(ModuleDependency dependency)Adds a dependency for the module.xml file.ModuleBuilderaddManifestResource(org.jboss.shrinkwrap.api.asset.Asset asset, String target)Adds a manifest resource,META-INF, inside the module JAR.ModuleBuilderaddPackage(Package p)Adds all the classes in the package to the generated module.ModuleBuilderaddPackage(String p)Adds all the classes in the package to the generated module.ModuleBuilderaddResource(org.jboss.shrinkwrap.api.spec.JavaArchive resource)Adds another resource root library to the module.ModuleBuilderaddResourcePath(String resourcePath)Adds a resource path to be added to the root resource.ModuleBuilderaddResourcePaths(String... resourcePaths)Adds the resource paths to be added to the root resource.ModuleBuilderaddResourcePaths(Set<String> resourcePaths)Adds the resource paths to be added to the root resource.ModuleBuilderaddResources(Collection<org.jboss.shrinkwrap.api.spec.JavaArchive> resources)Adds more resource root libraries to the module.ModuleBuilderaddResources(org.jboss.shrinkwrap.api.spec.JavaArchive... resources)Adds more resource root libraries to the module.ModuleBuilderaddServiceProvider(Class<?> intf, Class<?>... implementations)Creates aMETA-INF/servicesfile for the interface with the implementations provied.ModuleDescriptionbuild()Creates the module by: Creating the module directory based on the modules name Generating a JAR file for the resource Generating a module.xml fileStringname()Returns the module name.static ModuleBuilderof(String moduleName)Creates a new module builder with an archive name of test-module.jar.static ModuleBuilderof(String moduleName, String archiveName)Creates a new module builder.static ModuleBuilderof(String moduleName, String archiveName, Path modulePath)Creates a new module builder.static ModuleBuilderof(String moduleName, org.jboss.shrinkwrap.api.spec.JavaArchive jar)Creates a new module builder with an archive name of test-module.jar.static ModuleBuilderof(String moduleName, org.jboss.shrinkwrap.api.spec.JavaArchive jar, Path modulePath)Creates a new module builder.
-
-
-
Method Detail
-
of
public static ModuleBuilder of(String moduleName)
Creates a new module builder with an archive name of test-module.jar.- Parameters:
moduleName- the name for the module- Returns:
- a new module builder
-
of
public static ModuleBuilder of(String moduleName, org.jboss.shrinkwrap.api.spec.JavaArchive jar)
Creates a new module builder with an archive name of test-module.jar.- Parameters:
moduleName- the name for the modulejar- the JAR to use for the module- Returns:
- a new module builder
-
of
public static ModuleBuilder of(String moduleName, String archiveName)
Creates a new module builder.- Parameters:
moduleName- the name for the modulearchiveName- the name for the archive- Returns:
- a new module builder
-
of
public static ModuleBuilder of(String moduleName, String archiveName, Path modulePath)
Creates a new module builder.- Parameters:
moduleName- the name for the modulearchiveName- the name for the archivemodulePath- the JBoss Modules path where the module should be created, ifnullthere will be an attempt to discover the path- Returns:
- a new module builder
-
of
public static ModuleBuilder of(String moduleName, org.jboss.shrinkwrap.api.spec.JavaArchive jar, Path modulePath)
Creates a new module builder.- Parameters:
moduleName- the name for the modulejar- the JAR to use for the modulemodulePath- the JBoss Modules path where the module should be created, ifnullthere will be an attempt to discover the path- Returns:
- a new module builder
-
name
public String name()
Returns the module name.- Returns:
- the module name
-
addAsset
public ModuleBuilder addAsset(org.jboss.shrinkwrap.api.asset.Asset asset, String target)
Adds an asset to the module library.- Parameters:
asset- the asset to addtarget- the target path for the asset- Returns:
- this builder
-
addClass
public ModuleBuilder addClass(Class<?> c)
Adds a class to the module to be generated.- Parameters:
c- the class to add- Returns:
- this builder
-
addClasses
public ModuleBuilder addClasses(Class<?>... classes)
Adds the classes to the module to be generated.- Parameters:
classes- the classes to add- Returns:
- this builder
-
addDependency
public ModuleBuilder addDependency(String dependency)
Adds a dependency for the module.xml file.- Parameters:
dependency- the dependency to add- Returns:
- this builder
-
addDependencies
public ModuleBuilder addDependencies(String... dependencies)
Adds the dependencies for the module.xml file.- Parameters:
dependencies- the dependencies to add- Returns:
- this builder
-
addDependency
public ModuleBuilder addDependency(ModuleDependency dependency)
Adds a dependency for the module.xml file.- Parameters:
dependency- the dependency to add- Returns:
- this builder
-
addDependencies
public ModuleBuilder addDependencies(ModuleDependency... dependencies)
Adds the dependencies for the module.xml file.- Parameters:
dependencies- the dependencies to add- Returns:
- this builder
-
addDependencies
public ModuleBuilder addDependencies(Collection<ModuleDependency> dependencies)
Adds the dependencies for the module.xml file.- Parameters:
dependencies- the dependencies to add- Returns:
- this builder
-
addServiceProvider
public ModuleBuilder addServiceProvider(Class<?> intf, Class<?>... implementations)
Creates aMETA-INF/servicesfile for the interface with the implementations provied.- Parameters:
intf- the interface to crate the services file forimplementations- the implemenations- Returns:
- this builder
-
addPackage
public ModuleBuilder addPackage(String p)
Adds all the classes in the package to the generated module.- Parameters:
p- the package to add- Returns:
- this builder
-
addPackage
public ModuleBuilder addPackage(Package p)
Adds all the classes in the package to the generated module.- Parameters:
p- the package to add- Returns:
- this builder
-
addManifestResource
public ModuleBuilder addManifestResource(org.jboss.shrinkwrap.api.asset.Asset asset, String target)
Adds a manifest resource,META-INF, inside the module JAR.- Parameters:
asset- the resource to addtarget- the target path within the archive in which to add the resource, relative to theMETA-INFpath- Returns:
- this builder
-
addResource
public ModuleBuilder addResource(org.jboss.shrinkwrap.api.spec.JavaArchive resource)
Adds another resource root library to the module.- Parameters:
resource- the resource to add- Returns:
- this builder
-
addResources
public ModuleBuilder addResources(org.jboss.shrinkwrap.api.spec.JavaArchive... resources)
Adds more resource root libraries to the module.- Parameters:
resources- the resources to add- Returns:
- this builder
-
addResources
public ModuleBuilder addResources(Collection<org.jboss.shrinkwrap.api.spec.JavaArchive> resources)
Adds more resource root libraries to the module.- Parameters:
resources- the resources to add- Returns:
- this builder
-
addResourcePath
public ModuleBuilder addResourcePath(String resourcePath)
Adds a resource path to be added to the root resource.- Parameters:
resourcePath- the resource path to add- Returns:
- this builder
-
addResourcePaths
public ModuleBuilder addResourcePaths(String... resourcePaths)
Adds the resource paths to be added to the root resource.- Parameters:
resourcePaths- the resource paths to add- Returns:
- this builder
-
addResourcePaths
public ModuleBuilder addResourcePaths(Set<String> resourcePaths)
Adds the resource paths to be added to the root resource.- Parameters:
resourcePaths- the resource paths to add- Returns:
- this builder
-
build
public ModuleDescription build()
Creates the module by:- Creating the module directory based on the modules name
- Generating a JAR file for the resource
- Generating a module.xml file
The returned cleanup task will attempt to delete the module directory. There are some cases where the module directory may not be able to be deleted. The
IOExceptionis caught in these cases and a shutdown hook is added to delete the files when the JVM exits.- Returns:
- a task to clean up the module
-
-