use of org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation in project mule by mulesoft.
the class ExtensionDescriptionsEnricher method enrich.
/**
* {@inheritDoc}
*/
@Override
public void enrich(ExtensionLoadingContext loadingContext) {
String name = loadingContext.getExtensionDeclarer().getDeclaration().getName();
ClassLoader classLoader = loadingContext.getExtensionClassLoader();
URL resource = classLoader.getResource("META-INF/" + serializer.getFileName(name));
if (resource != null) {
try {
XmlExtensionDocumentation documenter = serializer.deserialize(IOUtils.toString(resource.openStream()));
document(loadingContext.getExtensionDeclarer().getDeclaration(), documenter);
} catch (IOException e) {
throw new RuntimeException("Cannot get descriptions persisted in the extensions-descriptions.xml file", e);
}
}
}
use of org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation in project mule by mulesoft.
the class ExtensionDescriptionsEnricher method document.
/**
* Fills all the descriptions in the provided {@link ExtensionDeclaration} based on the
* <strong>extensions-descriptions.xml</strong> file.
*
* @param declaration the declaration to describe.
* @param documentation the extension documentation with its corresponding description.
*/
private void document(ExtensionDeclaration declaration, XmlExtensionDocumentation documentation) {
declaration.setDescription(documentation.getExtension().getDescription());
new DeclarationWalker() {
@Override
protected void onConfiguration(ConfigurationDeclaration declaration) {
document(declaration, documentation.getConfigs());
}
@Override
protected void onOperation(WithOperationsDeclaration owner, OperationDeclaration declaration) {
document(declaration, documentation.getOperations());
}
@Override
protected void onConnectionProvider(ConnectedDeclaration owner, ConnectionProviderDeclaration declaration) {
document(declaration, documentation.getConnections());
}
@Override
protected void onSource(WithSourcesDeclaration owner, SourceDeclaration declaration) {
document(declaration, documentation.getSources());
}
private void document(ParameterizedDeclaration<?> declaration, List<XmlExtensionElementDocumentation> elements) {
elements.stream().filter(e -> e.getName().equals(declaration.getName())).findAny().ifPresent(e -> {
declaration.setDescription(e.getDescription());
declaration.getAllParameters().forEach(param -> e.getParameters().stream().filter(p -> p.getName().equals(param.getName())).findAny().ifPresent(p -> param.setDescription(p.getDescription())));
});
}
}.walk(declaration);
}
Aggregations