Class ArchiveBuilder<T extends ArchiveBuilder<T,A>,A extends org.jboss.shrinkwrap.api.Archive<A>>
- java.lang.Object
-
- org.jboss.cdi.tck.shrinkwrap.ArchiveBuilder<T,A>
-
- Type Parameters:
T- Self type to enable abstract builder patternA- Final shrinkwrap archive
- Direct Known Subclasses:
WebArchiveBuilder
public abstract class ArchiveBuilder<T extends ArchiveBuilder<T,A>,A extends org.jboss.shrinkwrap.api.Archive<A>> extends Object
Abstract ShrinkWrap archive builder for CDI TCK Arquillian test.This is a base class for builders that try to solve most JBoss Test Harness to Arquillian migration issues. The main goal was to use CDI TCK 1.0 tests with minimum code changes.
Note that all Arquillian tests running in as-client mode (including tests using
ShouldThrowException) must not contain testing related stuff (anything that depends on Arquillian, TestNG, incl. test class itself) since Arquillian is not enriching as-client test archives. That's whyisAsClientModehas to be properly set.In case of
isTestArchiveset tofalsethis archive may not include any testing related stuff as it is probably part of another test archive.- Author:
- Martin Kouba
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected classArchiveBuilder.LibraryDescriptorInternal library descriptor.protected classArchiveBuilder.ResourceDescriptorInternal resource descriptor.protected classArchiveBuilder.ServiceProviderDescriptorInternal service provider descriptor.
-
Field Summary
-
Constructor Summary
Constructors Constructor Description ArchiveBuilder()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description Abuild()protected abstract AbuildInternal()TdebugMode()Enable debug mode.protected org.jboss.shrinkwrap.api.asset.AssetgetBeansDescriptorAsset()protected StringgetBeansDescriptorTarget()StringgetName()protected StringgetSha1OfTestClass()BooleanisAsClientMode()booleanisTestArchive()TnotTestArchive()Mark this archive as non-testing.protected <P extends org.jboss.shrinkwrap.api.Archive<?> & org.jboss.shrinkwrap.api.container.ClassContainer<?>>
voidprocessClasses(P archive)Process classes.protected voidprocessLibraries(org.jboss.shrinkwrap.api.container.LibraryContainer<?> archive)Process libraries.protected voidprocessManifestResources(org.jboss.shrinkwrap.api.container.ManifestContainer<?> archive)Process manifest resources.protected <P extends org.jboss.shrinkwrap.api.Archive<?> & org.jboss.shrinkwrap.api.container.ClassContainer<?>>
voidprocessPackages(P archive)Process packages.protected voidprocessResources(org.jboss.shrinkwrap.api.container.ResourceContainer<?> archive)Process resources.voidreadSystemProperties()abstract Tself()TsetAsClientMode(boolean isAsClientMode)TwithBeanLibrary(Class<?>... beanClasses)Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.TwithBeanLibrary(String name, Class<?>... beanClasses)Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.TwithBeanLibrary(String name, BeansXml beansXml, Class<?>... beanClasses)Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.TwithBeanLibrary(BeansXml beansXml, Class<?>... beanClasses)Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.TwithBeansXml(String beansXml)Addbeans.xmllocated in src/main/resource/{testPackagePath}.TwithBeansXml(BeansXml beansDescriptor)Addbeans.xmldescriptor created with TCK utilsTwithBuildCompatibleExtension(Class<? extends jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension> extensionClass)Add CDI build compatible extension.TwithBuildCompatibleExtensions(Class<? extends jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension>... extensionClasses)Add CDI build compatible extensions.TwithClass(Class<?> clazz)Add class to archive.TwithClasses(Class<?>... classes)Add classes to archive.TwithDefaultPersistenceXml()Add default persistence.xml.TwithEjbJarXml(String ejbJarXml)Add ejb-jar.xml located in src/main/resource/{testPackagePath}.TwithEjbJarXml(org.jboss.shrinkwrap.descriptor.api.ejbjar31.EjbJarDescriptor descriptor)Add ejb-jar.xml descriptor created with shrinkwrap-descriptors.TwithExcludedClass(String clazz)Specified class must be excluded from final archive unless also added viawithClass(Class)orwithClasses(Class...).TwithExcludedClasses(String... classes)Specified classes must be excluded from final archive unless also added viawithClass(Class)orwithClasses(Class...).TwithExtension(Class<? extends jakarta.enterprise.inject.spi.Extension> extensionClass)Add CDI extension.TwithExtensions(Class<? extends jakarta.enterprise.inject.spi.Extension>... extensionClasses)Add CDI extensions.TwithLibraries(org.jboss.shrinkwrap.api.spec.JavaArchive... libraries)Add specified ShrinkWrap libraries.TwithLibrary(File library)Add library.TwithLibrary(Class<?>... classes)Add library that consists of defined classes.TwithLibrary(String name, BeansXml beansXml, boolean includeEmptyBeanXml, Class<?>... classes)Add library that consists of defined classes.TwithLibrary(org.jboss.shrinkwrap.api.spec.JavaArchive library)Add the specified ShrinkWrap library.TwithLibrary(BeansXml beansXml, boolean includeEmptyBeanXml, Class<?>... classes)Add library that consists of defined classes.TwithManifestResource(String source)Add resource to META-INF.TwithManifestResource(String source, boolean useTestPackageToLocateSource)Add resource to META-INF.TwithManifestResource(String source, String target, boolean useTestPackageToLocateSource)Add resource to META-INF.TwithName(String name)Set the name of the archive.TwithoutBeansXml()Suppresses adding thebeans.xmldescriptor to the archive.TwithPackage(Package pack)Add package (that is its content).TwithPersistenceXml(org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor)Add persistence.xml descriptor created with shrinkwrap-descriptors.TwithResource(String source)Add resource.TwithResource(String source, boolean useTestPackageToLocateSource)Add resource.TwithResource(String source, String target, boolean useTestPackageToLocateSource)Add resource.TwithServiceProvider(ArchiveBuilder.ServiceProviderDescriptor serviceProvider)Add service provider.TwithTestClass(Class<?> testClazz)Add test class to archive and set test class definition for configuration purpose.TwithTestClassDefinition(Class<?> testClazz)Set test class definition for configuration purpose.TwithTestClassPackage(Class<?> testClazz)Add all classes in the test class package to archive and set test class definition for configuration purpose.TwithWebResource(String source)Add web resource.TwithWebResource(String source, boolean useTestPackageToLocateSource)Add web resource.TwithWebResource(String source, String target)Add web resource.TwithWebResource(String source, String target, boolean useTestPackageToLocateSource)Add web resource.TwithWebXml(String webXml)Add web.xml located in src/main/resource/{testPackagePath}.TwithWebXml(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXml)Addweb.xmldescriptor created with shrinkwrap-descriptors.
-
-
-
Field Detail
-
DEFAULT_EJB_VERSION
public static final String DEFAULT_EJB_VERSION
- See Also:
- Constant Field Values
-
DEBUG_MODE_PROPERTY
public static final String DEBUG_MODE_PROPERTY
- See Also:
- Constant Field Values
-
beansXml
protected ArchiveBuilder.ResourceDescriptor beansXml
-
beansDescriptor
protected BeansXml beansDescriptor
-
includeBeansXml
protected boolean includeBeansXml
-
webXml
protected ArchiveBuilder.ResourceDescriptor webXml
-
webXmlDescriptor
protected org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXmlDescriptor
-
persistenceDescriptor
protected org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor
-
ejbJarDescriptor
protected org.jboss.shrinkwrap.descriptor.api.ejbjar31.EjbJarDescriptor ejbJarDescriptor
-
ejbJarXml
protected ArchiveBuilder.ResourceDescriptor ejbJarXml
-
manifestResources
protected List<ArchiveBuilder.ResourceDescriptor> manifestResources
-
resources
protected List<ArchiveBuilder.ResourceDescriptor> resources
-
webResources
protected List<ArchiveBuilder.ResourceDescriptor> webResources
-
libraries
protected List<ArchiveBuilder.LibraryDescriptor> libraries
-
shrinkWrapLibraries
protected List<org.jboss.shrinkwrap.api.spec.JavaArchive> shrinkWrapLibraries
-
serviceProviders
protected List<ArchiveBuilder.ServiceProviderDescriptor> serviceProviders
-
-
Method Detail
-
readSystemProperties
public void readSystemProperties()
-
withBeansXml
public T withBeansXml(String beansXml)
Addbeans.xmllocated in src/main/resource/{testPackagePath}.Do not use this in new tests - use
withBeansXml(BeansXml)instead.- Parameters:
beansXml-- Returns:
- self
-
withBeansXml
public T withBeansXml(BeansXml beansDescriptor)
Addbeans.xmldescriptor created with TCK utils- Parameters:
beansDescriptor-- Returns:
- self
-
withoutBeansXml
public T withoutBeansXml()
Suppresses adding thebeans.xmldescriptor to the archive. If this method is called, any previous or following calls towithBeansXml(String)orwithBeansXml(BeansXml)are ignored.- Returns:
- self
-
withExtension
public T withExtension(Class<? extends jakarta.enterprise.inject.spi.Extension> extensionClass)
Add CDI extension. This method does not add the specified extension class to the archive.- Parameters:
extensionClass-- Returns:
- self
-
withExtensions
public T withExtensions(Class<? extends jakarta.enterprise.inject.spi.Extension>... extensionClasses)
Add CDI extensions. This method does not add the specified extension classes to the archive.- Parameters:
extensionClasses-- Returns:
- self
-
withBuildCompatibleExtension
public T withBuildCompatibleExtension(Class<? extends jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension> extensionClass)
Add CDI build compatible extension. This method does not add the specified extension class to the archive.- Parameters:
extensionClass-- Returns:
- self
-
withBuildCompatibleExtensions
public T withBuildCompatibleExtensions(Class<? extends jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension>... extensionClasses)
Add CDI build compatible extensions. This method does not add the specified extension classes to the archive.- Parameters:
extensionClasses-- Returns:
- self
-
withServiceProvider
public T withServiceProvider(ArchiveBuilder.ServiceProviderDescriptor serviceProvider)
Add service provider.- Parameters:
serviceProvider-- Returns:
-
withClass
public T withClass(Class<?> clazz)
Add class to archive.- Parameters:
clazz-- Returns:
- self
-
withClasses
public T withClasses(Class<?>... classes)
Add classes to archive.- Parameters:
classes-- Returns:
- self
-
withExcludedClass
public T withExcludedClass(String clazz)
Specified class must be excluded from final archive unless also added viawithClass(Class)orwithClasses(Class...). Useful for exluding some classes from package added viawithPackage(Package). Avoid using this feature if possible - the implementation has negative performance effects.- Parameters:
clazz- Fully qualified class name- Returns:
- self
-
withExcludedClasses
public T withExcludedClasses(String... classes)
Specified classes must be excluded from final archive unless also added viawithClass(Class)orwithClasses(Class...). Useful for exluding some classes from package added viawithPackage(Package). Avoid using this feature if possible - the implementation has negative performance effects.- Parameters:
classes- Fully qualified class names- Returns:
- self
-
withTestClassPackage
public T withTestClassPackage(Class<?> testClazz)
Add all classes in the test class package to archive and set test class definition for configuration purpose.- Parameters:
testClazz-- Returns:
- self
-
withTestClass
public T withTestClass(Class<?> testClazz)
Add test class to archive and set test class definition for configuration purpose.- Parameters:
testClazz-- Returns:
- self
-
withTestClassDefinition
public T withTestClassDefinition(Class<?> testClazz)
Set test class definition for configuration purpose. Do not add it to final archive. Always use this for as-client test archives, e.g. deployment method annotated withShouldThrowException.- Parameters:
testClazz-- Returns:
- self
-
withPackage
public T withPackage(Package pack)
Add package (that is its content). Subpackages are not included.- Parameters:
pack-- Returns:
- self
-
withManifestResource
public T withManifestResource(String source)
Add resource to META-INF.- Parameters:
source-- Returns:
- self
-
withManifestResource
public T withManifestResource(String source, boolean useTestPackageToLocateSource)
Add resource to META-INF.- Parameters:
source-useTestPackageToLocateSource-- Returns:
- self
-
withManifestResource
public T withManifestResource(String source, String target, boolean useTestPackageToLocateSource)
Add resource to META-INF.- Parameters:
source-target-useTestPackageToLocateSource-- Returns:
- self
-
withResource
public T withResource(String source, boolean useTestPackageToLocateSource)
Add resource.- Parameters:
source-useTestPackageToLocateSource-- Returns:
- self
-
withResource
public T withResource(String source, String target, boolean useTestPackageToLocateSource)
Add resource.- Parameters:
source-target-useTestPackageToLocateSource-- Returns:
- self
-
withWebResource
public T withWebResource(String source)
Add web resource.- Parameters:
source-- Returns:
- self
-
withWebResource
public T withWebResource(String source, String target)
Add web resource.- Parameters:
source-target-- Returns:
- self
-
withWebResource
public T withWebResource(String source, boolean useTestPackageToLocateSource)
Add web resource.- Parameters:
source-useTestPackageToLocateSource-- Returns:
- self
-
withWebResource
public T withWebResource(String source, String target, boolean useTestPackageToLocateSource)
Add web resource.- Parameters:
source-- Returns:
-
withEjbJarXml
public T withEjbJarXml(String ejbJarXml)
Add ejb-jar.xml located in src/main/resource/{testPackagePath}.- Parameters:
ejbJarXml-- Returns:
-
withEjbJarXml
public T withEjbJarXml(org.jboss.shrinkwrap.descriptor.api.ejbjar31.EjbJarDescriptor descriptor)
Add ejb-jar.xml descriptor created with shrinkwrap-descriptors.- Parameters:
descriptor-- Returns:
-
withWebXml
public T withWebXml(String webXml)
Add web.xml located in src/main/resource/{testPackagePath}.Do not use this in new tests - use
withWebXml(WebAppDescriptor)instead.- Parameters:
webXml-- Returns:
-
withWebXml
public T withWebXml(org.jboss.shrinkwrap.descriptor.api.webapp30.WebAppDescriptor webXml)
Addweb.xmldescriptor created with shrinkwrap-descriptors.- Parameters:
webXml-- Returns:
-
withDefaultPersistenceXml
public T withDefaultPersistenceXml()
Add default persistence.xml.- Returns:
- self
-
withPersistenceXml
public T withPersistenceXml(org.jboss.shrinkwrap.descriptor.api.persistence20.PersistenceDescriptor persistenceDescriptor)
Add persistence.xml descriptor created with shrinkwrap-descriptors.- Parameters:
persistenceDescriptor-- Returns:
- self
-
withBeanLibrary
public T withBeanLibrary(Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.- Parameters:
beanClasses-- Returns:
- self
-
withBeanLibrary
public T withBeanLibrary(BeansXml beansXml, Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.- Parameters:
beanClasses-- Returns:
- self
-
withBeanLibrary
public T withBeanLibrary(String name, Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.- Parameters:
beanClasses-- Returns:
- self
-
withBeanLibrary
public T withBeanLibrary(String name, BeansXml beansXml, Class<?>... beanClasses)
Add bean library that consists of defined bean classes; automatically include emptybeans.xmland if any of defined classes implementsExtensionadd corresponding service provider.- Parameters:
beanClasses-- Returns:
- self
-
withLibrary
public T withLibrary(Class<?>... classes)
Add library that consists of defined classes.- Parameters:
classes-- Returns:
- self
-
withLibrary
public T withLibrary(BeansXml beansXml, boolean includeEmptyBeanXml, Class<?>... classes)
Add library that consists of defined classes. Include empty beans.xml if necessary.- Parameters:
beansXml-includeEmptyBeanXml-classes-- Returns:
- self
-
withLibrary
public T withLibrary(String name, BeansXml beansXml, boolean includeEmptyBeanXml, Class<?>... classes)
Add library that consists of defined classes. Include empty beans.xml if necessary.- Parameters:
name-beansXml-includeEmptyBeanXml-classes-- Returns:
- self
-
withLibrary
public T withLibrary(org.jboss.shrinkwrap.api.spec.JavaArchive library)
Add the specified ShrinkWrap library.- Parameters:
library-- Returns:
- self
-
withLibraries
public T withLibraries(org.jboss.shrinkwrap.api.spec.JavaArchive... libraries)
Add specified ShrinkWrap libraries.- Parameters:
libraries-- Returns:
-
isAsClientMode
public Boolean isAsClientMode()
- Returns:
trueif building as-client mode archive,falseotherwise
-
setAsClientMode
public T setAsClientMode(boolean isAsClientMode)
- Parameters:
isAsClientMode-- See Also:
resolveAsClientMode()
-
isTestArchive
public boolean isTestArchive()
- Returns:
trueif TCK specific infrastructure (porting package, utils, etc.) should be automatically added,falseotherwise- See Also:
resolveAsClientMode()
-
notTestArchive
public T notTestArchive()
Mark this archive as non-testing. TCK specific infrastructure (porting package, utils, etc.) will not be automatically added.
-
debugMode
public T debugMode()
Enable debug mode. Basically shows the content of the default beans.xml and built ShrinkWrap archive in the log.
-
getName
public String getName()
- Returns:
- name of final archive
-
self
public abstract T self()
- Returns:
- self to enable generic builder
-
build
public A build()
- Returns:
- ShrinkWrap archive
-
buildInternal
protected abstract A buildInternal()
- Returns:
- concrete shrinkwrap archive
-
processPackages
protected <P extends org.jboss.shrinkwrap.api.Archive<?> & org.jboss.shrinkwrap.api.container.ClassContainer<?>> void processPackages(P archive)
Process packages. Exclude classes specified viawithExcludedClass(String). If in as-client mode, filter test class.- Parameters:
archive-
-
processClasses
protected <P extends org.jboss.shrinkwrap.api.Archive<?> & org.jboss.shrinkwrap.api.container.ClassContainer<?>> void processClasses(P archive)
Process classes.- Parameters:
archive- - the test archive
-
processLibraries
protected void processLibraries(org.jboss.shrinkwrap.api.container.LibraryContainer<?> archive)
Process libraries.- Parameters:
archive-
-
processResources
protected void processResources(org.jboss.shrinkwrap.api.container.ResourceContainer<?> archive)
Process resources.- Parameters:
archive-
-
processManifestResources
protected void processManifestResources(org.jboss.shrinkwrap.api.container.ManifestContainer<?> archive)
Process manifest resources.- Parameters:
archive-
-
getBeansDescriptorAsset
protected org.jboss.shrinkwrap.api.asset.Asset getBeansDescriptorAsset()
- Returns:
- corresponding beans descriptor asset
-
getBeansDescriptorTarget
protected String getBeansDescriptorTarget()
- Returns:
-
getSha1OfTestClass
protected String getSha1OfTestClass()
-
-