Search in sources :

Example 6 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlMergeTest method testMergeWithoutDuplicates.

@Test
public void testMergeWithoutDuplicates() {
    final BeansXml beansXml1 = createBeansXmlTestInstance();
    final BeansXml beansXml2 = createBeansXmlTestInstance();
    final List<BeansXml> beansXMLFiles = Arrays.asList(beansXml1, beansXml2, BeansXml.EMPTY_BEANS_XML);
    final BeansXml mergedBeansXml = BeansXmlParser.mergeExistingDescriptors(beansXMLFiles, true);
    assertNotNull(mergedBeansXml);
    assertNotNull(mergedBeansXml.getEnabledAlternativeClasses());
    assertNotNull(mergedBeansXml.getEnabledAlternativeStereotypes());
    assertNotNull(mergedBeansXml.getEnabledDecorators());
    assertNotNull(mergedBeansXml.getEnabledInterceptors());
    assertNotNull(mergedBeansXml.getScanning());
    assertNotNull(mergedBeansXml.getScanning().getExcludes());
    assertNotNull(mergedBeansXml.getScanning().getIncludes());
    assertEquals(1, mergedBeansXml.getEnabledAlternativeClasses().size());
    assertEquals(1, mergedBeansXml.getEnabledAlternativeStereotypes().size());
    assertEquals(1, mergedBeansXml.getEnabledDecorators().size());
    assertEquals(1, mergedBeansXml.getEnabledInterceptors().size());
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Test(org.junit.Test)

Example 7 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlMergeTest method testMergeAll.

@Test
public void testMergeAll() {
    final BeansXml beansXml1 = createBeansXmlTestInstance();
    final BeansXml beansXml2 = createBeansXmlTestInstance();
    final List<BeansXml> beansXMLFiles = Arrays.asList(beansXml1, beansXml2, BeansXml.EMPTY_BEANS_XML);
    final BeansXml mergedBeansXml = BeansXmlParser.mergeExistingDescriptors(beansXMLFiles, false);
    assertNotNull(mergedBeansXml);
    assertNotNull(mergedBeansXml.getEnabledAlternativeClasses());
    assertNotNull(mergedBeansXml.getEnabledAlternativeStereotypes());
    assertNotNull(mergedBeansXml.getEnabledDecorators());
    assertNotNull(mergedBeansXml.getEnabledInterceptors());
    assertNotNull(mergedBeansXml.getScanning());
    assertNotNull(mergedBeansXml.getScanning().getExcludes());
    assertNotNull(mergedBeansXml.getScanning().getIncludes());
    assertEquals(2, mergedBeansXml.getEnabledAlternativeClasses().size());
    assertEquals(2, mergedBeansXml.getEnabledAlternativeStereotypes().size());
    assertEquals(2, mergedBeansXml.getEnabledDecorators().size());
    assertEquals(2, mergedBeansXml.getEnabledInterceptors().size());
    assertEquals(2, mergedBeansXml.getScanning().getExcludes().size());
    assertEquals(2, mergedBeansXml.getScanning().getIncludes().size());
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Test(org.junit.Test)

Example 8 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class BeansXmlMergeTest method testMergeEmptyBeansXML.

@Test
public void testMergeEmptyBeansXML() {
    final List<BeansXml> beansXMLFiles = Arrays.asList(BeansXml.EMPTY_BEANS_XML, BeansXml.EMPTY_BEANS_XML);
    final BeansXml mergedBeansXml = BeansXmlParser.mergeExistingDescriptors(beansXMLFiles, false);
    assertNotNull(mergedBeansXml);
    assertNotNull(mergedBeansXml.getEnabledAlternativeClasses());
    assertNotNull(mergedBeansXml.getEnabledAlternativeStereotypes());
    assertNotNull(mergedBeansXml.getEnabledDecorators());
    assertNotNull(mergedBeansXml.getEnabledInterceptors());
    assertNotNull(mergedBeansXml.getScanning());
    assertNotNull(mergedBeansXml.getScanning().getExcludes());
    assertNotNull(mergedBeansXml.getScanning().getIncludes());
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) Test(org.junit.Test)

Example 9 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class Reports method addBeanArchives.

private static void addBeanArchives(HtmlTag body, List<BeanDeploymentArchive> bdas) {
    body.add(HtmlTag.aname(BDAS));
    body.add(HtmlTag.h2(TITLE_BDAS));
    HtmlTag table = HtmlTag.stripedTable().appendTo(HtmlTag.div(BDAS).appendTo(body));
    HtmlTag.tr().add(HtmlTag.th(""), HtmlTag.th("Identifier"), HtmlTag.th("Bean Discovery Mode"), HtmlTag.th("beans.xml")).appendTo(table);
    int idx = 0;
    for (BeanDeploymentArchive bda : bdas) {
        HtmlTag tr = HtmlTag.tr().add(HtmlTag.td(++idx + "."), HtmlTag.td(bda.getId())).appendTo(table);
        BeansXml beansXml = bda.getBeansXml();
        tr.add(HtmlTag.td(beansXml != null ? beansXml.getBeanDiscoveryMode().toString() : BeanDiscoveryMode.ANNOTATED.toString()));
        if (beansXml != null && !beansXml.equals(BeansXml.EMPTY_BEANS_XML)) {
            HtmlTag.div().attr(HtmlTag.TITLE, beansXml.getUrl() != null ? beansXml.getUrl().toString() : "URL not available").add(beansXml.getVersion() != null ? beansXml.getVersion() : "Version not defined").appendTo(HtmlTag.td().appendTo(tr));
        } else {
            tr.add(HtmlTag.td("No beans.xml"));
        }
    }
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 10 with BeansXml

use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.

the class GlobalEnablementBuilder method createModuleEnablement.

public ModuleEnablement createModuleEnablement(BeanDeployment deployment) {
    ClassLoader loader = new ClassLoader(deployment.getBeanManager().getServices().get(ResourceLoader.class));
    BeansXml beansXml = deployment.getBeanDeploymentArchive().getBeansXml();
    Set<Class<?>> alternativeClasses = null;
    Set<Class<? extends Annotation>> alternativeStereotypes = null;
    List<Class<?>> globallyEnabledInterceptors = getInterceptorList(null);
    List<Class<?>> globallyEnabledDecorators = getDecoratorList(null);
    ImmutableList.Builder<Class<?>> moduleInterceptorsBuilder = ImmutableList.<Class<?>>builder();
    moduleInterceptorsBuilder.addAll(globallyEnabledInterceptors);
    ImmutableList.Builder<Class<?>> moduleDecoratorsBuilder = ImmutableList.<Class<?>>builder();
    moduleDecoratorsBuilder.addAll(globallyEnabledDecorators);
    if (beansXml != null) {
        checkForDuplicates(beansXml.getEnabledInterceptors(), ValidatorLogger.INTERCEPTOR_SPECIFIED_TWICE);
        checkForDuplicates(beansXml.getEnabledDecorators(), ValidatorLogger.DECORATOR_SPECIFIED_TWICE);
        checkForDuplicates(beansXml.getEnabledAlternativeClasses(), ValidatorLogger.ALTERNATIVE_CLASS_SPECIFIED_MULTIPLE_TIMES);
        checkForDuplicates(beansXml.getEnabledAlternativeStereotypes(), ValidatorLogger.ALTERNATIVE_STEREOTYPE_SPECIFIED_MULTIPLE_TIMES);
        List<Class<?>> interceptorClasses = beansXml.getEnabledInterceptors().stream().map(loader).collect(Collectors.toList());
        moduleInterceptorsBuilder.addAll(filter(interceptorClasses, globallyEnabledInterceptors, ValidatorLogger.INTERCEPTOR_ENABLED_FOR_APP_AND_ARCHIVE, deployment));
        List<Class<?>> decoratorClasses = beansXml.getEnabledDecorators().stream().map(loader).collect(Collectors.toList());
        moduleDecoratorsBuilder.addAll(filter(decoratorClasses, globallyEnabledDecorators, ValidatorLogger.DECORATOR_ENABLED_FOR_APP_AND_ARCHIVE, deployment));
        alternativeClasses = beansXml.getEnabledAlternativeClasses().stream().map(loader).collect(ImmutableSet.collector());
        alternativeStereotypes = cast(beansXml.getEnabledAlternativeStereotypes().stream().map(loader).collect(ImmutableSet.collector()));
    } else {
        alternativeClasses = Collections.emptySet();
        alternativeStereotypes = Collections.emptySet();
    }
    Map<Class<?>, Integer> globalAlternatives = getGlobalAlternativeMap();
    // We suppose that enablements are always created all at once
    dirty = false;
    return new ModuleEnablement(moduleInterceptorsBuilder.build(), moduleDecoratorsBuilder.build(), globalAlternatives, alternativeClasses, alternativeStereotypes);
}
Also used : ResourceLoader(org.jboss.weld.resources.spi.ResourceLoader) ImmutableList(org.jboss.weld.util.collections.ImmutableList) Annotation(java.lang.annotation.Annotation) BigInteger(java.math.BigInteger) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml)

Aggregations

BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)34 Test (org.testng.annotations.Test)12 URL (java.net.URL)9 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)6 ArrayList (java.util.ArrayList)5 File (java.io.File)4 Test (org.junit.Test)4 HashSet (java.util.HashSet)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)2 IOException (java.io.IOException)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)2 ZipFile (java.util.zip.ZipFile)2 Bean (javax.enterprise.inject.spi.Bean)2 BeanManager (javax.enterprise.inject.spi.BeanManager)2 DeploymentContext (org.glassfish.api.deployment.DeploymentContext)2 ReadableArchive (org.glassfish.api.deployment.archive.ReadableArchive)2 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)2