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