Search in sources :

Example 1 with ComponentModel

use of org.apache.camel.tools.apt.model.ComponentModel in project camel by apache.

the class EndpointAnnotationProcessor method writeJSonSchemeDocumentation.

protected void writeJSonSchemeDocumentation(PrintWriter writer, RoundEnvironment roundEnv, TypeElement classElement, UriEndpoint uriEndpoint, String title, String scheme, String extendsScheme, String label, String[] schemes) {
    // gather component information
    ComponentModel componentModel = findComponentProperties(roundEnv, uriEndpoint, classElement, title, scheme, extendsScheme, label);
    // get endpoint information which is divided into paths and options (though there should really only be one path)
    Set<EndpointPath> endpointPaths = new LinkedHashSet<EndpointPath>();
    Set<EndpointOption> endpointOptions = new LinkedHashSet<EndpointOption>();
    Set<ComponentOption> componentOptions = new LinkedHashSet<ComponentOption>();
    TypeElement componentClassElement = findTypeElement(processingEnv, roundEnv, componentModel.getJavaType());
    if (componentClassElement != null) {
        findComponentClassProperties(writer, roundEnv, componentModel, componentOptions, componentClassElement, "");
    }
    findClassProperties(writer, roundEnv, componentModel, endpointPaths, endpointOptions, classElement, "", uriEndpoint.excludeProperties());
    String json = createParameterJsonSchema(componentModel, componentOptions, endpointPaths, endpointOptions, schemes);
    writer.println(json);
}
Also used : LinkedHashSet(java.util.LinkedHashSet) ComponentOption(org.apache.camel.tools.apt.model.ComponentOption) TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) ComponentModel(org.apache.camel.tools.apt.model.ComponentModel) EndpointOption(org.apache.camel.tools.apt.model.EndpointOption) EndpointPath(org.apache.camel.tools.apt.model.EndpointPath)

Example 2 with ComponentModel

use of org.apache.camel.tools.apt.model.ComponentModel in project camel by apache.

the class EndpointAnnotationProcessor method findComponentProperties.

protected ComponentModel findComponentProperties(RoundEnvironment roundEnv, UriEndpoint uriEndpoint, TypeElement endpointClassElement, String title, String scheme, String extendsScheme, String label) {
    ComponentModel model = new ComponentModel(scheme);
    // if the scheme is an alias then replace the scheme name from the syntax with the alias
    String syntax = scheme + ":" + Strings.after(uriEndpoint.syntax(), ":");
    // alternative syntax is optional
    if (!Strings.isNullOrEmpty(uriEndpoint.alternativeSyntax())) {
        String alternativeSyntax = scheme + ":" + Strings.after(uriEndpoint.alternativeSyntax(), ":");
        model.setAlternativeSyntax(alternativeSyntax);
    }
    model.setExtendsScheme(extendsScheme);
    model.setSyntax(syntax);
    model.setTitle(title);
    model.setLabel(label);
    model.setConsumerOnly(uriEndpoint.consumerOnly());
    model.setProducerOnly(uriEndpoint.producerOnly());
    model.setLenientProperties(uriEndpoint.lenientProperties());
    model.setAsync(implementsInterface(processingEnv, roundEnv, endpointClassElement, "org.apache.camel.AsyncEndpoint"));
    // what is the first version this component was added to Apache Camel
    String firstVersion = uriEndpoint.firstVersion();
    if (Strings.isNullOrEmpty(firstVersion) && endpointClassElement.getAnnotation(Metadata.class) != null) {
        // fallback to @Metadata if not from @UriEndpoint
        firstVersion = endpointClassElement.getAnnotation(Metadata.class).firstVersion();
    }
    if (!Strings.isNullOrEmpty(firstVersion)) {
        model.setFirstVersion(firstVersion);
    }
    String data = loadResource(processingEnv, "META-INF/services/org/apache/camel/component", scheme);
    if (data != null) {
        Map<String, String> map = parseAsMap(data);
        model.setJavaType(map.get("class"));
    }
    data = loadResource(processingEnv, "META-INF/services/org/apache/camel", "component.properties");
    if (data != null) {
        Map<String, String> map = parseAsMap(data);
        // now we have a lot more data, so we need to load it as key/value
        // need to sanitize the description first
        String doc = map.get("projectDescription");
        if (doc != null) {
            model.setDescription(sanitizeDescription(doc, true));
        } else {
            model.setDescription("");
        }
        // we can mark a component as deprecated by using the annotation or in the pom.xml
        boolean deprecated = endpointClassElement.getAnnotation(Deprecated.class) != null;
        if (!deprecated) {
            String name = map.get("projectName");
            // we may have marked a component as deprecated in the project name
            deprecated = name != null && name.contains("(deprecated)");
        }
        model.setDeprecated(deprecated);
        if (map.containsKey("groupId")) {
            model.setGroupId(map.get("groupId"));
        } else {
            model.setGroupId("");
        }
        if (map.containsKey("artifactId")) {
            model.setArtifactId(map.get("artifactId"));
        } else {
            model.setArtifactId("");
        }
        if (map.containsKey("version")) {
            model.setVersionId(map.get("version"));
        } else {
            model.setVersionId("");
        }
    }
    // favor to use endpoint class javadoc as description
    Elements elementUtils = processingEnv.getElementUtils();
    TypeElement typeElement = findTypeElement(processingEnv, roundEnv, endpointClassElement.getQualifiedName().toString());
    if (typeElement != null) {
        String doc = elementUtils.getDocComment(typeElement);
        if (doc != null) {
            // need to sanitize the description first (we only want a summary)
            doc = sanitizeDescription(doc, true);
            // the javadoc may actually be empty, so only change the doc if we got something
            if (!Strings.isNullOrEmpty(doc)) {
                model.setDescription(doc);
            }
        }
    }
    return model;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) AnnotationProcessorHelper.findTypeElement(org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement) ComponentModel(org.apache.camel.tools.apt.model.ComponentModel) Elements(javax.lang.model.util.Elements)

Aggregations

TypeElement (javax.lang.model.element.TypeElement)2 AnnotationProcessorHelper.findTypeElement (org.apache.camel.tools.apt.AnnotationProcessorHelper.findTypeElement)2 ComponentModel (org.apache.camel.tools.apt.model.ComponentModel)2 LinkedHashSet (java.util.LinkedHashSet)1 Elements (javax.lang.model.util.Elements)1 ComponentOption (org.apache.camel.tools.apt.model.ComponentOption)1 EndpointOption (org.apache.camel.tools.apt.model.EndpointOption)1 EndpointPath (org.apache.camel.tools.apt.model.EndpointPath)1