use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class BeansXmlParsingTest method testExplicitVersionAndMode1.
@Test
public void testExplicitVersionAndMode1() {
BeansXml xml = getBeansXml("cdi11-beans2.xml");
assertEquals(xml.getBeanDiscoveryMode(), BeanDiscoveryMode.NONE);
assertEquals(xml.getVersion(), "1.1");
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class BeansXmlParsingTest method testExplicitVersionAndMode2.
@Test
public void testExplicitVersionAndMode2() {
BeansXml xml = getBeansXml("cdi11-beans3.xml");
assertEquals(xml.getBeanDiscoveryMode(), BeanDiscoveryMode.ANNOTATED);
assertEquals(xml.getVersion(), "1.1");
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project core by weld.
the class BeansXmlParsingTest method testExclusionFilters1.
@Test
public void testExclusionFilters1() {
BeansXml xml = getBeansXml("cdi11-exclude-beans1.xml");
Collection<Metadata<Filter>> filters = xml.getScanning().getExcludes();
assertEquals(filters.size(), 3);
for (Metadata<Filter> filter : filters) {
new FilterPredicate(filter, DefaultResourceLoader.INSTANCE);
}
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project wildfly by wildfly.
the class ExternalBeanArchiveProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
return;
}
if (deploymentUnit.getParent() != null) {
return;
}
final Set<String> componentClassNames = new HashSet<>();
final ServiceLoader<ComponentSupport> supportServices = ServiceLoader.load(ComponentSupport.class, WildFlySecurityManager.getClassLoaderPrivileged(ExternalBeanArchiveProcessor.class));
final String beanArchiveIdPrefix = deploymentUnit.getName() + ".external.";
// This set is used for external bean archives with annotated discovery mode
final Set<AnnotationType> beanDefiningAnnotations = new HashSet<>(deploymentUnit.getAttachment(WeldAttachments.BEAN_DEFINING_ANNOTATIONS));
final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
deploymentUnits.add(deploymentUnit);
deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));
BeansXmlParser parser = BeansXmlParserFactory.getPropertyReplacingParser(deploymentUnit, Utils.getRootDeploymentUnit(deploymentUnit).getAttachment(WeldConfiguration.ATTACHMENT_KEY).isLegacyEmptyBeansXmlTreatment());
final HashSet<URL> existing = new HashSet<URL>();
// build a set of all deployment unit names, used later on to skip processing of some dependencies
final Set<String> depUnitNames = new HashSet<>();
final String prefix = "deployment.";
for (DeploymentUnit deployment : deploymentUnits) {
depUnitNames.add(prefix + deployment.getName());
try {
final ExplicitBeanArchiveMetadataContainer weldDeploymentMetadata = deployment.getAttachment(ExplicitBeanArchiveMetadataContainer.ATTACHMENT_KEY);
if (weldDeploymentMetadata != null) {
for (ExplicitBeanArchiveMetadata md : weldDeploymentMetadata.getBeanArchiveMetadata().values()) {
existing.add(md.getBeansXmlFile().toURL());
if (md.getAdditionalBeansXmlFile() != null) {
existing.add(md.getAdditionalBeansXmlFile().toURL());
}
}
}
} catch (MalformedURLException e) {
throw new DeploymentUnitProcessingException(e);
}
EEModuleDescription moduleDesc = deployment.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
if (moduleDesc != null) {
for (ComponentDescription component : moduleDesc.getComponentDescriptions()) {
for (ComponentSupport support : supportServices) {
if (!support.isDiscoveredExternalType(component)) {
componentClassNames.add(component.getComponentClassName());
break;
}
}
}
}
}
final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
Set<String> skipPrecalculatedJandexModules = getSkipPrecalculatedJandexModules(deploymentUnit);
// This map is a cache that allows us to avoid repeated introspection of Module's exported resources
// it is of little importance for small deployment, but makes a difference in massive ones, see WFLY-14055
Map<String, Map<URL, URL>> exportedResourcesCache = new HashMap<>();
for (DeploymentUnit deployment : deploymentUnits) {
final Module module = deployment.getAttachment(Attachments.MODULE);
if (module == null) {
return;
}
for (DependencySpec dep : module.getDependencies()) {
if (!(dep instanceof ModuleDependencySpec)) {
continue;
}
if (depUnitNames.contains(((ModuleDependencySpec) dep).getName())) {
// we want to skip processing this as it will be (or already was) processed as another dep. unit
continue;
}
final Module dependency = loadModuleDependency(dep);
if (dependency == null) {
continue;
}
Map<URL, URL> resourcesMap = findExportedResources(dependency, exportedResourcesCache);
if (!resourcesMap.isEmpty()) {
List<BeanDeploymentArchiveImpl> moduleBdas = new ArrayList<>();
for (Entry<URL, URL> entry : resourcesMap.entrySet()) {
URL beansXmlUrl = entry.getKey();
if (existing.contains(beansXmlUrl)) {
continue;
}
/*
* Workaround for http://java.net/jira/browse/JAVASERVERFACES-2837
*/
if (beansXmlUrl.toString().contains("jsf-impl-2.2")) {
continue;
}
/*
* Workaround for resteasy-cdi bundling beans.xml
*/
if (beansXmlUrl.toString().contains("resteasy-cdi")) {
continue;
}
/*
* check if the dependency processes META-INF, if it doesn't we don't want to pick up beans
* See https://docs.wildfly.org/17/Developer_Guide.html#CDI_Reference
*/
if (!dep.getImportFilter().accept("META-INF")) {
continue;
}
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found external beans.xml: %s", beansXmlUrl.toString());
final BeansXml beansXml = parseBeansXml(beansXmlUrl, parser, deploymentUnit);
if (BeanDiscoveryMode.NONE.equals(beansXml.getBeanDiscoveryMode())) {
// Scanning suppressed per spec
continue;
}
final boolean skipPrecalculatedJandex = skipPrecalculatedJandexModules.contains(dependency.getName());
Map<String, List<String>> allAndBeanClasses = discover(beansXml.getBeanDiscoveryMode(), beansXmlUrl, entry.getValue(), beanDefiningAnnotations, skipPrecalculatedJandex);
Collection<String> discoveredBeanClasses = allAndBeanClasses.get(BEAN_CLASSES);
Collection<String> allKnownClasses = allAndBeanClasses.get(ALL_KNOWN_CLASSES);
if (discoveredBeanClasses == null) {
// URL scanner probably does not understand the protocol
continue;
}
discoveredBeanClasses.removeAll(componentClassNames);
final BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(new HashSet<String>(discoveredBeanClasses), new HashSet<String>(allKnownClasses), beansXml, dependency, beanArchiveIdPrefix + beansXmlUrl.toExternalForm(), BeanArchiveType.EXTERNAL);
WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
// Add module services to external bean deployment archive
for (Entry<Class<? extends Service>, Service> moduleService : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deployment, module, null).entrySet()) {
bda.getServices().add(moduleService.getKey(), Reflections.cast(moduleService.getValue()));
}
deploymentUnit.addToAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES, bda);
moduleBdas.add(bda);
// make sure that if this beans.xml is seen by some other module, it is not processed twice
existing.add(beansXmlUrl);
}
// BDA's from inside the same module have visibility on each other
for (BeanDeploymentArchiveImpl i : moduleBdas) {
for (BeanDeploymentArchiveImpl j : moduleBdas) {
if (i != j) {
i.addBeanDeploymentArchive(j);
}
}
}
}
}
}
}
use of org.jboss.weld.bootstrap.spi.BeansXml in project Payara by payara.
the class BeanDeploymentArchiveImpl method parseBeansXML.
@SuppressWarnings("unchecked")
protected BeansXml parseBeansXML(ReadableArchive archive, String beansXMLPath) throws IOException {
URL url = getBeansXMLFileURL(archive, beansXMLPath);
BeansXml result = weldBootstrap.parse(url);
JarFileUtils.closeCachedJarFiles();
return result;
}
Aggregations