Search in sources :

Example 1 with MuleDomainModelJsonSerializer

use of org.mule.runtime.api.deployment.persistence.MuleDomainModelJsonSerializer 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;
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleDomainModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MuleDomainModelJsonSerializer) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) FileWriter(java.io.FileWriter) IOException(java.io.IOException) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) File(java.io.File) MuleDomainModel(org.mule.runtime.api.deployment.meta.MuleDomainModel)

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)1 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)1 MuleDomainModel (org.mule.runtime.api.deployment.meta.MuleDomainModel)1 MuleDomainModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MuleDomainModelJsonSerializer)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1