use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder in project mule by mulesoft.
the class MulePluginDescriptorGenerator method generateResource.
/**
* {@inheritDoc}
*/
@Override
public Optional<GeneratedResource> generateResource(ExtensionModel extensionModel) {
final Optional<ExtensionTypeDescriptorModelProperty> typeProperty = extensionModel.getModelProperty(ExtensionTypeDescriptorModelProperty.class);
if (!typeProperty.isPresent()) {
return empty();
}
final ExportedArtifactsCollector exportCollector = new ExportedArtifactsCollector(extensionModel, new DefaultClassPackageFinder(processingEnvironment));
final MulePluginModelBuilder builder = new MulePluginModelBuilder();
// Set only for testing purposes, the value will be reset by the plugin packager.
builder.setName(extensionModel.getName());
builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID).addProperty(EXPORTED_PACKAGES, exportCollector.getExportedPackages()).addProperty(EXPORTED_RESOURCES, exportCollector.getExportedResources()).addProperty(PRIVILEGED_EXPORTED_PACKAGES, exportCollector.getPrivilegedExportedPackages()).addProperty(PRIVILEGED_ARTIFACTS_IDS, exportCollector.getPrivilegedArtifacts()).build());
builder.withExtensionModelDescriber().setId(getLoaderId(extensionModel)).addProperty(TYPE_PROPERTY_NAME, typeProperty.get().getType().getTypeName()).addProperty("version", extensionModel.getVersion());
builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
final Optional<LicenseModelProperty> licenseModelPropertyOptional = extensionModel.getModelProperty(LicenseModelProperty.class);
builder.setRequiredProduct(extensionModel.getCategory().equals(COMMUNITY) ? MULE : MULE_EE);
licenseModelPropertyOptional.ifPresent(licenseModelProperty -> {
builder.setRequiredProduct(licenseModelProperty.requiresEeLicense() ? MULE_EE : MULE);
if (licenseModelProperty.requiresEeLicense()) {
builder.withLicenseModel().setAllowsEvaluationLicense(licenseModelProperty.isAllowsEvaluationLicense());
licenseModelProperty.getRequiredEntitlement().ifPresent(requiredEntitlement -> builder.withLicenseModel().setProvider(extensionModel.getVendor()).setRequiredEntitlement(requiredEntitlement));
}
});
final String descriptorJson = new MulePluginModelJsonSerializer().serialize(builder.build());
return of(new GeneratedResource(AUTO_GENERATED_MULE_ARTIFACT_DESCRIPTOR, descriptorJson.getBytes()));
}
use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder in project mule by mulesoft.
the class ApplicationFileBuilder method createApplicationJsonDescriptorFile.
private File createApplicationJsonDescriptorFile(Optional<Boolean> redeploymentEnabled, Optional<String> configResources, Optional<String> exportedPackages, Optional<String> exportedResources) {
File applicationDescriptor = new File(getTempFolder(), getArtifactId() + "application.json");
applicationDescriptor.deleteOnExit();
MuleApplicationModel.MuleApplicationModelBuilder muleApplicationModelBuilder = new MuleApplicationModel.MuleApplicationModelBuilder();
muleApplicationModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
redeploymentEnabled.ifPresent(muleApplicationModelBuilder::setRedeploymentEnabled);
configResources.ifPresent(configs -> {
String[] configFiles = configs.split(",");
muleApplicationModelBuilder.setConfigs(new HashSet<>(asList(configFiles)));
});
MuleArtifactLoaderDescriptorBuilder muleArtifactLoaderDescriptorBuilder = new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID);
exportedPackages.ifPresent(packages -> {
muleArtifactLoaderDescriptorBuilder.addProperty(EXPORTED_PACKAGES, packages.split(","));
});
exportedResources.ifPresent(resources -> {
muleArtifactLoaderDescriptorBuilder.addProperty(EXPORTED_RESOURCES, resources.split(","));
});
muleApplicationModelBuilder.withClassLoaderModelDescriptorLoader(muleArtifactLoaderDescriptorBuilder.build());
muleApplicationModelBuilder.withBundleDescriptorLoader(muleArtifactLoaderDescriptorBuilder.build());
String applicationDescriptorContent = new MuleApplicationModelJsonSerializer().serialize(muleApplicationModelBuilder.build());
try (FileWriter fileWriter = new FileWriter(applicationDescriptor)) {
fileWriter.write(applicationDescriptorContent);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
return applicationDescriptor;
}
use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder in project mule by mulesoft.
the class DomainFileBuilder method createDomainJsonDescriptorFile.
private File createDomainJsonDescriptorFile(Optional<Boolean> redeploymentEnabled, Optional<String> configResources, Optional<String> exportedResources) {
File domainDescriptor = new File(getTempFolder(), getArtifactId() + "domain.json");
domainDescriptor.deleteOnExit();
MuleDomainModel.MuleDomainModelBuilder muleDomainModelBuilder = new MuleDomainModel.MuleDomainModelBuilder();
muleDomainModelBuilder.setName(getArtifactId()).setMinMuleVersion("4.0.0").setRequiredProduct(MULE);
redeploymentEnabled.ifPresent(muleDomainModelBuilder::setRedeploymentEnabled);
configResources.ifPresent(configs -> {
String[] configFiles = configs.split(",");
muleDomainModelBuilder.setConfigs(new HashSet<>(asList(configFiles)));
});
MuleArtifactLoaderDescriptorBuilder muleArtifactClassLoaderDescriptorBuilder = new MuleArtifactLoaderDescriptorBuilder().setId(MULE_LOADER_ID);
exportedResources.ifPresent(resources -> {
muleArtifactClassLoaderDescriptorBuilder.addProperty(EXPORTED_RESOURCES, resources.split(","));
});
muleDomainModelBuilder.withClassLoaderModelDescriptorLoader(muleArtifactClassLoaderDescriptorBuilder.build());
muleDomainModelBuilder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
String applicationDescriptorContent = new MuleDomainModelJsonSerializer().serialize(muleDomainModelBuilder.build());
try (FileWriter fileWriter = new FileWriter(domainDescriptor)) {
fileWriter.write(applicationDescriptorContent);
} catch (IOException e) {
throw new MuleRuntimeException(e);
}
return domainDescriptor;
}
use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder in project mule by mulesoft.
the class PluginResourcesResolverTestCase method resolvePluginResourcesForMulePlugin.
@Test
public void resolvePluginResourcesForMulePlugin() throws Exception {
MulePluginModelBuilder builder = new MulePluginModelBuilder();
builder.withClassLoaderModelDescriptorLoader(new MuleArtifactLoaderDescriptorBuilder().setId("mule").addProperty(EXPORTED_PACKAGES, newArrayList(ORG_MULE_TEST_RUNNER, ORG_MULE_TEST_RUNNER_API)).addProperty(EXPORTED_RESOURCES, newArrayList(META_INF_RESOURCE_PROPERTIES, META_INF_ANOTHER_RESOURCE_PROPERTIES)).build());
builder.withBundleDescriptorLoader(new MuleArtifactLoaderDescriptor(MULE_LOADER_ID, emptyMap()));
MulePluginModel mulePluginModel = builder.setName("samplePlugin").setMinMuleVersion("4.0.0").build();
String mulePluginModelJson = new MulePluginModelJsonSerializer().serialize(mulePluginModel);
File pluginPropertiesFile = new File(new File(new File(temporaryFolder.getRoot(), "META-INF"), "mule-artifact"), MULE_ARTIFACT_JSON_DESCRIPTOR);
writeStringToFile(pluginPropertiesFile, mulePluginModelJson);
URL classPathUrl = temporaryFolder.getRoot().toURI().toURL();
List<URL> urls = newArrayList(classPathUrl);
PluginUrlClassification mulePluginClassification = newPluginUrlClassification(urls);
PluginResourcesResolver resolver = new PluginResourcesResolver();
PluginUrlClassification result = resolver.resolvePluginResourcesFor(mulePluginClassification);
assertResolvedResources(mulePluginClassification, result);
}
use of org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder 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));
}
Aggregations