Search in sources :

Example 1 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionModelDiscoverer method discoverRuntimeExtensionModels.

/**
 * Discover the extension models provided by the runtime.
 *
 * @return {@link Set} of the runtime provided {@link ExtensionModel}s.
 */
public Set<ExtensionModel> discoverRuntimeExtensionModels() {
    final Set<ExtensionModel> extensionModels = new HashSet<>();
    Collection<RuntimeExtensionModelProvider> runtimeExtensionModelProviders = new SpiServiceRegistry().lookupProviders(RuntimeExtensionModelProvider.class, Thread.currentThread().getContextClassLoader());
    for (RuntimeExtensionModelProvider runtimeExtensionModelProvider : runtimeExtensionModelProviders) {
        extensionModels.add(runtimeExtensionModelProvider.createExtensionModel());
    }
    return extensionModels;
}
Also used : RuntimeExtensionModelProvider(org.mule.runtime.core.api.extension.RuntimeExtensionModelProvider) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) HashSet(java.util.HashSet)

Example 2 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionModelDiscoverer method discoverPluginsExtensionModels.

/**
 * For each artifactPlugin discovers the {@link ExtensionModel}.
 *
 * @param loaderRepository {@link ExtensionModelLoaderRepository} with the available extension loaders.
 * @param artifactPlugins {@link Pair} of {@link ArtifactPluginDescriptor} and {@link ArtifactClassLoader} for artifact plugins
 *        deployed inside the artifact. Non null.
 * @param parentArtifactExtensions {@link Set} of {@link ExtensionModel} to also take into account when parsing extensions
 * @return {@link Set} of {@link Pair} carrying the {@link ArtifactPluginDescriptor} and it's corresponding
 *         {@link ExtensionModel}.
 */
public Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> discoverPluginsExtensionModels(ExtensionModelLoaderRepository loaderRepository, List<Pair<ArtifactPluginDescriptor, ArtifactClassLoader>> artifactPlugins, Set<ExtensionModel> parentArtifactExtensions) {
    final Set<Pair<ArtifactPluginDescriptor, ExtensionModel>> descriptorsWithExtensions = new HashSet<>();
    artifactPlugins.forEach(artifactPlugin -> {
        Set<ExtensionModel> extensions = descriptorsWithExtensions.stream().map(Pair::getSecond).collect(toSet());
        extensions.addAll(parentArtifactExtensions);
        final ArtifactPluginDescriptor artifactPluginDescriptor = artifactPlugin.getFirst();
        Optional<LoaderDescriber> loaderDescriber = artifactPluginDescriptor.getExtensionModelDescriptorProperty();
        ClassLoader artifactClassloader = artifactPlugin.getSecond().getClassLoader();
        String artifactName = artifactPluginDescriptor.getName();
        ExtensionModel extension = loaderDescriber.map(describer -> discoverExtensionThroughJsonDescriber(loaderRepository, describer, extensions, artifactClassloader, artifactName)).orElse(null);
        if (extension != null) {
            descriptorsWithExtensions.add(new Pair<>(artifactPluginDescriptor, extension));
        }
    });
    return descriptorsWithExtensions;
}
Also used : ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) ExtensionModelLoaderRepository(org.mule.runtime.module.extension.internal.loader.ExtensionModelLoaderRepository) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) Collection(java.util.Collection) Set(java.util.Set) String.format(java.lang.String.format) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SpiServiceRegistry(org.mule.runtime.core.api.registry.SpiServiceRegistry) RuntimeExtensionModelProvider(org.mule.runtime.core.api.extension.RuntimeExtensionModelProvider) HashSet(java.util.HashSet) List(java.util.List) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Optional(java.util.Optional) Pair(org.mule.runtime.api.util.Pair) DslResolvingContext.getDefault(org.mule.runtime.api.dsl.DslResolvingContext.getDefault) ExtensionModelLoader(org.mule.runtime.extension.api.loader.ExtensionModelLoader) Collectors.toSet(java.util.stream.Collectors.toSet) MulePluginModel(org.mule.runtime.api.deployment.meta.MulePluginModel) ArtifactPluginDescriptor(org.mule.runtime.deployment.model.api.plugin.ArtifactPluginDescriptor) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ArtifactClassLoader(org.mule.runtime.module.artifact.api.classloader.ArtifactClassLoader) LoaderDescriber(org.mule.runtime.deployment.model.api.plugin.LoaderDescriber) Pair(org.mule.runtime.api.util.Pair) HashSet(java.util.HashSet)

Example 3 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class BaseExtensionResourcesGeneratorAnnotationProcessor method process.

@Override
public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
    log("Starting Resources generator for Extensions");
    ResourcesGenerator generator = new AnnotationProcessorResourceGenerator(fetchResourceFactories(), processingEnv);
    try {
        getExtension(roundEnv).ifPresent(extensionElement -> {
            if (!shouldProcess(extensionElement, processingEnv)) {
                return;
            }
            Optional<Class<Object>> annotatedClass = processor.classFor(extensionElement, processingEnv);
            ExtensionElement extension = toExtensionElement(extensionElement, processingEnv);
            ClassLoader classLoader = annotatedClass.map(Class::getClassLoader).orElseGet(ExtensionModel.class::getClassLoader);
            withContextClassLoader(classLoader, () -> {
                ExtensionModel extensionModel = parseExtension(extensionElement, extension, roundEnv, classLoader);
                generator.generateFor(extensionModel);
            });
        });
        return false;
    } catch (MuleRuntimeException e) {
        Optional<IllegalModelDefinitionException> exception = extractOfType(e, IllegalModelDefinitionException.class);
        if (exception.isPresent()) {
            throw exception.get();
        }
        processingEnv.getMessager().printMessage(ERROR, format("%s\n%s", e.getMessage(), getStackTrace(e)));
        throw e;
    }
}
Also used : IllegalModelDefinitionException(org.mule.runtime.extension.api.exception.IllegalModelDefinitionException) Optional(java.util.Optional) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ResourcesGenerator(org.mule.runtime.extension.api.resources.ResourcesGenerator) ExtensionElement(org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement) MuleRuntimeException(org.mule.runtime.api.exception.MuleRuntimeException) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)

Example 4 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionModelJsonGeneratorTestCase method load.

@Test
public void load() throws Exception {
    ExtensionModel result = generator.deserialize(expectedJson);
    assertThat(result, is(extensionUnderTest));
}
Also used : ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Example 5 with ExtensionModel

use of org.mule.runtime.api.meta.model.ExtensionModel in project mule by mulesoft.

the class ExtensionDescriptionDocumenterTestCase method loadDocumentationFromFile.

@Test
public void loadDocumentationFromFile() {
    ClassLoader cl = currentThread().getContextClassLoader();
    ExtensionLoadingContext ctx = new DefaultExtensionLoadingContext(cl, getDefault(emptySet()));
    DefaultJavaModelLoaderDelegate loader = new DefaultJavaModelLoaderDelegate(extensionClass, "1.0.0-dev");
    loader.declare(ctx);
    ExtensionDescriptionsEnricher enricher = new ExtensionDescriptionsEnricher();
    enricher.enrich(ctx);
    ExtensionModelFactory factory = new ExtensionModelFactory();
    ExtensionModel extensionModel = factory.create(ctx);
    assertDescribedExtensionModel(extensionModel);
}
Also used : ExtensionDescriptionsEnricher(org.mule.runtime.module.extension.internal.loader.enricher.ExtensionDescriptionsEnricher) DefaultExtensionLoadingContext(org.mule.runtime.extension.internal.loader.DefaultExtensionLoadingContext) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) DefaultExtensionLoadingContext(org.mule.runtime.extension.internal.loader.DefaultExtensionLoadingContext) DefaultJavaModelLoaderDelegate(org.mule.runtime.module.extension.internal.loader.java.DefaultJavaModelLoaderDelegate) ExtensionModel(org.mule.runtime.api.meta.model.ExtensionModel) ExtensionModelFactory(org.mule.runtime.extension.internal.loader.ExtensionModelFactory) SmallTest(org.mule.tck.size.SmallTest) Test(org.junit.Test)

Aggregations

ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)94 Test (org.junit.Test)50 SmallTest (org.mule.tck.size.SmallTest)34 OperationModel (org.mule.runtime.api.meta.model.operation.OperationModel)31 Optional (java.util.Optional)26 ConfigurationModel (org.mule.runtime.api.meta.model.config.ConfigurationModel)24 List (java.util.List)22 Set (java.util.Set)19 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)19 ParameterModel (org.mule.runtime.api.meta.model.parameter.ParameterModel)19 ConnectionProviderModel (org.mule.runtime.api.meta.model.connection.ConnectionProviderModel)16 HashMap (java.util.HashMap)15 SourceModel (org.mule.runtime.api.meta.model.source.SourceModel)15 String.format (java.lang.String.format)13 Collectors.toList (java.util.stream.Collectors.toList)13 HashSet (java.util.HashSet)12 Map (java.util.Map)12 Reference (org.mule.runtime.api.util.Reference)12 Optional.empty (java.util.Optional.empty)11 ObjectType (org.mule.metadata.api.model.ObjectType)11