Search in sources :

Example 31 with BeanDeploymentArchive

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

the class Reports method generateValidationReport.

static void generateValidationReport(Probe probe, Exception exception, Environment environment, BeanManagerImpl manager) {
    HtmlTag html = HtmlTag.html();
    HtmlTag head = HtmlTag.head().appendTo(html);
    head.add(HtmlTag.title(TITLE));
    head.add(HtmlTag.style().add(SafeString.of(IOUtils.getResourceAsString("/report.css"))));
    HtmlTag body = HtmlTag.body().appendTo(html);
    body.add(HtmlTag.h1(TITLE));
    HtmlTag meta = HtmlTag.stripedTable().appendTo(body);
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Generated at:")), HtmlTag.td(LocalDateTime.now().toString())));
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Weld Version:")), HtmlTag.td(Formats.getSimpleVersion())));
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Weld Environment:")), HtmlTag.td(environment.toString())));
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Java Version:")), HtmlTag.td(AccessController.doPrivileged(new GetSystemPropertyAction("java.version")))));
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Java Vendor:")), HtmlTag.td(AccessController.doPrivileged(new GetSystemPropertyAction("java.vendor")))));
    meta.add(HtmlTag.tr().add(HtmlTag.td().add(HtmlTag.strong("Operating System:")), HtmlTag.td(AccessController.doPrivileged(new GetSystemPropertyAction("os.name")))));
    HtmlTag contents = HtmlTag.ol().appendTo(body);
    contents.add(HtmlTag.li().add(HtmlTag.a("#" + EXCEPTION).add(TITLE_EXCEPTION)));
    contents.add(HtmlTag.li().add(HtmlTag.a("#" + BDAS).add(TITLE_BDAS)));
    contents.add(HtmlTag.li().add(HtmlTag.a("#" + DEPS).add(TITLE_DEPS)));
    contents.add(HtmlTag.li().add(HtmlTag.a("#" + BEANS).add(TITLE_BEANS)));
    contents.add(HtmlTag.li().add(HtmlTag.a("#" + CONFIG).add(TITLE_CONFIG)));
    body.add(HtmlTag.aname(EXCEPTION));
    body.add(HtmlTag.h2(TITLE_EXCEPTION));
    body.add(HtmlTag.p(exception.getMessage()).attr(HtmlTag.STYLE, "font-size: large;color: red;font-weight:bold;"));
    body.add(HtmlTag.h(3, "Exception Stack:"));
    final StringWriter stackWriter = new StringWriter();
    exception.printStackTrace(new PrintWriter(stackWriter));
    body.add(HtmlTag.div(EXCEPTION).add(HtmlTag.pre(stackWriter.toString())));
    Map<BeanDeploymentArchive, BeanManagerImpl> beanDeploymentArchivesMap = Container.instance(manager).beanDeploymentArchives();
    List<BeanDeploymentArchive> bdas = new ArrayList<BeanDeploymentArchive>(beanDeploymentArchivesMap.keySet());
    Collections.sort(bdas, probe.getBdaComparator());
    addBeanArchives(body, bdas);
    addInvalidDependencies(probe, body);
    addBeans(probe, body, bdas);
    addConfiguration(body, manager);
    String export = manager.getServices().get(WeldConfiguration.class).getStringProperty(ConfigurationKey.PROBE_EXPORT_DATA_AFTER_DEPLOYMENT);
    File exportPath;
    if (!export.isEmpty()) {
        exportPath = new File(export);
    } else {
        exportPath = new File(System.getProperty("user.dir"));
    }
    if (!exportPath.canWrite()) {
        ProbeLogger.LOG.invalidExportPath(exportPath);
        return;
    }
    try {
        File exportFile = new File(exportPath, VALIDATION_REPORT_FILE_NAME);
        Files.write(exportFile.toPath(), html.toString().getBytes(Charset.forName("UTF-8")));
        ProbeLogger.LOG.validationReportExported("file://" + exportFile.getAbsolutePath());
    } catch (IOException e) {
        ProbeLogger.LOG.unableToExportData(exportPath, e.getCause() != null ? e.getCause() : e);
        ProbeLogger.LOG.catchingTrace(e);
    }
}
Also used : ArrayList(java.util.ArrayList) SafeString(org.jboss.weld.probe.HtmlTag.SafeString) IOException(java.io.IOException) StringWriter(java.io.StringWriter) BeanManagerImpl(org.jboss.weld.manager.BeanManagerImpl) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) GetSystemPropertyAction(org.jboss.weld.security.GetSystemPropertyAction) WeldConfiguration(org.jboss.weld.config.WeldConfiguration) File(java.io.File) PrintWriter(java.io.PrintWriter)

Example 32 with BeanDeploymentArchive

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

the class NonBdaExtensionTest method test.

/*
    * description = "WELD-233"
    */
@Test
public void test() {
    // Create the BDA in which we will deploy Observer1 and Foo. This is equivalent to a war or ejb jar
    final BeanDeploymentArchiveImpl bda1 = new BeanDeploymentArchiveImpl("1", Observer1.class, Foo.class);
    // Create the BDA to return from loadBeanDeploymentArchive for Observer2, this is probably a library, though could be another war or ejb jar
    // bda2 is accessible from bda1, but isn't added to it's accessibility graph by default. This similar to an archive which doesn't contain a beans.xml but does contain an extension
    final BeanDeploymentArchive bda2 = new BeanDeploymentArchiveImpl("2", Observer2.class);
    // Create a deployment, that we can use to mirror the structure of one Extension inside a BDA, and one outside
    Deployment deployment = new FlatDeployment(bda1, new Observer1(), new Observer2(), new CountingObserver1(), new CountingObserver2()) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            // Return bda2 if it is Observer2. Stick anything else which this test isn't about in bda1
            if (beanClass.equals(Observer2.class)) {
                // If Observer2 is requested, then we need to add bda2 to the accessibility graph of bda1
                bda1.getBeanDeploymentArchives().add(bda2);
                return bda2;
            } else {
                return bda1;
            }
        }
    };
    TestContainer container = new TestContainer(deployment);
    // Cause the container to deploy the beans etc.
    container.startContainer();
    // Get the bean manager for bda1 and bda2
    BeanManager beanManager1 = container.getBeanManager(bda1);
    BeanManager beanManager2 = container.getBeanManager(bda2);
    Observer1 observer1 = Utils.getReference(beanManager1, Observer1.class);
    Assert.assertTrue(observer1.isBeforeBeanDiscoveryCalled());
    Assert.assertEquals(beanManager1, observer1.getBeforeBeanDiscoveryBeanManager());
    Assert.assertTrue(observer1.isAfterBeanDiscoveryCalled());
    Assert.assertTrue(observer1.isAfterDeploymentValidationCalled());
    Assert.assertTrue(observer1.isProcessInjectionTargetCalled());
    Assert.assertTrue(observer1.isProcessManagedBeanCalled());
    Assert.assertTrue(observer1.isProcessProducerCalled());
    Assert.assertEquals(1, beanManager2.getBeans(Observer2.class).size());
    // Also check that the accessibility graph has been updated
    Assert.assertEquals(1, beanManager1.getBeans(Observer2.class).size());
    Observer2 observer2 = Utils.getReference(beanManager2, Observer2.class);
    Assert.assertTrue(observer2.isBeforeBeanDiscoveryCalled());
    Assert.assertEquals(beanManager2, observer2.getBeforeBeanDiscoveryBeanManager());
    Assert.assertTrue(observer2.isAfterBeanDiscoveryCalled());
    Assert.assertTrue(observer2.isAfterDeploymentValidationCalled());
    Assert.assertTrue(observer2.isProcessInjectionTargetCalled());
    Assert.assertTrue(observer2.isProcessManagedBeanCalled());
    Assert.assertTrue(observer2.isProcessProducerCalled());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 33 with BeanDeploymentArchive

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

the class NonBdaExtensionTest method testEventsSentOnceOnly.

/*
    * description = "WELD-258"
    */
@Test
public void testEventsSentOnceOnly() {
    // Create the BDA in which we will deploy Observer1 and Foo. This is equivalent to a war or ejb jar
    final BeanDeploymentArchiveImpl bda1 = new BeanDeploymentArchiveImpl("1", CountingObserver1.class, Foo.class);
    // Create the BDA to return from loadBeanDeploymentArchive for Observer2, this is probably a library, though could be another war or ejb jar
    // bda2 is accessible from bda1, but isn't added to it's accessibility graph by default. This similar to an archive which doesn't contain a beans.xml but does contain an extension
    final BeanDeploymentArchive bda2 = new BeanDeploymentArchiveImpl("2", CountingObserver2.class);
    // Create a deployment, that we can use to mirror the structure of one Extension inside a BDA, and one outside
    Deployment deployment = new FlatDeployment(bda1, new Observer1(), new Observer2(), new CountingObserver1(), new CountingObserver2()) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            // Return bda2 if it is Observer2. Stick anything else which this test isn't about in bda1
            if (beanClass.equals(CountingObserver2.class) || beanClass.equals(Bar.class)) {
                // If Observer2 is requested, then we need to add bda2 to the accessibility graph of bda1
                bda1.getBeanDeploymentArchives().add(bda2);
                return bda2;
            } else {
                return bda1;
            }
        }
    };
    TestContainer container = new TestContainer(deployment);
    // Cause the container to deploy the beans etc.
    container.startContainer();
    // Get the bean manager for bda1 and bda2
    BeanManager beanManager1 = container.getBeanManager(bda1);
    CountingObserver1 observer1 = Utils.getReference(beanManager1, CountingObserver1.class);
    CountingObserver2 observer2 = Utils.getReference(beanManager1, CountingObserver2.class);
    Assert.assertEquals(1, observer1.getBeforeBeanDiscovery());
    Assert.assertEquals(1, observer1.getProcessFooManagedBean());
    Assert.assertEquals(1, observer1.getProcessBarManagedBean());
    Assert.assertEquals(1, observer2.getBeforeBeanDiscovery());
    Assert.assertEquals(1, observer2.getProcessFooManagedBean());
    Assert.assertEquals(1, observer2.getProcessBarManagedBean());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) BeanManager(javax.enterprise.inject.spi.BeanManager) Test(org.testng.annotations.Test)

Example 34 with BeanDeploymentArchive

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

the class InjectionTargetCreationTest method test.

@Test
public void test() {
    // Create the BDA in which we will deploy FooExtension. This BDA does not have access to bda2
    final BeanDeploymentArchive bda1 = new BeanDeploymentArchiveImpl("1", FooExtension.class);
    // Create the BDA in which we will deploy FooTarget and SimpleBean. This BDA does not have access to bda1
    final BeanDeploymentArchive bda2 = new BeanDeploymentArchiveImpl("2", SimpleBean.class, FooTarget.class);
    final FooExtension extension = new FooExtension();
    // Create a deployment, that we can use to mirror the structure of one Extension inside a BDA, and one outside
    Deployment deployment = new FlatDeployment(new BeanDeploymentArchive[] { bda1, bda2 }, extension) {

        public BeanDeploymentArchive loadBeanDeploymentArchive(Class<?> beanClass) {
            // Return bda2 if it is Observer2. Stick anything else which this test isn't about in bda1
            if (beanClass.equals(FooExtension.class)) {
                return bda1;
            } else {
                return bda2;
            }
        }

        public BeanDeploymentArchive getBeanDeploymentArchive(Class<?> beanClass) {
            return loadBeanDeploymentArchive(beanClass);
        }
    };
    TestContainer container = new TestContainer(deployment);
    // Cause the container to deploy the beans etc.
    container.startContainer();
    InjectionTarget<FooTarget> target = extension.getTarget();
    CreationalContext<FooTarget> ctx = container.getBeanManager(bda2).createCreationalContext(null);
    FooTarget instance = target.produce(ctx);
    target.postConstruct(instance);
    target.inject(instance, ctx);
    /*
         * Verify that the BeanManager for BDA2 (which can see SimpleBean) is used to inject FooTarget
         */
    assertNotNull(instance.getBean());
    container.stopContainer();
}
Also used : TestContainer(org.jboss.arquillian.container.weld.embedded.mock.TestContainer) BeanDeploymentArchiveImpl(org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) FlatDeployment(org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment) Deployment(org.jboss.weld.bootstrap.spi.Deployment) Test(org.testng.annotations.Test)

Example 35 with BeanDeploymentArchive

use of org.jboss.weld.bootstrap.spi.BeanDeploymentArchive in project Payara by payara.

the class WeldDeployer method fireProcessInjectionTargetEvents.

/*
     * We are only firing ProcessInjectionTarget<X> for non-contextual EE components and not using the
     * InjectionTarget<X> from the event during instance creation in JCDIServiceImpl.java TODO weld
     * would provide a better way to do this, otherwise we may need TODO to store InjectionTarget<X> to
     * be used in instance creation
     */
private void fireProcessInjectionTargetEvents(WeldBootstrap bootstrap, DeploymentImpl deploymentImpl) {
    List<BeanDeploymentArchive> beanDeploymentArchives = deploymentImpl.getBeanDeploymentArchives();
    Class<?> messageListenerClass = getMessageListenerClass();
    // Web-Profile and other lighter distributions would not ship the JMS
    // API and implementations.
    // So, the weld-integration layer cannot have a direct dependency on the JMS API
    boolean isFullProfile = messageListenerClass != null;
    for (BeanDeploymentArchive beanDeploymentArchive : beanDeploymentArchives) {
        for (Class<?> bdaClazz : ((BeanDeploymentArchiveImpl) beanDeploymentArchive).getBeanClassObjects()) {
            for (Class<?> nonClazz : NON_CONTEXT_CLASSES) {
                if (nonClazz.isAssignableFrom(bdaClazz)) {
                    firePITEvent(bootstrap, beanDeploymentArchive, bdaClazz);
                }
            }
            // fire <code>ProcessInjectionTarget</code> events (see GLASSFISH-16730)
            if (isFullProfile && messageListenerClass.isAssignableFrom(bdaClazz)) {
                if (logger.isLoggable(FINE)) {
                    logger.log(FINE, MDB_PIT_EVENT, new Object[] { bdaClazz });
                }
                firePITEvent(bootstrap, beanDeploymentArchive, bdaClazz);
            }
        }
    }
}
Also used : BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)

Aggregations

BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)47 WeldBootstrap (org.jboss.weld.bootstrap.WeldBootstrap)11 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)7 HashSet (java.util.HashSet)7 Deployment (org.jboss.weld.bootstrap.spi.Deployment)7 BeanDeploymentArchiveImpl (org.jboss.arquillian.container.weld.embedded.mock.BeanDeploymentArchiveImpl)6 FlatDeployment (org.jboss.arquillian.container.weld.embedded.mock.FlatDeployment)6 TestContainer (org.jboss.arquillian.container.weld.embedded.mock.TestContainer)6 BeansXml (org.jboss.weld.bootstrap.spi.BeansXml)6 BeanManagerImpl (org.jboss.weld.manager.BeanManagerImpl)6 Test (org.testng.annotations.Test)6 BeanManager (javax.enterprise.inject.spi.BeanManager)5 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)4 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)4 Test (org.junit.Test)4 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)3 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)3 Metadata (org.jboss.weld.bootstrap.spi.Metadata)3 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)2 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)2