Search in sources :

Example 1 with XmlExtensionDocumentation

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);
        }
    }
}
Also used : XmlExtensionDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation) IOException(java.io.IOException) URL(java.net.URL)

Example 2 with XmlExtensionDocumentation

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);
}
Also used : XmlExtensionDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) URL(java.net.URL) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ParameterizedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration) ExtensionDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration) ExtensionLoadingContext(org.mule.runtime.extension.api.loader.ExtensionLoadingContext) IOException(java.io.IOException) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) IOUtils(org.apache.commons.io.IOUtils) List(java.util.List) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) DeclarationEnricher(org.mule.runtime.extension.api.loader.DeclarationEnricher) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration) ExtensionDescriptionsSerializer(org.mule.runtime.module.extension.internal.resources.documentation.ExtensionDescriptionsSerializer) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) ConfigurationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration) ConnectionProviderDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration) WithOperationsDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration) OperationDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration) ConnectedDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration) DeclarationWalker(org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker) XmlExtensionElementDocumentation(org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation) WithSourcesDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration) SourceDeclaration(org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)

Aggregations

IOException (java.io.IOException)2 URL (java.net.URL)2 XmlExtensionDocumentation (org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionDocumentation)2 List (java.util.List)1 IOUtils (org.apache.commons.io.IOUtils)1 ConfigurationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConfigurationDeclaration)1 ConnectedDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConnectedDeclaration)1 ConnectionProviderDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ConnectionProviderDeclaration)1 ExtensionDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ExtensionDeclaration)1 OperationDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.OperationDeclaration)1 ParameterizedDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.ParameterizedDeclaration)1 SourceDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.SourceDeclaration)1 WithOperationsDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.WithOperationsDeclaration)1 WithSourcesDeclaration (org.mule.runtime.api.meta.model.declaration.fluent.WithSourcesDeclaration)1 DeclarationWalker (org.mule.runtime.api.meta.model.declaration.fluent.util.DeclarationWalker)1 DeclarationEnricher (org.mule.runtime.extension.api.loader.DeclarationEnricher)1 ExtensionLoadingContext (org.mule.runtime.extension.api.loader.ExtensionLoadingContext)1 ExtensionDescriptionsSerializer (org.mule.runtime.module.extension.internal.resources.documentation.ExtensionDescriptionsSerializer)1 XmlExtensionElementDocumentation (org.mule.runtime.module.extension.internal.resources.documentation.XmlExtensionElementDocumentation)1