Search in sources :

Example 1 with BeansXml

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()));
            }
        }
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) URL(java.net.URL)

Example 2 with BeansXml

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();
}
Also used : ImmutableList(org.jboss.weld.util.collections.ImmutableList) BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) URL(java.net.URL)

Example 3 with BeansXml

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);
}
Also used : BeansXml(org.jboss.weld.bootstrap.spi.BeansXml) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) HashSet(java.util.HashSet)

Example 4 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 5 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)

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