diff --git a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java index f53bad9ef16..98d633bacc3 100644 --- a/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java +++ b/appserver/concurrent/concurrent-impl/src/main/java/org/glassfish/concurrent/runtime/ContextSetupProviderImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2023] [Payara Foundation and/or its affiliates] package org.glassfish.concurrent.runtime; @@ -378,7 +378,9 @@ public void reset(ContextHandle contextHandle) { restorer.endContext(); } - Utility.setContextClassLoader(handle.getContextClassLoader()); + if (handle.getContextClassLoader() != null) { + Utility.setContextClassLoader(handle.getContextClassLoader()); + } if (handle.getSecurityContext() != null) { SecurityContext.setCurrent(handle.getSecurityContext()); } diff --git a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassLoaderServiceImpl.java b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassLoaderServiceImpl.java index 843503e041d..9839e947c26 100644 --- a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassLoaderServiceImpl.java +++ b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorClassLoaderServiceImpl.java @@ -37,27 +37,22 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package com.sun.appserv.connectors.internal.api; -import jakarta.inject.Provider; -import org.glassfish.deployment.common.DeploymentUtils; import org.glassfish.internal.api.*; -import org.glassfish.internal.deployment.Deployment; import org.jvnet.hk2.annotations.Service; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.*; -import java.util.concurrent.atomic.AtomicReference; -import java.util.function.UnaryOperator; import java.util.logging.Logger; import java.util.logging.Level; import com.sun.logging.LogDomains; import jakarta.inject.Inject; +import jakarta.inject.Provider; /** * We support two policies: @@ -77,13 +72,13 @@ public class ConnectorClassLoaderServiceImpl implements ConnectorClassLoaderServ * class loader for all applications. In other words, we make every * standalone RARs available to all applications. */ - private final AtomicReference globalConnectorCL = new AtomicReference<>(); - private final AtomicReference globalConnectorWithWarLibCL = new AtomicReference<>(); + private volatile DelegatingClassLoader globalConnectorCL; @Inject private AppSpecificConnectorClassLoaderUtil appsSpecificCCLUtil; + @Inject - private Provider connectorsClassLoaderUtil; + private Provider classLoaderHierarchyProvider; private Logger logger = LogDomains.getLogger(ConnectorClassLoaderServiceImpl.class, LogDomains.RSR_LOGGER); @@ -97,8 +92,34 @@ public class ConnectorClassLoaderServiceImpl implements ConnectorClassLoaderServ public DelegatingClassLoader getConnectorClassLoader(String appName) { DelegatingClassLoader loader = null; + // We do not have dependency on common-class-loader explicitly + // and also cannot initialize globalConnectorCL during postConstruct via ClassLoaderHierarchy + // which will result in circular dependency injection between kernel and connector module + // Hence initializing globalConnectorCL lazily + if (globalConnectorCL == null) { + synchronized (ConnectorClassLoaderServiceImpl.class) { + if (globalConnectorCL == null) { + //[parent is assumed to be common-class-loader in ConnectorClassLoaderUtil.createRARClassLoader() also] + final ClassLoader parent = getCommonClassLoader(); + globalConnectorCL = AccessController.doPrivileged(new PrivilegedAction() { + public DelegatingClassLoader run() { + DelegatingClassLoader dcl = new DelegatingClassLoader(parent); + for (DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()) { + dcl.addDelegate(cf); + } + return dcl; + } + }); + + for (DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()) { + globalConnectorCL.addDelegate(cf); + } + } + } + } if (hasGlobalAccessForRARs(appName)) { - loader = getGlobalConnectorClassLoader(); + assert (globalConnectorCL != null); + loader = globalConnectorCL; } else { appsSpecificCCLUtil.detectReferredRARs(appName); loader = createConnectorClassLoaderForApplication(appName); @@ -112,42 +133,14 @@ private boolean hasGlobalAccessForRARs(String appName) { (ConnectorConstants.RAR_VISIBILITY_GLOBAL_ACCESS); } - private DelegatingClassLoader getGlobalConnectorClassLoader() { - // We do not have dependency on common-class-loader explicitly - // and also cannot initialize globalConnectorCL during postConstruct via ClassLoaderHierarchy - // which will result in circular dependency injection between kernel and connector module - // Hence initializing globalConnectorCL lazily - UnaryOperator updateOperator = currentValue -> { - if (currentValue == null) { - //[parent is assumed to be common-class-loader in ConnectorClassLoaderUtil.createRARClassLoader() also] - var newValue = AccessController.doPrivileged(new PrivilegedAction() { - public DelegatingClassLoader run() { - DelegatingClassLoader dcl = new DelegatingClassLoader(connectorsClassLoaderUtil.get().getCommonClassLoader()); - for (DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()) { - dcl.addDelegate(cf); - } - return dcl; - } - }); - - for (DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()) { - newValue.addDelegate(cf); - } - return newValue; - } - return currentValue; - }; - if (DeploymentUtils.useWarLibraries(DeploymentUtils.getCurrentDeploymentContext())) { - return globalConnectorWithWarLibCL.updateAndGet(updateOperator); - } else { - return globalConnectorCL.updateAndGet(updateOperator); - } + private ClassLoader getCommonClassLoader(){ + return classLoaderHierarchyProvider.get().getCommonClassLoader(); } private DelegatingClassLoader createConnectorClassLoaderForApplication(String appName){ DelegatingClassLoader appSpecificConnectorClassLoader = - new DelegatingClassLoader(connectorsClassLoaderUtil.get().getCommonClassLoader()); + new DelegatingClassLoader(getCommonClassLoader()); //add system ra classloaders for(DelegatingClassLoader.ClassFinder cf : appsSpecificCCLUtil.getSystemRARClassLoaders()){ @@ -185,7 +178,7 @@ private void addRarClassLoader(String appName, DelegatingClassLoader appSpecific } private DelegatingClassLoader.ClassFinder getClassFinder(String raName) { - List delegates = getGlobalConnectorClassLoader().getDelegates(); + List delegates = globalConnectorCL.getDelegates(); DelegatingClassLoader.ClassFinder classFinder = null; for(DelegatingClassLoader.ClassFinder cf : delegates){ if(raName.equals(((ConnectorClassFinder)cf).getResourceAdapterName())){ @@ -195,4 +188,5 @@ private DelegatingClassLoader.ClassFinder getClassFinder(String raName) { } return classFinder; } + } diff --git a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorsClassLoaderUtil.java b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorsClassLoaderUtil.java index 16368f267cf..015067aa5aa 100644 --- a/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorsClassLoaderUtil.java +++ b/appserver/connectors/connectors-internal-api/src/main/java/com/sun/appserv/connectors/internal/api/ConnectorsClassLoaderUtil.java @@ -37,21 +37,15 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package com.sun.appserv.connectors.internal.api; -import com.sun.enterprise.loader.CurrentBeforeParentClassLoader; -import org.glassfish.deployment.common.DeploymentUtils; -import org.glassfish.deployment.common.InstalledLibrariesResolver; import org.glassfish.internal.api.ClassLoaderHierarchy; import org.glassfish.internal.api.DelegatingClassLoader; import org.glassfish.api.admin.*; import org.glassfish.api.event.Events; import org.glassfish.api.event.EventListener; import org.glassfish.api.event.EventTypes; -import org.glassfish.internal.api.Globals; -import org.glassfish.internal.deployment.Deployment; import org.jvnet.hk2.annotations.Service; import jakarta.inject.Singleton; @@ -59,11 +53,9 @@ import java.io.*; import java.net.MalformedURLException; import java.net.URI; -import java.net.URL; import java.security.AccessController; import java.security.PrivilegedExceptionAction; import java.security.PrivilegedActionException; -import java.util.concurrent.atomic.AtomicReference; import java.util.logging.Level; import java.util.logging.Logger; import java.util.Collection; @@ -89,8 +81,7 @@ public class ConnectorsClassLoaderUtil { @Inject private ClassLoaderHierarchy clh; - // warLibClassLoader is used to load libraries from the war file - private final AtomicReference warLibClassLoader = new AtomicReference<>(); + //private static List systemRARClassLoaders; private Logger _logger = LogDomains.getLogger(ConnectorRuntime.class, LogDomains.RSR_LOGGER); @@ -218,7 +209,7 @@ public Collection getSystemRARClassLoaders() throws Connec libraries = ConnectorsUtil.getInstalledLibrariesFromManifest(location, env); } - ConnectorClassFinder ccf = createRARClassLoader(location, getCommonClassLoader(), rarName, libraries); + ConnectorClassFinder ccf = createRARClassLoader(location, null, rarName, libraries); classLoaders.add(ccf); } // systemRARClassLoaders = classLoaders; @@ -227,29 +218,6 @@ public Collection getSystemRARClassLoaders() throws Connec return classLoaders; } - public ClassLoader getCommonClassLoader() { - if (DeploymentUtils.useWarLibraries(DeploymentUtils.getCurrentDeploymentContext())) { - return warLibClassLoader.updateAndGet(currentValue -> { - if (currentValue == null) { - var newValue = new CurrentBeforeParentClassLoader(InstalledLibrariesResolver.getWarLibraries() - .stream().map(uri -> { - try { - return uri.toUri().toURL(); - } catch (MalformedURLException e) { - throw new RuntimeException(e); - } - }) - .toArray(URL[]::new), clh.getCommonClassLoader()); - newValue.enableCurrentBeforeParentUnconditional(); - return newValue; - } - return currentValue; - }); - } else { - return clh.getCommonClassLoader(); - } - } - public ConnectorClassFinder getSystemRARClassLoader(String rarName) throws ConnectorRuntimeException { if (ConnectorsUtil.belongsToSystemRA(rarName)) { diff --git a/appserver/deployment/javaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarDeployer.java b/appserver/deployment/javaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarDeployer.java index 66f93f89b78..ac8567bdd46 100644 --- a/appserver/deployment/javaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarDeployer.java +++ b/appserver/deployment/javaee-full/src/main/java/org/glassfish/javaee/full/deployment/EarDeployer.java @@ -37,7 +37,6 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package org.glassfish.javaee.full.deployment; @@ -102,7 +101,7 @@ @Service @PerLookup public class EarDeployer implements Deployer { - public static final String PER_BDA_METADATA_KEY = "[PerBDA]"; + // private static final Class GLASSFISH_APPCLIENT_GROUP_FACADE_CLASS = // org.glassfish.appclient.client.AppClientGroupFacade.class; // Currently using a string instead of a Class constant to avoid a circular @@ -458,21 +457,15 @@ public U getCommandParameters(Class commandParametersTy @Override public void addTransientAppMetaData(String metaDataKey, Object metaData) { - if (metaDataKey.startsWith(PER_BDA_METADATA_KEY)) { - super.addTransientAppMetaData(metaDataKey, metaData); - } else { - context.addTransientAppMetaData(metaDataKey, metaData); - } + context.addTransientAppMetaData(metaDataKey, + metaData); } @Override public T getTransientAppMetaData(String metaDataKey, Class metadataType) { - if (metaDataKey.startsWith(PER_BDA_METADATA_KEY)) { - return super.getTransientAppMetaData(metaDataKey, metadataType); - } else { - return context.getTransientAppMetaData(metaDataKey, metadataType); - } + return context.getTransientAppMetaData(metaDataKey, + metadataType); } @Override diff --git a/appserver/web/gf-weld-connector/src/main/java/org/glassfish/weld/connector/WeldUtils.java b/appserver/web/gf-weld-connector/src/main/java/org/glassfish/weld/connector/WeldUtils.java index f5f8050012c..2c8eb51d0fa 100644 --- a/appserver/web/gf-weld-connector/src/main/java/org/glassfish/weld/connector/WeldUtils.java +++ b/appserver/web/gf-weld-connector/src/main/java/org/glassfish/weld/connector/WeldUtils.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates] package org.glassfish.weld.connector; @@ -48,13 +48,9 @@ import java.io.InputStream; import java.lang.annotation.Annotation; import java.net.URI; -import java.nio.file.Path; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Objects; import java.util.Set; import jakarta.decorator.Decorator; @@ -64,7 +60,6 @@ import jakarta.enterprise.context.*; import jakarta.enterprise.inject.Model; import jakarta.enterprise.inject.Stereotype; -import jakarta.faces.flow.FlowScoped; import jakarta.inject.Inject; import jakarta.inject.Scope; import jakarta.inject.Singleton; @@ -73,7 +68,6 @@ import org.glassfish.api.admin.ServerEnvironment; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.archive.ReadableArchive; -import org.glassfish.deployment.common.DeploymentUtils; import org.glassfish.hk2.api.ServiceLocator; import org.glassfish.hk2.classmodel.reflect.AnnotationModel; import org.glassfish.hk2.classmodel.reflect.AnnotationType; @@ -89,7 +83,6 @@ import org.xml.sax.helpers.DefaultHandler; import java.util.logging.Logger; import java.util.logging.Level; -import java.util.stream.Collectors; public class WeldUtils { @@ -142,7 +135,6 @@ public enum BDAType { WAR, JAR, RAR, UNKNOWN }; cdi.add("jakarta.faces.view.ViewScoped"); cdi.add("jakarta.faces.flow.FlowScoped"); cdi.add(ConversationScoped.class.getName()); - cdi.add(FlowScoped.class.getName()); cdi.add(ApplicationScoped.class.getName()); cdi.add(SessionScoped.class.getName()); cdi.add(RequestScoped.class.getName()); @@ -226,13 +218,16 @@ public static boolean hasCDIEnablingAnnotations(DeploymentContext context, URI p * @return true, if there is at least one bean annotated with a qualified annotation in the specified paths */ public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Collection paths) { - final Set exclusions = new HashSet<>(); - for (final Type type : getAllTypes(context, paths)) { - if (!(type instanceof AnnotationType) && type.wasDefinedIn(paths)) { - for (final AnnotationModel am : type.getAnnotations()) { - final AnnotationType at = am.getType(); - if (isCDIEnablingAnnotation(at, exclusions)) { - return true; + final Types types = getTypes(context); + if (types != null) { + final Set exclusions = new HashSet<>(); + for (final Type type : types.getAllTypes()) { + if (!(type instanceof AnnotationType) && type.wasDefinedIn(paths)) { + for (final AnnotationModel am : type.getAnnotations()) { + final AnnotationType at = am.getType(); + if (isCDIEnablingAnnotation(at, exclusions)) { + return true; + } } } } @@ -241,6 +236,7 @@ public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Colle return false; } + /** * Get the names of any annotation types that are applied to beans, which should enable CDI * processing even in the absence of a beans.xml descriptor. @@ -252,13 +248,16 @@ public static boolean hasCDIEnablingAnnotations(DeploymentContext context, Colle public static String[] getCDIEnablingAnnotations(DeploymentContext context) { final Set result = new HashSet<>(); - final Set exclusions = new HashSet<>(); - for (final Type type : getAllTypes(context, List.of())) { - if (!(type instanceof AnnotationType)) { - for (final AnnotationModel am : type.getAnnotations()) { - final AnnotationType at = am.getType(); - if (isCDIEnablingAnnotation(at, exclusions)) { - result.add(at.getName()); + final Types types = getTypes(context); + if (types != null) { + final Set exclusions = new HashSet<>(); + for (final Type type : types.getAllTypes()) { + if (!(type instanceof AnnotationType)) { + for (final AnnotationModel am : type.getAnnotations()) { + final AnnotationType at = am.getType(); + if (isCDIEnablingAnnotation(at, exclusions)) { + result.add(at.getName()); + } } } } @@ -281,13 +280,16 @@ public static Collection getCDIAnnotatedClassNames(DeploymentContext con final Set cdiEnablingAnnotations = new HashSet<>(); Collections.addAll(cdiEnablingAnnotations, getCDIEnablingAnnotations(context)); - for (final Type type : getAllTypes(context, List.of())) { - if (!(type instanceof AnnotationType)) { - for (final AnnotationModel am : type.getAnnotations()) { - final AnnotationType at = am.getType(); - if (cdiEnablingAnnotations.contains(at.getName())) { - result.add(type.getName()); - break; + final Types types = getTypes(context); + if (types != null) { + for (final Type type : types.getAllTypes()) { + if (!(type instanceof AnnotationType)) { + for (final AnnotationModel am : type.getAnnotations()) { + final AnnotationType at = am.getType(); + if (cdiEnablingAnnotations.contains(at.getName())) { + result.add(type.getName()); + break; + } } } } @@ -702,24 +704,6 @@ public static String getBeanDiscoveryMode(InputStream beansXmlInputStream) { return beanDiscoveryMode; } - private static List getAllTypes(DeploymentContext context, Collection paths) { - final Types types = getTypes(context); - if (types == null) { - return List.of(); - } - - List allTypes = new ArrayList<>(types.getAllTypes()); - Map cache = DeploymentUtils.getWarLibraryCache(); - for (URI path : paths.isEmpty() ? cache.keySet().stream().map(Path::of).map(Path::toUri) - .collect(Collectors.toList()) : paths) { - var descriptor = cache.get(path.getRawPath()); - if (descriptor != null) { - allTypes.addAll(descriptor.getTypes()); - } - } - return allTypes; - } - private static class LocalDefaultHandler extends DefaultHandler { String beanDiscoveryMode = null; diff --git a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/CachingReflectionUtil.java b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/CachingReflectionUtil.java index 2d516ab184a..e43996df5ea 100644 --- a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/CachingReflectionUtil.java +++ b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/CachingReflectionUtil.java @@ -42,49 +42,60 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; +import java.util.Map; +import java.util.concurrent.ConcurrentHashMap; +import java.util.logging.Level; +import java.util.logging.Logger; -/** - * @deprecated This class is not used and will be removed in a future release. - * Functionality has been moved to {@link com.sun.enterprise.loader.CachingReflectionUtil}. - */ -@Deprecated(forRemoval = true) public class CachingReflectionUtil { - /** - * @deprecated This method is not used and will be removed in a future release. - * Functionality has been moved to {@link com.sun.enterprise.loader.CachingReflectionUtil}. - * @param className - * @param classLoader - * @return - */ - @Deprecated(forRemoval = true) + private static final Logger logger = LogFacade.getLogger(); + private static final Map> classCache = new ConcurrentHashMap<>(); + private static final Map methodCache = new ConcurrentHashMap<>(); + private static final Map fieldCache = new ConcurrentHashMap<>(); + public static Class getClassFromCache(String className, ClassLoader classLoader) { - return com.sun.enterprise.loader.CachingReflectionUtil.getClassFromCache(className, classLoader); + var cls = classCache.computeIfAbsent(className, k -> { + try { + return classLoader.loadClass(className); + } catch (ClassNotFoundException e) { + logger.log(Level.FINE, "Class not found: " + className, e); + return null; + } + }); + return cls; } - /** - * @deprecated This method is not used and will be removed in a future release. - * Functionality has been moved to {@link com.sun.enterprise.loader.CachingReflectionUtil}. - * @param cls - * @param methodName - * @param isPrivate - * @param parameterTypes - * @return - */ - @Deprecated(forRemoval = true) public static Method getMethodFromCache(Class cls, String methodName, boolean isPrivate, Class... parameterTypes) { - return com.sun.enterprise.loader.CachingReflectionUtil.getMethodFromCache(cls, methodName, isPrivate, parameterTypes); + return methodCache.computeIfAbsent(methodName, k -> { + try { + if (isPrivate) { + Method method = cls.getDeclaredMethod(methodName, parameterTypes); + method.setAccessible(true); + return method; + } else { + return cls.getMethod(methodName, parameterTypes); + } + } catch (NoSuchMethodException e) { + logger.log(Level.FINE, "Method not found: " + methodName, e); + return null; + } + }); } - /** - * @deprecated This method is not used and will be removed in a future release. - * Functionality has been moved to {@link com.sun.enterprise.loader.CachingReflectionUtil}. - * @param cls - * @param fieldName - * @param isPrivate - * @return - */ - @Deprecated(forRemoval = true) public static Field getFieldFromCache(Class cls, String fieldName, boolean isPrivate) { - return com.sun.enterprise.loader.CachingReflectionUtil.getFieldFromCache(cls, fieldName, isPrivate); + return fieldCache.computeIfAbsent(fieldName, k -> { + try { + if (isPrivate) { + Field field = cls.getDeclaredField(fieldName); + field.setAccessible(true); + return field; + } else { + return cls.getField(fieldName); + } + } catch (NoSuchFieldException e) { + logger.log(Level.FINE, "Field not found: " + fieldName, e); + return null; + } + }); } } diff --git a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java index 2d50b915609..93578a1a19a 100644 --- a/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java +++ b/appserver/web/war-util/src/main/java/org/glassfish/web/loader/WebappClassLoader.java @@ -65,7 +65,6 @@ import com.sun.enterprise.deployment.Application; import com.sun.enterprise.deployment.util.DOLUtils; import com.sun.enterprise.glassfish.bootstrap.MainHelper.HotSwapHelper; -import com.sun.enterprise.loader.CacheCleaner; import com.sun.enterprise.security.integration.DDPermissionsLoader; import com.sun.enterprise.security.integration.PermsHolder; import com.sun.enterprise.util.io.FileUtils; @@ -2052,7 +2051,7 @@ public void stop() throws Exception { // START SJSAS 6258619 ClassLoaderUtil.releaseLoader(this); // END SJSAS 6258619 - CacheCleaner.clearCaches(this); + clearJaxRSCache(); synchronized(jarFilesLock) { started = false; @@ -2659,6 +2658,23 @@ private void clearReferencesRmiTargets() { } } + private void clearJaxRSCache() { + try { + Class cdiComponentProvider = CachingReflectionUtil + .getClassFromCache("org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider", this); + if (cdiComponentProvider != null) { + Field runtimeSpecificsField = CachingReflectionUtil.getFieldFromCache(cdiComponentProvider, + "runtimeSpecifics", true); + Object runtimeSpecifics = runtimeSpecificsField.get(null); + CachingReflectionUtil.getMethodFromCache(runtimeSpecifics.getClass(), + "clearJaxRsResource", true, ClassLoader.class) + .invoke(runtimeSpecifics, this); + } + } catch (Exception e) { + logger.log(Level.WARNING, "Error clearing Jax-Rs cache", e); + } + } + /** * Clear the {@link ResourceBundle} cache of any bundles loaded by this * class loader or any class loader where this loader is a parent class diff --git a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/annotation/impl/WarScanner.java b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/annotation/impl/WarScanner.java index fb8e0536f3b..bccd46a1e53 100644 --- a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/annotation/impl/WarScanner.java +++ b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/annotation/impl/WarScanner.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2021] [Payara Foundation and/or its affiliates] package org.glassfish.web.deployment.annotation.impl; @@ -98,15 +98,7 @@ public void process(File archiveFile, WebBundleDescriptor webBundleDesc, public void process(ReadableArchive readableArchive, WebBundleDescriptor webBundleDesc, ClassLoader classLoader, Parser parser) throws IOException { - WebFragmentDescriptor webFragmentDesc = new WebFragmentDescriptor(); - if (webBundleDesc instanceof WebFragmentDescriptor) { - webFragmentDesc = (WebFragmentDescriptor) webBundleDesc; - } - if (webFragmentDesc.isWarLibrary()) { - this.archiveFile = new File(webFragmentDesc.getWarLibraryPath()); - } else { - this.archiveFile = new File(readableArchive.getURI()); - } + this.archiveFile = new File(readableArchive.getURI()); this.classLoader = classLoader; setParser(parser); @@ -116,7 +108,7 @@ public void process(ReadableArchive readableArchive, WebBundleDescriptor webBund AnnotationUtils.getLogger().log(Level.FINE, "classLoader is {0}", classLoader); } - if (!webFragmentDesc.isWarLibrary() && !archiveFile.isDirectory()) { + if (!archiveFile.isDirectory()) { // on client side return; } @@ -130,19 +122,16 @@ public void process(ReadableArchive readableArchive, WebBundleDescriptor webBund File webinf = new File(archiveFile, "WEB-INF"); if (webBundleDesc instanceof WebFragmentDescriptor) { - if (webFragmentDesc.isWarLibrary()) { - addScanJar(archiveFile); - } else { - File lib = new File(webinf, "lib"); - if (lib.exists()) { - File jarFile = new File(lib, webFragmentDesc.getJarName()); - if (jarFile.exists()) { - // support exploded jar file - if (jarFile.isDirectory()) { - addScanDirectory(jarFile); - } else { - addScanJar(jarFile); - } + WebFragmentDescriptor webFragmentDesc = (WebFragmentDescriptor)webBundleDesc; + File lib = new File(webinf, "lib"); + if (lib.exists()) { + File jarFile = new File(lib, webFragmentDesc.getJarName()); + if (jarFile.exists()) { + // support exploded jar file + if (jarFile.isDirectory()) { + addScanDirectory(jarFile); + } else { + addScanJar(jarFile); } } } diff --git a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/archivist/WebArchivist.java b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/archivist/WebArchivist.java index eca18f0b6f6..83498d21c09 100644 --- a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/archivist/WebArchivist.java +++ b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/archivist/WebArchivist.java @@ -37,23 +37,16 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2014-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2014-2021] [Payara Foundation and/or its affiliates] package org.glassfish.web.deployment.archivist; -import com.sun.enterprise.deploy.shared.ArchiveFactory; import com.sun.enterprise.deployment.Application; -import com.sun.enterprise.deployment.EarType; -import org.glassfish.deployment.common.InstalledLibrariesResolver; import org.glassfish.deployment.common.RootDeploymentDescriptor; import com.sun.enterprise.deployment.EjbBundleDescriptor; import com.sun.enterprise.deployment.EjbDescriptor; import com.sun.enterprise.deployment.WebComponentDescriptor; import com.sun.enterprise.deployment.annotation.impl.ModuleScanner; -import org.glassfish.hk2.classmodel.reflect.Parser; -import org.glassfish.hk2.classmodel.reflect.Type; -import org.glassfish.hk2.classmodel.reflect.Types; -import org.glassfish.internal.deployment.Deployment; import org.glassfish.web.deployment.annotation.impl.WarScanner; import com.sun.enterprise.deployment.archivist.Archivist; import com.sun.enterprise.deployment.archivist.ArchivistFor; @@ -79,18 +72,15 @@ import java.io.IOException; import java.io.InputStream; import java.io.File; -import java.nio.file.Path; import java.util.ArrayList; import java.util.Enumeration; import java.util.HashMap; -import java.util.LinkedHashSet; import java.util.List; import java.util.Map; -import java.util.Set; +import java.util.Vector; import java.net.URL; import java.util.logging.Level; import java.util.logging.Logger; -import java.util.stream.Collectors; /** @@ -113,10 +103,6 @@ public class WebArchivist extends Archivist { private ServerEnvironment env; private WebBundleDescriptorImpl defaultWebXmlBundleDescriptor = null; - @Inject - private ArchiveFactory archiveFactory; - @Inject - private Deployment deployment; /** * @return the module type handled by this archivist @@ -310,37 +296,24 @@ protected String getArchiveExtension() { /** * @return a list of libraries included in the archivist */ - public Set getLibraries(ReadableArchive archive) throws IOException { - Set libraries = new LinkedHashSet<>(); - // WAR libraries - extractLibraries(archive, true, libraries); - ReadableArchive parentArchive = archive.getParentArchive(); - if (parentArchive != null && parentArchive.getExtraData(ArchiveType.class).toString().equals(EarType.ARCHIVE_TYPE)) { - // EAR shared libraries - extractLibraries(parentArchive.getSubArchive("lib"), false, libraries); - } - // Webapp shared libraries - if(DeploymentUtils.useWarLibraries(deployment.getCurrentDeploymentContext())) { - InstalledLibrariesResolver.getWarLibraries().forEach(warLibrary -> libraries.add(warLibrary.toString())); - } - return libraries; - } + public Vector getLibraries(Archive archive) { - private static void extractLibraries(Archive archive, boolean hasWebInfPrefix, Set libs) { - Enumeration entries = archive != null ? archive.entries() : null; + Enumeration entries = archive.entries(); if (entries==null) - return; + return null; + Vector libs = new Vector(); while (entries.hasMoreElements()) { String entryName = entries.nextElement(); - if (hasWebInfPrefix && !entryName.startsWith("WEB-INF/lib")) { - continue; // not in prefix (i.e. WEB-INF)... + if (!entryName.startsWith("WEB-INF/lib")) { + continue; // not in WEB-INF... } if (entryName.endsWith(".jar")) { libs.add(entryName); } } + return libs; } @Override @@ -360,27 +333,10 @@ protected void postAnnotationProcess(WebBundleDescriptorImpl descriptor, // all web fragment metadata-complete // should be overridden and be true also if (descriptor.isFullAttribute()) { - wfDesc.setFullAttribute( - String.valueOf(descriptor.isFullAttribute())); - } - if (wfDesc.isWarLibrary()) { - if (!DeploymentUtils.getWarLibraryCache().containsKey(wfDesc.getWarLibraryPath())) { - ReadableArchive warArchive = null; - try { - warArchive = archiveFactory.openArchive(new File(wfDesc.getWarLibraryPath())); - warArchive.setExtraData(Parser.class, archive.getExtraData(Parser.class)); - super.readAnnotations(warArchive, wfDesc, localExtensions); - } finally { - if (warArchive != null) { - warArchive.close(); - } - } - DeploymentUtils.getWarLibraryCache().putIfAbsent(wfDesc.getWarLibraryPath(), - new DeploymentUtils.WarLibraryDescriptor(wfDesc, filterTypesByWarLibrary(wfDesc))); - } - } else { - super.readAnnotations(archive, wfDesc, localExtensions); + wfDesc.setFullAttribute( + String.valueOf(descriptor.isFullAttribute())); } + super.readAnnotations(archive, wfDesc, localExtensions); } // scan manifest classpath @@ -418,15 +374,6 @@ protected void postAnnotationProcess(WebBundleDescriptorImpl descriptor, descriptor.addDefaultWebBundleDescriptor(defaultWebBundleDescriptor); } - private List filterTypesByWarLibrary(WebFragmentDescriptor wfDesc) { - Types types = deployment.getCurrentDeploymentContext().getTransientAppMetaData(Types.class.getName(), Types.class); - if (types == null) { - return List.of(); - } - return types.getAllTypes().stream().filter(key -> key.wasDefinedIn( - List.of(Path.of(wfDesc.getWarLibraryPath()).toUri()))).collect(Collectors.toList()); - } - /** * This method will return the list of web fragment in the desired order. */ @@ -434,67 +381,54 @@ private List readStandardFragments(WebBundleDescriptorImp ReadableArchive archive) throws IOException { List wfList = new ArrayList(); - for (String lib : getLibraries(archive)) { - Archivist wfArchivist = new WebFragmentArchivist(this, habitat); - wfArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation()); - wfArchivist.setRuntimeXMLValidationLevel( - this.getRuntimeXMLValidationLevel()); - wfArchivist.setAnnotationProcessingRequested(false); - - WebFragmentDescriptor wfDesc = null; - ReadableArchive embeddedArchive = null; - boolean isWarLibrary = false; - if (lib.startsWith("WEB-INF")) { - embeddedArchive = archive.getSubArchive(lib); - } else if (archive.getParentArchive() != null) { - embeddedArchive = archive.getParentArchive().getSubArchive("lib").getSubArchive(lib); - } else if (!DeploymentUtils.getWarLibraryCache().containsKey(lib) && lib.startsWith("/") - && lib.contains(DeploymentUtils.WAR_LIBRARIES)) { - embeddedArchive = archiveFactory.openArchive(new File(lib)); - isWarLibrary = true; - } - try { - if (embeddedArchive != null && - wfArchivist.hasStandardDeploymentDescriptor(embeddedArchive)) { - try { - wfDesc = (WebFragmentDescriptor) wfArchivist.open(embeddedArchive); - } catch (SAXParseException ex) { - IOException ioex = new IOException(); - ioex.initCause(ex); - throw ioex; + Vector libs = getLibraries(archive); + if (libs != null && libs.size() > 0) { + + for (int i = 0; i < libs.size(); i++) { + String lib = (String)libs.get(i); + Archivist wfArchivist = new WebFragmentArchivist(this, habitat); + wfArchivist.setRuntimeXMLValidation(this.getRuntimeXMLValidation()); + wfArchivist.setRuntimeXMLValidationLevel( + this.getRuntimeXMLValidationLevel()); + wfArchivist.setAnnotationProcessingRequested(false); + + WebFragmentDescriptor wfDesc = null; + ReadableArchive embeddedArchive = archive.getSubArchive(lib); + try { + if (embeddedArchive != null && + wfArchivist.hasStandardDeploymentDescriptor(embeddedArchive)) { + try { + wfDesc = (WebFragmentDescriptor)wfArchivist.open(embeddedArchive); + } catch(SAXParseException ex) { + IOException ioex = new IOException(); + ioex.initCause(ex); + throw ioex; + } + } else { + wfDesc = new WebFragmentDescriptor(); + wfDesc.setExists(false); + } + } finally { + if (embeddedArchive != null) { + embeddedArchive.close(); } - } else if (DeploymentUtils.getWarLibraryCache().containsKey(lib)) { - wfDesc = (WebFragmentDescriptor) DeploymentUtils.getWarLibraryCache().get(lib).getDescriptor(); - } else { - wfDesc = new WebFragmentDescriptor(); - wfDesc.setExists(false); - } - } finally { - if (embeddedArchive != null) { - embeddedArchive.close(); - } - } - wfDesc.setJarName(lib.substring(lib.lastIndexOf('/') + 1)); - if (isWarLibrary) { - if (wfDesc.getClassLoader() != null) { - wfDesc.setClassLoader(wfDesc.getClassLoader().getParent()); } - wfDesc.setWarLibraryPath(lib); - } - wfList.add(wfDesc); + wfDesc.setJarName(lib.substring(lib.lastIndexOf('/') + 1)); + wfList.add(wfDesc); - descriptor.putJarNameWebFragmentNamePair(wfDesc.getJarName(), wfDesc.getName()); + descriptor.putJarNameWebFragmentNamePair(wfDesc.getJarName(), wfDesc.getName()); - } + } - if (((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor() != null) { - wfList = ((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor().order(wfList); - } else { - OrderingDescriptor.sort(wfList); - } + if (((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor() != null) { + wfList = ((WebBundleDescriptorImpl)descriptor).getAbsoluteOrderingDescriptor().order(wfList); + } else { + OrderingDescriptor.sort(wfList); + } - for (WebFragmentDescriptor wf : wfList) { - descriptor.addOrderedLib(wf.getJarName()); + for (WebFragmentDescriptor wf : wfList) { + descriptor.addOrderedLib(wf.getJarName()); + } } return wfList; diff --git a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/descriptor/WebFragmentDescriptor.java b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/descriptor/WebFragmentDescriptor.java index 0aee2faf08d..2cf2e0ac60c 100644 --- a/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/descriptor/WebFragmentDescriptor.java +++ b/appserver/web/web-glue/src/main/java/org/glassfish/web/deployment/descriptor/WebFragmentDescriptor.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2014-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2014-2019] [Payara Foundation and/or its affiliates] package org.glassfish.web.deployment.descriptor; @@ -60,7 +60,6 @@ public class WebFragmentDescriptor extends WebBundleDescriptorImpl private String jarName = null; private OrderingDescriptor ordering = null; private boolean exists = true; - private String warLibraryPath; /** * Constrct an empty web app [{0}]. @@ -94,18 +93,6 @@ public void setExists(boolean exists) { this.exists = exists; } - public boolean isWarLibrary() { - return warLibraryPath != null; - } - - public String getWarLibraryPath() { - return warLibraryPath; - } - - public void setWarLibraryPath(String warLibraryPath) { - this.warLibraryPath = warLibraryPath; - } - @Override protected WebComponentDescriptor combineWebComponentDescriptor( WebComponentDescriptor webComponentDescriptor) { diff --git a/appserver/web/web-naming/src/main/java/org/apache/naming/resources/WebDirContext.java b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/WebDirContext.java index cab75ea75cf..87e09149cdb 100644 --- a/appserver/web/web-naming/src/main/java/org/apache/naming/resources/WebDirContext.java +++ b/appserver/web/web-naming/src/main/java/org/apache/naming/resources/WebDirContext.java @@ -55,7 +55,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -// Portions Copyright [2024] Payara Foundation and/or affiliates package org.apache.naming.resources; @@ -323,9 +322,6 @@ protected JarFileEntry lookupFromJars(String name) { String jeName = getAbsoluteJarResourceName(name); for (JarFile jarFile : jarFiles) { JarEntry jarEntry = null; - if (jarFile == null) { - return null; - } if (jeName.charAt(jeName.length() - 1) != '/') { jarEntry = jarFile.getJarEntry(jeName + '/'); if (jarEntry != null) { diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ACLSingletonProvider.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ACLSingletonProvider.java index 79f89f969a9..184a492b006 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ACLSingletonProvider.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ACLSingletonProvider.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. * - * Portions Copyright [2017-2024] Payara Foundation and/or affiliates + * Portions Copyright [2017-2019] Payara Foundation and/or affiliates */ package org.glassfish.weld; @@ -108,11 +108,11 @@ public ClassLoader run() @Override public T get( String id ) { - T instance = storeById.get(id); + ClassLoader acl = getClassLoader(); + T instance = store.get(acl); if (instance == null) { - ClassLoader acl = getClassLoader(); - instance = store.get(acl); + instance = storeById.get(id); if (instance == null) { throw new IllegalStateException("Singleton not set for " + acl); } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java index 235ed40151a..b61dcc8a2b9 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanDeploymentArchiveImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates] package org.glassfish.weld; @@ -62,12 +62,9 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.io.ObjectInputStream; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; import java.net.MalformedURLException; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLClassLoader; import java.util.*; @@ -82,37 +79,37 @@ import static org.glassfish.weld.WeldDeployer.WELD_BOOTSTRAP; import static org.glassfish.weld.connector.WeldUtils.*; + + /* * The means by which Weld Beans are discovered on the classpath. */ -public class BeanDeploymentArchiveImpl implements BeanDeploymentArchive, Serializable { - private static final long serialVersionUID = 1L; +public class BeanDeploymentArchiveImpl implements BeanDeploymentArchive { private static final Logger logger = Logger.getLogger(BeanDeploymentArchiveImpl.class.getName()); - private transient ReadableArchive archive; - private final String id; - private final List moduleClassNames; // Names of classes in the module - private final List beanClassNames; // Names of bean classes in the module - private transient List> moduleClasses; // Classes in the module - private transient List> beanClasses; // Classes identified as Beans through Weld SPI - private final List beansXmlURLs; - private transient Collection> ejbDescImpls; - private transient Set beanDeploymentArchives; - private transient List deserializedBDAs; + private ReadableArchive archive; + private String id; + private List moduleClassNames = null; // Names of classes in the module + private List beanClassNames = null; // Names of bean classes in the module + private List> moduleClasses = null; // Classes in the module + private List> beanClasses = null; // Classes identified as Beans through Weld SPI + private List beansXmlURLs = null; + private final Collection> ejbDescImpls; + private List beanDeploymentArchives; - private transient SimpleServiceRegistry simpleServiceRegistry = null; - private int originalIdentity; + private SimpleServiceRegistry simpleServiceRegistry = null; private BDAType bdaType = BDAType.UNKNOWN; - transient DeploymentContext context; - transient WeldBootstrap weldBootstrap; + private DeploymentContext context; + + private WeldBootstrap weldBootstrap; - private transient Map, InjectionTarget> itMap = new HashMap<>(); + private final Map, InjectionTarget> itMap = new HashMap<>(); //workaround: WELD-781 - private transient ClassLoader moduleClassLoaderForBDA; + private ClassLoader moduleClassLoaderForBDA = null; private String friendlyId = ""; @@ -150,8 +147,8 @@ public BeanDeploymentArchiveImpl(ReadableArchive archive, } this.friendlyId = this.id; - this.ejbDescImpls = new LinkedHashSet<>(); - this.beanDeploymentArchives = new LinkedHashSet<>(); + this.ejbDescImpls = new HashSet<>(); + this.beanDeploymentArchives = new ArrayList<>(); this.context = ctx; this.weldBootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); @@ -187,8 +184,8 @@ public BeanDeploymentArchiveImpl(String } this.beansXmlURLs = beansXmlUrls; - this.ejbDescImpls = new LinkedHashSet<>(); - this.beanDeploymentArchives = new LinkedHashSet<>(); + this.ejbDescImpls = new HashSet<>(); + this.beanDeploymentArchives = new ArrayList<>(); this.context = ctx; this.weldBootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); populateEJBsForThisBDA(ejbs); @@ -197,39 +194,6 @@ public BeanDeploymentArchiveImpl(String getClassLoader(); } - public BeanDeploymentArchiveImpl(BeanDeploymentArchiveImpl beanDeploymentArchive) { - this.id = beanDeploymentArchive.id; - this.originalIdentity = beanDeploymentArchive.originalIdentity; - this.moduleClassNames = new ArrayList<>(beanDeploymentArchive.moduleClassNames); - this.beanClassNames = new ArrayList<>(beanDeploymentArchive.beanClassNames); - this.beansXmlURLs = new CopyOnWriteArrayList<>(beanDeploymentArchive.beansXmlURLs); - this.deserializedBDAs = beanDeploymentArchive.deserializedBDAs; - this.friendlyId = beanDeploymentArchive.friendlyId; - this.bdaType = beanDeploymentArchive.bdaType; - this.deploymentComplete = beanDeploymentArchive.deploymentComplete; - - initializeFromOriginal(); - } - - void initializeFromOriginal() { - if (context == null) { - this.context = DeploymentImpl.currentDeploymentContext.get(); - this.weldBootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); - this.moduleClasses = getOriginal().moduleClasses; - this.beanClasses = getOriginal().beanClasses; - getServices().addAll(getOriginal().getServices().entrySet()); - this.moduleClassLoaderForBDA = getOriginal().moduleClassLoaderForBDA; - this.ejbDescImpls = new LinkedHashSet<>(getOriginal().ejbDescImpls); - if (this.itMap == null) { - this.itMap = new HashMap<>(); - } - this.itMap.putAll(getOriginal().itMap); - } - } - - BeanDeploymentArchiveImpl getOriginal() { - return DeploymentImpl.currentBDAs.get().get(originalIdentity); - } private void populateEJBsForThisBDA(Collection ejbs) { for (com.sun.enterprise.deployment.EjbDescriptor next : ejbs) { @@ -244,15 +208,11 @@ private void populateEJBsForThisBDA(Collection getBeanDeploymentArchives() { - if (beanDeploymentArchives == null && deserializedBDAs != null) { - beanDeploymentArchives = new LinkedHashSet<>(deserializedBDAs); - } return beanDeploymentArchives; } @Override public Collection getBeanClasses() { - initializeFromOriginal(); //This method is called during BeanDeployment.deployBeans, so this would //be the right time to place the module classloader for the BDA as the TCL if (logger.isLoggable(FINER)) { @@ -270,7 +230,6 @@ public Collection getBeanClasses() { } public Collection> getBeanClassObjects() { - initializeFromOriginal(); return beanClasses; } @@ -279,7 +238,6 @@ public Collection getModuleBeanClasses() { } public Collection> getModuleBeanClassObjects() { - initializeFromOriginal(); return moduleClasses; } @@ -314,7 +272,7 @@ public BeansXml getBeansXml() { if (beansXmlURLs.size() == 1) { result = weldBootstrap.parse(beansXmlURLs.get(0)); } else { - // This method attempts to perform a merge, but loses some + // This method attempts to performs a merge, but loses some // information (e.g., version, bean-discovery-mode) result = weldBootstrap.parse(beansXmlURLs); } @@ -329,12 +287,11 @@ public BeansXml getBeansXml() { */ @Override public Collection> getEjbs() { - initializeFromOriginal(); + return ejbDescImpls; } public EjbDescriptor getEjbDescriptor(String ejbName) { - initializeFromOriginal(); EjbDescriptor match = null; for (EjbDescriptor next : ejbDescImpls) { @@ -349,7 +306,6 @@ public EjbDescriptor getEjbDescriptor(String ejbName) { @Override public ServiceRegistry getServices() { - initializeFromOriginal(); if (simpleServiceRegistry == null) { simpleServiceRegistry = new SimpleServiceRegistry(); } @@ -372,36 +328,10 @@ public Collection getKnownClasses() { @Override public Collection> getLoadedBeanClasses() { - initializeFromOriginal(); return beanClasses; } - Object readResolve() throws ObjectStreamException { - return new BeanDeploymentArchiveImpl(this); - } - private void writeObject(ObjectOutputStream out) throws IOException { - out.defaultWriteObject(); - originalIdentity = System.identityHashCode(this); - if (DeploymentImpl.currentBDAs.get().put(originalIdentity, this) != null) { - throw new IllegalStateException("Duplicate BDA detected: " + this); - } - out.writeInt(originalIdentity); - out.writeInt(beanDeploymentArchives.size()); - for (BeanDeploymentArchive bda : beanDeploymentArchives) { - out.writeObject(bda); - } - } - - private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException { - in.defaultReadObject(); - originalIdentity = in.readInt(); - int size = in.readInt(); - deserializedBDAs = new ArrayList<>(size); - for (int i = 0; i < size; i++) { - deserializedBDAs.add((BeanDeploymentArchive) in.readObject()); - } - } //A graphical representation of the BDA hierarchy to aid in debugging //and to provide a better representation of how Weld treats the deployed @@ -671,13 +601,14 @@ private void ensureWebLibJarVisibility(List webLibBDA } //update modified BDA if (modified) { + int idx = this.beanDeploymentArchives.indexOf(firstBDA); if (logger.isLoggable(FINE)) { logger.log(FINE, CDILoggerInfo.ENSURE_WEB_LIB_JAR_VISIBILITY_ASSOCIATION_UPDATING, new Object[]{firstBDA.getFriendlyId()}); } - if (this.beanDeploymentArchives.remove(firstBDA)) { - this.beanDeploymentArchives.add(firstBDA); + if (idx >= 0) { + this.beanDeploymentArchives.set(idx, firstBDA); } } } @@ -691,8 +622,9 @@ private void ensureWebLibJarVisibility(List webLibBDA CDILoggerInfo.ENSURE_WEB_LIB_JAR_VISIBILITY_ASSOCIATION_INCLUDING, new Object[]{subBDA.getId(), this.getId()}); } - if (this.beanDeploymentArchives.remove(subBDA)) { - this.beanDeploymentArchives.add(subBDA); + int idx = this.beanDeploymentArchives.indexOf(subBDA); + if (idx >= 0) { + this.beanDeploymentArchives.set(idx, subBDA); } } } @@ -809,17 +741,14 @@ private ClassLoader getClassLoader() { } public InjectionTarget getInjectionTarget(AnnotatedType annotatedType) { - initializeFromOriginal(); return itMap.get(annotatedType); } void putInjectionTarget(AnnotatedType annotatedType, InjectionTarget it) { - initializeFromOriginal(); itMap.put(annotatedType, it); } public ClassLoader getModuleClassLoaderForBDA() { - initializeFromOriginal(); return moduleClassLoaderForBDA; } @@ -924,17 +853,4 @@ static String stripMavenVersion(String name) { } return name; } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof BeanDeploymentArchiveImpl)) return false; - BeanDeploymentArchiveImpl that = (BeanDeploymentArchiveImpl) o; - return Objects.equals(id, that.id) && Objects.equals(beanClasses, that.beanClasses); - } - - @Override - public int hashCode() { - return Objects.hash(id, beanClasses); - } } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java index f156f38e081..b9974012c6d 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/BeanManagerNamingProxy.java @@ -37,7 +37,6 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package org.glassfish.weld; @@ -94,9 +93,7 @@ public Object handle(String name) throws NamingException { if( inv != null ) { - JndiNameEnvironment componentEnv = inv.getComponentId() != null - ? compEnvManager.getJndiNameEnvironment(inv.getComponentId()) - : null; + JndiNameEnvironment componentEnv = compEnvManager.getJndiNameEnvironment(inv.getComponentId()); if( componentEnv != null ) { @@ -115,7 +112,7 @@ public Object handle(String name) throws NamingException { if( bundle != null ) { BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle); if( bda != null ) { - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); //System.out.println("BeanManagerNamingProxy:: getting BeanManagerImpl for" + bda); beanManager = bootstrap.getManager(bda); } @@ -125,6 +122,7 @@ public Object handle(String name) throws NamingException { throw new IllegalStateException("Cannot resolve bean manager"); } + } else { throw new IllegalStateException("No invocation context found"); } @@ -139,4 +137,6 @@ public Object handle(String name) throws NamingException { return beanManager; } + + } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java index 620314edebf..22d6f77fb00 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/DeploymentImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2025] [Payara Foundation and/or its affiliates] +// Portions Copyright 2016-2025 Payara Foundation and/or its affiliates package org.glassfish.weld; @@ -45,19 +45,12 @@ import static java.util.logging.Level.FINE; import static java.util.logging.Level.WARNING; import static java.util.stream.Collectors.toList; -import static java.util.stream.Collectors.toSet; import static org.glassfish.weld.connector.WeldUtils.*; -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; import java.io.IOException; -import java.io.ObjectOutputStream; -import java.io.ObjectStreamException; -import java.io.Serializable; import java.net.URI; import java.net.URISyntaxException; import java.net.URL; -import java.nio.file.Path; import java.util.*; import java.util.concurrent.CopyOnWriteArrayList; import java.util.function.Supplier; @@ -69,12 +62,9 @@ import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.api.deployment.archive.ReadableArchive; import org.glassfish.cdi.CDILoggerInfo; -import org.glassfish.common.util.ObjectInputStreamWithLoader; import org.glassfish.deployment.common.DeploymentContextImpl; -import org.glassfish.deployment.common.DeploymentUtils; import org.glassfish.deployment.common.InstalledLibrariesResolver; import org.glassfish.hk2.classmodel.reflect.Types; -import org.glassfish.internal.data.ApplicationInfo; import org.glassfish.javaee.core.deployment.ApplicationHolder; import org.glassfish.weld.connector.WeldUtils; import org.glassfish.weld.connector.WeldUtils.BDAType; @@ -95,51 +85,47 @@ import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension; import org.jboss.weld.lite.extension.translator.LiteExtensionTranslator; import java.security.PrivilegedAction; -import java.util.stream.Stream; import static java.lang.System.getSecurityManager; import static java.security.AccessController.doPrivileged; import jakarta.enterprise.inject.build.compatible.spi.SkipIfPortableExtensionPresent; + /* * Represents a deployment of a CDI (Weld) application. */ -public class DeploymentImpl implements CDI11Deployment, Serializable { - private static final long serialVersionUID = 1L; - static final ThreadLocal currentDeployment = new ThreadLocal<>(); - static final ThreadLocal> currentBDAs = new ThreadLocal<>(); - static final ThreadLocal currentDeploymentContext = new ThreadLocal<>(); +public class DeploymentImpl implements CDI11Deployment { // Keep track of our BDAs for this deployment - private final Set rarRootBdas = new LinkedHashSet<>(); - final Set ejbRootBdas = new LinkedHashSet<>(); - private final Set warRootBdas = new LinkedHashSet<>(); - private final Set libJarRootBdas = new LinkedHashSet<>(); + private List rarRootBdas; + private List ejbRootBdas; + private List warRootBdas; + private List libJarRootBdas = null; - private final Set beanDeploymentArchives = new LinkedHashSet<>(); - final transient DeploymentContext context; + private List beanDeploymentArchives = new ArrayList<>(); + private DeploymentContext context; // A convenience Map to get BDA for a given BDA ID - final Map idToBeanDeploymentArchive = new HashMap<>(); - private transient SimpleServiceRegistry simpleServiceRegistry = null; + private Map idToBeanDeploymentArchive = new HashMap<>(); + private SimpleServiceRegistry simpleServiceRegistry = null; - private final transient Logger logger; + private Logger logger = CDILoggerInfo.getLogger(); // holds BDA's created for extensions - private final Map extensionBDAMap = new HashMap<>(); + private Map extensionBDAMap = new HashMap<>(); - private final List> extensions = new ArrayList<>(); + private Iterable> extensions; - private final List> dynamicExtensions = new ArrayList<>(); + private List> dynamicExtensions = new ArrayList<>(); - private final transient Collection deployedEjbs; - private final transient ArchiveFactory archiveFactory; + private Collection deployedEjbs = new LinkedList<>(); + private ArchiveFactory archiveFactory; private boolean earContextAppLibBdasProcessed = false; private String appName; private String contextId; - final transient InjectionManager injectionManager; + final InjectionManager injectionManager; /** * Produce BeanDeploymentArchives for this Deployment @@ -151,8 +137,6 @@ public DeploymentImpl(ReadableArchive archive, ArchiveFactory archiveFactory, String moduleName, InjectionManager injectionManager) { - logger = CDILoggerInfo.getLogger(); - deployedEjbs = new LinkedList<>(); if ( logger.isLoggable( FINE ) ) { logger.log(FINE, CDILoggerInfo.CREATING_DEPLOYMENT_ARCHIVE, new Object[]{ archive.getName()}); } @@ -163,8 +147,8 @@ public DeploymentImpl(ReadableArchive archive, // Collect /lib Jar BDAs (if any) from the parent module. // If we've produced BDA(s) from any /lib jars, return as // additional BDA(s) will be produced for any subarchives (war/jar). - libJarRootBdas.addAll(scanForLibJars(archive, ejbs, context)); - if (!libJarRootBdas.isEmpty()) { + libJarRootBdas = scanForLibJars(archive, ejbs, context); + if ((libJarRootBdas != null) && !libJarRootBdas.isEmpty()) { return; } @@ -181,112 +165,24 @@ public DeploymentImpl(ReadableArchive archive, createModuleBda(archive, ejbs, context, contextId); } - DeploymentImpl(DeploymentImpl deployment) { - this.rarRootBdas.addAll(deployment.rarRootBdas); - this.ejbRootBdas.addAll(deployment.ejbRootBdas); - this.warRootBdas.addAll(deployment.warRootBdas); - this.libJarRootBdas.addAll(deployment.libJarRootBdas); - this.beanDeploymentArchives.addAll(deployment.beanDeploymentArchives); - this.appName = deployment.appName; - this.contextId = deployment.contextId; - this.earContextAppLibBdasProcessed = deployment.earContextAppLibBdasProcessed; - - this.context = currentDeploymentContext.get(); - this.archiveFactory = currentDeployment.get().archiveFactory; - getServices().addAll(currentDeployment.get().getServices().entrySet()); - this.injectionManager = currentDeployment.get().injectionManager; - this.logger = currentDeployment.get().logger; - this.deployedEjbs = currentDeployment.get().deployedEjbs; - } - - DeploymentImpl filter(RootBeanDeploymentArchive rootBDA, ApplicationInfo applicationInfo) { - DeploymentImpl filteredDeployment; - try { - filteredDeployment = serializeAndDeserialize(this, applicationInfo.getAppClassLoader()); - } catch (IOException | ClassNotFoundException e) { - throw new IllegalStateException(e); - } - - List nonRooIDs = List.of(rootBDA.getId(), rootBDA.getModuleBda().getId()); - filteredDeployment.clearAndAddAll(filteredDeployment.warRootBdas, filterBDAs(filteredDeployment.warRootBdas, nonRooIDs)); - filteredDeployment.clearAndAddAll(filteredDeployment.beanDeploymentArchives, - filterBDAs(filteredDeployment.beanDeploymentArchives, nonRooIDs, filteredDeployment.rarRootBdas, - filteredDeployment.ejbRootBdas, filteredDeployment.libJarRootBdas)); - filteredDeployment.contextId = rootBDA.getId() + ".bda"; - return filteredDeployment; - } - - private void clearAndAddAll(Set originalBdas, Set bdas) { - originalBdas.clear(); - originalBdas.addAll(bdas); - } - - Set getRootBDAs() { - if (!warRootBdas.isEmpty()) { - return warRootBdas; - } else if (!ejbRootBdas.isEmpty()) { - return ejbRootBdas; - } else if (!rarRootBdas.isEmpty()) { - return rarRootBdas; - } else if (!libJarRootBdas.isEmpty()) { - return libJarRootBdas; - } else { - return Collections.emptySet(); - } - } - - @SuppressWarnings("unchecked") - private TT serializeAndDeserialize(TT original, ClassLoader classLoader) - throws IOException, ClassNotFoundException { - // serialize - var byteArrayOutputStream = new ByteArrayOutputStream(); - try (var outputStream = new ObjectOutputStream(byteArrayOutputStream)) { - outputStream.writeObject(original); - } - - // deserialize - try (var inputStream = new ObjectInputStreamWithLoader( - new ByteArrayInputStream(byteArrayOutputStream.toByteArray()), classLoader)) { - return (TT) inputStream.readObject(); - } - } - - Object readResolve() throws ObjectStreamException { - return new DeploymentImpl(this); - } - - @SafeVarargs - private Set filterBDAs(Set bdas, List bda, - Set... include) { - if (bdas == null) { - return null; - } - List includeRootList = Arrays.stream(include) - .filter(Objects::nonNull) - .flatMap(Collection::stream) - .collect(toList()); - List includeList = includeRootList.stream() - .flatMap(list -> Stream.of(list, list.getModuleBda())) - .collect(toList()); - return bdas.stream() - .filter(b -> bda.stream().anyMatch(b.getId()::startsWith) || includeList.contains(b)) - .collect(toSet()); - } - private void addBeanDeploymentArchives(RootBeanDeploymentArchive bda) { - rootBDAs(bda).add(bda); - } - - private Set rootBDAs(RootBeanDeploymentArchive bda) { BDAType moduleBDAType = bda.getModuleBDAType(); if (moduleBDAType.equals(BDAType.WAR)) { - return warRootBdas; + if (warRootBdas == null) { + warRootBdas = new ArrayList<>(); + } + warRootBdas.add(bda); } else if (moduleBDAType.equals(BDAType.JAR)) { - return ejbRootBdas; + if (ejbRootBdas == null) { + ejbRootBdas = new ArrayList<>(); + } + ejbRootBdas.add(bda); } else if (moduleBDAType.equals(BDAType.RAR)) { - return rarRootBdas; + if (rarRootBdas == null) { + rarRootBdas = new ArrayList<>(); + } + rarRootBdas.add(bda); } - throw new IllegalArgumentException("Unknown BDAType: " + moduleBDAType); } /** @@ -296,13 +192,14 @@ private Set rootBDAs(RootBeanDeploymentArchive bda) { * been created. */ public void scanArchive(ReadableArchive archive, Collection ejbs, DeploymentContext context, String moduleName) { - if (libJarRootBdas.isEmpty()) { - libJarRootBdas.addAll(scanForLibJars(archive, ejbs, context)); - if (!libJarRootBdas.isEmpty()) { + if (libJarRootBdas == null) { + libJarRootBdas = scanForLibJars(archive, ejbs, context); + if ((libJarRootBdas != null) && !libJarRootBdas.isEmpty()) { return; } } + this.context = context; createModuleBda(archive, ejbs, context, moduleName); } @@ -317,44 +214,52 @@ public void buildDeploymentGraph() { // /ejb1.jar <----> /ejb2.jar // If there are any application (/lib) jars, make them accessible - for (RootBeanDeploymentArchive ejbRootBda : ejbRootBdas) { - BeanDeploymentArchive ejbModuleBda = ejbRootBda.getModuleBda(); + if (ejbRootBdas != null) { + for (RootBeanDeploymentArchive ejbRootBda : ejbRootBdas) { + BeanDeploymentArchive ejbModuleBda = ejbRootBda.getModuleBda(); - boolean modifiedArchive = false; - for (RootBeanDeploymentArchive otherEjbRootBda : ejbRootBdas) { - BeanDeploymentArchive otherEjbModuleBda = otherEjbRootBda.getModuleBda(); - if (otherEjbModuleBda.getId().equals(ejbModuleBda.getId())) { - continue; + boolean modifiedArchive = false; + for (RootBeanDeploymentArchive otherEjbRootBda : ejbRootBdas) { + BeanDeploymentArchive otherEjbModuleBda = otherEjbRootBda.getModuleBda(); + if (otherEjbModuleBda.getId().equals(ejbModuleBda.getId())) { + continue; + } + ejbRootBda.getBeanDeploymentArchives().add(otherEjbRootBda); + ejbRootBda.getBeanDeploymentArchives().add(otherEjbModuleBda); + ejbModuleBda.getBeanDeploymentArchives().add(otherEjbModuleBda); + modifiedArchive = true; } - ejbRootBda.getBeanDeploymentArchives().add(otherEjbRootBda); - ejbRootBda.getBeanDeploymentArchives().add(otherEjbModuleBda); - ejbModuleBda.getBeanDeploymentArchives().add(otherEjbModuleBda); - modifiedArchive = true; - } - // Make /lib jars accessible to the ejbs. - for (RootBeanDeploymentArchive libJarRootBda : libJarRootBdas) { - BeanDeploymentArchive libJarModuleBda = libJarRootBda.getModuleBda(); - ejbRootBda.getBeanDeploymentArchives().add(libJarRootBda); - ejbRootBda.getBeanDeploymentArchives().add(libJarModuleBda); - ejbModuleBda.getBeanDeploymentArchives().add(libJarRootBda); - ejbModuleBda.getBeanDeploymentArchives().add(libJarModuleBda); - modifiedArchive = true; - } + // Make /lib jars accessible to the ejbs. + if (libJarRootBdas != null) { + for (RootBeanDeploymentArchive libJarRootBda : libJarRootBdas) { + BeanDeploymentArchive libJarModuleBda = libJarRootBda.getModuleBda(); + ejbRootBda.getBeanDeploymentArchives().add(libJarRootBda); + ejbRootBda.getBeanDeploymentArchives().add(libJarModuleBda); + ejbModuleBda.getBeanDeploymentArchives().add(libJarRootBda); + ejbModuleBda.getBeanDeploymentArchives().add(libJarModuleBda); + modifiedArchive = true; + } + } - // Make rars accessible to ejbs - for (RootBeanDeploymentArchive rarRootBda : rarRootBdas) { - BeanDeploymentArchive rarModuleBda = rarRootBda.getModuleBda(); - ejbRootBda.getBeanDeploymentArchives().add(rarRootBda); - ejbRootBda.getBeanDeploymentArchives().add(rarModuleBda); - ejbModuleBda.getBeanDeploymentArchives().add(rarRootBda); - ejbModuleBda.getBeanDeploymentArchives().add(rarModuleBda); - modifiedArchive = true; - } + // Make rars accessible to ejbs + if (rarRootBdas != null) { + for (RootBeanDeploymentArchive rarRootBda : rarRootBdas) { + BeanDeploymentArchive rarModuleBda = rarRootBda.getModuleBda(); + ejbRootBda.getBeanDeploymentArchives().add(rarRootBda); + ejbRootBda.getBeanDeploymentArchives().add(rarModuleBda); + ejbModuleBda.getBeanDeploymentArchives().add(rarRootBda); + ejbModuleBda.getBeanDeploymentArchives().add(rarModuleBda); + modifiedArchive = true; + } + } - if (modifiedArchive) { - if (getBeanDeploymentArchives().remove(ejbModuleBda)) { - getBeanDeploymentArchives().add(ejbModuleBda); + if (modifiedArchive) { + int idx = getBeanDeploymentArchives().indexOf(ejbModuleBda); + if (idx >= 0) { + getBeanDeploymentArchives().remove(idx); + getBeanDeploymentArchives().add(ejbModuleBda); + } } } } @@ -363,75 +268,73 @@ public void buildDeploymentGraph() { // /web.war ----> /ejb.jar // If there are any application (/lib) jars, make them accessible - Iterator warIter = warRootBdas.iterator(); - boolean modifiedArchive = false; - while (warIter.hasNext()) { - RootBeanDeploymentArchive warRootBda = warIter.next(); - BeanDeploymentArchive warModuleBda = warRootBda.getModuleBda(); - for (RootBeanDeploymentArchive ejbRootBda : ejbRootBdas) { - BeanDeploymentArchive ejbModuleBda = ejbRootBda.getModuleBda(); - warRootBda.getBeanDeploymentArchives().add(ejbRootBda); - warRootBda.getBeanDeploymentArchives().add(ejbModuleBda); - warModuleBda.getBeanDeploymentArchives().add(ejbRootBda); - warModuleBda.getBeanDeploymentArchives().add(ejbModuleBda); - - for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { - oneBda.getBeanDeploymentArchives().add( ejbRootBda ); - oneBda.getBeanDeploymentArchives().add( ejbModuleBda ); + if (warRootBdas != null) { + ListIterator warIter = warRootBdas.listIterator(); + boolean modifiedArchive = false; + while (warIter.hasNext()) { + RootBeanDeploymentArchive warRootBda = warIter.next(); + BeanDeploymentArchive warModuleBda = warRootBda.getModuleBda(); + if (ejbRootBdas != null) { + for (RootBeanDeploymentArchive ejbRootBda : ejbRootBdas) { + BeanDeploymentArchive ejbModuleBda = ejbRootBda.getModuleBda(); + warRootBda.getBeanDeploymentArchives().add(ejbRootBda); + warRootBda.getBeanDeploymentArchives().add(ejbModuleBda); + warModuleBda.getBeanDeploymentArchives().add(ejbRootBda); + warModuleBda.getBeanDeploymentArchives().add(ejbModuleBda); + + for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { + oneBda.getBeanDeploymentArchives().add( ejbRootBda ); + oneBda.getBeanDeploymentArchives().add( ejbModuleBda ); + } + + modifiedArchive = true; + } } - modifiedArchive = true; - } + // Make /lib jars accessible to the war and it's sub bdas + if (libJarRootBdas != null) { + for (RootBeanDeploymentArchive libJarRootBda : libJarRootBdas) { + BeanDeploymentArchive libJarModuleBda = libJarRootBda.getModuleBda(); + warRootBda.getBeanDeploymentArchives().add(libJarRootBda); + warRootBda.getBeanDeploymentArchives().add(libJarModuleBda); + warModuleBda.getBeanDeploymentArchives().add(libJarRootBda); + warModuleBda.getBeanDeploymentArchives().add(libJarModuleBda); + + for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { + oneBda.getBeanDeploymentArchives().add( libJarRootBda ); + oneBda.getBeanDeploymentArchives().add( libJarModuleBda ); + } - // Make /lib jars accessible to the war and it's sub bdas - for (RootBeanDeploymentArchive libJarRootBda : libJarRootBdas) { - BeanDeploymentArchive libJarModuleBda = libJarRootBda.getModuleBda(); - warRootBda.getBeanDeploymentArchives().add(libJarRootBda); - warRootBda.getBeanDeploymentArchives().add(libJarModuleBda); - warModuleBda.getBeanDeploymentArchives().add(libJarRootBda); - warModuleBda.getBeanDeploymentArchives().add(libJarModuleBda); - - // make WAR's BDAs accessible to libJar BDAs - Set seen = Collections.newSetFromMap(new IdentityHashMap<>()); - beanDeploymentArchives.stream() - .filter(RootBeanDeploymentArchive.class::isInstance) - .map(RootBeanDeploymentArchive.class::cast) - .forEach(bda -> recursivelyAdd(bda.getBeanDeploymentArchives(), warModuleBda, seen)); - recursivelyAdd(beanDeploymentArchives, warModuleBda, seen); - libJarRootBda.getBeanDeploymentArchives().add(warRootBda); - libJarModuleBda.getBeanDeploymentArchives().add(warRootBda); - libJarRootBda.getBeanDeploymentArchives().add(warModuleBda); - libJarModuleBda.getBeanDeploymentArchives().add(warModuleBda); - - for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { - oneBda.getBeanDeploymentArchives().add( libJarRootBda ); - oneBda.getBeanDeploymentArchives().add( libJarModuleBda ); + modifiedArchive = true; + } } - modifiedArchive = true; - } - - // Make rars accessible to wars and it's sub bdas - for (RootBeanDeploymentArchive rarRootBda : rarRootBdas) { - BeanDeploymentArchive rarModuleBda = rarRootBda.getModuleBda(); - warRootBda.getBeanDeploymentArchives().add(rarRootBda); - warRootBda.getBeanDeploymentArchives().add(rarModuleBda); - warModuleBda.getBeanDeploymentArchives().add(rarRootBda); - warModuleBda.getBeanDeploymentArchives().add(rarModuleBda); - - for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { - oneBda.getBeanDeploymentArchives().add( rarRootBda ); - oneBda.getBeanDeploymentArchives().add( rarModuleBda ); + // Make rars accessible to wars and it's sub bdas + if (rarRootBdas != null) { + for (RootBeanDeploymentArchive rarRootBda : rarRootBdas) { + BeanDeploymentArchive rarModuleBda = rarRootBda.getModuleBda(); + warRootBda.getBeanDeploymentArchives().add(rarRootBda); + warRootBda.getBeanDeploymentArchives().add(rarModuleBda); + warModuleBda.getBeanDeploymentArchives().add(rarRootBda); + warModuleBda.getBeanDeploymentArchives().add(rarModuleBda); + + for ( BeanDeploymentArchive oneBda : warModuleBda.getBeanDeploymentArchives() ) { + oneBda.getBeanDeploymentArchives().add( rarRootBda ); + oneBda.getBeanDeploymentArchives().add( rarModuleBda ); + } + + modifiedArchive = true; + } } - modifiedArchive = true; - } - - if (modifiedArchive) { - if (getBeanDeploymentArchives().remove(warModuleBda)) { - getBeanDeploymentArchives().add(warModuleBda); + if (modifiedArchive) { + int idx = getBeanDeploymentArchives().indexOf(warModuleBda); + if (idx >= 0) { + getBeanDeploymentArchives().remove(idx); + getBeanDeploymentArchives().add(warModuleBda); + } + modifiedArchive = false; } - modifiedArchive = false; } } @@ -458,17 +361,8 @@ private void addDependentBdas() { } } - private void recursivelyAdd(Collection bdas, BeanDeploymentArchive bda, Set seen) { - for (BeanDeploymentArchive subBda : new LinkedHashSet<>(bdas)) { - if (seen.add(subBda)) { - subBda.getBeanDeploymentArchives().add(bda); - recursivelyAdd(subBda.getBeanDeploymentArchives(), bda, seen); - } - } - } - @Override - public Set getBeanDeploymentArchives() { + public List getBeanDeploymentArchives() { if ( logger.isLoggable( FINE ) ) { logger.log(FINE, CDILoggerInfo.GET_BEAN_DEPLOYMENT_ARCHIVES, new Object[] {beanDeploymentArchives}); } @@ -480,9 +374,9 @@ public BeanDeploymentArchive loadBeanDeploymentArchive(Class beanClass) { if ( logger.isLoggable( FINE ) ) { logger.log(FINE, CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE, new Object[] { beanClass }); } - Set beanDeploymentArchives = getBeanDeploymentArchives(); + List beanDeploymentArchives = getBeanDeploymentArchives(); - Iterator lIter = beanDeploymentArchives.iterator(); + ListIterator lIter = beanDeploymentArchives.listIterator(); while (lIter.hasNext()) { BeanDeploymentArchive bda = lIter.next(); if ( logger.isLoggable( FINE ) ) { @@ -552,7 +446,7 @@ public BeanDeploymentArchive loadBeanDeploymentArchive(Class beanClass) { CDILoggerInfo.LOAD_BEAN_DEPLOYMENT_ARCHIVE_ADD_NEW_BDA_TO_ROOTS, new Object[] {} ); } - lIter = beanDeploymentArchives.iterator(); + lIter = beanDeploymentArchives.listIterator(); while (lIter.hasNext()) { BeanDeploymentArchive bda = lIter.next(); bda.getBeanDeploymentArchives().add(newBda); @@ -585,11 +479,11 @@ public ServiceRegistry getServices() { @Override public Iterable> getExtensions() { - if (!extensions.isEmpty()) { + if (extensions != null) { return extensions; } - Set bdas = getBeanDeploymentArchives(); + List bdas = getBeanDeploymentArchives(); ArrayList> extnList = new ArrayList<>(); //registering the org.jboss.weld.lite.extension.translator.LiteExtensionTranslator @@ -622,12 +516,14 @@ public LiteExtensionTranslator run() { ClassLoader moduleClassLoader = ((BeanDeploymentArchiveImpl)bda).getModuleClassLoaderForBDA(); if (!scannedClassLoaders.contains(moduleClassLoader)) { scannedClassLoaders.add(moduleClassLoader); - var extensions = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, - WeldBootstrap.class).loadExtensions(moduleClassLoader); - for (Metadata bdaExtn : extensions) { - if (loadedExtensions.get(bdaExtn.getValue().getClass()) == null) { - extnList.add(bdaExtn); - loadedExtensions.put(bdaExtn.getValue().getClass(), bdaExtn); + extensions = context.getTransientAppMetaData(WeldDeployer.WELD_BOOTSTRAP, + WeldBootstrap.class).loadExtensions(moduleClassLoader); + if (extensions != null) { + for (Metadata bdaExtn : extensions) { + if (loadedExtensions.get(bdaExtn.getValue().getClass()) == null) { + extnList.add(bdaExtn); + loadedExtensions.put(bdaExtn.getValue().getClass(), bdaExtn); + } } } } @@ -647,7 +543,7 @@ public LiteExtensionTranslator run() { } extnList.addAll(dynamicExtensions); - extensions.addAll(extnList); + extensions = extnList; return extnList; } @@ -666,8 +562,10 @@ public void clearDynamicExtensions() { @Override public String toString() { StringBuilder valBuff = new StringBuilder(); - Set beanDeploymentArchives = getBeanDeploymentArchives(); - for(BeanDeploymentArchive bda : beanDeploymentArchives) { + List beanDeploymentArchives = getBeanDeploymentArchives(); + ListIterator lIter = beanDeploymentArchives.listIterator(); + while (lIter.hasNext()) { + BeanDeploymentArchive bda = lIter.next(); valBuff.append(bda.toString()); } return valBuff.toString(); @@ -678,11 +576,23 @@ public BeanDeploymentArchive getBeanDeploymentArchiveForArchive(String archiveId } public void cleanup() { - ejbRootBdas.clear(); - warRootBdas.clear(); - libJarRootBdas.clear(); - rarRootBdas.clear(); - idToBeanDeploymentArchive.clear(); + if (ejbRootBdas != null) { + ejbRootBdas.clear(); + } + if (warRootBdas != null) { + warRootBdas.clear(); + } + if (libJarRootBdas != null) { + libJarRootBdas.clear(); + } + + if ( rarRootBdas != null ) { + rarRootBdas.clear(); + } + + if (idToBeanDeploymentArchive != null) { + idToBeanDeploymentArchive.clear(); + } } private List> getBuildCompatibleExtensions() { @@ -690,14 +600,14 @@ private List> getBuildCompatibleExtens ServiceLoader.load(BuildCompatibleExtension.class, Thread.currentThread().getContextClassLoader()) .stream() .map(java.util.ServiceLoader.Provider::get) - .map(BuildCompatibleExtension::getClass) + .map(e -> e.getClass()) .filter(e -> !e.isAnnotationPresent(SkipIfPortableExtensionPresent.class)) .collect(toList()); } // This method creates and returns a List of BeanDeploymentArchives for each // Weld enabled jar under /lib of an existing Archive. - private Set scanForLibJars( ReadableArchive archive, + private List scanForLibJars( ReadableArchive archive, Collection ejbs, DeploymentContext context) { List libJars = null; @@ -753,6 +663,9 @@ private void createLibJarBda(RootBeanDeploymentArchive rootLibBda) { if (moduleBeansXml == null || !moduleBeansXml.getBeanDiscoveryMode().equals(BeanDiscoveryMode.NONE)) { addBdaToDeploymentBdas(rootLibBda); addBdaToDeploymentBdas(libModuleBda); + if (libJarRootBdas == null) { + libJarRootBdas = new ArrayList<>(); + } for ( RootBeanDeploymentArchive existingLibJarRootBda : libJarRootBdas) { rootLibBda.getBeanDeploymentArchives().add( existingLibJarRootBda ); @@ -796,18 +709,30 @@ private void processBdasForAppLibs( ReadableArchive archive, DeploymentContext c for ( URI oneAppLib : appLibs ) { for ( String oneInstalledLibrary : installedLibraries ) { if ( oneAppLib.getPath().endsWith( oneInstalledLibrary ) ) { - addLibBDA(archive, context, oneAppLib, libBdas); + ReadableArchive libArchive = null; + try { + libArchive = archiveFactory.openArchive(oneAppLib); + if ( libArchive.exists( WeldUtils.META_INF_BEANS_XML ) ) { + String bdaId = archive.getName() + "_" + libArchive.getName(); + RootBeanDeploymentArchive rootBda = + new RootBeanDeploymentArchive(libArchive, + Collections.emptyList(), + context, + bdaId ); + libBdas.add(rootBda); + } + } finally { + if ( libArchive != null ) { + try { + libArchive.close(); + } catch ( Exception ignore ) {} + } + } break; } } } } - - if (DeploymentUtils.useWarLibraries(context)) { - for (Path warLibrary : InstalledLibrariesResolver.getWarLibraries()) { - addLibBDA(archive, context, warLibrary.toUri(), libBdas); - } - } } catch (URISyntaxException | IOException e) { //todo: log error } @@ -817,28 +742,6 @@ private void processBdasForAppLibs( ReadableArchive archive, DeploymentContext c } } - private void addLibBDA(ReadableArchive archive, DeploymentContext context, URI oneAppLib, List libBdas) throws IOException { - ReadableArchive libArchive = null; - try { - libArchive = archiveFactory.openArchive(oneAppLib); - if ( libArchive.exists( WeldUtils.META_INF_BEANS_XML ) || WeldUtils.isImplicitBeanArchive(context, libArchive) ) { - String bdaId = archive.getName() + "_" + libArchive.getName(); - RootBeanDeploymentArchive rootBda = - new RootBeanDeploymentArchive(libArchive, - Collections.emptyList(), - context, - bdaId ); - libBdas.add(rootBda); - } - } finally { - if ( libArchive != null ) { - try { - libArchive.close(); - } catch ( Exception ignore ) {} - } - } - } - protected void addDeployedEjbs( Collection ejbs ) { if ( ejbs != null ) { deployedEjbs.addAll( ejbs ); @@ -863,9 +766,9 @@ public BeanDeploymentArchive getBeanDeploymentArchive(Class beanClass) { return null; } - for (BeanDeploymentArchive oneBda : beanDeploymentArchives) { + for ( BeanDeploymentArchive oneBda : beanDeploymentArchives ) { BeanDeploymentArchiveImpl beanDeploymentArchiveImpl = (BeanDeploymentArchiveImpl) oneBda; - if (beanDeploymentArchiveImpl.getKnownClasses().contains(beanClass.getName())) { + if ( beanDeploymentArchiveImpl.getKnownClasses().contains(beanClass.getName()) ) { return oneBda; } } @@ -887,7 +790,7 @@ public BeanDeploymentArchive getBeanDeploymentArchive(Class beanClass) { return rootBda; } - private RootBeanDeploymentArchive findRootBda( ClassLoader classLoader, Set rootBdas ) { + private RootBeanDeploymentArchive findRootBda( ClassLoader classLoader, List rootBdas ) { if ( rootBdas == null || classLoader == null ) { return null; } @@ -934,10 +837,16 @@ private void createModuleBda( ReadableArchive archive, public Iterator getLibJarRootBdas() { + if ( libJarRootBdas == null ) { + return null; + } return libJarRootBdas.iterator(); } public Iterator getRarRootBdas() { + if ( rarRootBdas == null ) { + return null; + } return rarRootBdas.iterator(); } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/GlassFishWeldProvider.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/GlassFishWeldProvider.java index 94ffbb866da..0d7d7282572 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/GlassFishWeldProvider.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/GlassFishWeldProvider.java @@ -37,15 +37,9 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package org.glassfish.weld; -import com.sun.enterprise.deployment.BundleDescriptor; -import com.sun.enterprise.deployment.EjbDescriptor; -import com.sun.enterprise.deployment.WebBundleDescriptor; -import org.glassfish.api.invocation.InvocationManager; -import org.glassfish.internal.api.Globals; import org.jboss.weld.Container; import org.jboss.weld.SimpleCDI; import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive; @@ -60,16 +54,7 @@ * @author JJ Snyder */ public class GlassFishWeldProvider implements CDIProvider { - private static final WeldDeployer weldDeployer = Globals.get(WeldDeployer.class); - private static final InvocationManager invocationManager = Globals.get(InvocationManager.class); - private static class GlassFishEnhancedWeld extends SimpleCDI { - GlassFishEnhancedWeld() { - } - - GlassFishEnhancedWeld(String contextId) { - super(contextId == null ? Container.instance() : Container.instance(contextId)); - } @Override protected BeanManagerImpl unsatisfiedBeanManager(String callerClassName) { @@ -107,30 +92,15 @@ protected BeanManagerImpl unsatisfiedBeanManager(String callerClassName) { @Override public CDI getCDI() { - try { - BundleDescriptor bundle = null; - Object componentEnv = invocationManager.getCurrentInvocation().getJNDIEnvironment(); - if( componentEnv instanceof EjbDescriptor) { - bundle = (BundleDescriptor) - ((EjbDescriptor) componentEnv).getEjbBundleDescriptor(). - getModuleDescriptor().getDescriptor(); - - } else if( componentEnv instanceof WebBundleDescriptor) { - bundle = (BundleDescriptor) componentEnv; - } - - BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle); - if (bda == null) { - return new GlassFishEnhancedWeld(); - } else { - return new GlassFishEnhancedWeld(weldDeployer.getContextIdForArchive(bda)); - } - } catch ( Throwable throwable ) { - Throwable cause = throwable.getCause(); - if ( cause instanceof IllegalStateException ) { - return null; - } - throw throwable; + try { + return new GlassFishEnhancedWeld(); + } catch ( Throwable throwable ) { + Throwable cause = throwable.getCause(); + if ( cause instanceof IllegalStateException ) { + return null; } + throw throwable; + } } + } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/RootBeanDeploymentArchive.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/RootBeanDeploymentArchive.java index 9d5c526eb9c..861813ec04d 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/RootBeanDeploymentArchive.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/RootBeanDeploymentArchive.java @@ -38,7 +38,7 @@ * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2017] [Payara Foundation and/or its affiliates] package org.glassfish.weld; @@ -49,12 +49,10 @@ import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive; import org.jboss.weld.bootstrap.spi.BeansXml; -import java.io.ObjectStreamException; import java.net.URL; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; -import java.util.Objects; /** * A root BDA represents the root of a module where a module is a war, ejb, rar, ear lib @@ -72,7 +70,7 @@ * @author JJ Snyder */ public class RootBeanDeploymentArchive extends BeanDeploymentArchiveImpl { - BeanDeploymentArchiveImpl moduleBda; + private BeanDeploymentArchiveImpl moduleBda; public RootBeanDeploymentArchive(ReadableArchive archive, Collection ejbs, @@ -92,11 +90,6 @@ public RootBeanDeploymentArchive(ReadableArchive archive, createModuleBda(archive, ejbs, deploymentContext, moduleBdaID); } - public RootBeanDeploymentArchive(RootBeanDeploymentArchive rootBeanDeploymentArchive) { - super(rootBeanDeploymentArchive); - moduleBda = rootBeanDeploymentArchive.moduleBda; - } - private void createModuleBda(ReadableArchive archive, Collection ejbs, DeploymentContext deploymentContext, @@ -157,21 +150,4 @@ public BeanDeploymentArchive getModuleBda() { public WeldUtils.BDAType getModuleBDAType() { return moduleBda.getBDAType(); } - - Object readResolve() throws ObjectStreamException { - return new RootBeanDeploymentArchive(this); - } - - @Override - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof RootBeanDeploymentArchive)) return false; - RootBeanDeploymentArchive that = (RootBeanDeploymentArchive) o; - return Objects.equals(moduleBda, that.moduleBda); - } - - @Override - public int hashCode() { - return Objects.hashCode(moduleBda); - } } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ValidationNamingProxy.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ValidationNamingProxy.java index 345ddfe2950..1e4f1e1780c 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ValidationNamingProxy.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/ValidationNamingProxy.java @@ -37,7 +37,6 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2024] [Payara Foundation and/or its affiliates] package org.glassfish.weld; @@ -49,6 +48,7 @@ import org.glassfish.api.invocation.ComponentInvocation; import org.glassfish.api.invocation.InvocationManager; import org.glassfish.api.naming.NamedNamingObjectProxy; +import org.glassfish.api.naming.NamespacePrefixes; import org.glassfish.hk2.api.ServiceLocator; import org.jboss.weld.bootstrap.WeldBootstrap; import org.jboss.weld.bootstrap.spi.BeanDeploymentArchive; @@ -59,7 +59,9 @@ import jakarta.inject.Inject; import jakarta.inject.Named; import javax.naming.NamingException; +import jakarta.validation.Validation; import jakarta.validation.Validator; +import jakarta.validation.ValidatorContext; import jakarta.validation.ValidatorFactory; import java.util.Set; @@ -187,7 +189,7 @@ private synchronized BeanManager obtainBeanManager() throws NamingException { if( bundle != null ) { BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(bundle); if( bda != null ) { - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); beanManager = bootstrap.getManager(bda); } diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java index d049c743e07..c5032e1ba48 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/WeldDeployer.java @@ -67,7 +67,6 @@ import static org.jboss.weld.manager.BeanManagerLookupService.lookupBeanManager; import java.security.AccessController; -import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; @@ -156,7 +155,7 @@ public class WeldDeployer extends SimpleDeployer appToBootstrap = new HashMap<>(); + private Map bundleToBeanDeploymentArchive = new HashMap<>(); private static final Class[] NON_CONTEXT_CLASSES = { @@ -275,7 +276,11 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext ReadableArchive archive = context.getSource(); - ensureWeldBootstrapCreated(context, applicationInfo); + boolean[] setTransientAppMetaData = {false}; + + // See if a WeldBootsrap has already been created - only want one per app. + WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData); + EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context); EjbServices ejbServices = null; @@ -290,7 +295,7 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext // If the archive is a composite, or has version numbers per maven conventions, strip them out String archiveName = getArchiveName(context, applicationInfo, archive); - DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class); + DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class); if (deploymentImpl == null) { deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class)); @@ -331,8 +336,14 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration); BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName); - if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE) - || forceInitialisation(context)) { + if (beanDeploymentArchive != null + && (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE) || forceInitialisation(context))) { + if (setTransientAppMetaData[0]) { + // Do this only if we have a root BDA + appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap); + applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap); + } + WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class); boolean developmentMode = isDevelopmentMode(context); if (webBundleDescriptor != null) { @@ -368,8 +379,8 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext } BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle; - if (bundle != null && (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE) - || forceInitialisation(context))) { + if (bundle != null + && (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE) || forceInitialisation(context))) { // Register EE injection manager at the bean deployment archive level. // We use the generic InjectionService service to handle all EE-style // injection instead of the per-dependency-type InjectionPoint approach. @@ -403,6 +414,7 @@ public WeldApplicationContainer load(WeldContainer container, DeploymentContext bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive); } + context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl); applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl); return new WeldApplicationContainer(); @@ -452,192 +464,139 @@ public boolean is299Enabled(BundleDescriptor bundle) { return bundleToBeanDeploymentArchive.containsKey(bundle); } - public WeldBootstrap getBootstrapForArchive(BeanDeploymentArchive archive) { - return ((BeanDeploymentArchiveImpl) archive).weldBootstrap; + public WeldBootstrap getBootstrapForApp(Application app) { + return appToBootstrap.get(app); } - public String getContextIdForArchive(BeanDeploymentArchive archive) { - var impl = (BeanDeploymentArchiveImpl) archive; - String rootContextId = impl.getBeanDeploymentArchives().stream() - .filter(RootBeanDeploymentArchive.class::isInstance) - .map(RootBeanDeploymentArchive.class::cast) - .filter(bda -> bda.moduleBda.getBDAType() != WeldUtils.BDAType.UNKNOWN) - .findFirst().map(BeanDeploymentArchive::getId).orElse(null); - return rootContextId == null ? null : rootContextId + ".bda"; - } + // ### Private methods - private WeldBootstrap ensureWeldBootstrapCreated(DeploymentContext context, ApplicationInfo applicationInfo) { - @SuppressWarnings("unchecked") - List toShutdown = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class); - if (toShutdown == null) { - toShutdown = new ArrayList<>(); - applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, toShutdown); - } - // See if a WeldBootstrap has already been created - only want one per context. + private WeldBootstrap getWeldBootstrap(DeploymentContext context, ApplicationInfo appInfo, boolean[] setTransientAppMetaData) { + // See if a WeldBootsrap has already been created - only want one per app. WeldBootstrap bootstrap = context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); + if (bootstrap != null && appInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class) == null) { + // No bootstrap if no CDI BDAs exist yet + bootstrap = null; + } + if (bootstrap == null) { bootstrap = new WeldBootstrap(); + setTransientAppMetaData[0] = true; - // 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. - applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false"); + appInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "false"); } + return bootstrap; } private void processApplicationLoaded(ApplicationInfo applicationInfo) { - DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class); - if (deploymentImpl == null) { - return; - } - - // Get current TCL - ClassLoader oldTCL = Thread.currentThread().getContextClassLoader(); - - invocationManager.pushAppEnvironment(applicationInfo::getName); - - ComponentInvocation componentInvocation = createComponentInvocation(applicationInfo); - - try { - invocationManager.preInvoke(componentInvocation); - // Modern, multiple WARs in an EAR scenario - if (deploymentImpl.ejbRootBdas.isEmpty()) { - for (RootBeanDeploymentArchive rootBDA : deploymentImpl.getRootBDAs()) { - DeploymentImpl.currentDeployment.set(deploymentImpl); - DeploymentImpl.currentBDAs.set(new HashMap<>()); - DeploymentImpl.currentDeploymentContext.set(rootBDA.context); - try { - DeploymentImpl filtered = deploymentImpl.filter(rootBDA, applicationInfo); - completeDeployment(filtered); - WeldBootstrap bootstrap = filtered.context.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); - startWeldBootstrap(applicationInfo, rootBDA, bootstrap, filtered, componentInvocation); - } finally { - DeploymentImpl.currentDeployment.remove(); - DeploymentImpl.currentBDAs.remove(); - DeploymentImpl.currentDeploymentContext.remove(); - } - } - } else if (!deploymentImpl.getRootBDAs().isEmpty()) { - completeDeployment(deploymentImpl); - // Legacy EJB-Jar scenario, one Weld instance per EAR - RootBeanDeploymentArchive bda = deploymentImpl.getRootBDAs().iterator().next(); - WeldBootstrap bootstrap = unifyBootstrap(bda, applicationInfo); - startWeldBootstrap(applicationInfo, bda, bootstrap, deploymentImpl, componentInvocation); - } - } catch (Throwable t) { - doBootstrapShutdown(applicationInfo); - - throw new DeploymentException(getDeploymentErrorMsgPrefix(t) + t.getMessage(), t); - } finally { - try { - invocationManager.postInvoke(componentInvocation); - invocationManager.popAppEnvironment(); - deploymentComplete(deploymentImpl); - } catch (Throwable t) { - logger.log(SEVERE, "Exception dispatching post deploy event", t); - } + WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); - // The TCL is originally the EAR classloader and is reset during Bean deployment to the - // corresponding module classloader in BeanDeploymentArchiveImpl.getBeans - // for Bean classloading to succeed. - // The TCL is reset to its old value here. - Thread.currentThread().setContextClassLoader(oldTCL); - } - } + if (bootstrap != null) { + DeploymentImpl deploymentImpl = applicationInfo.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class); + deploymentImpl.buildDeploymentGraph(); - private void completeDeployment(DeploymentImpl deploymentImpl) { - deploymentImpl.buildDeploymentGraph(); + List archives = deploymentImpl.getBeanDeploymentArchives(); - Set archives = deploymentImpl.getBeanDeploymentArchives(); + addResourceLoaders(archives); + addCdiServicesToNonModuleBdas(deploymentImpl.getLibJarRootBdas(), services.getService(InjectionManager.class)); + addCdiServicesToNonModuleBdas(deploymentImpl.getRarRootBdas(), services.getService(InjectionManager.class)); - addResourceLoaders(archives); - addCdiServicesToNonModuleBdas(deploymentImpl.getLibJarRootBdas(), services.getService(InjectionManager.class)); - addCdiServicesToNonModuleBdas(deploymentImpl.getRarRootBdas(), services.getService(InjectionManager.class)); - } + // Get current TCL + ClassLoader oldTCL = Thread.currentThread().getContextClassLoader(); - 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(); - } + invocationManager.pushAppEnvironment(applicationInfo::getName); - private static void createProxyEJBs(RootBeanDeploymentArchive warRootBDA, WeldBootstrap bootstrap, - ComponentInvocation componentInvocation, DeploymentImpl deploymentImpl) { - BeanManagerImpl beanManager = bootstrap.getManager(warRootBDA); - componentInvocation.setInstance(beanManager); - ServiceRegistry rootServices = beanManager.getServices(); - EjbSupport originalEjbSupport = rootServices.get(EjbSupport.class); - if (originalEjbSupport != null) { - // We need to create a proxy instead of a simple wrapper - EjbSupport proxyEjbSupport = (EjbSupport) java.lang.reflect.Proxy.newProxyInstance(EjbSupport.class.getClassLoader(), - new Class[]{EjbSupport.class}, new java.lang.reflect.InvocationHandler() { - @Override - public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable { - if (method.getName().equals("isEjb")) { - - EjbSupport targetEjbSupport = getTargetEjbSupport((Class) args[0]); - - if (targetEjbSupport != null) { - return method.invoke(targetEjbSupport, args); - } - - } else if (method.getName().equals("createSessionBeanAttributes")) { - Object enhancedAnnotated = args[0]; - - Class beanClass = (Class) - enhancedAnnotated.getClass() - .getMethod("getJavaClass") - .invoke(enhancedAnnotated); - - EjbSupport targetEjbSupport = getTargetEjbSupport(beanClass); - if (targetEjbSupport != null) { - return method.invoke(targetEjbSupport, args); - } - } - - return method.invoke(originalEjbSupport, args); - } + ComponentInvocation componentInvocation = createComponentInvocation(applicationInfo); - private EjbSupport getTargetEjbSupport(Class beanClass) { - BeanDeploymentArchive ejbArchive = deploymentImpl.getBeanDeploymentArchive(beanClass); - if (ejbArchive == null) { - return null; - } + try { + invocationManager.preInvoke(componentInvocation); + bootstrap.startExtensions(postProcessExtensions(deploymentImpl.getExtensions(), archives)); + bootstrap.startContainer(deploymentImpl.getContextId() + ".bda", SERVLET, deploymentImpl); + + //This changes added to pass the following test + // CreateBeanAttributesTest#testBeanAttributesForSessionBean + if(!deploymentImpl.getBeanDeploymentArchives().isEmpty()) { + BeanDeploymentArchive rootArchive = deploymentImpl.getBeanDeploymentArchives().get(0); + ServiceRegistry rootServices = bootstrap.getManager(rootArchive).getServices(); + EjbSupport originalEjbSupport = rootServices.get(EjbSupport.class); + if (originalEjbSupport != null) { + // We need to create a proxy instead of a simple wrapper + EjbSupport proxyEjbSupport = (EjbSupport) java.lang.reflect.Proxy.newProxyInstance(EjbSupport.class.getClassLoader(), + new Class[]{EjbSupport.class}, new java.lang.reflect.InvocationHandler() { + @Override + public Object invoke(Object proxy, java.lang.reflect.Method method, Object[] args) throws Throwable { + if (method.getName().equals("isEjb")) { + + EjbSupport targetEjbSupport = getTargetEjbSupport((Class) args[0]); + + if (targetEjbSupport != null) { + return method.invoke(targetEjbSupport, args); + } + + } else if (method.getName().equals("createSessionBeanAttributes")) { + Object enhancedAnnotated = args[0]; + + Class beanClass = (Class) + enhancedAnnotated.getClass() + .getMethod("getJavaClass") + .invoke(enhancedAnnotated); + + EjbSupport targetEjbSupport = getTargetEjbSupport(beanClass); + if (targetEjbSupport != null) { + return method.invoke(targetEjbSupport, args); + } + } + + return method.invoke(originalEjbSupport, args); + } + + private EjbSupport getTargetEjbSupport(Class beanClass) { + BeanDeploymentArchive ejbArchive = deploymentImpl.getBeanDeploymentArchive(beanClass); + if (ejbArchive == null) { + return null; + } + + BeanManagerImpl ejbBeanManager = lookupBeanManager(beanClass, bootstrap.getManager(ejbArchive)); + + return ejbBeanManager.getServices().get(EjbSupport.class); + } + }); + rootServices.add(EjbSupport.class, proxyEjbSupport); + } + } + bootstrap.startInitialization(); + fireProcessInjectionTargetEvents(bootstrap, applicationInfo, deploymentImpl); + bootstrap.deployBeans(); + bootstrap.validateBeans(); + bootstrap.endInitialization(); + } catch (Throwable t) { + doBootstrapShutdown(applicationInfo); - BeanManagerImpl ejbBeanManager = lookupBeanManager(beanClass, bootstrap.getManager(ejbArchive)); + throw new DeploymentException(getDeploymentErrorMsgPrefix(t) + t.getMessage(), t); + } finally { + try { + invocationManager.postInvoke(componentInvocation); + invocationManager.popAppEnvironment(); + deploymentComplete(deploymentImpl); + } catch (Throwable t) { + logger.log(SEVERE, "Exception dispatching post deploy event", t); + } - return ejbBeanManager.getServices().get(EjbSupport.class); - } - }); - rootServices.add(EjbSupport.class, proxyEjbSupport); + // The TCL is originally the EAR classloader and is reset during Bean deployment to the + // corresponding module classloader in BeanDeploymentArchiveImpl.getBeans + // for Bean classloading to succeed. + // The TCL is reset to its old value here. + Thread.currentThread().setContextClassLoader(oldTCL); + } } } @@ -646,6 +605,7 @@ private void processApplicationStopped(ApplicationInfo applicationInfo) { Application application = applicationInfo.getMetaData(Application.class); if (application != null) { removeBundleDescriptors(application); + appToBootstrap.remove(application); } String shutdown = applicationInfo.getTransientAppMetaData(WELD_SHUTDOWN, String.class); @@ -657,6 +617,8 @@ private void processApplicationStopped(ApplicationInfo applicationInfo) { Thread.currentThread().setContextClassLoader(applicationInfo.getAppClassLoader()); try { + WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); + if (bootstrap != null) { invocationManager.pushAppEnvironment(applicationInfo::getName); try { @@ -668,6 +630,7 @@ private void processApplicationStopped(ApplicationInfo applicationInfo) { } applicationInfo.addTransientAppMetaData(WELD_SHUTDOWN, "true"); + } } finally { Thread.currentThread().setContextClassLoader(currentContextClassLoader); } @@ -679,7 +642,7 @@ private void processApplicationStopped(ApplicationInfo applicationInfo) { } - private void addResourceLoaders(Set archives) { + private void addResourceLoaders(List archives) { for (BeanDeploymentArchive archive : archives) { archive.getServices().add( ResourceLoader.class, @@ -704,7 +667,7 @@ private ComponentInvocation createComponentInvocation(ApplicationInfo applicatio return componentInvocation; } - private Iterable> postProcessExtensions(Iterable> extensions, Set archives) { + private Iterable> postProcessExtensions(Iterable> extensions, List archives) { // See if the Jersey extension that scans all classes in the bean archives is present. // Normally this should always be the case as this extension is statically included with Jersey, @@ -747,7 +710,7 @@ private Optional> findJerseyProcessAll(Iterable e.getValue().getClass().getName().equals(JERSEY_PROCESS_ALL_CLASS_NAME)).findAny(); } - private boolean hasJerseyHk2Provider(Set archives, ClassLoader jaxRsClassLoader) + private boolean hasJerseyHk2Provider(List archives, ClassLoader jaxRsClassLoader) throws ClassNotFoundException { Class hk2Provider = Class.forName(JERSEY_HK2_CLASS_NAME, false, jaxRsClassLoader); @@ -793,13 +756,11 @@ private void deploymentComplete(DeploymentImpl deploymentImpl) { } private void doBootstrapShutdown(ApplicationInfo applicationInfo) { - List bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, List.class); + WeldBootstrap bootstrap = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP, WeldBootstrap.class); String bootstrapShutdown = applicationInfo.getTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, String.class); if (bootstrapShutdown == null || Boolean.valueOf(bootstrapShutdown).equals(FALSE)) { - if (bootstrap != null) { - bootstrap.forEach(WeldBootstrap::shutdown); - } + bootstrap.shutdown(); applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP_SHUTDOWN, "true"); } } @@ -846,7 +807,7 @@ private String getDeploymentErrorMsgPrefix(Throwable t) { */ private void fireProcessInjectionTargetEvents(WeldBootstrap bootstrap, ApplicationInfo applicationInfo, DeploymentImpl deploymentImpl) { - Set beanDeploymentArchives = deploymentImpl.getBeanDeploymentArchives(); + List beanDeploymentArchives = deploymentImpl.getBeanDeploymentArchives(); Class messageListenerClass = getMessageListenerClass(); diff --git a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java index 1447d3de0a1..a29bf9be94e 100644 --- a/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java +++ b/appserver/web/weld-integration/src/main/java/org/glassfish/weld/services/JCDIServiceImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] +// Portions Copyright [2016-2022] [Payara Foundation and/or its affiliates] package org.glassfish.weld.services; @@ -213,7 +213,7 @@ private JCDIInjectionContext _createJCDIInjectionContext(EjbDescriptor ej // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName()); - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication()); WeldManager weldManager = bootstrap.getManager(bda); //sanitizing the null reference of weldManager and returning null //when calling _createJCDIInjectionContext @@ -350,8 +350,9 @@ public void injectManagedObject(T managedObject, BundleDescriptor bundle) { BundleDescriptor topLevelBundleDesc = (BundleDescriptor) bundle.getModuleDescriptor().getDescriptor(); // First get BeanDeploymentArchive for this ejb - BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName()); - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); + //BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, managedObject.getClass().getName()); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); @SuppressWarnings("unchecked") AnnotatedType annotatedType = beanManager.createAnnotatedType((Class) managedObject.getClass()); @@ -399,7 +400,7 @@ public T createInterceptorInstance(Class interceptorClass, // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = getBDAForBeanClass(topLevelBundleDesc, ejb.getEjbClassName()); - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(ejb.getEjbBundleDescriptor().getApplication()); BeanManagerImpl beanManager = bootstrap.getManager(bda); org.jboss.weld.ejb.spi.EjbDescriptor ejbDesc = beanManager.getEjbDescriptor( ejb.getName()); @@ -480,7 +481,7 @@ public JCDIInjectionContext createManagedObject(Class managedClass, Bu // First get BeanDeploymentArchive for this ejb BeanDeploymentArchive bda = weldDeployer.getBeanDeploymentArchiveForBundle(topLevelBundleDesc); - WeldBootstrap bootstrap = weldDeployer.getBootstrapForArchive(bda); + WeldBootstrap bootstrap = weldDeployer.getBootstrapForApp(bundle.getApplication()); BeanManager beanManager = bootstrap.getManager(bda); diff --git a/appserver/web/weld-integration/src/test/java/org/glassfish/weld/services/JCDIServiceImplTest.java b/appserver/web/weld-integration/src/test/java/org/glassfish/weld/services/JCDIServiceImplTest.java index d63a137c465..b0600055c20 100644 --- a/appserver/web/weld-integration/src/test/java/org/glassfish/weld/services/JCDIServiceImplTest.java +++ b/appserver/web/weld-integration/src/test/java/org/glassfish/weld/services/JCDIServiceImplTest.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2021-2024] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2021] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -96,24 +96,26 @@ public void createJCDIInjectionContextWithoutNullPointerException() { Collection emptyListNames = Collections.emptyList(); Collection emptyListOfArchives = Collections.emptyList(); when(ejbDescriptor.getEjbBundleDescriptor()).thenReturn(ejbBundleDescriptor); + when(ejbBundleDescriptor.getApplication()).thenReturn(application); when(ejbBundleDescriptor.getModuleDescriptor()).thenReturn(moduleDescriptor); when(moduleDescriptor.getDescriptor()).thenReturn(bundleDescriptor); when(ejbDescriptor.getEjbClassName()).thenReturn("EjbName"); when(weldDeployer.getBeanDeploymentArchiveForBundle(bundleDescriptor)).thenReturn(beanDeploymentArchive); - when(weldDeployer.getBootstrapForArchive(beanDeploymentArchive)).thenReturn(bootstrap); + when(weldDeployer.getBootstrapForApp(application)).thenReturn(bootstrap); when(beanDeploymentArchive.getBeanClasses()).thenReturn(emptyListNames); when(beanDeploymentArchive.getBeanDeploymentArchives()).thenReturn(emptyListOfArchives); Object obj = jcdiServiceImpl.createJCDIInjectionContext(ejbDescriptor, ejbInfo); assertNull(obj); - verify(ejbDescriptor, times(1)).getEjbBundleDescriptor(); + verify(ejbDescriptor, times(2)).getEjbBundleDescriptor(); verify(ejbBundleDescriptor, times(1)).getModuleDescriptor(); verify(moduleDescriptor, times(1)).getDescriptor(); verify(weldDeployer, times(1)).getBeanDeploymentArchiveForBundle(bundleDescriptor); verify(beanDeploymentArchive, times(1)).getBeanClasses(); verify(beanDeploymentArchive, times(1)).getBeanDeploymentArchives(); - verify(weldDeployer, times(1)).getBootstrapForArchive(beanDeploymentArchive); + verify(ejbBundleDescriptor, times(1)).getApplication(); + verify(weldDeployer, times(1)).getBootstrapForApp(application); verify(bootstrap, times(1)).getManager(beanDeploymentArchive); } } \ No newline at end of file diff --git a/nucleus/admin/template/src/main/resources/lib/warlibs/.gitkeep b/nucleus/admin/template/src/main/resources/lib/warlibs/.gitkeep deleted file mode 100644 index e69de29bb2d..00000000000 diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java index d2a7c3a1881..1f9b249c51f 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/ASURLClassLoader.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ - // Portions Copyright [2016-2025] [Payara Foundation and/or its affiliates] + // Portions Copyright [2016-2024] [Payara Foundation and/or its affiliates] package com.sun.enterprise.loader; @@ -197,8 +197,6 @@ public void done() { return; } - CacheCleaner.clearCaches(this); - // Capture the fact that the classloader is now effectively disabled. // First create a snapshot of our state. This should be called // before setting doneCalled = true. @@ -727,14 +725,9 @@ protected Class findClass(String name) throws ClassNotFoundException { // set all spec and impl data for the package, // so just use null. This is consistent will the // JDK code that does the same. - var manifest = classData.jarFile == null ? null : classData.jarFile.getManifest(); - if (manifest == null) { - definePackage(packageName, null, null, null, - null, null, null, null); - } else { - definePackage(packageName, manifest, classData.pd.getCodeSource().getLocation()); - } - } catch(IllegalArgumentException | IOException iae) { + definePackage(packageName, null, null, null, + null, null, null, null); + } catch(IllegalArgumentException iae) { // duplicate attempt to define same package. // safe to ignore. _logger.log(Level.FINE, "duplicate package " + @@ -809,14 +802,14 @@ protected synchronized ClassData findClassData(String name) throws ClassNotFound byte[] result = loadClassData0(u, entryName); if (result != null) { if (System.getSecurityManager() == null) { - return new ClassData(result, u.pd, u.zip); + return new ClassData(result, u.pd); } else { //recreate the pd to include the declared permissions CodeSource cs = u.pd.getCodeSource(); PermissionCollection pc = this.getPermissions(cs); ProtectionDomain pdWithPemissions = new ProtectionDomain(u.pd.getCodeSource(), pc, u.pd.getClassLoader(), u.pd.getPrincipals()); - return new ClassData(result, pdWithPemissions, u.zip); + return new ClassData(result, pdWithPemissions); } } } @@ -1328,12 +1321,10 @@ private static final class ClassData { /** must be 'final' to ensure thread visibility */ private final ProtectionDomain pd; - private final JarFile jarFile; - ClassData(byte[] classBytes, ProtectionDomain pd, JarFile jarFile) { + ClassData(byte[] classBytes, ProtectionDomain pd) { this.classBytes = classBytes; this.pd = pd; - this.jarFile = jarFile; } private synchronized byte[] getClassBytes() { return classBytes; diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CacheCleaner.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CacheCleaner.java deleted file mode 100644 index 5360afee697..00000000000 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CacheCleaner.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2024] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/main/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package com.sun.enterprise.loader; - -import com.sun.enterprise.util.CULoggerInfo; -import java.lang.reflect.Field; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class CacheCleaner { - private static final Logger logger = CULoggerInfo.getLogger(); - - public static void clearCaches(ClassLoader classLoader) { - clearOmniFacesCache(classLoader); - clearJNACache(classLoader); - while (classLoader != null) { - clearJaxRSCache(classLoader); - classLoader = classLoader.getParent(); - } - } - - private static void clearJaxRSCache(ClassLoader classLoader) { - try { - Class cdiComponentProvider = CachingReflectionUtil - .getClassFromCache("org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider", classLoader); - if (cdiComponentProvider != null) { - Field runtimeSpecificsField = CachingReflectionUtil.getFieldFromCache(cdiComponentProvider, - "runtimeSpecifics", true); - Object runtimeSpecifics = runtimeSpecificsField.get(null); - CachingReflectionUtil.getMethodFromCache(runtimeSpecifics.getClass(), - "clearJaxRsResource", true, ClassLoader.class) - .invoke(runtimeSpecifics, classLoader); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Error clearing Jax-Rs cache", e); - } - } - - private static void clearOmniFacesCache(ClassLoader classLoader) { - try { - Class eagerBeans = CachingReflectionUtil - .getClassFromCache("org.omnifaces.cdi.eager.EagerBeansRepository", classLoader); - if (eagerBeans != null && eagerBeans.getClassLoader() instanceof CurrentBeforeParentClassLoader) { - Field instance = CachingReflectionUtil.getFieldFromCache(eagerBeans, "instance", true); - instance.set(null, null); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Error clearing OmniFaces cache", e); - } - } - - private static void clearJNACache(ClassLoader classLoader) { - try { - Class cleanerClass = CachingReflectionUtil - .getClassFromCache("com.sun.jna.internal.Cleaner", classLoader); - if (cleanerClass != null && cleanerClass.getClassLoader() instanceof CurrentBeforeParentClassLoader) { - Field instanceField = CachingReflectionUtil.getFieldFromCache(cleanerClass, "INSTANCE", true); - Object instance = instanceField.get(null); - CachingReflectionUtil.getFieldFromCache(instance.getClass(), "cleanerThread", true) - .set(instance, null); - } - } catch (Exception e) { - logger.log(Level.WARNING, "Error clearing JNA cache", e); - } - } -} diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CachingReflectionUtil.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CachingReflectionUtil.java deleted file mode 100644 index 4d38a905345..00000000000 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/CachingReflectionUtil.java +++ /dev/null @@ -1,106 +0,0 @@ -/* - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. - * - * Copyright (c) [2024] Payara Foundation and/or its affiliates. All rights reserved. - * - * The contents of this file are subject to the terms of either the GNU - * General Public License Version 2 only ("GPL") or the Common Development - * and Distribution License("CDDL") (collectively, the "License"). You - * may not use this file except in compliance with the License. You can - * obtain a copy of the License at - * https://github.com/payara/Payara/blob/main/LICENSE.txt - * See the License for the specific - * language governing permissions and limitations under the License. - * - * When distributing the software, include this License Header Notice in each - * file and include the License file at glassfish/legal/LICENSE.txt. - * - * GPL Classpath Exception: - * The Payara Foundation designates this particular file as subject to the "Classpath" - * exception as provided by the Payara Foundation in the GPL Version 2 section of the License - * file that accompanied this code. - * - * Modifications: - * If applicable, add the following below the License Header, with the fields - * enclosed by brackets [] replaced by your own identifying information: - * "Portions Copyright [year] [name of copyright owner]" - * - * Contributor(s): - * If you wish your version of this file to be governed by only the CDDL or - * only the GPL Version 2, indicate your decision by adding "[Contributor] - * elects to include this software in this distribution under the [CDDL or GPL - * Version 2] license." If you don't indicate a single choice of license, a - * recipient has the option to distribute your version of this file under - * either the CDDL, the GPL Version 2 or to extend the choice of license to - * its licensees as provided above. However, if you add GPL Version 2 code - * and therefore, elected the GPL Version 2 license, then the option applies - * only if the new code is made subject to such option by the copyright - * holder. - */ -package com.sun.enterprise.loader; - - -import com.sun.enterprise.util.CULoggerInfo; -import java.lang.reflect.Field; -import java.lang.reflect.Method; -import java.util.Map; -import java.util.concurrent.ConcurrentHashMap; -import java.util.logging.Level; -import java.util.logging.Logger; - -public class CachingReflectionUtil { - private static final Logger logger = CULoggerInfo.getLogger(); - - private static final Map> classCache = new ConcurrentHashMap<>(); - private static final Map methodCache = new ConcurrentHashMap<>(); - private static final Map fieldCache = new ConcurrentHashMap<>(); - - public static Class getClassFromCache(String className, ClassLoader classLoader) { - var cls = classCache.computeIfAbsent(className, k -> { - try { - return classLoader.loadClass(className); - } catch (ClassNotFoundException e) { - logger.log(Level.FINE, "Class not found: " + className, e); - return null; - } - }); - if (cls != null && cls.getClassLoader() == classLoader) { - classCache.remove(cls.getName()); - } - return cls; - } - - public static Method getMethodFromCache(Class cls, String methodName, boolean isPrivate, Class... parameterTypes) { - return methodCache.computeIfAbsent(methodName, k -> { - try { - if (isPrivate) { - Method method = cls.getDeclaredMethod(methodName, parameterTypes); - method.setAccessible(true); - return method; - } else { - return cls.getMethod(methodName, parameterTypes); - } - } catch (NoSuchMethodException e) { - logger.log(Level.FINE, "Method not found: " + methodName, e); - return null; - } - }); - } - - public static Field getFieldFromCache(Class cls, String fieldName, boolean isPrivate) { - return fieldCache.computeIfAbsent(fieldName, k -> { - try { - if (isPrivate) { - Field field = cls.getDeclaredField(fieldName); - field.setAccessible(true); - return field; - } else { - return cls.getField(fieldName); - } - } catch (NoSuchFieldException e) { - logger.log(Level.FINE, "Field not found: " + fieldName, e); - return null; - } - }); - } -} diff --git a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/DirWatcher.java b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/DirWatcher.java index d060653b2dd..d6599566f67 100644 --- a/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/DirWatcher.java +++ b/nucleus/common/common-util/src/main/java/com/sun/enterprise/loader/DirWatcher.java @@ -1,7 +1,7 @@ /* * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. * - * Copyright (c) [2019-2024] Payara Foundation and/or its affiliates. All rights reserved. + * Copyright (c) [2019] Payara Foundation and/or its affiliates. All rights reserved. * * The contents of this file are subject to the terms of either the GNU * General Public License Version 2 only ("GPL") or the Common Development @@ -208,7 +208,7 @@ protected void register() { try (Stream stream = Files.list(root)){ stream.forEach(this::registerSubProcessor); } catch (IOException e) { - LOGGER.log(Level.FINE, "Error when listing directory",e); + LOGGER.log(Level.INFO, "Error when listing directory",e); } } diff --git a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java index b3eb8bcb7cc..4329a06d885 100644 --- a/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java +++ b/nucleus/core/kernel/src/main/java/com/sun/enterprise/v3/server/ApplicationLifecycle.java @@ -604,7 +604,6 @@ public void actOn(Logger logger) { if (report.getActionExitCode() != ActionReport.ExitCode.SUCCESS) { context.postDeployClean(false /* not final clean-up yet */); events.send(new Event<>(Deployment.DEPLOYMENT_FAILURE, context)); - currentDeploymentContext.get().pop(); } } ApplicationDeployment depl = new ApplicationDeployment(appInfo, context); @@ -647,8 +646,8 @@ public void initialize(ApplicationInfo appInfo, Collection sn events.send(new Event<>(Deployment.DEPLOYMENT_SUCCESS, appInfo)); } } + currentDeploymentContext.get().pop(); } - currentDeploymentContext.get().pop(); } @Override diff --git a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentContextImpl.java b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentContextImpl.java index 235ecdcc119..f35a5bc88ca 100644 --- a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentContextImpl.java +++ b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentContextImpl.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2019-2024] Payara Foundation and/or affiliates +// Portions Copyright [2019-2022] Payara Foundation and/or affiliates package org.glassfish.deployment.common; @@ -55,7 +55,6 @@ import org.glassfish.internal.deployment.*; import org.glassfish.loader.util.ASClassLoaderUtil; -import java.lang.ref.WeakReference; import java.util.*; import java.util.logging.Logger; import java.io.File; @@ -72,6 +71,8 @@ import com.sun.enterprise.util.io.FileUtils; import fish.payara.nucleus.hotdeploy.ApplicationState; import fish.payara.nucleus.hotdeploy.HotDeployService; +import java.io.Closeable; +import java.util.logging.Level; import static java.util.logging.Level.FINE; import static java.util.logging.Level.FINEST; import org.glassfish.api.deployment.DeployCommandParameters; @@ -116,7 +117,7 @@ public class DeploymentContextImpl implements ExtendedDeploymentContext, PreDest Map modulesMetaData = new HashMap(); List transformers = new ArrayList(); Phase phase = Phase.UNKNOWN; - WeakReference sharableTemp = null; + ClassLoader sharableTemp = null; Map modulePropsMap = new HashMap(); Map transientAppMetaData = new HashMap(); Map moduleArchiveHandlers = new HashMap(); @@ -183,7 +184,7 @@ public synchronized void preDestroy() { boolean hotDeploy = getCommandParameters(DeployCommandParameters.class).hotDeploy; if (!hotDeploy) { try { - PreDestroy.class.cast(sharableTemp.get()).preDestroy(); + PreDestroy.class.cast(sharableTemp).preDestroy(); } catch (Exception e) { // ignore, the classloader does not need to be destroyed } @@ -248,9 +249,9 @@ public synchronized void createDeploymentClassLoader(ClassLoaderHierarchy clh, A this.addTransientAppMetaData(ExtendedDeploymentContext.IS_TEMP_CLASSLOADER, Boolean.TRUE); boolean hotDeploy = getCommandParameters(DeployCommandParameters.class).hotDeploy; if (hotDeploy && this.cloader != null) { - this.sharableTemp = new WeakReference<>(this.cloader); + this.sharableTemp = this.cloader; } else { - this.sharableTemp = new WeakReference<>(createClassLoader(clh, handler, null)); + this.sharableTemp = createClassLoader(clh, handler, null); } } @@ -279,7 +280,7 @@ public synchronized ClassLoader getClassLoader(boolean sharable) { // otherwise, we return the final one. if (phase == Phase.PREPARE) { if (sharable) { - return sharableTemp.get(); + return sharableTemp; } else { InstrumentableClassLoader cl = InstrumentableClassLoader.class.cast(sharableTemp); return cl.copy(); @@ -287,7 +288,7 @@ public synchronized ClassLoader getClassLoader(boolean sharable) { } else { // we are out of the prepare phase, destroy the shareableTemp and // return the final classloader - if (sharableTemp != null && sharableTemp.get() != cloader) { + if (sharableTemp != null && sharableTemp != cloader) { try { PreDestroy.class.cast(sharableTemp).preDestroy(); } catch (Exception e) { diff --git a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentUtils.java b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentUtils.java index 9ea44d5fefb..f9bb91ba00d 100644 --- a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentUtils.java +++ b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/DeploymentUtils.java @@ -37,7 +37,7 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright [2018-2024] Payara Foundation and/or affiliates +// Portions Copyright [2018] Payara Foundation and/or affiliates package org.glassfish.deployment.common; @@ -54,9 +54,6 @@ import fish.payara.enterprise.config.serverbeans.DeploymentGroup; import org.glassfish.api.deployment.DeploymentContext; import org.glassfish.hk2.api.ServiceLocator; -import org.glassfish.hk2.classmodel.reflect.Type; -import org.glassfish.internal.api.Globals; -import org.glassfish.internal.deployment.Deployment; import org.glassfish.loader.util.ASClassLoaderUtil; @@ -65,9 +62,7 @@ import java.io.InputStream; import java.io.OutputStream; import java.io.BufferedInputStream; -import java.nio.file.Path; import java.util.Enumeration; -import java.util.Map; import java.util.Properties; import java.net.URI; import java.net.URL; @@ -75,8 +70,6 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; -import java.util.concurrent.ConcurrentHashMap; -import java.util.stream.Collectors; import java.util.zip.Adler32; import java.util.jar.Manifest; import java.util.jar.JarFile; @@ -86,6 +79,8 @@ import org.glassfish.logging.annotation.LogMessageInfo; +import org.glassfish.logging.annotation.LoggerInfo; +import org.glassfish.logging.annotation.LogMessagesResourceBundle; /** * Utility methods for deployment. @@ -99,8 +94,7 @@ public class DeploymentUtils { private static final String EXCEPTION_CAUGHT = "NCLS-DEPLOYMENT-00010"; public static final String DEPLOYMENT_PROPERTY_JAVA_WEB_START_ENABLED = "java-web-start-enabled"; - public static final String WAR_LIBRARIES = "warlibs"; - + final private static LocalStringManagerImpl localStrings = new LocalStringManagerImpl(DeploymentUtils.class); private static final String V2_COMPATIBILITY = "v2"; @@ -113,26 +107,6 @@ public class DeploymentUtils { private final static String DOWNLOADABLE_ARTIFACTS_KEY_PREFIX = "downloadable"; private final static String GENERATED_ARTIFACTS_KEY_PREFIX = "generated"; - private static final Map warLibraryCache = new ConcurrentHashMap<>(); - - public static class WarLibraryDescriptor { - private final Descriptor descriptor; - private final List types; - - public WarLibraryDescriptor(Descriptor descriptor, List types) { - this.descriptor = descriptor; - this.types = types; - } - - public Descriptor getDescriptor() { - return descriptor; - } - - public List getTypes() { - return types; - } - } - public static boolean isDASTarget(final String targetName) { return DAS_TARGET_NAME.equals(targetName); } @@ -462,36 +436,9 @@ public static List getExternalLibraries(ReadableArchive archive) { } catch (Exception e) { Logger.getAnonymousLogger().log(Level.WARNING, e.getMessage(), e); } - externalLibURIs.addAll(getWarLibraryURIs(getCurrentDeploymentContext())); return externalLibURIs; } - public static DeploymentContext getCurrentDeploymentContext() { - try { - return Globals.getDefaultHabitat().getService(Deployment.class).getCurrentDeploymentContext(); - } catch (Exception e) { - return null; - } - } - - public static List getWarLibraryURIs(DeploymentContext context) { - if(useWarLibraries(context)) { - return InstalledLibrariesResolver.getWarLibraries().stream() - .filter(key -> !warLibraryCache.containsKey(key.toString())) - .map(Path::toUri).collect(Collectors.toList()); - } else { - return List.of(); - } - } - - public static boolean useWarLibraries(DeploymentContext context) { - return context != null && Boolean.parseBoolean(context.getAppProps().getProperty(WAR_LIBRARIES)); - } - - public static Map getWarLibraryCache() { - return warLibraryCache; - } - /** * Opens the specified file as an archive, using the provided archive factory. * @param dir directory to be opened as an archive diff --git a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/InstalledLibrariesResolver.java b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/InstalledLibrariesResolver.java index 6df72755c4a..192e5ffab46 100644 --- a/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/InstalledLibrariesResolver.java +++ b/nucleus/deployment/common/src/main/java/org/glassfish/deployment/common/InstalledLibrariesResolver.java @@ -37,13 +37,11 @@ * only if the new code is made subject to such option by the copyright * holder. */ -// Portions Copyright 2018-2024 Payara Foundation and/or affiliates +// Portions Copyright 2018-2022 Payara Foundation and/or affiliates package org.glassfish.deployment.common; import java.io.*; -import java.nio.file.Files; -import java.nio.file.Path; import java.text.MessageFormat; import java.util.jar.JarFile; import java.util.jar.Manifest; @@ -51,7 +49,6 @@ import java.util.jar.JarInputStream; import java.util.logging.*; import java.util.*; -import java.util.stream.Collectors; import org.glassfish.api.deployment.archive.ReadableArchive; @@ -68,7 +65,6 @@ public class InstalledLibrariesResolver { // installed libraries list (accounts only for "domainRoot/lib/applibs" and not any // of "java.ext.dirs" entries) private static Map appLibsDirLibsStore = new HashMap(); - private static List warLibraries = new ArrayList<>(); public static final Logger deplLogger = org.glassfish.deployment.common.DeploymentContextImpl.deplLogger; @@ -115,13 +111,6 @@ public static boolean resolveDependencies(Manifest manifest, String archiveUri) * @param libDir libraryDirectory */ public static void initializeInstalledLibRegistry(String libDir ) { - try (var jarStream = Files.list(Path.of(String.format("%s/warlibs", libDir))) - .filter(path -> (Files.isRegularFile(path) || Files.isSymbolicLink(path)) - && path.toString().endsWith(".jar"))){ - warLibraries = jarStream.collect(Collectors.toList()); - } catch (IOException e) { - deplLogger.fine("Error in opening package directory " + libDir + " due to exception: " + e.getMessage()); - } initializeInstalledLibRegistryForApplibs(libDir); } @@ -158,15 +147,6 @@ public static Set getInstalledLibraries(ReadableArchive archive) throws return libraries; } - /** - * These libraries will be included in non-internal WAR applications, - * to improve developer experience and not require all dependencies to be included in the WAR. - * @return list of libraries in /lib/warlibs - */ - public static List getWarLibraries() { - return warLibraries; - } - private static Set getInstalledLibraries(String archiveURI, Manifest manifest, boolean strict, Map libraryStore) { Set libraries = new HashSet();