use of org.mule.runtime.api.deployment.persistence.MuleApplicationModelJsonSerializer 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;
}
Aggregations