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());
}
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());
}
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());
}
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"));
}
}
}
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);
}
Aggregations