Search in sources :

Example 1 with ExtensionElement

use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement 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 2 with ExtensionElement

use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement in project mule by mulesoft.

the class AbstractJavaExtensionModelLoader method declareExtension.

/**
 * {@inheritDoc}
 */
@Override
protected void declareExtension(ExtensionLoadingContext context) {
    ExtensionElement extensionType = getExtensionType(context);
    String version = context.<String>getParameter(VERSION).orElseThrow(() -> new IllegalArgumentException("version not specified"));
    factory.getLoader(extensionType, version).declare(context);
}
Also used : ExtensionElement(org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement)

Example 3 with ExtensionElement

use of org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement in project mule by mulesoft.

the class AbstractJavaExtensionModelLoader method getPrivilegedDeclarationEnrichers.

private Collection<DeclarationEnricher> getPrivilegedDeclarationEnrichers(ExtensionLoadingContext context) {
    ExtensionElement extensionType = getExtensionType(context);
    if (extensionType.getDeclaringClass().isPresent()) {
        try {
            // TODO: MULE-12744. If this call throws an exception it means that the extension cannot access the privileged API.
            ClassLoader extensionClassLoader = context.getExtensionClassLoader();
            Class annotation = extensionClassLoader.loadClass(DeclarationEnrichers.class.getName());
            return (Collection<DeclarationEnricher>) extensionType.getAnnotation((Class<DeclarationEnrichers>) annotation).map(enrichers -> withContextClassLoader(extensionClassLoader, () -> stream(enrichers.value()).map(this::instantiateOrFail).collect(toList()))).orElse(emptyList());
        } catch (ClassNotFoundException e) {
        // Do nothing
        }
    }
    return emptyList();
}
Also used : ExtensionElement(org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement) ClassUtils.withContextClassLoader(org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader) Collection(java.util.Collection) ClassUtils.loadClass(org.mule.runtime.core.api.util.ClassUtils.loadClass) DeclarationEnrichers(org.mule.runtime.extension.api.annotation.privileged.DeclarationEnrichers)

Aggregations

ExtensionElement (org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement)3 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)2 Collection (java.util.Collection)1 Optional (java.util.Optional)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 ClassUtils.loadClass (org.mule.runtime.core.api.util.ClassUtils.loadClass)1 DeclarationEnrichers (org.mule.runtime.extension.api.annotation.privileged.DeclarationEnrichers)1 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)1 ResourcesGenerator (org.mule.runtime.extension.api.resources.ResourcesGenerator)1