public TestRegionClassLoader(ClassLoader parent, ClassLoaderLookupPolicy lookupPolicy) { super("Region", new ArtifactDescriptor("Region"), parent, lookupPolicy); }
@Override public String toString() { return format("%s[%s]", getClass().getSimpleName(), getName()); }
private void doValidate(ArtifactDescriptor descriptor) { String bundleDescriptorVersion = descriptor.getBundleDescriptor().getVersion(); checkState(bundleDescriptorVersion != null, format("No version specified in the bundle descriptor of the artifact %s", descriptor.getName())); MuleVersion artifactVersion = new MuleVersion(bundleDescriptorVersion); checkState(artifactVersion.getRevision() != NO_REVISION, format("Artifact %s version %s must contain a revision number. The version format must be x.y.z and the z part is missing", descriptor.getName(), artifactVersion)); }
@Override public void validate(ArtifactDescriptor descriptor) { Product requiredProduct = descriptor.getRequiredProduct(); Product runtimeProduct = getProductByName(getProductName()); if (!runtimeProduct.supports(requiredProduct)) { throw new MuleRuntimeException(createStaticMessage("The artifact %s requires a different runtime. The artifact required runtime is %s and the runtime is %s", descriptor.getName(), descriptor.getRequiredProduct().name(), runtimeProduct.name())); } }
private void doValidation(ArtifactDescriptor descriptor, MuleVersion minMuleVersion, MuleVersion runtimeVersion) { if (runtimeVersion.priorTo(minMuleVersion)) { throw new MuleRuntimeException( createStaticMessage("Artifact %s requires a newest runtime version. Artifact required version is %s and Mule Runtime version is %s", descriptor.getName(), descriptor.getMinMuleVersion().toCompleteNumericVersion(), runtimeVersion.toCompleteNumericVersion())); } }
final ClassLoaderLookupPolicy containerLookupPolicy, ArtifactDescriptor artifactDescriptor) { final ArtifactDescriptor containerDescriptor = new ArtifactDescriptor("mule"); new MuleArtifactClassLoader(containerDescriptor.getName(), containerDescriptor, urls, parentClassLoader, containerLookupPolicy);
/** * Loads a descriptor from an artifact model * * @param artifactLocation folder where the artifact is located, it can be a folder or file depending on the artifact type. * @param artifactModel model representing the artifact. * @return a descriptor matching the provided model. */ protected final T loadFromJsonDescriptor(File artifactLocation, M artifactModel, Optional<Properties> deploymentProperties) { artifactModel.validateModel(artifactLocation.getName()); final T descriptor = createArtifactDescriptor(artifactLocation, artifactModel.getName(), deploymentProperties); if (artifactLocation.isDirectory()) { descriptor.setRootFolder(artifactLocation); } BundleDescriptor bundleDescriptor = getBundleDescriptor(artifactLocation, artifactModel); descriptor.setBundleDescriptor(bundleDescriptor); descriptor.setMinMuleVersion(new MuleVersion(artifactModel.getMinMuleVersion())); descriptor.setRequiredProduct(artifactModel.getRequiredProduct()); ClassLoaderModel classLoaderModel = getClassLoaderModel(artifactLocation, deploymentProperties, artifactModel.getClassLoaderModelLoaderDescriptor(), bundleDescriptor); descriptor.setClassLoaderModel(classLoaderModel); doDescriptorConfig(artifactModel, descriptor, artifactLocation); artifactDescriptorValidator.validate(descriptor); return descriptor; }
return classLoader.findResource(normalizedResource); } else { ClassLoaderModel classLoaderModel = this.getArtifactDescriptor().getClassLoaderModel(); for (BundleDependency dependency : classLoaderModel.getDependencies()) { BundleDescriptor descriptor = dependency.getDescriptor(); if (exportingArtifactClassLoaders != null) { for (ArtifactClassLoader artifactClassLoader : exportingArtifactClassLoaders) { BundleDescriptor descriptor = artifactClassLoader.getArtifactDescriptor().getBundleDescriptor();
@Override public void validate(ArtifactDescriptor descriptor) { if (doNotFailIfBundleDescriptorNotPresent && descriptor.getBundleDescriptor() == null) { return; } doValidate(descriptor); }
createArtifactClassLoaderFilter(artifactDescriptor.getClassLoaderModel(), parentLookupPolicy); for (ArtifactPluginDescriptor artifactPluginDescriptor : artifactPluginDescriptors) { final ArtifactClassLoaderFilter classLoaderFilter = createPluginClassLoaderFilter(artifactPluginDescriptor, artifactDescriptor.getClassLoaderModel().getExportedPackages(), parentLookupPolicy); regionClassLoader.addClassLoader(artifactPluginClassLoaders.get(artifactPluginIndex), classLoaderFilter);
public boolean shouldConfigureContext(MuleLoggerContext context) { if (!context.isArtifactClassloader()) { return true; } ArtifactDescriptor descriptor = context.getArtifactDescriptor(); if (descriptor == null || !descriptor.getDeploymentProperties().isPresent()) { return true; } Properties properties = descriptor.getDeploymentProperties().get(); return !parseBoolean(properties.getProperty(MULE_MUTE_APP_LOGS_DEPLOYMENT_PROPERTY, "false")); }
@Override public void setClassLoaderModel(ClassLoaderModel classLoaderModel) { checkArgument(classLoaderModel.getExportedPackages().isEmpty(), POLICY_EXPORTED_PACKAGES_ERROR); checkArgument(classLoaderModel.getExportedResources().isEmpty(), POLICY_EXPORTED_RESOURCE_ERROR); super.setClassLoaderModel(classLoaderModel); } }
/** * Overrides the method in order to create a {@link ArtifactClassLoader} that will have a CHILD_FIRST * {@link ClassLoaderLookupPolicy}, it is needed due to as difference from a mule standalone container where the parent * {@link ClassLoader} for the container only has bootstrap jars plugins mule modules and third-party libraries when the runner * runs this tests using has a full class path with all the artifacts declared as dependencies for the artifact so we have to * change that and change the look strategy to be CHILD_FIRST for the container. * <p/> * The {@code muleModules} parameter will be ignored due to it has all the modules in classpath, instead they are discovered * once again but using a {@link URLClassLoader} that has the {@link URL}'s classified for the container {@link ClassLoader}. * * @param parentClassLoader the parent {@link ClassLoader} to delegate PARENT look ups * @param muleModules {@link MuleModule} discovered from the launcher {@link ClassLoader} but will be not considered here due to * it has all the class path * @param containerLookupPolicy the default {@link ClassLoaderLookupPolicy} defined for a container but will be ignored due to * it has to be different when running with a full class path as parent {@link ClassLoader} * @param artifactDescriptor * @return the {@link ArtifactClassLoader} to be used for the container */ @Override protected ArtifactClassLoader createArtifactClassLoader(final ClassLoader parentClassLoader, final List<MuleModule> muleModules, final ClassLoaderLookupPolicy containerLookupPolicy, ArtifactDescriptor artifactDescriptor) { final ArtifactDescriptor containerDescriptor = new ArtifactDescriptor("mule"); containerClassLoader = new MuleArtifactClassLoader(containerDescriptor.getName(), containerDescriptor, urls, parentClassLoader, containerLookupPolicy); return createContainerFilteringClassLoader(withContextClassLoader(classLoader, () -> testContainerModuleRepository.getModules()), containerClassLoader); }
@Override public void validate(ArtifactDescriptor descriptor) { Product requiredProduct = descriptor.getRequiredProduct(); Product runtimeProduct = getProductByName(getProductName()); if (!runtimeProduct.supports(requiredProduct)) { throw new MuleRuntimeException(createStaticMessage("The artifact %s requires a different runtime. The artifact required runtime is %s and the runtime is %s", descriptor.getName(), descriptor.getRequiredProduct().name(), runtimeProduct.name())); } }
private void doValidation(ArtifactDescriptor descriptor, MuleVersion minMuleVersion, MuleVersion runtimeVersion) { if (runtimeVersion.priorTo(minMuleVersion)) { throw new MuleRuntimeException( createStaticMessage("Artifact %s requires a newest runtime version. Artifact required version is %s and Mule Runtime version is %s", descriptor.getName(), descriptor.getMinMuleVersion().toCompleteNumericVersion(), runtimeVersion.toCompleteNumericVersion())); } }
/** * Loads a descriptor from an artifact model * * @param artifactLocation folder where the artifact is located, it can be a folder or file depending on the artifact type. * @param artifactModel model representing the artifact. * @return a descriptor matching the provided model. */ protected final T loadFromJsonDescriptor(File artifactLocation, M artifactModel, Optional<Properties> deploymentProperties) { artifactModel.validateModel(artifactLocation.getName()); BundleDescriptor bundleDescriptor = getBundleDescriptor(artifactLocation, artifactModel); final T descriptor = createArtifactDescriptor(artifactLocation, artifactModel.getName(), deploymentProperties); if (artifactLocation.isDirectory()) { descriptor.setRootFolder(artifactLocation); } descriptor.setBundleDescriptor(bundleDescriptor); descriptor.setMinMuleVersion(new MuleVersion(artifactModel.getMinMuleVersion())); descriptor.setRequiredProduct(artifactModel.getRequiredProduct()); ClassLoaderModel classLoaderModel = getClassLoaderModel(artifactLocation, artifactModel.getClassLoaderModelLoaderDescriptor()); descriptor.setClassLoaderModel(classLoaderModel); doDescriptorConfig(artifactModel, descriptor, artifactLocation); artifactDescriptorValidator.validate(descriptor); return descriptor; }
Optional<ArtifactClassLoader> pluginClassLoader = classLoaders.stream().filter( c -> c.getArtifactDescriptor() .getBundleDescriptor().getArtifactId() .equals(dependencyPluginDescriptor .getBundleDescriptor()
@Test public void remembersRamlApiClassLoader() throws Exception { final ClassLoader parentClassLoader = mock(ClassLoader.class); ArtifactDescriptor appDescriptor = mock(ArtifactDescriptor.class); RegionClassLoader regionClassLoader = new RegionClassLoader(ARTIFACT_ID, appDescriptor, parentClassLoader, lookupPolicy); createClassLoaders(parentClassLoader); ClassLoaderModel classLoaderModel = new ClassLoaderModel.ClassLoaderModelBuilder() .dependingOn(newHashSet(new BundleDependency.Builder() .setBundleUri(API_LOCATION.toURI()) .setDescriptor(new BundleDescriptor.Builder() .setGroupId(GROUP_ID) .setArtifactId(SPECIFIC_ARTIFACT_ID) .setVersion(ARTIFACT_VERSION) .setClassifier("raml") .setType("zip") .build()) .build())) .build(); when(appDescriptor.getClassLoaderModel()).thenReturn(classLoaderModel); String apiResource = format(SPECIFIC_RESOURCE_FORMAT, ARTIFACT_VERSION, "raml", "zip", API_RESOURCE_NAME); assertThat(regionClassLoader.findResource(apiResource), is(API_LOADED_RESOURCE)); assertThat(regionClassLoader.findResource(apiResource), is(API_LOADED_RESOURCE)); assertThat(regionClassLoader.findResource(apiResource), is(API_LOADED_RESOURCE)); assertThat(regionClassLoader.findResource(apiResource), is(API_LOADED_RESOURCE)); assertThat(regionClassLoader.findResource(apiResource), is(API_LOADED_RESOURCE)); verify(appDescriptor, times(1)).getClassLoaderModel(); }
@Before public void before() throws Exception { selector = new ArtifactAwareContextSelector(); when(artifactDescriptor.getDeploymentProperties()).thenReturn(empty()); when(regionClassLoader.getArtifactId()).thenReturn(getClass().getName()); when(regionClassLoader.findLocalResource("log4j2.xml")).thenReturn(CONFIG_LOCATION.toURI().toURL()); when(regionClassLoader.getArtifactDescriptor()).thenReturn(artifactDescriptor); }
public TestArtifactClassLoader(ClassLoader parentCl) { super("testId", new ArtifactDescriptor("test"), new URL[0], parentCl, new ClassLoaderLookupPolicy() { @Override public LookupStrategy getClassLookupStrategy(String className) { return PARENT_FIRST; } @Override public LookupStrategy getPackageLookupStrategy(String packageName) { return null; } @Override public ClassLoaderLookupPolicy extend(Map<String, LookupStrategy> lookupStrategies) { return null; } }); }