diff --git a/modules/container/src/main/java/module-info.java b/modules/container/src/main/java/module-info.java index 415e91e98223..a09aa67a1274 100644 --- a/modules/container/src/main/java/module-info.java +++ b/modules/container/src/main/java/module-info.java @@ -32,5 +32,6 @@ org.mule.runtime.deployment.model.impl, org.mule.runtime.service, org.mule.runtime.spring.config, - org.mule.test.runner; + org.mule.test.runner, + gorg.mule.framework; } diff --git a/modules/service/src/main/java/module-info.java b/modules/service/src/main/java/module-info.java index 2d966a301d3f..2bab454c4827 100644 --- a/modules/service/src/main/java/module-info.java +++ b/modules/service/src/main/java/module-info.java @@ -31,7 +31,8 @@ exports org.mule.runtime.module.service.api.manager; exports org.mule.runtime.module.service.internal.artifact to - org.mule.test.runner; + org.mule.test.runner, + giorg.mule.framework; exports org.mule.runtime.module.service.internal.discoverer to org.mule.runtime.artifact.activation, org.mule.runtime.deployment.model.impl; diff --git a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactory.java b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactory.java index 8eaca4f3006b..7ae61f7f9627 100644 --- a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactory.java +++ b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactory.java @@ -1,77 +1,23 @@ -/* - * Copyright 2023 Salesforce, Inc. All rights reserved. - * The software in this package is published under the terms of the CPAL v1.0 - * license, a copy of which has been included with this distribution in the - * LICENSE.txt file. - */ package org.mule.runtime.module.service.api.artifact; import org.mule.runtime.container.api.ContainerDependantArtifactClassLoaderFactory; import org.mule.runtime.container.api.MuleContainerClassLoaderWrapper; -import org.mule.runtime.container.internal.DefaultMuleContainerClassLoaderWrapper; import org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader; import org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoaderFactory; import org.mule.runtime.module.artifact.api.classloader.ClassLoaderLookupPolicy; -import org.mule.runtime.module.artifact.api.classloader.MuleArtifactClassLoader; -/** - * Creates {@link ArtifactClassLoader} for service descriptors. - * - */ -// TODO W-12780081 - remove usages of deprecated creation method -public class ServiceClassLoaderFactory - implements ArtifactClassLoaderFactory, ContainerDependantArtifactClassLoaderFactory { +public interface ServiceClassLoaderFactory + extends ArtifactClassLoaderFactory, ContainerDependantArtifactClassLoaderFactory { - /** - * @deprecated from 4.6 use {@link ServiceClassLoaderFactoryProvider} instead. - */ - @Deprecated - public ServiceClassLoaderFactory() { - // Nothing to do - } - - /** - * {@inheritDoc} - * - * @deprecated since 4.6, use {@link #create(String, ServiceDescriptor, MuleContainerClassLoaderWrapper)}. - */ @Override @Deprecated - public ArtifactClassLoader create(String artifactId, ServiceDescriptor descriptor, ClassLoader parent, - ClassLoaderLookupPolicy lookupPolicy) { - return new MuleArtifactClassLoader(artifactId, descriptor, descriptor.getClassLoaderConfiguration().getUrls(), parent, - lookupPolicy); - } + ArtifactClassLoader create(String artifactId, ServiceDescriptor descriptor, ClassLoader parent, + ClassLoaderLookupPolicy lookupPolicy); - /** - * {@inheritDoc} - */ @Override - public ArtifactClassLoader create(String artifactId, ServiceDescriptor descriptor, - MuleContainerClassLoaderWrapper containerClassLoader) { - return new MuleArtifactClassLoader(artifactId, descriptor, descriptor.getClassLoaderConfiguration().getUrls(), - containerClassLoader.getContainerClassLoader().getClassLoader(), - containerClassLoader.getContainerClassLoaderLookupPolicy()); - } - - /** - * Creates a {@link ClassLoader} from a given descriptor. - * - * @param artifactId artifact unique ID. - * @param descriptor descriptor of the artifact owner of the created class loader. - * @param containerClassLoader parent for the new artifact class loader. - * @return a new class loader for described artifact. - * - * @since 4.6 - */ - public ArtifactClassLoader create(String artifactId, ServiceDescriptor descriptor, - ArtifactClassLoader containerClassLoader) { - return create(artifactId, descriptor, new DefaultMuleContainerClassLoaderWrapper(containerClassLoader)); - } + ArtifactClassLoader create(String artifactId, ServiceDescriptor descriptor, + MuleContainerClassLoaderWrapper containerClassLoader); @Override - public void setParentLayerFrom(Class clazz) { - // Nothing to do - } - + void setParentLayerFrom(Class clazz); } diff --git a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceModuleLayerFactory.java b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryImpl.java similarity index 97% rename from modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceModuleLayerFactory.java rename to modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryImpl.java index 6085a0d1da38..c019e07caefd 100644 --- a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceModuleLayerFactory.java +++ b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryImpl.java @@ -36,10 +36,13 @@ /** * Creates {@link ArtifactClassLoader} for service descriptors. + * */ -class ServiceModuleLayerFactory extends ServiceClassLoaderFactory { +public class ServiceClassLoaderFactoryImpl + implements + ServiceClassLoaderFactory { - private static final Logger LOGGER = LoggerFactory.getLogger(ServiceModuleLayerFactory.class); + private static final Logger LOGGER = LoggerFactory.getLogger(ServiceClassLoaderFactoryImpl.class); private static final String CONTAINER_LAYER_NAME = "Mule Container Module Layer"; // prefixes of services provided by the Mule Runtime team @@ -55,7 +58,7 @@ private MuleServiceClassLoader(String artifactId, ArtifactDescriptor artifactDes } } - private Optional parentLayer = ofNullable(ServiceModuleLayerFactory.class.getModule().getLayer()); + private Optional parentLayer = ofNullable(ServiceClassLoaderFactoryImpl.class.getModule().getLayer()); /** * {@inheritDoc} @@ -157,5 +160,4 @@ public ArtifactClassLoader create(String artifactId, ServiceDescriptor descripto public void setParentLayerFrom(Class clazz) { parentLayer = ofNullable(clazz.getModule().getLayer()); } - } diff --git a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryProvider.java b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryProvider.java index e5bf2d50af7b..712a5d01905b 100644 --- a/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryProvider.java +++ b/modules/service/src/main/java/org/mule/runtime/module/service/api/artifact/ServiceClassLoaderFactoryProvider.java @@ -6,8 +6,6 @@ */ package org.mule.runtime.module.service.api.artifact; -import static org.mule.runtime.api.util.MuleSystemProperties.classloaderContainerJpmsModuleLayer; - import org.mule.runtime.module.artifact.api.descriptor.ClassLoaderConfigurationLoader; import org.mule.runtime.module.service.internal.artifact.LibFolderClassLoaderConfigurationLoader; @@ -30,23 +28,10 @@ public static ClassLoaderConfigurationLoader serviceClassLoaderConfigurationLoad return new LibFolderClassLoaderConfigurationLoader(); } - private static boolean withinModularizedContainer = ServiceClassLoaderFactoryProvider.class.getModule().isNamed(); - public static ServiceClassLoaderFactory serviceClassLoaderFactory() { - if (classloaderContainerJpmsModuleLayer() - // Only if the container is modularized it makes sense to load services as module layers - && withinModularizedContainer) { - LOGGER.debug("MRJAR 'ServiceClassLoaderFactoryProvider' implementation, using 'ServiceModuleLayerFactory'..."); - final ServiceModuleLayerFactory serviceModuleLayerFactory = new ServiceModuleLayerFactory(); - serviceModuleLayerFactory.setParentLayerFrom(ServiceClassLoaderFactoryProvider.class); - return serviceModuleLayerFactory; - } else { - LOGGER.debug("MRJAR 'ServiceClassLoaderFactoryProvider' implementation, using 'ServiceClassLoaderFactory'..."); - return new ServiceClassLoaderFactory(); - } - } - - public static void setWithinModularizedContainer(boolean withinModularizedContainer) { - ServiceClassLoaderFactoryProvider.withinModularizedContainer = withinModularizedContainer; + LOGGER.debug("MRJAR 'ServiceClassLoaderFactoryProvider' implementation, using 'ServiceClassLoaderFactoryImpl'..."); + final ServiceClassLoaderFactory serviceModuleLayerFactory = new ServiceClassLoaderFactoryImpl(); + serviceModuleLayerFactory.setParentLayerFrom(ServiceClassLoaderFactoryProvider.class); + return serviceModuleLayerFactory; } } diff --git a/modules/service/src/test/java/org/mule/runtime/module/service/internal/test/discoverer/FileSystemServiceProviderDiscovererTestCase.java b/modules/service/src/test/java/org/mule/runtime/module/service/internal/test/discoverer/FileSystemServiceProviderDiscovererTestCase.java index 35a5e24afc64..bca675943e56 100644 --- a/modules/service/src/test/java/org/mule/runtime/module/service/internal/test/discoverer/FileSystemServiceProviderDiscovererTestCase.java +++ b/modules/service/src/test/java/org/mule/runtime/module/service/internal/test/discoverer/FileSystemServiceProviderDiscovererTestCase.java @@ -36,6 +36,7 @@ import org.mule.runtime.module.artifact.api.descriptor.ClassLoaderConfigurationLoader; import org.mule.runtime.module.artifact.api.descriptor.DescriptorLoaderRepository; import org.mule.runtime.module.service.api.artifact.ServiceClassLoaderFactory; +import org.mule.runtime.module.service.api.artifact.ServiceClassLoaderFactoryImpl; import org.mule.runtime.module.service.api.artifact.ServiceDescriptor; import org.mule.runtime.module.service.api.discoverer.ServiceAssembly; import org.mule.runtime.module.service.builder.ServiceFileBuilder; @@ -65,7 +66,7 @@ public class FileSystemServiceProviderDiscovererTestCase extends AbstractMuleTes @Rule public SystemPropertyTemporaryFolder temporaryFolder = new SystemPropertyTemporaryFolder(MULE_HOME_DIRECTORY_PROPERTY); - private final ServiceClassLoaderFactory serviceClassLoaderFactory = mock(ServiceClassLoaderFactory.class); + private final ServiceClassLoaderFactory serviceClassLoaderFactory = mock(ServiceClassLoaderFactoryImpl.class); private final ArtifactClassLoader containerClassLoader = mock(ArtifactClassLoader.class); private final DescriptorLoaderRepository descriptorLoaderRepository = mock(DescriptorLoaderRepository.class); private final ArtifactDescriptorValidator artifactDescriptorValidator = mock(ArtifactDescriptorValidator.class); diff --git a/tests/runner/src/main/java/org/mule/test/runner/classloader/IsolatedClassLoaderFactory.java b/tests/runner/src/main/java/org/mule/test/runner/classloader/IsolatedClassLoaderFactory.java index 1fe7edd0cb0c..6d8e40279421 100644 --- a/tests/runner/src/main/java/org/mule/test/runner/classloader/IsolatedClassLoaderFactory.java +++ b/tests/runner/src/main/java/org/mule/test/runner/classloader/IsolatedClassLoaderFactory.java @@ -55,8 +55,7 @@ import org.mule.runtime.module.artifact.internal.util.FileJarExplorer; import org.mule.runtime.module.artifact.internal.util.JarExplorer; import org.mule.runtime.module.artifact.internal.util.JarInfo; -import org.mule.runtime.module.service.api.artifact.ServiceClassLoaderFactory; -import org.mule.runtime.module.service.api.artifact.ServiceClassLoaderFactoryProvider; +import org.mule.runtime.module.service.api.artifact.ServiceClassLoaderFactoryImpl; import org.mule.runtime.module.service.api.artifact.ServiceDescriptor; import org.mule.test.runner.api.ArtifactClassLoaderHolder; import org.mule.test.runner.api.ArtifactsUrlClassification; @@ -146,10 +145,9 @@ public ArtifactClassLoaderHolder createArtifactClassLoader(List extraBoo containerClassLoaderWrapper = testContainerClassLoaderAssembler.createContainerClassLoader(); ModuleRepository moduleRepository = testContainerClassLoaderAssembler.getModuleRepository(); - ServiceClassLoaderFactoryProvider.setWithinModularizedContainer(true); ContainerDependantArtifactClassLoaderFactory serviceClassLoaderFactory = serviceClassLoaderFactory(); serviceClassLoaderFactory.setParentLayerFrom(containerClassLoaderWrapper.getContainerClassLoader().getClassLoader() - .loadClass(ServiceClassLoaderFactory.class.getName())); + .loadClass(ServiceClassLoaderFactoryImpl.class.getName())); List serviceArtifactClassLoaders = createServiceClassLoaders(serviceClassLoaderFactory, containerClassLoaderWrapper, artifactsUrlClassification);