private static void addAnnotations(final DeploymentUnit deploymentUnit, Collection<AnnotationType> annotations) { for(AnnotationType annotation : annotations){ addAnnotation(deploymentUnit, annotation); } }
private void addDependency(ModuleSpecification moduleSpecification, ModuleLoader moduleLoader, ModuleIdentifier moduleIdentifier) { addDependency(moduleSpecification, moduleLoader, moduleIdentifier, false); }
private void handleResourceRoot(Map<ResourceRoot, BeanDeploymentArchiveImpl> bdaMap, ResourceRoot resourceRoot) throws DeploymentUnitProcessingException { BeanDeploymentArchiveImpl bda = processResourceRoot(resourceRoot); if (bda != null) { bdaMap.put(resourceRoot, bda); } }
.build(); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.STRUCTURE, Phase.STRUCTURE_REGISTER_JBOSS_ALL_WELD, jbossAllParsers); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_CONFIGURATION, new WeldConfigurationProcessor(requireBeanDescriptor, nonPortableMode, developmentMode)); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_CDI_ANNOTATIONS, new CdiAnnotationProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_CDI_BEAN_DEFINING_ANNOTATIONS, new BeanDefiningAnnotationProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_DEPLOYMENT, new BeansXmlProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.PARSE, Phase.PARSE_WELD_IMPLICIT_DEPLOYMENT_DETECTION, new WeldImplicitDeploymentProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.DEPENDENCIES, Phase.DEPENDENCIES_WELD, new WeldDependencyProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_WEB_INTEGRATION, new WebIntegrationProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_DEVELOPMENT_MODE, new DevelopmentModeProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_BEAN_ARCHIVE, new BeanArchiveProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_EXTERNAL_BEAN_ARCHIVE, new ExternalBeanArchiveProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_PORTABLE_EXTENSIONS, new WeldPortableExtensionProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.POST_MODULE, Phase.POST_MODULE_WELD_COMPONENT_INTEGRATION, new WeldComponentIntegrationProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_WELD_DEPLOYMENT, new WeldDeploymentProcessor(checkJtsEnabled(context))); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.INSTALL, Phase.INSTALL_WELD_BEAN_MANAGER, new WeldBeanManagerServiceProcessor()); processorTarget.addDeploymentProcessor(WeldExtension.SUBSYSTEM_NAME, Phase.CLEANUP, Phase.CLEANUP_EE - 1, new WeldDeploymentCleanupProcessor());
Index index = tryLoadIndex(indexUrl); if (index != null) { ClassInfo classInfo = index.getClassByName(DotName.createSimple(name)); allKnownClasses.add(name); if (classInfo != null && hasBeanDefiningAnnotation(classInfo, beanDefiningAnnotations)) { discoveredBeanClasses.add(name); try (InputStream in = classFile.openStream()) { ClassInfo classInfo = indexer.index(in); allKnownClasses.add(name); if (classInfo != null && hasBeanDefiningAnnotation(classInfo, beanDefiningAnnotations)) { discoveredBeanClasses.add(name); result.put(ALL_KNOWN_CLASSES, allKnownClasses); result.put(BEAN_CLASSES, discoveredBeanClasses); UrlScanner scanner = new UrlScanner(beansXmlUrl, consumer); return scanner.scan() ? result : null;
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (deploymentUnit.getParent() != null) { return; // only run for top-level deployments } final CompositeIndex index = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX); // CDI built-in normal scopes plus @Dependent addAnnotations(deploymentUnit, CdiAnnotations.BEAN_DEFINING_ANNOTATIONS); // CDI @Model stereotype addAnnotation(deploymentUnit, new AnnotationType(CdiAnnotations.MODEL.getDotName(), false)); // EE7 built-in normal scopes and stereotypes addAnnotation(deploymentUnit, new AnnotationType(TransactionScoped.class)); addAnnotation(deploymentUnit, new AnnotationType(VIEW_SCOPED_NAME, true)); addAnnotation(deploymentUnit, new AnnotationType(FLOW_SCOPED_NAME, true)); for (AnnotationType annotationType : CdiAnnotations.BEAN_DEFINING_META_ANNOTATIONS) { addAnnotations(deploymentUnit, getAnnotationsAnnotatedWith(index, annotationType.getName())); } }
private void handleDirectory(File file, String path) { WeldLogger.DEPLOYMENT_LOGGER.tracef("handling directory: %s", file); for (File child : file.listFiles()) { String newPath = (path == null) ? child.getName() : (path + '/' + child.getName()); if (child.isDirectory()) { handleDirectory(child, newPath); } else { handleFile(newPath, () -> child.toURI().toURL().openStream()); } } }
private BeanDeploymentArchiveImpl createExplicitBeanDeploymentArchive(final Index index, ExplicitBeanArchiveMetadata beanArchiveMetadata, boolean root) throws DeploymentUnitProcessingException { Set<String> classNames = getAllKnownClasses(index); return new BeanDeploymentArchiveImpl(classNames, classNames, beanArchiveMetadata.getBeansXml(), module, createBeanArchiveId(beanArchiveMetadata.getResourceRoot()), BeanArchiveType.EXPLICIT, root); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); if (deploymentUnit.getParent() != null) { return; // only attach the configuration to the root deployment } boolean requireBeanDescriptor = requireBeanDescriptorGlobal; boolean nonPortableMode = nonPortableModeGlobal; boolean developmentMode = developmentModeGlobal; WeldJBossAllConfiguration configuration = deploymentUnit.getAttachment(WeldJBossAllConfiguration.ATTACHMENT_KEY); if (configuration != null) { requireBeanDescriptor = getValue(configuration.getRequireBeanDescriptor(), requireBeanDescriptorGlobal); nonPortableMode = getValue(configuration.getNonPortableMode(), nonPortableModeGlobal); developmentMode = getValue(configuration.getDevelopmentMode(), developmentModeGlobal); } WeldConfiguration mergedConfiguration = new WeldConfiguration(requireBeanDescriptor, nonPortableMode, developmentMode); deploymentUnit.putAttachment(WeldConfiguration.ATTACHMENT_KEY, mergedConfiguration); }
private void handle(String urlPath) { try { WeldLogger.DEPLOYMENT_LOGGER.tracef("scanning: %s", urlPath); if (urlPath.startsWith("file:")) { urlPath = urlPath.substring(5); } if (urlPath.indexOf('!') > 0) { urlPath = urlPath.substring(0, urlPath.indexOf('!')); } File file = new File(urlPath); if (file.isDirectory()) { handleDirectory(file, null); } else { handleArchiveByFile(file); } } catch (IOException ioe) { WeldLogger.DEPLOYMENT_LOGGER.couldNotReadEntries(ioe); } }
private void bindBeanManager(ServiceTarget serviceTarget, ServiceName beanManagerServiceName, ServiceName contextServiceName, final Collection<ServiceName> dependencies, final ServiceRegistry serviceRegistry) { final ServiceName beanManagerBindingServiceName = contextServiceName.append("BeanManager"); dependencies.add(beanManagerBindingServiceName); BinderService beanManagerBindingService = new BinderService("BeanManager"); final BeanManagerManagedReferenceFactory referenceFactory = new BeanManagerManagedReferenceFactory(); beanManagerBindingService.getManagedObjectInjector().inject(referenceFactory); serviceTarget.addService(beanManagerBindingServiceName, beanManagerBindingService) .addDependency(contextServiceName, ServiceBasedNamingStore.class, beanManagerBindingService.getNamingStoreInjector()) .addDependency(beanManagerServiceName, BeanManager.class, referenceFactory.beanManager) .install(); }
@Override public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException { final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit(); // for war modules we require a beans.xml to load portable extensions if (PrivateSubDeploymentMarker.isPrivate(deploymentUnit)) { if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) { return; } } else { // if any deployments have a beans.xml we need to load portable extensions // even if this one does not. if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) { return; } } WeldPortableExtensions extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit); final Module module = deploymentUnit.getAttachment(Attachments.MODULE); ClassLoader oldCl = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(module.getClassLoader()); loadAttachments(module, deploymentUnit, extensions); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(oldCl); } }
protected void handleFile(String name, ClassFile loader) { if (name.endsWith(".class")) { classConsumer.accept(filenameToClassname(name), loader); } }
private void handle(VirtualFile urlPath) { WeldLogger.DEPLOYMENT_LOGGER.tracef("scanning: %s", urlPath); handleDirectory(urlPath, null); }
private void handleArchiveByFile(File file) throws IOException { try { WeldLogger.DEPLOYMENT_LOGGER.trace("archive: " + file); try (ZipFile zip = new ZipFile(file)) { Enumeration<? extends ZipEntry> entries = zip.entries(); while (entries.hasMoreElements()) { ZipEntry entry = entries.nextElement(); String name = entry.getName(); handleFile(name, () -> zip.getInputStream(entry)); } } } catch (ZipException e) { throw new RuntimeException("Error handling file " + file, e); } }
/** * The entry key is bean.xml URL, value is (optional) jandex index URL. * * @param dependencyModule * @return the map of exported resources */ private Map<URL, URL> findExportedResources(Module dependencyModule) { Set<URL> beanXmls = findExportedResource(dependencyModule, META_INF_BEANS_XML); if (beanXmls.isEmpty()) { return Collections.emptyMap(); } Set<URL> indexes = findExportedResource(dependencyModule, META_INF_JANDEX_IDX); Map<URL, URL> ret = new HashMap<>(); for (URL beansXml : beanXmls) { String urlBase = beansXml.toString().substring(0, beansXml.toString().length() - META_INF_BEANS_XML.length()); URL idx = null; for (URL index : indexes) { if (index.toString().startsWith(urlBase)) { idx = index; break; } } ret.put(beansXml, idx); } return ret; }
@Override public Object processInvocation(InterceptorContext context) throws Exception { ManagedReference reference = (ManagedReference) context.getPrivateData(ComponentInstance.class).getInstanceData(BasicComponentInstance.INSTANCE_KEY); if (reference != null) { run(reference.getInstance()); } return context.proceed(); }
private ResourceRootHandler(DeploymentUnit deploymentUnit, Components components, Map<ResourceRoot, Index> indexes) { this.deploymentUnit = deploymentUnit; this.explicitBeanArchives = deploymentUnit.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY); this.module = deploymentUnit.getAttachment(Attachments.MODULE); this.indexes = indexes; this.components = components; this.reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX); this.deploymentResourceRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT); this.classesResourceRoot = deploymentUnit.getAttachment(WeldAttachments.CLASSES_RESOURCE_ROOT); HashSet<AnnotationType> annotationTypes = new HashSet<>(getRootDeploymentUnit(deploymentUnit).getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS)); List<DotName> definingAnnotations = getRootDeploymentUnit(deploymentUnit).getAttachmentList(InjectionTargetDefiningAnnotations.INJECTION_TARGET_DEFINING_ANNOTATIONS); for(DotName annotation : definingAnnotations) { annotationTypes.add(new AnnotationType(annotation, false)); } this.beanDefiningAnnotations = annotationTypes; this.requireBeanDescriptor = getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isRequireBeanDescriptor(); }
private void installBootstrapConfigurationService(WeldDeployment deployment, DeploymentUnit parentDeploymentUnit) { final boolean nonPortableMode = parentDeploymentUnit.getAttachment(WeldConfiguration.ATTACHMENT_KEY).isNonPortableMode(); final ExternalConfiguration configuration = new ExternalConfigurationBuilder() .add(ConfigurationKey.NON_PORTABLE_MODE.get(), nonPortableMode) .add(ConfigurationKey.ALLOW_OPTIMIZED_CLEANUP.get(), true) .build(); deployment.getServices().add(ExternalConfiguration.class, configuration); }
private void handleDirectory(VirtualFile file, String path) { WeldLogger.DEPLOYMENT_LOGGER.tracef("handling directory: %s", file); for (VirtualFile child : file.getChildren()) { String newPath = (path == null) ? child.getName() : (path + '/' + child.getName()); if (child.isDirectory()) { handleDirectory(child, newPath); } else { handleFile(newPath, () -> file.toURL().openStream()); } } }