Search in sources :

Example 1 with ResourcesGenerator

use of org.mule.runtime.extension.api.resources.ResourcesGenerator 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)

Aggregations

Optional (java.util.Optional)1 MuleRuntimeException (org.mule.runtime.api.exception.MuleRuntimeException)1 ExtensionModel (org.mule.runtime.api.meta.model.ExtensionModel)1 ClassUtils.withContextClassLoader (org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader)1 IllegalModelDefinitionException (org.mule.runtime.extension.api.exception.IllegalModelDefinitionException)1 ResourcesGenerator (org.mule.runtime.extension.api.resources.ResourcesGenerator)1 ExtensionElement (org.mule.runtime.module.extension.api.loader.java.type.ExtensionElement)1