Search in sources :

Example 1 with OtherModel

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

the class PrepareReadmeMojo method generateOtherModel.

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

Example 2 with OtherModel

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

the class PrepareUserGuideMojo method executeOthers.

protected void executeOthers() throws MojoExecutionException, MojoFailureException {
    Set<File> otherFiles = new TreeSet<>();
    if (othersDir != null && othersDir.isDirectory()) {
        File[] files = othersDir.listFiles();
        if (files != null) {
            otherFiles.addAll(Arrays.asList(files));
        }
    }
    try {
        List<OtherModel> models = new ArrayList<>();
        for (File file : otherFiles) {
            String json = loadText(new FileInputStream(file));
            OtherModel model = generateOtherModel(json);
            models.add(model);
        }
        // sor the models
        Collections.sort(models, new OtherComparator());
        // the summary file has the TOC
        File file = new File(userGuideDir, "SUMMARY.md");
        // update core components
        StringBuilder other = new StringBuilder();
        other.append("* Miscellaneous Components\n");
        for (OtherModel model : models) {
            String line = "\t* " + link(model) + "\n";
            other.append(line);
        }
        boolean updated = updateOthers(file, other.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) OtherModel(org.apache.camel.maven.packaging.model.OtherModel) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) File(java.io.File)

Example 3 with OtherModel

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

the class PrepareUserGuideMojo method generateOtherModel.

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

Example 4 with OtherModel

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

the class PrepareReadmeMojo method executeOthersReadme.

protected void executeOthersReadme() throws MojoExecutionException, MojoFailureException {
    Set<File> otherFiles = new TreeSet<>();
    if (othersDir != null && othersDir.isDirectory()) {
        File[] files = othersDir.listFiles();
        if (files != null) {
            otherFiles.addAll(Arrays.asList(files));
        }
    }
    try {
        List<OtherModel> others = new ArrayList<>();
        for (File file : otherFiles) {
            String json = loadText(new FileInputStream(file));
            OtherModel model = generateOtherModel(json);
            others.add(model);
        }
        // sort the models
        Collections.sort(others, new OtherComparator());
        // how many different artifacts
        int count = others.stream().map(OtherModel::getArtifactId).collect(toSet()).size();
        // how many deprecated
        long deprecated = others.stream().filter(o -> "true".equals(o.getDeprecated())).count();
        // update the big readme file in the components dir
        File file = new File(readmeComponentsDir, "readme.adoc");
        // update regular components
        boolean exists = file.exists();
        String changed = templateOthers(others, count, deprecated);
        boolean updated = updateOthers(file, changed);
        if (updated) {
            getLog().info("Updated readme.adoc file: " + file);
        } else if (exists) {
            getLog().debug("No changes to readme.adoc file: " + file);
        } else {
            getLog().warn("No readme.adoc file: " + file);
        }
    } catch (IOException e) {
        throw new MojoFailureException("Error due " + e.getMessage(), e);
    }
}
Also used : Arrays(java.util.Arrays) PackageHelper.writeText(org.apache.camel.maven.packaging.PackageHelper.writeText) MavenProjectHelper(org.apache.maven.project.MavenProjectHelper) HashMap(java.util.HashMap) TreeSet(java.util.TreeSet) LanguageModel(org.apache.camel.maven.packaging.model.LanguageModel) ArrayList(java.util.ArrayList) OtherModel(org.apache.camel.maven.packaging.model.OtherModel) MavenProject(org.apache.maven.project.MavenProject) Map(java.util.Map) ComponentModel(org.apache.camel.maven.packaging.model.ComponentModel) Collectors.toSet(java.util.stream.Collectors.toSet) Set(java.util.Set) IOException(java.io.IOException) FileInputStream(java.io.FileInputStream) TemplateRuntime(org.mvel2.templates.TemplateRuntime) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) File(java.io.File) Collections(edu.emory.mathcs.backport.java.util.Collections) EipModel(org.apache.camel.maven.packaging.model.EipModel) MojoFailureException(org.apache.maven.plugin.MojoFailureException) List(java.util.List) PackageHelper.loadText(org.apache.camel.maven.packaging.PackageHelper.loadText) Comparator(java.util.Comparator) DataFormatModel(org.apache.camel.maven.packaging.model.DataFormatModel) AbstractMojo(org.apache.maven.plugin.AbstractMojo) ArrayList(java.util.ArrayList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) IOException(java.io.IOException) OtherModel(org.apache.camel.maven.packaging.model.OtherModel) FileInputStream(java.io.FileInputStream) TreeSet(java.util.TreeSet) File(java.io.File)

Aggregations

OtherModel (org.apache.camel.maven.packaging.model.OtherModel)4 Map (java.util.Map)3 File (java.io.File)2 FileInputStream (java.io.FileInputStream)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 TreeSet (java.util.TreeSet)2 MojoFailureException (org.apache.maven.plugin.MojoFailureException)2 Collections (edu.emory.mathcs.backport.java.util.Collections)1 Arrays (java.util.Arrays)1 Comparator (java.util.Comparator)1 List (java.util.List)1 Set (java.util.Set)1 Collectors.toSet (java.util.stream.Collectors.toSet)1 PackageHelper.loadText (org.apache.camel.maven.packaging.PackageHelper.loadText)1 PackageHelper.writeText (org.apache.camel.maven.packaging.PackageHelper.writeText)1 ComponentModel (org.apache.camel.maven.packaging.model.ComponentModel)1 DataFormatModel (org.apache.camel.maven.packaging.model.DataFormatModel)1 EipModel (org.apache.camel.maven.packaging.model.EipModel)1