Java Code Examples for javax.enterprise.inject.spi.Extension

The following examples show how to use javax.enterprise.inject.spi.Extension. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: smallrye-metrics   Source File: ArchiveProcessor.java    License: Apache License 2.0 7 votes vote down vote up
@Override
public void process(TestDeployment testDeployment, Archive<?> protocolArchive) {
    WebArchive war = (WebArchive) protocolArchive;
    war.addAsWebInfResource("WEB-INF/jboss-web.xml", "jboss-web.xml");
    String[] deps = {
            "io.smallrye:smallrye-config",
            "io.smallrye:smallrye-metrics",
            "io.smallrye:smallrye-metrics-testsuite-common",
            "org.eclipse.microprofile.metrics:microprofile-metrics-api",
            "org.jboss.weld.servlet:weld-servlet-core"
    };

    File[] dependencies = Maven.resolver().loadPomFromFile(new File("pom.xml")).resolve(deps).withTransitivity().asFile();

    war.addAsLibraries(dependencies);

    war.addClass(SmallRyeBeanArchiveHandler.class);
    war.addClass(MetricsHttpServlet.class);
    war.addClass(MetricsInitializer.class);
    war.addAsResource("io/smallrye/metrics/base-metrics.properties", "/io/smallrye/metrics/base-metrics.properties");
    war.addAsServiceProvider(BeanArchiveHandler.class, SmallRyeBeanArchiveHandler.class);
    war.addAsServiceProvider(Extension.class, ConfigExtension.class);
    war.addAsServiceProvider(ConfigProviderResolver.class, SmallRyeConfigProviderResolver.class);
}
 
Example 2
@Override
public Archive<?> createAuxiliaryArchive() {
    JavaArchive configJar = ShrinkWrap
            .create(JavaArchive.class, "smallrye-config.jar")
            .addPackage(SmallRyeConfig.class.getPackage())
            .addPackage(ConfigExtension.class.getPackage())
            .addAsServiceProvider(Extension.class, ConfigExtension.class)
            .addAsServiceProvider(ConfigProviderResolver.class, SmallRyeConfigProviderResolver.class);
    return configJar;
}
 
Example 3
Source Project: ee8-sandbox   Source File: DynamicGreeterTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment(name = "test")
public static Archive<?> createDeployment() {

    JavaArchive archive = ShrinkWrap.create(JavaArchive.class)
            .addClasses(
                    Greeter.class,
                    Resources.class,
                    CdiConfig.class
            )
            .addAsServiceProvider(Extension.class, CdiConfig.class)
            .addAsManifestResource("META-INF/test-persistence.xml", "persistence.xml")
            .addAsManifestResource("META-INF/test-beans.xml", "beans.xml");
            
    // System.out.println(archive.toString(true));
    return archive;
}
 
Example 4
Source Project: deltaspike   Source File: SimpleMessageTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
public static WebArchive deploy()
{
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "simpleMessageTest.jar")
            .addPackage(SimpleMessageTest.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap
            .create(WebArchive.class, "simpleMessageTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class,
                    MessageBundleExtension.class);
}
 
Example 5
Source Project: openwebbeans-meecrowave   Source File: Cxfs.java    License: Apache License 2.0 6 votes vote down vote up
public static Extension mapCdiExtensionIfNeeded(final Extension extension) {
    if ("org.apache.cxf.cdi.JAXRSCdiResourceExtension".equals(extension.getClass().getName())) {
        final Field serviceBeans;
        try {
            serviceBeans = org.apache.cxf.cdi.JAXRSCdiResourceExtension.class
                    .getDeclaredField("serviceBeans");
        } catch (final NoSuchFieldException e) {
            new org.apache.meecrowave.logging.tomcat.LogFacade(Cxfs.class.getName()).warn(e.getMessage(), e);
            return extension;
        }
        if (!serviceBeans.isAccessible()) {
            serviceBeans.setAccessible(true);
        }
        return new ContractFriendlyJAXRSCdiResourceExtension(serviceBeans);
    }
    return extension;
}
 
Example 6
Source Project: deltaspike   Source File: MessageFormattedMessageTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
public static WebArchive deploy()
{
    Asset beansXml = new StringAsset(
            "<beans><alternatives>" +
                    "<class>" + MessageFormatMessageInterpolator.class.getName() + "</class>" +
                    "</alternatives></beans>"
    );
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "messageFormattedMessageTest.jar")
            .addPackage(MessageFormattedMessageTest.class.getPackage())
            .addAsManifestResource(beansXml, "beans.xml");

    return ShrinkWrap
            .create(WebArchive.class, "messageFormattedMessageTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class,
                    MessageBundleExtension.class);
}
 
Example 7
Source Project: deltaspike   Source File: BrokenMessageBundleOnClassTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
@ShouldThrowException(Exception.class)
public static WebArchive deploy()
{
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "invalidMessageBundleTest.jar")
            .addPackage(BrokenMessageBundleClass.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap
            .create(WebArchive.class, "invalidMessageBundleTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class,
                    MessageBundleExtension.class);
}
 
Example 8
Source Project: deltaspike   Source File: AbstractContextTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
public static WebArchive deploy()
{
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "abstractContextTest.jar")
            .addClass(AbstractContextTest.class)
            .addClass(DummyBean.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class, DummyScopeExtension.class);

    return ShrinkWrap
            .create(WebArchive.class, "abstractContextTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 9
Source Project: deltaspike   Source File: MinimalMessagesTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
public static WebArchive deploy()
{
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "minimalMessageTest.jar")
            .addPackages(false, Filters.exclude(MessageContextTest.class),
                    MinimalMessagesTest.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap
            .create(WebArchive.class, "minimalMessageTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsResource("customMinimalMessage_en.properties")
            .addAsResource("org/apache/deltaspike/test/core/api/message/MinimalMessages_en.properties")
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class,
                    MessageBundleExtension.class);
}
 
Example 10
Source Project: deltaspike   Source File: SimpleCacheTest.java    License: Apache License 2.0 6 votes vote down vote up
@Deployment
public static WebArchive war()
{
    String simpleName = SimpleCacheTest.class.getSimpleName();
    String archiveName = simpleName.substring(0, 1).toLowerCase() + simpleName.substring(1);

    // CDI 1.0/Weld 1.x needs EnableInterceptorsInterceptor
    BeansDescriptor beansWithEnablingInterceptor = Descriptors.create(BeansDescriptor.class);
    beansWithEnablingInterceptor.getOrCreateInterceptors().clazz(EnableInterceptorsInterceptor.class.getName());
    
    // war archive needs SimpleCacheInterceptor enabled
    BeansDescriptor beans = Descriptors.create(BeansDescriptor.class);
    beans.getOrCreateInterceptors().clazz(SimpleCacheInterceptor.class.getName());
      
    JavaArchive testJar = ShrinkWrap.create(JavaArchive.class, archiveName + ".jar")
            .addPackage(SimpleCacheTest.class.getPackage())
            .addAsManifestResource(new StringAsset(beansWithEnablingInterceptor.exportAsString()), "beans.xml");

    return ShrinkWrap.create(WebArchive.class, archiveName + ".war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreAndProxyArchive())
            .addAsLibraries(testJar)
            .addAsServiceProvider(Extension.class, SimpleCacheExtension.class)
            .addAsWebInfResource(new StringAsset(beans.exportAsString()), "beans.xml");
}
 
Example 11
Source Project: deltaspike   Source File: ParentExtensionStorage.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * @return the Extension from the same type but registered in a hierarchic 'parent' BeanManager
 */
public static synchronized <T extends Extension> T getParentExtension(Extension extension)
{
    if (usingParentExtension())
    {
        ClassLoader parentClassLoader = ClassUtils.getClassLoader(null).getParent();

        Iterator<ExtensionStorageInfo> extIt = extensionStorage.iterator();
        while (extIt.hasNext())
        {
            ExtensionStorageInfo extensionInfo = extIt.next();
            if (!extensionInfo.isAbandoned() && // weak reference case
                extension.getClass().equals(extensionInfo.getExtension().getClass()) &&
                extensionInfo.getClassLoader().equals(parentClassLoader))
            {
                return (T) extensionInfo.getExtension();
            }
        }
    }
    return null;
}
 
Example 12
Source Project: deltaspike   Source File: MessageTest.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * X TODO creating a WebArchive is only a workaround because JavaArchive
 * cannot contain other archives.
 */
@Deployment
public static WebArchive deploy()
{
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "messageTest.jar")
            .addPackage(MessageTest.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");

    return ShrinkWrap
            .create(WebArchive.class, "messageTest.war")
            .addAsLibraries(ArchiveUtils.getDeltaSpikeCoreArchive())
            .addAsLibraries(testJar)
            .addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class,
                    MessageBundleExtension.class);
}
 
Example 13
Source Project: smallrye-jwt   Source File: SmallRyeJWTArchiveProcessor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public void process(Archive<?> applicationArchive, TestClass testClass) {
    if (applicationArchive instanceof WebArchive) {
        WebArchive war = (WebArchive) applicationArchive;
        war.addClass(OptionalAwareSmallRyeJWTAuthCDIExtension.class);
        war.addClass(SmallRyeJWTAuthJaxRsFeature.class);
        war.addAsServiceProvider(Extension.class, OptionalAwareSmallRyeJWTAuthCDIExtension.class);

        if (!war.contains("META-INF/microprofile-config.properties")) {
            war.addAsManifestResource("microprofile-config-local.properties", "microprofile-config.properties");
        }

        // A few tests require the apps to be deployed in the root. Check PublicKeyAsJWKLocationURLTest and PublicKeyAsPEMLocationURLTest
        // Both tests set the public key location url to be in root.
        war.addAsWebInfResource("jboss-web.xml");

        String[] deps = {
                "io.smallrye:smallrye-jwt",
                "io.smallrye.config:smallrye-config",
                "org.jboss.resteasy:resteasy-servlet-initializer",
                "org.jboss.resteasy:resteasy-jaxrs",
                "org.jboss.resteasy:resteasy-client",
                "org.jboss.resteasy:resteasy-cdi",
                "org.jboss.resteasy:resteasy-json-binding-provider",
                "org.jboss.weld.servlet:weld-servlet-core"
        };
        File[] dependencies = Maven.resolver()
                .loadPomFromFile(new File("pom.xml"))
                .resolve(deps)
                .withTransitivity()
                .asFile();

        war.addAsLibraries(dependencies);
    }
}
 
Example 14
@Override
public void extend(JavaArchive archive) {
    System.setProperty(STRICT_MODE_PROPERTY, "true");
    archive
            .addPackages(true, ChannelRegistry.class.getPackage())
            .addAsServiceProvider(Extension.class, ReactiveMessagingExtension.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 15
Source Project: weld-junit   Source File: ClassScanning.java    License: Apache License 2.0 5 votes vote down vote up
private static Extension createExtension(Class<? extends Extension> clazz) {
    try {
        return clazz.getDeclaredConstructor().newInstance();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
}
 
Example 16
Source Project: weld-junit   Source File: WeldInitiator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a builder instance.
 *
 * @param beanClasses
 * @return a builder instance
 * @see #of(Class...)
 */
@SuppressWarnings("unchecked")
public static Builder from(Class<?>... beanClasses) {
    Weld weld = createWeld();
    for (Class<?> clazz : beanClasses) {
        if (Extension.class.isAssignableFrom(clazz)) {
            weld.addExtensions((Class<? extends Extension>) clazz);
        } else {
            weld.addBeanClass(clazz);
        }
    }
    return from(weld);
}
 
Example 17
Source Project: weld-junit   Source File: WeldInitiator.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Create a builder instance.
 *
 * @param weld
 * @return a builder instance
 * @see #of(Class...)
 */
public static Builder from(Class<?>... beanClasses) {
    Weld weld = createWeld();
    for (Class<?> clazz : beanClasses) {
        if (Extension.class.isAssignableFrom(clazz)) {
            weld.addExtensions((Class<? extends Extension>) clazz);
        } else {
            weld.addBeanClass(clazz);
        }
    }
    return from(weld);
}
 
Example 18
Source Project: ee8-sandbox   Source File: GreeterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Test(expected = UnsatisfiedResolutionException.class)
public void bootWeldSeContainer() {
    Extension testExtension = ContainerLifecycleObserver.extensionBuilder()
        .add(afterBeanDiscovery((e) -> System.out.println("Bean discovery completed!")))
        .add(processAnnotatedType().notify((e) -> {
            if (e.getAnnotatedType().getJavaClass().getName().startsWith("com.hantsylab")) {
                e.veto();
            }
        })).build();
    try (WeldContainer container = new Weld().addExtension(testExtension).initialize()) {
        Greeter greeter = container.select(Greeter.class).get();
        //assertTrue(greeter == null);
    }

}
 
Example 19
@Override
public <T> List<T> load(final Class<T> serviceType, final ClassLoader classLoader) {
    if (Extension.class == serviceType) {
        return doLoad(serviceType, classLoader)
                .map(e -> serviceType.cast(Cxfs.mapCdiExtensionIfNeeded(Extension.class.cast(e))))
                .collect(toList());
    }
    return doLoad(serviceType, classLoader)
            .collect(toList());
}
 
Example 20
private JAXRSFIeldInjectionAT(final Extension extension, final AnnotatedType<T> original) {
    super(extension, original,
            AnnotatedTypeWrapper.class.isInstance(original) ? AnnotatedTypeWrapper.class.cast(original).getId()
                    : getDefaultId(extension, original));
    this.annotations = new HashSet<>(original.getAnnotations().size() + 1);
    this.annotations.addAll(original.getAnnotations());
    this.annotations.add(JAXRSFieldInjectionInterceptor.Binding.INSTANCE);
}
 
Example 21
Source Project: activemq-artemis   Source File: CDIBootstrapProducerTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> createArchive() {
   return ShrinkWrap.create(JavaArchive.class)
      .addAsServiceProviderAndClasses(Extension.class, ArtemisExtension.class)
      .addClasses(ConnectionFactoryProvider.class, CDIProducers.class)
      .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml");
}
 
Example 22
Source Project: hammock   Source File: FlywayTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addClasses(DataSourceDefinitionBuilder.class)
            .addPackage(EntityManagerFactoryProvider.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class, DataSourceExtension.class, FlywayExtension.class);
}
 
Example 23
Source Project: hammock   Source File: ProgrammaticPUTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addClasses(AnotherEmployeeService.class, ProgrammaticPUTest.class, PUConfiguration.class)
            .addAsServiceProviderAndClasses(Extension.class, DataSourceExtension.class, JPAExtension.class)
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsManifestResource("META-INF/beans.xml", "beans.xml");
}
 
Example 24
Source Project: hammock   Source File: HibernateTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addPackage(HibernateTest.class.getPackage())
            .addAsServiceProviderAndClasses(Extension.class, DataSourceExtension.class, JPAExtension.class)
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsManifestResource("META-INF/beans.xml", "beans.xml")
            .addAsManifestResource("META-INF/load.sql")
            .addAsManifestResource("META-INF/persistence.xml");
}
 
Example 25
Source Project: hammock   Source File: PackageRegisterTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addPackage(Employee.class.getPackage())
            .addAsServiceProviderAndClasses(Extension.class, DataSourceExtension.class, JPAExtension.class)
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsManifestResource("META-INF/beans.xml", "beans.xml")
            .addAsManifestResource("META-INF/load.sql")
            .addAsManifestResource("META-INF/persistence.xml");
}
 
Example 26
Source Project: hammock   Source File: DataSourceTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addClasses(BeanWithDataSource.class, BuilderBackedBean.class,
                    DataSourceDefinitionBuilder.class, SimpleWrapper.class)
            .addPackage(DataSourceDelegateBean.class.getPackage())
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsServiceProvider(Extension.class, DataSourceExtension.class);
}
 
Example 27
Source Project: hammock   Source File: LoggedInTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> deployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addClasses(LoggedIn.class, SecurityInterceptor.class)
            .addAsServiceProviderAndClasses(Extension.class, SecurityExtension.class);
}
 
Example 28
Source Project: hammock   Source File: HasAllRolesTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> deployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addClasses(HasAllRoles.class,  SecurityInterceptor.class)
            .addAsServiceProviderAndClasses(Extension.class, SecurityExtension.class);
}
 
Example 29
Source Project: hammock   Source File: ProgrammaticPUTest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addClasses(AnotherEmployeeService.class, ProgrammaticPUTest.class, PUConfiguration.class)
            .addAsServiceProviderAndClasses(Extension.class, DataSourceExtension.class, JPAExtension.class)
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsManifestResource("META-INF/beans.xml", "beans.xml");
}
 
Example 30
Source Project: hammock   Source File: OpenJPATest.java    License: Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
            .addClasses(Employee.class, EmployeeService.class, OpenJPATest.class, SimpleEmployeeService.class)
       .addAsServiceProviderAndClasses(Extension.class, DataSourceExtension.class, JPAExtension.class)
            .addPackage(EntityManagerProducer.class.getPackage())
            .addAsManifestResource("META-INF/beans.xml", "beans.xml")
            .addAsManifestResource("META-INF/persistence.xml");
}