Skip to content

Commit

Permalink
...
Browse files Browse the repository at this point in the history
  • Loading branch information
lbarrios committed Nov 21, 2024
1 parent 533154b commit 7c4ead8
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 91 deletions.
3 changes: 2 additions & 1 deletion modules/container/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
3 changes: 2 additions & 1 deletion modules/service/src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<ServiceDescriptor>, ContainerDependantArtifactClassLoaderFactory<ServiceDescriptor> {
public interface ServiceClassLoaderFactory
extends ArtifactClassLoaderFactory<ServiceDescriptor>, ContainerDependantArtifactClassLoaderFactory<ServiceDescriptor> {

/**
* @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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -55,7 +58,7 @@ private MuleServiceClassLoader(String artifactId, ArtifactDescriptor artifactDes
}
}

private Optional<ModuleLayer> parentLayer = ofNullable(ServiceModuleLayerFactory.class.getModule().getLayer());
private Optional<ModuleLayer> parentLayer = ofNullable(ServiceClassLoaderFactoryImpl.class.getModule().getLayer());

/**
* {@inheritDoc}
Expand Down Expand Up @@ -157,5 +160,4 @@ public ArtifactClassLoader create(String artifactId, ServiceDescriptor descripto
public void setParentLayerFrom(Class clazz) {
parentLayer = ofNullable(clazz.getModule().getLayer());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -146,10 +145,9 @@ public ArtifactClassLoaderHolder createArtifactClassLoader(List<String> extraBoo
containerClassLoaderWrapper = testContainerClassLoaderAssembler.createContainerClassLoader();
ModuleRepository moduleRepository = testContainerClassLoaderAssembler.getModuleRepository();

ServiceClassLoaderFactoryProvider.setWithinModularizedContainer(true);
ContainerDependantArtifactClassLoaderFactory<ServiceDescriptor> serviceClassLoaderFactory = serviceClassLoaderFactory();
serviceClassLoaderFactory.setParentLayerFrom(containerClassLoaderWrapper.getContainerClassLoader().getClassLoader()
.loadClass(ServiceClassLoaderFactory.class.getName()));
.loadClass(ServiceClassLoaderFactoryImpl.class.getName()));
List<ArtifactClassLoader> serviceArtifactClassLoaders =
createServiceClassLoaders(serviceClassLoaderFactory, containerClassLoaderWrapper, artifactsUrlClassification);

Expand Down

0 comments on commit 7c4ead8

Please sign in to comment.