Search in sources :

Example 6 with MuleArtifactLoaderDescriptorBuilder

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()));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ExportedArtifactsCollector(org.mule.runtime.module.extension.internal.resources.manifest.ExportedArtifactsCollector) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) ExtensionTypeDescriptorModelProperty(org.mule.runtime.module.extension.internal.loader.java.type.property.ExtensionTypeDescriptorModelProperty) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) DefaultClassPackageFinder(org.mule.runtime.module.extension.internal.resources.manifest.DefaultClassPackageFinder) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) LicenseModelProperty(org.mule.runtime.module.extension.internal.loader.java.property.LicenseModelProperty)

Example 7 with MuleArtifactLoaderDescriptorBuilder

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;
}
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)

Example 8 with MuleArtifactLoaderDescriptorBuilder

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;
}
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)

Example 9 with MuleArtifactLoaderDescriptorBuilder

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);
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) MulePluginModelJsonSerializer(org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer) MulePluginModelBuilder(org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder) FileUtils.writeStringToFile(org.apache.commons.io.FileUtils.writeStringToFile) File(java.io.File) URL(java.net.URL) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 10 with MuleArtifactLoaderDescriptorBuilder

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));
}
Also used : MuleArtifactLoaderDescriptor(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor) ArtifactPluginFileBuilder(org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder) MuleArtifactLoaderDescriptorBuilder(org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) HashMap(java.util.HashMap) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Aggregations

MuleArtifactLoaderDescriptorBuilder (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptorBuilder)15 MulePluginModel (org.mule.runtime.api.deployment.meta.MulePluginModel)10 ArtifactPluginFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ArtifactPluginFileBuilder)10 File (java.io.File)6 MulePluginModelBuilder (org.mule.runtime.api.deployment.meta.MulePluginModel.MulePluginModelBuilder)6 JarFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.JarFileBuilder)6 MuleArtifactLoaderDescriptor (org.mule.runtime.api.deployment.meta.MuleArtifactLoaderDescriptor)5 Test (org.junit.Test)4 IOException (java.io.IOException)3 Matchers.containsString (org.hamcrest.Matchers.containsString)3 MulePluginModelJsonSerializer (org.mule.runtime.api.deployment.persistence.MulePluginModelJsonSerializer)3 FileWriter (java.io.FileWriter)2 FileUtils.writeStringToFile (org.apache.commons.io.FileUtils.writeStringToFile)2 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)2 ApplicationFileBuilder (org.mule.runtime.module.deployment.impl.internal.builder.ApplicationFileBuilder)2 URISyntaxException (java.net.URISyntaxException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 LinkedList (java.util.LinkedList)1 FileUtils.copyFile (org.apache.commons.io.FileUtils.copyFile)1