Search in sources :

Example 1 with ClassFileServices

use of org.jboss.weld.resources.spi.ClassFileServices in project wildfly by wildfly.

the class WeldClassFileServicesTest method init.

@BeforeClass
public static void init() throws IOException {
    ClassFileServices service = new WeldClassFileServices(IndexUtils.createIndex(Alpha.class, AlphaImpl.class, AbstractAlpha.class, InnerClasses.class, Bravo.class, "org/jboss/as/weld/discovery/vetoed/package-info.class", Inject.class, Named.class, Charlie.class), Thread.currentThread().getContextClassLoader());
    alpha = service.getClassFileInfo(Alpha.class.getName());
    abstractAlpha = service.getClassFileInfo(AbstractAlpha.class.getName());
    alphaImpl = service.getClassFileInfo(AlphaImpl.class.getName());
    innerInterface = service.getClassFileInfo(InnerClasses.InnerInterface.class.getName());
    bravo = service.getClassFileInfo(Bravo.class.getName());
    charlie = service.getClassFileInfo(Charlie.class.getName());
}
Also used : Inject(javax.inject.Inject) Named(javax.inject.Named) ClassFileServices(org.jboss.weld.resources.spi.ClassFileServices) Bravo(org.jboss.as.weld.discovery.vetoed.Bravo) BeforeClass(org.junit.BeforeClass)

Example 2 with ClassFileServices

use of org.jboss.weld.resources.spi.ClassFileServices in project core by weld.

the class Weld method createDeployment.

/**
 * <p>
 * Extensions to Weld SE can subclass and override this method to customize the deployment before weld boots up. For example, to add a custom
 * ResourceLoader, you would subclass Weld like so:
 * </p>
 *
 * <pre>
 * public class MyWeld extends Weld {
 *     protected Deployment createDeployment(ResourceLoader resourceLoader, CDI11Bootstrap bootstrap) {
 *         return super.createDeployment(new MyResourceLoader(), bootstrap);
 *     }
 * }
 * </pre>
 *
 * <p>
 * This could then be used as normal:
 * </p>
 *
 * <pre>
 * WeldContainer container = new MyWeld().initialize();
 * </pre>
 *
 * @param resourceLoader
 * @param bootstrap
 */
protected Deployment createDeployment(ResourceLoader resourceLoader, CDI11Bootstrap bootstrap) {
    final Iterable<Metadata<Extension>> extensions = getExtensions();
    final TypeDiscoveryConfiguration typeDiscoveryConfiguration = bootstrap.startExtensions(extensions);
    final Deployment deployment;
    final Set<WeldBeanDeploymentArchive> beanDeploymentArchives = new HashSet<WeldBeanDeploymentArchive>();
    final Map<Class<? extends Service>, Service> additionalServices = new HashMap<>(this.additionalServices);
    final Set<Class<? extends Annotation>> beanDefiningAnnotations = ImmutableSet.<Class<? extends Annotation>>builder().addAll(typeDiscoveryConfiguration.getKnownBeanDefiningAnnotations()).add(ThreadScoped.class).build();
    if (discoveryEnabled) {
        DiscoveryStrategy strategy = DiscoveryStrategyFactory.create(resourceLoader, bootstrap, beanDefiningAnnotations, isEnabled(Jandex.DISABLE_JANDEX_DISCOVERY_STRATEGY, false));
        if (isImplicitScanEnabled()) {
            strategy.setScanner(new ClassPathBeanArchiveScanner(bootstrap));
        }
        beanDeploymentArchives.addAll(strategy.performDiscovery());
        ClassFileServices classFileServices = strategy.getClassFileServices();
        if (classFileServices != null) {
            additionalServices.put(ClassFileServices.class, classFileServices);
        }
    }
    if (isSyntheticBeanArchiveRequired()) {
        ImmutableSet.Builder<String> beanClassesBuilder = ImmutableSet.builder();
        beanClassesBuilder.addAll(scanPackages());
        Set<String> setOfAllBeanClasses = beanClassesBuilder.build();
        // the creation process differs based on bean discovery mode
        if (BeanDiscoveryMode.ANNOTATED.equals(beanDiscoveryMode)) {
            // Annotated bean discovery mode, filter classes
            ImmutableSet.Builder<String> filteredSetbuilder = ImmutableSet.builder();
            for (String className : setOfAllBeanClasses) {
                Class<?> clazz = Reflections.loadClass(resourceLoader, className);
                if (clazz != null && Reflections.hasBeanDefiningAnnotation(clazz, beanDefiningAnnotations)) {
                    filteredSetbuilder.add(className);
                }
            }
            setOfAllBeanClasses = filteredSetbuilder.build();
        }
        WeldBeanDeploymentArchive syntheticBeanArchive = new WeldBeanDeploymentArchive(WeldDeployment.SYNTHETIC_BDA_ID, setOfAllBeanClasses, null, buildSyntheticBeansXml(), Collections.emptySet(), ImmutableSet.copyOf(beanClasses));
        beanDeploymentArchives.add(syntheticBeanArchive);
    }
    if (beanDeploymentArchives.isEmpty() && this.containerLifecycleObservers.isEmpty() && this.extensions.isEmpty()) {
        throw WeldSELogger.LOG.weldContainerCannotBeInitializedNoBeanArchivesFound();
    }
    Multimap<String, BeanDeploymentArchive> problems = BeanArchives.findBeanClassesDeployedInMultipleBeanArchives(beanDeploymentArchives);
    if (!problems.isEmpty()) {
        // Right now, we only log a warning for each bean class deployed in multiple bean archives
        for (Entry<String, Collection<BeanDeploymentArchive>> entry : problems.entrySet()) {
            WeldSELogger.LOG.beanClassDeployedInMultipleBeanArchives(entry.getKey(), WeldCollections.toMultiRowString(entry.getValue()));
        }
    }
    if (isEnabled(ARCHIVE_ISOLATION_SYSTEM_PROPERTY, true)) {
        deployment = new WeldDeployment(resourceLoader, bootstrap, beanDeploymentArchives, extensions);
        CommonLogger.LOG.archiveIsolationEnabled();
    } else {
        Set<WeldBeanDeploymentArchive> flatDeployment = new HashSet<WeldBeanDeploymentArchive>();
        flatDeployment.add(WeldBeanDeploymentArchive.merge(bootstrap, beanDeploymentArchives));
        deployment = new WeldDeployment(resourceLoader, bootstrap, flatDeployment, extensions);
        CommonLogger.LOG.archiveIsolationDisabled();
    }
    // Register additional services if a service with higher priority not present
    for (Entry<Class<? extends Service>, Service> entry : additionalServices.entrySet()) {
        Services.put(deployment.getServices(), entry.getKey(), entry.getValue());
    }
    return deployment;
}
Also used : WeldBeanDeploymentArchive(org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive) HashMap(java.util.HashMap) Metadata(org.jboss.weld.bootstrap.spi.Metadata) Deployment(org.jboss.weld.bootstrap.spi.Deployment) WeldDeployment(org.jboss.weld.environment.deployment.WeldDeployment) WeldDeployment(org.jboss.weld.environment.deployment.WeldDeployment) DiscoveryStrategy(org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy) TypeDiscoveryConfiguration(org.jboss.weld.bootstrap.api.TypeDiscoveryConfiguration) ImmutableSet(org.jboss.weld.util.collections.ImmutableSet) HashSet(java.util.HashSet) ClassPathBeanArchiveScanner(org.jboss.weld.environment.deployment.discovery.ClassPathBeanArchiveScanner) Service(org.jboss.weld.bootstrap.api.Service) ThreadScoped(org.jboss.weld.environment.se.contexts.ThreadScoped) Annotation(java.lang.annotation.Annotation) ClassFileServices(org.jboss.weld.resources.spi.ClassFileServices) WeldBeanDeploymentArchive(org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive) BeanDeploymentArchive(org.jboss.weld.bootstrap.spi.BeanDeploymentArchive) Collection(java.util.Collection)

Example 3 with ClassFileServices

use of org.jboss.weld.resources.spi.ClassFileServices in project core by weld.

the class WeldStartup method installFastProcessAnnotatedTypeResolver.

// needs to be resolved once extension beans are deployed
private void installFastProcessAnnotatedTypeResolver(ServiceRegistry services) {
    ClassFileServices classFileServices = services.get(ClassFileServices.class);
    if (classFileServices != null) {
        final GlobalObserverNotifierService observers = services.get(GlobalObserverNotifierService.class);
        try {
            final FastProcessAnnotatedTypeResolver resolver = new FastProcessAnnotatedTypeResolver(observers.getAllObserverMethods());
            services.add(FastProcessAnnotatedTypeResolver.class, resolver);
        } catch (UnsupportedObserverMethodException e) {
            BootstrapLogger.LOG.notUsingFastResolver(e.getObserver());
            return;
        }
    }
}
Also used : ClassFileServices(org.jboss.weld.resources.spi.ClassFileServices) GlobalObserverNotifierService(org.jboss.weld.event.GlobalObserverNotifierService)

Aggregations

ClassFileServices (org.jboss.weld.resources.spi.ClassFileServices)3 Annotation (java.lang.annotation.Annotation)1 Collection (java.util.Collection)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Inject (javax.inject.Inject)1 Named (javax.inject.Named)1 Bravo (org.jboss.as.weld.discovery.vetoed.Bravo)1 Service (org.jboss.weld.bootstrap.api.Service)1 TypeDiscoveryConfiguration (org.jboss.weld.bootstrap.api.TypeDiscoveryConfiguration)1 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)1 Deployment (org.jboss.weld.bootstrap.spi.Deployment)1 Metadata (org.jboss.weld.bootstrap.spi.Metadata)1 WeldBeanDeploymentArchive (org.jboss.weld.environment.deployment.WeldBeanDeploymentArchive)1 WeldDeployment (org.jboss.weld.environment.deployment.WeldDeployment)1 ClassPathBeanArchiveScanner (org.jboss.weld.environment.deployment.discovery.ClassPathBeanArchiveScanner)1 DiscoveryStrategy (org.jboss.weld.environment.deployment.discovery.DiscoveryStrategy)1 ThreadScoped (org.jboss.weld.environment.se.contexts.ThreadScoped)1 GlobalObserverNotifierService (org.jboss.weld.event.GlobalObserverNotifierService)1 ImmutableSet (org.jboss.weld.util.collections.ImmutableSet)1