Class 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 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 module
        jar - 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 module
        archiveName - 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 module
        archiveName - the name for the archive
        modulePath - the JBoss Modules path where the module should be created, if null there 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 module
        jar - the JAR to use for the module
        modulePath - the JBoss Modules path where the module should be created, if null there 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 add
        target - 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 a META-INF/services file for the interface with the implementations provied.
        Parameters:
        intf - the interface to crate the services file for
        implementations - 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 add
        target - the target path within the archive in which to add the resource, relative to the META-INF path
        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 IOException is 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