use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class AbstractArtifactClassLoaderBuilder method build.
/**
* Creates a new {@code ArtifactClassLoader} using the provided configuration. It will create the proper class loader hierarchy
* and filters the artifact resources and plugins classes and resources are resolve correctly.
*
* @return a {@code ArtifactClassLoader} created from the provided configuration.
* @throws IOException exception cause when it was not possible to access the file provided as dependencies
*/
public ArtifactClassLoader build() throws IOException {
checkState(artifactDescriptor != null, "artifact descriptor cannot be null");
parentClassLoader = getParentClassLoader();
checkState(parentClassLoader != null, "parent class loader cannot be null");
final String artifactId = getArtifactId(artifactDescriptor);
ClassLoaderLookupPolicy parentLookupPolicy = getParentLookupPolicy(parentClassLoader);
RegionClassLoader regionClassLoader = new RegionClassLoader(artifactId, artifactDescriptor, parentClassLoader.getClassLoader(), parentLookupPolicy);
ArtifactClassLoaderFilter artifactClassLoaderFilter = createArtifactClassLoaderFilter(artifactDescriptor.getClassLoaderModel(), parentLookupPolicy);
Map<String, LookupStrategy> appAdditionalLookupStrategy = new HashMap<>();
artifactClassLoaderFilter.getExportedClassPackages().stream().forEach(p -> appAdditionalLookupStrategy.put(p, PARENT_FIRST));
artifactPluginClassLoaders = pluginClassLoadersFactory.createPluginClassLoaders(regionClassLoader, artifactPluginDescriptors, regionClassLoader.getClassLoaderLookupPolicy().extend(appAdditionalLookupStrategy));
final ArtifactClassLoader artifactClassLoader = createArtifactClassLoader(artifactId, regionClassLoader);
regionClassLoader.addClassLoader(artifactClassLoader, artifactClassLoaderFilter);
int artifactPluginIndex = 0;
for (ArtifactPluginDescriptor artifactPluginDescriptor : artifactPluginDescriptors) {
final ArtifactClassLoaderFilter classLoaderFilter = createPluginClassLoaderFilter(artifactPluginDescriptor, artifactDescriptor.getClassLoaderModel().getExportedPackages(), parentLookupPolicy);
regionClassLoader.addClassLoader(artifactPluginClassLoaders.get(artifactPluginIndex), classLoaderFilter);
artifactPluginIndex++;
}
return artifactClassLoader;
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class DefaultApplicationFactory method createArtifact.
public Application createArtifact(ApplicationDescriptor descriptor) throws IOException {
Domain domain = getApplicationDomain(descriptor);
List<ArtifactPluginDescriptor> resolvedArtifactPluginDescriptors = pluginDependenciesResolver.resolve(domain.getDescriptor().getPlugins(), new ArrayList<>(getArtifactPluginDescriptors(descriptor)));
// Refreshes the list of plugins on the descriptor with the resolved from domain and transitive plugin dependencies
Set resolvedArtifactPlugins = new LinkedHashSet<>();
resolvedArtifactPlugins.addAll(resolvedArtifactPluginDescriptors);
descriptor.setPlugins(resolvedArtifactPlugins);
ApplicationClassLoaderBuilder artifactClassLoaderBuilder = applicationClassLoaderBuilderFactory.createArtifactClassLoaderBuilder();
MuleDeployableArtifactClassLoader applicationClassLoader = artifactClassLoaderBuilder.setDomain(domain).addArtifactPluginDescriptors(resolvedArtifactPluginDescriptors.toArray(new ArtifactPluginDescriptor[0])).setArtifactId(descriptor.getName()).setArtifactDescriptor(descriptor).build();
List<ArtifactPlugin> artifactPlugins = createArtifactPluginList(applicationClassLoader, resolvedArtifactPluginDescriptors);
MuleApplicationPolicyProvider applicationPolicyProvider = new MuleApplicationPolicyProvider(new DefaultPolicyTemplateFactory(policyTemplateClassLoaderBuilderFactory, pluginDependenciesResolver, licenseValidator), new DefaultPolicyInstanceProviderFactory(serviceRepository, classLoaderRepository, extensionModelLoaderRepository));
DefaultMuleApplication delegate = new DefaultMuleApplication(descriptor, applicationClassLoader, artifactPlugins, domainRepository, serviceRepository, extensionModelLoaderRepository, descriptor.getArtifactLocation(), classLoaderRepository, applicationPolicyProvider);
applicationPolicyProvider.setApplication(delegate);
return new ApplicationWrapper(delegate);
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class ArtifactPluginDescriptorFactoryTestCase method createPluginDescriptor.
@Test
public void createPluginDescriptor() throws Exception {
String pluginName = "samplePlugin";
MulePluginModel.MulePluginModelBuilder builder = new MulePluginModel.MulePluginModelBuilder();
builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId("mule").build());
Map<String, Object> attributes = new HashMap<>();
attributes.put(GROUP_ID, "org.mule.test");
attributes.put(ARTIFACT_ID, pluginName);
attributes.put(VERSION, "1.0.0");
attributes.put(CLASSIFIER, MULE_PLUGIN_CLASSIFIER);
attributes.put(TYPE, "jar");
builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(PROPERTIES_BUNDLE_DESCRIPTOR_LOADER_ID, attributes));
builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
MulePluginModel mulePluginModel = builder.setName(pluginName).setMinMuleVersion("4.0.0").setRequiredProduct(MULE).build();
ArtifactPluginFileBuilder pluginFileBuilder = new ArtifactPluginFileBuilder(PLUGIN_NAME).tempFolder(pluginsTempFolder.newFolder()).describedBy(mulePluginModel);
final ArtifactPluginDescriptor artifactPluginDescriptor = descriptorFactory.create(pluginFileBuilder.getArtifactFile(), empty());
assertThat(artifactPluginDescriptor.getName(), equalTo(pluginName));
assertThat(artifactPluginDescriptor.getBundleDescriptor().getArtifactId(), equalTo(pluginName));
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class AbstractDeployableDescriptorFactory method createArtifactPluginDescriptors.
private Set<ArtifactPluginDescriptor> createArtifactPluginDescriptors(ClassLoaderModel classLoaderModel) throws IOException {
Set<ArtifactPluginDescriptor> pluginDescriptors = new HashSet<>();
for (BundleDependency bundleDependency : classLoaderModel.getDependencies()) {
if (bundleDependency.getDescriptor().isPlugin()) {
File pluginFile = new File(bundleDependency.getBundleUri());
pluginDescriptors.add(artifactPluginDescriptorLoader.load(pluginFile));
}
}
return pluginDescriptors;
}
use of org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor in project mule by mulesoft.
the class ArtifactPluginDescriptorFactory method create.
@Override
public ArtifactPluginDescriptor create(File pluginJarFile, Optional<Properties> deploymentProperties) throws ArtifactDescriptorCreateException {
try {
checkArgument(pluginJarFile.isDirectory() || pluginJarFile.getName().endsWith(".jar"), "provided file is not a plugin: " + pluginJarFile.getAbsolutePath());
// Use / instead of File.separator as the file is going to be accessed inside the jar as a URL
String mulePluginJsonPathInsideJarFile = MULE_ARTIFACT_PATH_INSIDE_JAR + "/" + MULE_ARTIFACT_JSON_DESCRIPTOR;
Optional<byte[]> jsonDescriptorContentOptional = loadFileContentFrom(pluginJarFile, mulePluginJsonPathInsideJarFile);
return jsonDescriptorContentOptional.map(jsonDescriptorContent -> loadFromJsonDescriptor(pluginJarFile, loadModelFromJson(new String(jsonDescriptorContent)), deploymentProperties)).orElseThrow(() -> new ArtifactDescriptorCreateException(pluginDescriptorNotFound(pluginJarFile, mulePluginJsonPathInsideJarFile)));
} catch (ArtifactDescriptorCreateException e) {
throw e;
} catch (IOException e) {
throw new ArtifactDescriptorCreateException(e);
}
}
Aggregations