Search in sources :

Example 6 with LanguageModel

use of org.apache.camel.maven.packaging.model.LanguageModel 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 7 with LanguageModel

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

the class PrepareUserGuideMojo method executeLanguages.

protected void executeLanguages() throws MojoExecutionException, MojoFailureException {
    Set<File> languageFiles = new TreeSet<>();
    if (languagesDir != null && languagesDir.isDirectory()) {
        File[] files = languagesDir.listFiles();
        if (files != null) {
            languageFiles.addAll(Arrays.asList(files));
        }
    }
    try {
        List<LanguageModel> models = new ArrayList<>();
        for (File file : languageFiles) {
            String json = loadText(new FileInputStream(file));
            LanguageModel model = generateLanguageModel(json);
            models.add(model);
        }
        // sor the models
        Collections.sort(models, new LanguageComparator());
        // the summary file has the TOC
        File file = new File(userGuideDir, "SUMMARY.md");
        // update languages
        StringBuilder languages = new StringBuilder();
        languages.append("* Expression Languages\n");
        for (LanguageModel model : models) {
            String line = "\t* " + link(model) + "\n";
            languages.append(line);
        }
        boolean updated = updateLanguages(file, languages.toString());
        if (updated) {
            getLog().info("Updated user guide file: " + file);
        } else {
            getLog().debug("No changes to user guide file: " + file);
        }
    } catch (IOException e) {
        throw new MojoFailureException("Error due " + e.getMessage(), e);
    }
}
Also used : ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) File(java.io.File)

Example 8 with LanguageModel

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

the class PrepareReadmeMojo method generateLanguageModel.

private LanguageModel generateLanguageModel(String json) {
    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language", json, false);
    LanguageModel language = new LanguageModel();
    language.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
    language.setName(JSonSchemaHelper.getSafeValue("name", rows));
    language.setModelName(JSonSchemaHelper.getSafeValue("modelName", rows));
    language.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
    language.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows));
    language.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
    language.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows));
    language.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
    language.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows));
    language.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows));
    language.setVersion(JSonSchemaHelper.getSafeValue("version", rows));
    return language;
}
Also used : LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 9 with LanguageModel

use of org.apache.camel.maven.packaging.model.LanguageModel 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

LanguageModel (org.apache.camel.maven.packaging.model.LanguageModel)9 Map (java.util.Map)6 File (java.io.File)5 TreeSet (java.util.TreeSet)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 FileInputStream (java.io.FileInputStream)3 IOException (java.io.IOException)3 List (java.util.List)3 LanguageOptionModel (org.apache.camel.maven.packaging.model.LanguageOptionModel)3 MojoFailureException (org.apache.maven.plugin.MojoFailureException)3 Arrays (java.util.Arrays)2 LinkedList (java.util.LinkedList)2 Set (java.util.Set)2 PackageHelper.loadText (org.apache.camel.maven.packaging.PackageHelper.loadText)2 ComponentModel (org.apache.camel.maven.packaging.model.ComponentModel)2 DataFormatModel (org.apache.camel.maven.packaging.model.DataFormatModel)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1