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