use of org.jboss.modules.DependencySpec 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.";
final List<DeploymentUnit> deploymentUnits = new ArrayList<DeploymentUnit>();
deploymentUnits.add(deploymentUnit);
deploymentUnits.addAll(deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS));
PropertyReplacingBeansXmlParser parser = new PropertyReplacingBeansXmlParser(deploymentUnit);
final HashSet<URL> existing = new HashSet<URL>();
for (DeploymentUnit deployment : deploymentUnits) {
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));
for (DeploymentUnit deployment : deploymentUnits) {
final Module module = deployment.getAttachment(Attachments.MODULE);
if (module == null) {
return;
}
for (DependencySpec dep : module.getDependencies()) {
final Module dependency = loadModuleDependency(dep);
if (dependency == null) {
continue;
}
Set<URL> urls = findExportedLocalBeansXml(dependency);
if (urls != null) {
List<BeanDeploymentArchiveImpl> moduleBdas = new ArrayList<>();
for (URL url : urls) {
if (existing.contains(url)) {
continue;
}
/*
* Workaround for http://java.net/jira/browse/JAVASERVERFACES-2837
*/
if (url.toString().contains("jsf-impl-2.2")) {
continue;
}
/*
* Workaround for resteasy-cdi bundling beans.xml
*/
if (url.toString().contains("resteasy-cdi")) {
continue;
}
WeldLogger.DEPLOYMENT_LOGGER.debugf("Found external beans.xml: %s", url.toString());
final BeansXml beansXml = parseBeansXml(url, parser, deploymentUnit);
final UrlScanner urlScanner = new UrlScanner();
final List<String> discoveredClasses = new ArrayList<String>();
if (!urlScanner.handleBeansXml(url, discoveredClasses)) {
continue;
}
discoveredClasses.removeAll(componentClassNames);
final BeanDeploymentArchiveImpl bda = new BeanDeploymentArchiveImpl(new HashSet<String>(discoveredClasses), beansXml, dependency, beanArchiveIdPrefix + url.toExternalForm(), BeanArchiveType.EXTERNAL);
WeldLogger.DEPLOYMENT_LOGGER.beanArchiveDiscovered(bda);
// Add module services to external bean deployment archive
for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deployment, module, null).entrySet()) {
bda.getServices().add(entry.getKey(), Reflections.cast(entry.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(url);
}
//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.modules.DependencySpec in project wildfly by wildfly.
the class BeanDeploymentArchiveImpl method isAccessible.
/**
* Determines if a class from this {@link BeanDeploymentArchiveImpl} instance can access a class in the
* {@link BeanDeploymentArchive} instance represented by the specified <code>BeanDeploymentArchive</code> parameter
* according to the Java EE class accessibility requirements.
*
* @param target
* @return true if an only if a class this archive can access a class from the archive represented by the specified parameter
*/
public boolean isAccessible(BeanDeploymentArchive target) {
if (this == target) {
return true;
}
BeanDeploymentArchiveImpl that = (BeanDeploymentArchiveImpl) target;
if (that.getModule() == null) {
/*
* The target BDA is the bootstrap BDA - it bundles classes loaded by the bootstrap classloader.
* Everyone can see the bootstrap classloader.
*/
return true;
}
if (module == null) {
/*
* This BDA is the bootstrap BDA - it bundles classes loaded by the bootstrap classloader. We assume that a
* bean whose class is loaded by the bootstrap classloader can only see other beans in the "bootstrap BDA".
*/
return that.getModule() == null;
}
if (module.equals(that.getModule())) {
return true;
}
// basic check whether the module is our dependency
for (DependencySpec dependency : module.getDependencies()) {
if (dependency instanceof ModuleDependencySpec) {
ModuleDependencySpec moduleDependency = (ModuleDependencySpec) dependency;
if (moduleDependency.getIdentifier().equals(that.getModule().getIdentifier())) {
return true;
}
}
}
/*
* full check - we try to load a class from the target bean archive and check whether its module
* is the same as the one of the bean archive
* See WFLY-4250 for more info
*/
Iterator<String> iterator = target.getBeanClasses().iterator();
if (iterator.hasNext()) {
Class<?> clazz = Reflections.loadClass(iterator.next(), module.getClassLoader());
if (clazz != null) {
Module classModule = Module.forClass(clazz);
return classModule != null && classModule.equals(that.getModule());
}
}
return false;
}
Aggregations