use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class ClassPathBeanArchiveScanner method scanJarFile.
private void scanJarFile(File entryFile, ImmutableList.Builder<ScanResult> results) throws IOException {
try (ZipFile zip = new ZipFile(entryFile)) {
ZipEntry beansXmlEntry = zip.getEntry(AbstractWeldDeployment.BEANS_XML);
if (beansXmlEntry != null) {
logger.debugv(BEANS_XML_FOUND_MESSAGE, entryFile);
BeansXml beansXml = parseBeansXml(new URL(PROCOTOL_JAR + ":" + entryFile.toURI().toURL().toExternalForm() + JAR_URL_SEPARATOR + beansXmlEntry.getName()));
if (accept(beansXml)) {
results.add(new ScanResult(beansXml, entryFile.getPath()));
}
} else {
// No beans.xml found - check whether the bean archive contains an extension
if (zip.getEntry(EXTENSION_FILE) == null) {
logger.debugv(BEANS_XML_NOT_FOUND_MESSAGE, entryFile);
results.add(new ScanResult(null, entryFile.getPath()));
}
}
}
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class DefaultBeanArchiveScanner method scan.
@Override
public List<ScanResult> scan() {
ImmutableList.Builder<ScanResult> results = ImmutableList.builder();
// META-INF/beans.xml
final String[] resources = AbstractWeldDeployment.RESOURCES;
// Find all beans.xml files
for (String resourceName : resources) {
for (URL beansXmlUrl : resourceLoader.getResources(resourceName)) {
final BeansXml beansXml = parseBeansXml(beansXmlUrl);
if (accept(beansXml)) {
results.add(new ScanResult(beansXml, getBeanArchiveReference(beansXmlUrl)));
}
}
}
return results.build();
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class WeldBeanDeploymentArchive method merge.
/**
* @param bootstrap
* @param archives
* @return the "flat" bean deployment archive
*/
public static <T extends BeanDeploymentArchive> WeldBeanDeploymentArchive merge(CDI11Bootstrap bootstrap, Iterable<T> archives) {
BeansXml mergedBeansXml = BeansXmlParser.mergeExisting(archives, true);
Set<String> beanClasses = new HashSet<String>();
for (BeanDeploymentArchive archive : archives) {
beanClasses.addAll(archive.getBeanClasses());
}
return new WeldBeanDeploymentArchive(ManagerObjectFactory.FLAT_BEAN_DEPLOYMENT_ID, beanClasses, mergedBeansXml);
}
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());
}
Aggregations