Search in sources :

Example 1 with MuleApplicationModelJsonSerializer

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

Aggregations

File (java.io.File)1 FileWriter (java.io.FileWriter)1 IOException (java.io.IOException)1 MuleApplicationModel (org.mule.runtime.api.deployment.meta.MuleApplicationModel)1 MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)1 MuleApplicationModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MuleApplicationModelJsonSerializer)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1