Skip to content

Commit

Permalink
fixed more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
lprimak committed Oct 28, 2024
1 parent 230e167 commit 1c8a517
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 28 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,7 @@ public BeansXml getBeansXml() {
if (beansXmlURLs.size() == 1) {
result = weldBootstrap.parse(beansXmlURLs.get(0));
} else {
// This method attempts to performs a merge, but loses some
// This method attempts to perform a merge, but loses some
// information (e.g., version, bean-discovery-mode)
result = weldBootstrap.parse(beansXmlURLs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,10 @@ List<RootBeanDeploymentArchive> getRootBDAs() {
return ejbRootBdas;
} else if (rarRootBdas != null) {
return rarRootBdas;
} else {
} else if (libJarRootBdas != null) {
return libJarRootBdas;
} else {
return Collections.emptyList();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext

ReadableArchive archive = context.getSource();

getOrCreateWeldBootstrap(context, applicationInfo);
ensureWeldBootstrapCreated(context, applicationInfo);
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);

EjbServices ejbServices = null;
Expand Down Expand Up @@ -468,28 +468,28 @@ public String getContextIdForArchive(BeanDeploymentArchive archive) {

// ### Private methods


private WeldBootstrap getOrCreateWeldBootstrap(DeploymentContext context, ApplicationInfo appInfo) {
// See if a WeldBootsrap has already been created - only want one per context.
WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
List<WeldBootstrap> toShutdown = appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class);
private WeldBootstrap ensureWeldBootstrapCreated(DeploymentContext context, ApplicationInfo applicationInfo) {
@SuppressWarnings("unchecked")
List<WeldBootstrap> toShutdown = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class);
if (toShutdown == null) {
toShutdown = new ArrayList<>();
appInfo.addTransientAppMetaData(WELD_BOOTSTRAP, toShutdown);
applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, toShutdown);
}

// See if a WeldBootstrap has already been created - only want one per context.
WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);

if (bootstrap == null) {
bootstrap = new WeldBootstrap();

// Stash the WeldBootstrap instance, so we may access the WeldManager later..
// Stash the WeldBootstrap instance, so we may access the WeldManager later...
context.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
toShutdown.add(bootstrap);

// Making sure that if WeldBootstrap is added, shutdown is set to false, as it is/would not have
// been called.
appInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false");
applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false");
}

return bootstrap;
}

Expand All @@ -515,23 +515,18 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) {

try {
invocationManager.preInvoke(componentInvocation);
for (RootBeanDeploymentArchive rootBDA : deploymentImpl.getRootBDAs()) {
DeploymentImpl filtered = deploymentImpl.filter(rootBDA);
WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
bootstrap.startExtensions(postProcessExtensions(filtered.getExtensions(),
filtered.getBeanDeploymentArchives()));
bootstrap.startContainer(filtered.getContextId(), SERVLET, filtered);

//This changes added to pass the following test
// CreateBeanAttributesTest#testBeanAttributesForSessionBean
if (!rootBDA.getBeanDeploymentArchives().isEmpty()) {
createProxyEJBs(rootBDA, bootstrap, componentInvocation, filtered);
// Modern, multiple WARs in an EAR scenario
if (deploymentImpl.ejbRootBdas == null || deploymentImpl.ejbRootBdas.isEmpty()) {
for (RootBeanDeploymentArchive rootBDA : deploymentImpl.getRootBDAs()) {
DeploymentImpl filtered = deploymentImpl.filter(rootBDA);
WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class);
startWeldBootstrap(applicationInfo, rootBDA, bootstrap, filtered, componentInvocation);
}
bootstrap.startInitialization();
fireProcessInjectionTargetEvents(bootstrap, applicationInfo, filtered);
bootstrap.deployBeans();
bootstrap.validateBeans();
bootstrap.endInitialization();
} else if (!deploymentImpl.getRootBDAs().isEmpty()) {
// Legacy EJB-Jar scenario, one Weld instance per EAR
RootBeanDeploymentArchive bda = deploymentImpl.getRootBDAs().get(0);
WeldBootstrap bootstrap = unifyBootstrap(bda, applicationInfo);
startWeldBootstrap(applicationInfo, bda, bootstrap, deploymentImpl, componentInvocation);
}
} catch (Throwable t) {
doBootstrapShutdown(applicationInfo);
Expand All @@ -554,6 +549,32 @@ private void processApplicationLoaded(ApplicationInfo applicationInfo) {
}
}

private WeldBootstrap unifyBootstrap(BeanDeploymentArchiveImpl rootArchive, ApplicationInfo applicationInfo) {
WeldBootstrap bootstrap = ensureWeldBootstrapCreated(rootArchive.context, applicationInfo);
rootArchive.getBeanDeploymentArchives().stream().map(BeanDeploymentArchiveImpl.class::cast)
.forEach(bda -> bda.weldBootstrap = bootstrap);
return bootstrap;
}

private void startWeldBootstrap(ApplicationInfo applicationInfo, RootBeanDeploymentArchive rootBDA,
WeldBootstrap bootstrap, DeploymentImpl deploymentImpl,
ComponentInvocation componentInvocation) {
bootstrap.startExtensions(postProcessExtensions(deploymentImpl.getExtensions(),
deploymentImpl.getBeanDeploymentArchives()));
bootstrap.startContainer(deploymentImpl.getContextId(), SERVLET, deploymentImpl);

//This changes added to pass the following test
// CreateBeanAttributesTest#testBeanAttributesForSessionBean
if (!rootBDA.getBeanDeploymentArchives().isEmpty()) {
createProxyEJBs(rootBDA, bootstrap, componentInvocation, deploymentImpl);
}
bootstrap.startInitialization();
fireProcessInjectionTargetEvents(bootstrap, applicationInfo, deploymentImpl);
bootstrap.deployBeans();
bootstrap.validateBeans();
bootstrap.endInitialization();
}

private static void createProxyEJBs(RootBeanDeploymentArchive warRootBDA, WeldBootstrap bootstrap,
ComponentInvocation componentInvocation, DeploymentImpl deploymentImpl) {
BeanManagerImpl beanManager = bootstrap.getManager(warRootBDA);
Expand Down

0 comments on commit 1c8a517

Please sign in to comment.