Search in sources :

Example 1 with EipModel

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

the class PrepareReadmeMojo method generateEipModel.

private EipModel generateEipModel(String json) {
    List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false);
    EipModel eip = new EipModel();
    eip.setName(JSonSchemaHelper.getSafeValue("name", rows));
    eip.setTitle(JSonSchemaHelper.getSafeValue("title", rows));
    eip.setDescription(JSonSchemaHelper.getSafeValue("description", rows));
    eip.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows));
    eip.setLabel(JSonSchemaHelper.getSafeValue("label", rows));
    eip.setDeprecated("true".equals(JSonSchemaHelper.getSafeValue("deprecated", rows)));
    eip.setInput("true".equals(JSonSchemaHelper.getSafeValue("input", rows)));
    eip.setOutput("true".equals(JSonSchemaHelper.getSafeValue("output", rows)));
    return eip;
}
Also used : EipModel(org.apache.camel.maven.packaging.model.EipModel) HashMap(java.util.HashMap) Map(java.util.Map)

Example 2 with EipModel

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

the class PrepareReadmeMojo method executeEipsReadme.

protected void executeEipsReadme() throws MojoExecutionException, MojoFailureException {
    Set<File> eipFiles = new TreeSet<>();
    if (eipsDir != null && eipsDir.isDirectory()) {
        File[] files = eipsDir.listFiles();
        if (files != null) {
            eipFiles.addAll(Arrays.asList(files));
        }
    }
    try {
        List<EipModel> models = new ArrayList<>();
        for (File file : eipFiles) {
            String json = loadText(new FileInputStream(file));
            EipModel model = generateEipModel(json);
            // we only want actual EIPs from the models
            if (model.getLabel().startsWith("eip")) {
                models.add(model);
            }
        }
        // re-order the EIPs so we have them in different categories
        // sort the models
        Collections.sort(models, new EipComparator());
        // how many deprecated
        long deprecated = models.stream().filter(EipModel::isDeprecated).count();
        // update the big readme file in the core dir
        File file = new File(readmeCoreDir, "readme-eip.adoc");
        // update regular components
        boolean exists = file.exists();
        String changed = templateEips(models, deprecated);
        boolean updated = updateEips(file, changed);
        if (updated) {
            getLog().info("Updated readme-eip.adoc file: " + file);
        } else if (exists) {
            getLog().debug("No changes to readme-eip.adoc file: " + file);
        } else {
            getLog().warn("No readme-eip.adoc 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) EipModel(org.apache.camel.maven.packaging.model.EipModel) TreeSet(java.util.TreeSet) File(java.io.File)

Example 3 with EipModel

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

the class UpdateReadmeMojo method generateEipModel.

private EipModel generateEipModel(String json) {
    List<Map<String, String>> rows = parseJsonSchema("model", json, false);
    EipModel eip = new EipModel();
    eip.setName(getSafeValue("name", rows));
    eip.setTitle(getSafeValue("title", rows));
    eip.setDescription(getSafeValue("description", rows));
    eip.setJavaType(getSafeValue("javaType", rows));
    eip.setLabel(getSafeValue("label", rows));
    eip.setDeprecated("true".equals(getSafeValue("deprecated", rows)));
    eip.setInput("true".equals(getSafeValue("input", rows)));
    eip.setOutput("true".equals(getSafeValue("output", rows)));
    rows = parseJsonSchema("properties", json, true);
    for (Map<String, String> row : rows) {
        EipOptionModel option = new EipOptionModel();
        option.setName(getSafeValue("name", row));
        option.setDisplayName(getSafeValue("displayName", row));
        option.setType(getSafeValue("type", row));
        option.setJavaType(getSafeValue("javaType", row));
        option.setRequired(getSafeValue("required", row));
        option.setDeprecated("true".equals(getSafeValue("deprecated", row)));
        option.setDescription(getSafeValue("description", row));
        option.setInput("true".equals(getSafeValue("input", row)));
        option.setOutput("true".equals(getSafeValue("output", row)));
        // lets put required in the description
        if ("true".equals(option.getRequired())) {
            String desc = "*Required* " + option.getDescription();
            option.setDescription(desc);
        }
        // skip option named id/description/expression/outputs
        if ("id".equals(option.getName()) || "description".equals(option.getName()) || "expression".equals(option.getName()) || "outputs".equals(option.getName())) {
            getLog().debug("Skipping option: " + option.getName());
        } else {
            eip.addEipOptionModel(option);
        }
    }
    return eip;
}
Also used : EipOptionModel(org.apache.camel.maven.packaging.model.EipOptionModel) EipModel(org.apache.camel.maven.packaging.model.EipModel) Map(java.util.Map)

Example 4 with EipModel

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

the class UpdateReadmeMojo method executeEips.

private void executeEips() throws MojoExecutionException, MojoFailureException {
    // only run if in camel-core
    String currentDir = Paths.get(".").normalize().toAbsolutePath().toString();
    if (!currentDir.endsWith("camel-core")) {
        return;
    }
    final Set<File> jsonFiles = new TreeSet<File>();
    // find all json files in camel-core
    File coreDir = new File(".");
    if (coreDir.isDirectory()) {
        File target = new File(coreDir, "target/classes/org/apache/camel/model");
        PackageHelper.findJsonFiles(target, jsonFiles, new PackageHelper.CamelComponentsModelFilter());
    }
    // only if there is dataformat we should update the documentation files
    if (!jsonFiles.isEmpty()) {
        getLog().debug("Found " + jsonFiles.size() + " eips");
        for (File jsonFile : jsonFiles) {
            String json = loadEipJson(jsonFile);
            if (json != null) {
                EipModel model = generateEipModel(json);
                String title = asEipTitle(model.getName(), model.getTitle());
                model.setTitle(title);
                String eipName = model.getName();
                // we only want actual EIPs from the models
                if (!model.getLabel().startsWith("eip")) {
                    continue;
                }
                File file = new File(eipDocDir, eipName + "-eip.adoc");
                String docTitle = model.getTitle() + " EIP";
                boolean deprecated = model.isDeprecated();
                if (deprecated) {
                    docTitle += " (deprecated)";
                }
                boolean exists = file.exists();
                boolean updated;
                updated = updateTitles(file, docTitle);
                String options = templateEipOptions(model);
                updated |= updateEipOptions(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 eip doc file: " + file);
                    if (isFailFast()) {
                        throw new MojoExecutionException("Failed build due failFast=true");
                    }
                }
            }
        }
    }
}
Also used : EipModel(org.apache.camel.maven.packaging.model.EipModel) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) TreeSet(java.util.TreeSet) File(java.io.File)

Aggregations

EipModel (org.apache.camel.maven.packaging.model.EipModel)4 File (java.io.File)2 Map (java.util.Map)2 TreeSet (java.util.TreeSet)2 FileInputStream (java.io.FileInputStream)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 EipOptionModel (org.apache.camel.maven.packaging.model.EipOptionModel)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1