Search in sources :

Example 1 with LanguageOptionModel

use of org.apache.camel.maven.packaging.model.LanguageOptionModel in project camel by apache.

the class SpringBootAutoConfigurationMojo method generateLanguageModel.

private static LanguageModel generateLanguageModel(String languageName, String json) {
    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language", json, false);
    LanguageModel language = new LanguageModel();
    language.setTitle(getSafeValue("title", rows));
    language.setName(getSafeValue("name", rows));
    language.setModelName(getSafeValue("modelName", rows));
    language.setDescription(getSafeValue("description", rows));
    language.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
    language.setLabel(getSafeValue("label", rows));
    language.setDeprecated(getSafeValue("deprecated", rows));
    language.setJavaType(getSafeValue("javaType", rows));
    language.setGroupId(getSafeValue("groupId", rows));
    language.setArtifactId(getSafeValue("artifactId", rows));
    language.setVersion(getSafeValue("version", rows));
    rows = JSonSchemaHelper.parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        LanguageOptionModel option = new LanguageOptionModel();
        option.setName(getSafeValue("name", row));
        option.setDisplayName(getSafeValue("displayName", row));
        option.setKind(getSafeValue("kind", row));
        option.setType(getSafeValue("type", row));
        option.setJavaType(getSafeValue("javaType", row));
        option.setDeprecated(getSafeValue("deprecated", row));
        option.setDescription(getSafeValue("description", row));
        option.setDefaultValue(getSafeValue("defaultValue", row));
        option.setEnumValues(getSafeValue("enum", row));
        language.addLanguageOption(option);
    }
    return language;
}
Also used : LanguageOptionModel(org.apache.camel.maven.packaging.model.LanguageOptionModel) LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) Map(java.util.Map) HashMap(java.util.HashMap)

Example 2 with LanguageOptionModel

use of org.apache.camel.maven.packaging.model.LanguageOptionModel in project camel by apache.

the class SpringBootAutoConfigurationMojo method createLanguageConfigurationSource.

private void createLanguageConfigurationSource(String packageName, LanguageModel model, String overrideLanguageName) throws MojoFailureException {
    final JavaClassSource javaClass = Roaster.create(JavaClassSource.class);
    int pos = model.getJavaType().lastIndexOf(".");
    String name = model.getJavaType().substring(pos + 1);
    name = name.replace("Language", "LanguageConfiguration");
    javaClass.setPackage(packageName).setName(name);
    String doc = "Generated by camel-package-maven-plugin - do not edit this file!";
    if (!Strings.isBlank(model.getDescription())) {
        doc = model.getDescription() + "\n\n" + doc;
    }
    javaClass.getJavaDoc().setFullText(doc);
    String prefix = "camel.language." + (overrideLanguageName != null ? overrideLanguageName : model.getName());
    // make sure prefix is in lower case
    prefix = prefix.toLowerCase(Locale.US);
    javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix);
    for (LanguageOptionModel option : model.getLanguageOptions()) {
        // skip option with name id, or expression in language as we do not need that and skip resultType as they are not global options
        if ("id".equals(option.getName()) || "expression".equals(option.getName()) || "resultType".equals(option.getName())) {
            continue;
        }
        // CHECKSTYLE:OFF
        if ("bean".equals(model.getName())) {
            // and skip following as they are not global options
            if ("bean".equals(option.getName()) || "ref".equals(option.getName()) || "method".equals(option.getName()) || "beanType".equals(option.getName())) {
                continue;
            }
        } else if ("tokenize".equals(model.getName())) {
            // and skip following as they are not global options
            if ("token".equals(option.getName()) || "endToken".equals(option.getName()) || "inheritNamespaceTagName".equals(option.getName()) || "headerName".equals(option.getName()) || "regex".equals(option.getName()) || "xml".equals(option.getName()) || "includeTokens".equals(option.getName()) || "group".equals(option.getName()) || "skipFirst".equals(option.getName())) {
                continue;
            }
        } else if ("xtokenize".equals(model.getName())) {
            // and skip following as they are not global options
            if ("headerName".equals(option.getName()) || "group".equals(option.getName())) {
                continue;
            }
        } else if ("xpath".equals(model.getName())) {
            // and skip following as they are not global options
            if ("headerName".equals(option.getName())) {
                continue;
            }
        } else if ("xquery".equals(model.getName())) {
            // and skip following as they are not global options
            if ("headerName".equals(option.getName())) {
                continue;
            }
        }
        // CHECKSTYLE:ON
        String type = option.getJavaType();
        type = getSimpleJavaType(type);
        PropertySource<JavaClassSource> prop = javaClass.addProperty(type, option.getName());
        if ("true".equals(option.getDeprecated())) {
            prop.getField().addAnnotation(Deprecated.class);
            prop.getAccessor().addAnnotation(Deprecated.class);
            prop.getMutator().addAnnotation(Deprecated.class);
            // DeprecatedConfigurationProperty must be on getter when deprecated
            prop.getAccessor().addAnnotation(DeprecatedConfigurationProperty.class);
        }
        if (!Strings.isBlank(option.getDescription())) {
            prop.getField().getJavaDoc().setFullText(option.getDescription());
        }
        if (!Strings.isBlank(option.getDefaultValue())) {
            if ("java.lang.String".equals(option.getType())) {
                prop.getField().setStringInitializer(option.getDefaultValue());
            } else if ("long".equals(option.getJavaType()) || "java.lang.Long".equals(option.getJavaType())) {
                // the value should be a Long number
                String value = option.getDefaultValue() + "L";
                prop.getField().setLiteralInitializer(value);
            } else if ("integer".equals(option.getType()) || "boolean".equals(option.getType())) {
                prop.getField().setLiteralInitializer(option.getDefaultValue());
            } else if (!Strings.isBlank(option.getEnumValues())) {
                String enumShortName = type.substring(type.lastIndexOf(".") + 1);
                prop.getField().setLiteralInitializer(enumShortName + "." + option.getDefaultValue());
                javaClass.addImport(model.getJavaType());
            }
        }
    }
    sortImports(javaClass);
    String fileName = packageName.replaceAll("\\.", "\\/") + "/" + name + ".java";
    writeSourceIfChanged(javaClass, fileName);
}
Also used : LanguageOptionModel(org.apache.camel.maven.packaging.model.LanguageOptionModel) JavaClassSource(org.jboss.forge.roaster.model.source.JavaClassSource)

Example 3 with LanguageOptionModel

use of org.apache.camel.maven.packaging.model.LanguageOptionModel in project camel by apache.

the class UpdateReadmeMojo method generateLanguageModel.

private LanguageModel generateLanguageModel(String languageName, String json) {
    List<Map<String, String>> rows = parseJsonSchema("language", json, false);
    LanguageModel language = new LanguageModel();
    language.setTitle(getSafeValue("title", rows));
    language.setModelName(getSafeValue("modelName", rows));
    language.setName(getSafeValue("name", rows));
    language.setDescription(getSafeValue("description", rows));
    language.setFirstVersion(getSafeValue("firstVersion", rows));
    language.setLabel(getSafeValue("label", rows));
    language.setDeprecated(getSafeValue("deprecated", rows));
    language.setJavaType(getSafeValue("javaType", rows));
    language.setGroupId(getSafeValue("groupId", rows));
    language.setArtifactId(getSafeValue("artifactId", rows));
    language.setVersion(getSafeValue("version", rows));
    rows = parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        LanguageOptionModel option = new LanguageOptionModel();
        option.setName(getSafeValue("name", row));
        option.setDisplayName(getSafeValue("displayName", row));
        option.setKind(getSafeValue("kind", row));
        option.setType(getSafeValue("type", row));
        option.setJavaType(getSafeValue("javaType", row));
        option.setDeprecated(getSafeValue("deprecated", row));
        option.setEnumValues(getSafeValue("enum", row));
        option.setDefaultValue(getSafeValue("defaultValue", row));
        option.setDescription(getSafeValue("description", row));
        // skip option named id/expression
        if ("id".equals(option.getName()) || "expression".equals(option.getName())) {
            getLog().debug("Skipping option: " + option.getName());
        } else {
            language.addLanguageOption(option);
        }
    }
    return language;
}
Also used : LanguageOptionModel(org.apache.camel.maven.packaging.model.LanguageOptionModel) LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) Map(java.util.Map)

Aggregations

LanguageOptionModel (org.apache.camel.maven.packaging.model.LanguageOptionModel)3 Map (java.util.Map)2 LanguageModel (org.apache.camel.maven.packaging.model.LanguageModel)2 HashMap (java.util.HashMap)1 JavaClassSource (org.jboss.forge.roaster.model.source.JavaClassSource)1