Search in sources :

Example 1 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource 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 2 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class MulePluginDescriptorGeneratorTestCase method generate.

@Test
public void generate() throws Exception {
    InputStream in = getClass().getResourceAsStream("/heisenberg-test-mule-artifact.json");
    assertThat(in, is(notNullValue()));
    String expectedDescriptor = IOUtils.toString(in);
    Optional<GeneratedResource> resource = generator.generateResource(extensionModel);
    assertThat(resource.isPresent(), is(true));
    String actualDescriptor = new String(resource.get().getContent());
    JSONAssert.assertEquals(expectedDescriptor, actualDescriptor, true);
}
Also used : InputStream(java.io.InputStream) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 3 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionModelResourceFactoryTestCase method generate.

@Test
public void generate() throws Exception {
    GeneratedResource resource = resourceFactory.generateResource(extensionModel).get();
    assertThat(resource.getPath(), equalTo(RESOURCE_NAME));
    XMLUnit.setIgnoreWhitespace(true);
    String expected = IOUtils.toString(currentThread().getContextClassLoader().getResource(RESOURCE_NAME).openStream());
    XMLUnit.compareXML(expected, new String(resource.getContent()));
}
Also used : GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) Test(org.junit.Test) SmallTest(org.mule.tck.size.SmallTest)

Example 4 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionFunctionalTestCase method generateResourcesAndAddToClasspath.

private void generateResourcesAndAddToClasspath(File generatedResourcesDirectory, List<GeneratedResource> resources) throws Exception {
    ClassLoader cl = getClass().getClassLoader();
    Method method = findMethod(cl.getClass(), "addURL", URL.class);
    method.setAccessible(true);
    for (GeneratedResource resource : resources) {
        URL generatedResourceURL = new File(generatedResourcesDirectory, resource.getPath()).toURI().toURL();
        method.invoke(cl, generatedResourceURL);
    }
}
Also used : ReflectionUtils.findMethod(org.springframework.util.ReflectionUtils.findMethod) Method(java.lang.reflect.Method) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) File(java.io.File) URL(java.net.URL)

Example 5 with GeneratedResource

use of org.mule.runtime.extension.api.resources.GeneratedResource in project mule by mulesoft.

the class ExtensionsTestInfrastructureDiscoverer method generateDslResources.

public List<GeneratedResource> generateDslResources(File generatedResourcesDirectory, ExtensionModel forExtensionModel) {
    DslResolvingContext context;
    if (extensionManager.getExtensions().stream().anyMatch(e -> !e.getImportedTypes().isEmpty())) {
        HashSet<ExtensionModel> models = new HashSet<>(extensionManager.getExtensions());
        models.add(MuleExtensionModelProvider.getExtensionModel());
        context = DslResolvingContext.getDefault(models);
    } else {
        context = new NullDslResolvingContext();
    }
    ExtensionsTestDslResourcesGenerator dslResourceGenerator = new ExtensionsTestDslResourcesGenerator(getDslResourceFactories(), generatedResourcesDirectory, context);
    extensionManager.getExtensions().stream().filter(runtimeExtensionModel -> forExtensionModel != null ? runtimeExtensionModel.equals(forExtensionModel) : true).forEach(dslResourceGenerator::generateFor);
    return dslResourceGenerator.dumpAll();
}
Also used : Manifest(java.util.jar.Manifest) MuleManifest.getProductVersion(org.mule.runtime.core.api.config.MuleManifest.getProductVersion) GeneratedResource(org.mule.runtime.extension.api.resources.GeneratedResource) HashMap(java.util.HashMap) Thread.currentThread(java.lang.Thread.currentThread) MuleManifest(org.mule.runtime.core.api.config.MuleManifest) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) GeneratedResourceFactory(org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory) HashSet(java.util.HashSet) Collections.singleton(java.util.Collections.singleton) ByteArrayInputStream(java.io.ByteArrayInputStream) TYPE_PROPERTY_NAME(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.TYPE_PROPERTY_NAME) Map(java.util.Map) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) ServiceRegistry(org.mule.runtime.core.api.registry.ServiceRegistry) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) FileOutputStream(java.io.FileOutputStream) Set(java.util.Set) IOException(java.io.IOException) ImmutableList.copyOf(com.google.common.collect.ImmutableList.copyOf) String.format(java.lang.String.format) File(java.io.File) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) List(java.util.List) ExtensionManager(org.mule.runtime.core.api.extension.ExtensionManager) VERSION(org.mule.runtime.module.extension.api.loader.java.DefaultJavaExtensionModelLoader.VERSION) ExtensionSchemaGenerator(org.mule.runtime.extension.api.dsl.syntax.resources.spi.ExtensionSchemaGenerator) FileUtils(org.mule.runtime.core.api.util.FileUtils) DslResourceFactory(org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory) ResourcesGenerator(org.mule.runtime.extension.api.resources.ResourcesGenerator) MuleExtensionModelProvider(org.mule.runtime.core.api.extension.MuleExtensionModelProvider) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) DslResolvingContext(org.mule.runtime.api.dsl.DslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) NullDslResolvingContext(org.mule.runtime.internal.dsl.NullDslResolvingContext) HashSet(java.util.HashSet)

Aggregations

GeneratedResource (org.mule.runtime.extension.api.resources.GeneratedResource)9 File (java.io.File)3 Test (org.junit.Test)3 GeneratedResourceFactory (org.mule.runtime.extension.api.resources.spi.GeneratedResourceFactory)3 SmallTest (org.mule.tck.size.SmallTest)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 HashMap (java.util.HashMap)2 List (java.util.List)2 Map (java.util.Map)2 Set (java.util.Set)2 DslResolvingContext (org.mule.runtime.api.dsl.DslResolvingContext)2 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)2 DslResourceFactory (org.mule.runtime.extension.api.dsl.syntax.resources.spi.DslResourceFactory)2 ImmutableList.copyOf (com.google.common.collect.ImmutableList.copyOf)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 FileOutputStream (java.io.FileOutputStream)1 String.format (java.lang.String.format)1 Thread.currentThread (java.lang.Thread.currentThread)1 Method (java.lang.reflect.Method)1