Search in sources :

Example 6 with DataFormatModel

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

the class UpdateReadmeMojo method executeDataFormat.

private void executeDataFormat() throws MojoExecutionException, MojoFailureException {
    // find the dataformat names
    List<String> dataFormatNames = findDataFormatNames();
    final Set<File> jsonFiles = new TreeSet<File>();
    PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
    // only if there is dataformat we should update the documentation files
    if (!dataFormatNames.isEmpty()) {
        getLog().debug("Found " + dataFormatNames.size() + " dataformats");
        for (String dataFormatName : dataFormatNames) {
            String json = loadDataFormatJson(jsonFiles, dataFormatName);
            if (json != null) {
                // special for some data formats
                dataFormatName = asDataFormatName(dataFormatName);
                File file = new File(docDir, dataFormatName + "-dataformat.adoc");
                DataFormatModel model = generateDataFormatModel(dataFormatName, json);
                String title = asDataFormatTitle(model.getName(), model.getTitle());
                model.setTitle(title);
                String docTitle = model.getTitle() + " DataFormat";
                boolean deprecated = "true".equals(model.getDeprecated());
                if (deprecated) {
                    docTitle += " (deprecated)";
                }
                boolean exists = file.exists();
                boolean updated;
                updated = updateTitles(file, docTitle);
                updated |= updateAvailableFrom(file, model.getFirstVersion());
                String options = templateDataFormatOptions(model);
                updated |= updateDataFormatOptions(file, options);
                if (updated) {
                    getLog().info("Updated doc file: " + file);
                } else if (exists) {
                    getLog().debug("No changes to doc file: " + file);
                } else {
                    getLog().warn("No dataformat doc file: " + file);
                    if (isFailFast()) {
                        throw new MojoExecutionException("Failed build due failFast=true");
                    }
                }
            }
        }
    }
}
Also used : DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) File(java.io.File)

Example 7 with DataFormatModel

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

the class PrepareUserGuideMojo method generateDataFormatModel.

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

Example 8 with DataFormatModel

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

the class UpdateReadmeMojo method generateDataFormatModel.

private DataFormatModel generateDataFormatModel(String dataFormatName, String json) {
    List<Map<String, String>> rows = parseJsonSchema("dataformat", json, false);
    DataFormatModel dataFormat = new DataFormatModel();
    dataFormat.setTitle(getSafeValue("title", rows));
    dataFormat.setModelName(getSafeValue("modelName", rows));
    dataFormat.setName(getSafeValue("name", rows));
    dataFormat.setDescription(getSafeValue("description", rows));
    dataFormat.setFirstVersion(getSafeValue("firstVersion", rows));
    dataFormat.setLabel(getSafeValue("label", rows));
    dataFormat.setDeprecated(getSafeValue("deprecated", rows));
    dataFormat.setJavaType(getSafeValue("javaType", rows));
    dataFormat.setGroupId(getSafeValue("groupId", rows));
    dataFormat.setArtifactId(getSafeValue("artifactId", rows));
    dataFormat.setVersion(getSafeValue("version", rows));
    rows = parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        DataFormatOptionModel option = new DataFormatOptionModel();
        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));
        // special for bindy as we reuse one readme file
        if (dataFormatName.startsWith("bindy") && option.getName().equals("type")) {
            option.setDefaultValue("");
            String doc = option.getDescription() + " The default value is either Csv or KeyValue depending on chosen dataformat.";
            option.setDescription(doc);
        }
        // skip option named id
        if ("id".equals(option.getName())) {
            getLog().debug("Skipping option: " + option.getName());
        } else {
            dataFormat.addDataFormatOption(option);
        }
    }
    return dataFormat;
}
Also used : DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) DataFormatOptionModel(org.apache.camel.maven.packaging.model.DataFormatOptionModel) Map(java.util.Map)

Example 9 with DataFormatModel

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

the class PrepareUserGuideMojo method executeDataFormats.

protected void executeDataFormats() throws MojoExecutionException, MojoFailureException {
    Set<File> dataFormatFiles = new TreeSet<>();
    if (dataFormatsDir != null && dataFormatsDir.isDirectory()) {
        File[] files = dataFormatsDir.listFiles();
        if (files != null) {
            dataFormatFiles.addAll(Arrays.asList(files));
        }
    }
    try {
        List<DataFormatModel> models = new ArrayList<>();
        for (File file : dataFormatFiles) {
            String json = loadText(new FileInputStream(file));
            DataFormatModel model = generateDataFormatModel(json);
            models.add(model);
        }
        // sor the models
        Collections.sort(models, new DataFormatComparator());
        // the summary file has the TOC
        File file = new File(userGuideDir, "SUMMARY.md");
        // update data formats
        StringBuilder dataFormats = new StringBuilder();
        dataFormats.append("* Data Formats\n");
        for (DataFormatModel model : models) {
            String line = "\t* " + link(model) + "\n";
            dataFormats.append(line);
        }
        boolean updated = updateDataFormats(file, dataFormats.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) DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) TreeSet(java.util.TreeSet) File(java.io.File)

Aggregations

DataFormatModel (org.apache.camel.maven.packaging.model.DataFormatModel)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 DataFormatOptionModel (org.apache.camel.maven.packaging.model.DataFormatOptionModel)3 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)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 LanguageModel (org.apache.camel.maven.packaging.model.LanguageModel)2 AbstractMojo (org.apache.maven.plugin.AbstractMojo)2 MavenProject (org.apache.maven.project.MavenProject)2