This is an automated email from the ASF dual-hosted git repository. djencks pushed a commit to branch camel-2.x in repository https://gitbox.apache.org/repos/asf/camel.git
commit f8c468546c4ca9889c62f8929d2cb7788d037c35 Author: David Jencks <djen...@apache.org> AuthorDate: Mon May 4 21:57:38 2020 -0700 Tooling changes, removing old table generation and adding attributes to partly generated docs. --- .../camel/maven/packaging/PrepareReadmeMojo.java | 635 ------------------- .../packaging/SpringBootAutoConfigurationMojo.java | 14 +- .../camel/maven/packaging/UpdateReadmeMojo.java | 702 +++++++++++++++------ .../camel/maven/packaging/model/ArtifactModel.java | 54 ++ .../model/{OtherModel.java => BaseModel.java} | 109 ++-- .../maven/packaging/model/ComponentModel.java | 114 +--- .../maven/packaging/model/DataFormatModel.java | 123 +--- .../camel/maven/packaging/model/EipModel.java | 82 +-- .../camel/maven/packaging/model/LanguageModel.java | 83 +-- .../camel/maven/packaging/model/OtherModel.java | 115 +--- .../camel/maven/packaging/model/Strings.java | 170 +++++ .../src/main/resources/dataformat-options.mvel | 8 +- .../src/main/resources/eip-options.mvel | 6 +- .../src/main/resources/language-options.mvel | 8 +- .../src/main/resources/readme-components.mvel | 14 - .../src/main/resources/readme-dataformats.mvel | 12 - .../src/main/resources/readme-languages.mvel | 12 - .../src/main/resources/readme-others.mvel | 12 - 18 files changed, 858 insertions(+), 1415 deletions(-) diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java index b3ea3e3..7bf73a4 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareReadmeMojo.java @@ -67,42 +67,12 @@ public class PrepareReadmeMojo extends AbstractMojo { protected File eipsDir; /** - * The directory for components catalog - */ - @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/components") - protected File componentsDir; - - /** - * The directory for data formats catalog - */ - @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/dataformats") - protected File dataFormatsDir; - - /** - * The directory for languages catalog - */ - @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/languages") - protected File languagesDir; - - /** - * The directory for others catalog - */ - @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/catalog/others") - protected File othersDir; - - /** * The directory for camel-core */ @Parameter(defaultValue = "${project.directory}/../../../camel-core") protected File readmeCoreDir; /** - * The directory for components - */ - @Parameter(defaultValue = "${project.directory}/../../../components") - protected File readmeComponentsDir; - - /** * Maven ProjectHelper. */ @Component @@ -118,14 +88,6 @@ public class PrepareReadmeMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { // update readme file in camel-core executeEipsReadme(); - executeComponentsReadme(true); - executeDataFormatsReadme(true); - executeLanguagesReadme(true); - // update readme file in components - executeComponentsReadme(false); - executeOthersReadme(); - executeDataFormatsReadme(false); - executeLanguagesReadme(false); } protected void executeEipsReadme() throws MojoExecutionException, MojoFailureException { @@ -181,294 +143,6 @@ public class PrepareReadmeMojo extends AbstractMojo { } } - protected void executeComponentsReadme(boolean coreOnly) throws MojoExecutionException, MojoFailureException { - Set<File> componentFiles = new TreeSet<>(); - - if (componentsDir != null && componentsDir.isDirectory()) { - File[] files = componentsDir.listFiles(); - if (files != null) { - componentFiles.addAll(Arrays.asList(files)); - } - } - - try { - List<ComponentModel> models = new ArrayList<>(); - for (File file : componentFiles) { - String json = loadText(new FileInputStream(file)); - ComponentModel model = generateComponentModel(json, coreOnly); - - // filter out alternative schemas which reuses documentation - boolean add = true; - if (!model.getAlternativeSchemes().isEmpty()) { - String first = model.getAlternativeSchemes().split(",")[0]; - if (!model.getScheme().equals(first)) { - add = false; - } - } - if (add) { - models.add(model); - - // special for camel-mail where we want to refer its imap scheme to mail so its mail.adoc in the doc link - if ("imap".equals(model.getScheme())) { - model.setScheme("mail"); - model.setTitle("Mail"); - } - } - } - - // sort the models - Collections.sort(models, new ComponentComparator()); - - // filter out unwanted components - List<ComponentModel> components = new ArrayList<>(); - for (ComponentModel model : models) { - if (coreOnly) { - if ("camel-core".equals(model.getArtifactId())) { - // only include core components - components.add(model); - } - } else { - // we want to include everything in the big file (also from camel-core) - components.add(model); - } - } - - // how many different artifacts - int count = components.stream() - .map(ComponentModel::getArtifactId) - .collect(toSet()).size(); - - // how many deprecated - long deprecated = components.stream() - .filter(c -> "true".equals(c.getDeprecated())) - .count(); - - // update the big readme file in the core/components dir - File file; - if (coreOnly) { - file = new File(readmeCoreDir, "readme.adoc"); - } else { - file = new File(readmeComponentsDir, "readme.adoc"); - } - - // update regular components - boolean exists = file.exists(); - String changed = templateComponents(components, count, deprecated); - boolean updated = updateComponents(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); - } - } - - 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); - } - } - - protected void executeDataFormatsReadme(boolean coreOnly) 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, coreOnly); - - // special for bindy as we have one common file - if (model.getName().startsWith("bindy")) { - model.setName("bindy"); - } - - models.add(model); - } - - // sort the models - Collections.sort(models, new DataFormatComparator()); - - // how many different artifacts - int count = models.stream() - .map(DataFormatModel::getArtifactId) - .collect(toSet()).size(); - - // how many deprecated - long deprecated = models.stream() - .filter(m -> "true".equals(m.getDeprecated())) - .count(); - - // filter out camel-core - List<DataFormatModel> dataFormats = new ArrayList<>(); - for (DataFormatModel model : models) { - if (coreOnly) { - if ("camel-core".equals(model.getArtifactId())) { - // only include core components - dataFormats.add(model); - } - } else { - // we want to include everything in the big file (also from camel-core) - dataFormats.add(model); - } - } - - // update the big readme file in the core/components dir - File file; - if (coreOnly) { - file = new File(readmeCoreDir, "readme.adoc"); - } else { - file = new File(readmeComponentsDir, "readme.adoc"); - } - - // update regular data formats - boolean exists = file.exists(); - String changed = templateDataFormats(dataFormats, count, deprecated); - boolean updated = updateDataFormats(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); - } - } - - protected void executeLanguagesReadme(boolean coreOnly) 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, coreOnly); - models.add(model); - } - - // sort the models - Collections.sort(models, new LanguageComparator()); - - // filter out camel-core - List<LanguageModel> languages = new ArrayList<>(); - for (LanguageModel model : models) { - if (coreOnly) { - if ("camel-core".equals(model.getArtifactId())) { - // only include core components - languages.add(model); - } - } else { - // we want to include everything in the big file (also from camel-core) - languages.add(model); - } - } - - // how many different artifacts - int count = languages.stream() - .map(LanguageModel::getArtifactId) - .collect(toSet()).size(); - - // how many deprecated - long deprecated = languages.stream() - .filter(l -> "true".equals(l.getDeprecated())) - .count(); - - // update the big readme file in the core/components dir - File file; - if (coreOnly) { - file = new File(readmeCoreDir, "readme.adoc"); - } else { - file = new File(readmeComponentsDir, "readme.adoc"); - } - - // update regular data formats - boolean exists = file.exists(); - String changed = templateLanguages(languages, count, deprecated); - boolean updated = updateLanguages(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); - } - } - private String templateEips(List<EipModel> models, long deprecated) throws MojoExecutionException { try { String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("readme-eips.mvel")); @@ -482,61 +156,6 @@ public class PrepareReadmeMojo extends AbstractMojo { } } - private String templateComponents(List<ComponentModel> models, int artifacts, long deprecated) throws MojoExecutionException { - try { - String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("readme-components.mvel")); - Map<String, Object> map = new HashMap<>(); - map.put("components", models); - map.put("numberOfArtifacts", artifacts); - map.put("numberOfDeprecated", deprecated); - String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE)); - return out; - } catch (Exception e) { - throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e); - } - } - - private String templateOthers(List<OtherModel> models, int artifacts, long deprecated) throws MojoExecutionException { - try { - String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("readme-others.mvel")); - Map<String, Object> map = new HashMap<>(); - map.put("others", models); - map.put("numberOfArtifacts", artifacts); - map.put("numberOfDeprecated", deprecated); - String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE)); - return out; - } catch (Exception e) { - throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e); - } - } - - private String templateDataFormats(List<DataFormatModel> models, int artifacts, long deprecated) throws MojoExecutionException { - try { - String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("readme-dataformats.mvel")); - Map<String, Object> map = new HashMap<>(); - map.put("dataformats", models); - map.put("numberOfArtifacts", artifacts); - map.put("numberOfDeprecated", deprecated); - String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE)); - return out; - } catch (Exception e) { - throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e); - } - } - - private String templateLanguages(List<LanguageModel> models, int artifacts, long deprecated) throws MojoExecutionException { - try { - String template = loadText(UpdateReadmeMojo.class.getClassLoader().getResourceAsStream("readme-languages.mvel")); - Map<String, Object> map = new HashMap<>(); - map.put("languages", models); - map.put("numberOfArtifacts", artifacts); - map.put("numberOfDeprecated", deprecated); - String out = (String) TemplateRuntime.eval(template, map, Collections.singletonMap("util", MvelHelper.INSTANCE)); - return out; - } catch (Exception e) { - throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e); - } - } private boolean updateEips(File file, String changed) throws MojoExecutionException { if (!file.exists()) { @@ -572,142 +191,6 @@ public class PrepareReadmeMojo extends AbstractMojo { } } - private boolean updateComponents(File file, String changed) throws MojoExecutionException { - if (!file.exists()) { - return false; - } - - try { - String text = loadText(new FileInputStream(file)); - - String existing = StringHelper.between(text, "// components: START", "// components: END"); - if (existing != null) { - // remove leading line breaks etc - existing = existing.trim(); - changed = changed.trim(); - if (existing.equals(changed)) { - return false; - } else { - String before = StringHelper.before(text, "// components: START"); - String after = StringHelper.after(text, "// components: END"); - text = before + "// components: START\n" + changed + "\n// components: END" + after; - writeText(file, text); - return true; - } - } else { - getLog().warn("Cannot find markers in file " + file); - getLog().warn("Add the following markers"); - getLog().warn("\t// components: START"); - getLog().warn("\t// components: END"); - return false; - } - } catch (Exception e) { - throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); - } - } - - private boolean updateOthers(File file, String changed) throws MojoExecutionException { - if (!file.exists()) { - return false; - } - - try { - String text = loadText(new FileInputStream(file)); - - String existing = StringHelper.between(text, "// others: START", "// others: END"); - if (existing != null) { - // remove leading line breaks etc - existing = existing.trim(); - changed = changed.trim(); - if (existing.equals(changed)) { - return false; - } else { - String before = StringHelper.before(text, "// others: START"); - String after = StringHelper.after(text, "// others: END"); - text = before + "// others: START\n" + changed + "\n// others: END" + after; - writeText(file, text); - return true; - } - } else { - getLog().warn("Cannot find markers in file " + file); - getLog().warn("Add the following markers"); - getLog().warn("\t// others: START"); - getLog().warn("\t// others: END"); - return false; - } - } catch (Exception e) { - throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); - } - } - - private boolean updateDataFormats(File file, String changed) throws MojoExecutionException { - if (!file.exists()) { - return false; - } - - try { - String text = loadText(new FileInputStream(file)); - - String existing = StringHelper.between(text, "// dataformats: START", "// dataformats: END"); - if (existing != null) { - // remove leading line breaks etc - existing = existing.trim(); - changed = changed.trim(); - if (existing.equals(changed)) { - return false; - } else { - String before = StringHelper.before(text, "// dataformats: START"); - String after = StringHelper.after(text, "// dataformats: END"); - text = before + "// dataformats: START\n" + changed + "\n// dataformats: END" + after; - writeText(file, text); - return true; - } - } else { - getLog().warn("Cannot find markers in file " + file); - getLog().warn("Add the following markers"); - getLog().warn("\t// dataformats: START"); - getLog().warn("\t// dataformats: END"); - return false; - } - } catch (Exception e) { - throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); - } - } - - private boolean updateLanguages(File file, String changed) throws MojoExecutionException { - if (!file.exists()) { - return false; - } - - try { - String text = loadText(new FileInputStream(file)); - - String existing = StringHelper.between(text, "// languages: START", "// languages: END"); - if (existing != null) { - // remove leading line breaks etc - existing = existing.trim(); - changed = changed.trim(); - if (existing.equals(changed)) { - return false; - } else { - String before = StringHelper.before(text, "// languages: START"); - String after = StringHelper.after(text, "// languages: END"); - text = before + "// languages: START\n" + changed + "\n// languages: END" + after; - writeText(file, text); - return true; - } - } else { - getLog().warn("Cannot find markers in file " + file); - getLog().warn("Add the following markers"); - getLog().warn("\t// languages: START"); - getLog().warn("\t// languages: END"); - return false; - } - } catch (Exception e) { - throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); - } - } - private static class EipComparator implements Comparator<EipModel> { @Override @@ -717,42 +200,6 @@ public class PrepareReadmeMojo extends AbstractMojo { } } - private static class ComponentComparator implements Comparator<ComponentModel> { - - @Override - public int compare(ComponentModel o1, ComponentModel o2) { - // lets sort by title - return o1.getTitle().compareToIgnoreCase(o2.getTitle()); - } - } - - private static class OtherComparator implements Comparator<OtherModel> { - - @Override - public int compare(OtherModel o1, OtherModel o2) { - // lets sort by title - return o1.getTitle().compareToIgnoreCase(o2.getTitle()); - } - } - - private static class DataFormatComparator implements Comparator<DataFormatModel> { - - @Override - public int compare(DataFormatModel o1, DataFormatModel o2) { - // lets sort by title - return o1.getTitle().compareToIgnoreCase(o2.getTitle()); - } - } - - private static class LanguageComparator implements Comparator<LanguageModel> { - - @Override - public int compare(LanguageModel o1, LanguageModel o2) { - // lets sort by title - return o1.getTitle().compareToIgnoreCase(o2.getTitle()); - } - } - private EipModel generateEipModel(String json) { List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("model", json, false); @@ -770,86 +217,4 @@ public class PrepareReadmeMojo extends AbstractMojo { return eip; } - private ComponentModel generateComponentModel(String json, boolean coreOnly) { - List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("component", json, false); - - ComponentModel component = new ComponentModel(coreOnly); - component.setScheme(JSonSchemaHelper.getSafeValue("scheme", rows)); - component.setSyntax(JSonSchemaHelper.getSafeValue("syntax", rows)); - component.setAlternativeSyntax(JSonSchemaHelper.getSafeValue("alternativeSyntax", rows)); - component.setAlternativeSchemes(JSonSchemaHelper.getSafeValue("alternativeSchemes", rows)); - component.setTitle(JSonSchemaHelper.getSafeValue("title", rows)); - component.setDescription(JSonSchemaHelper.getSafeValue("description", rows)); - component.setFirstVersion(JSonSchemaHelper.getSafeValue("firstVersion", rows)); - component.setLabel(JSonSchemaHelper.getSafeValue("label", rows)); - component.setDeprecated(JSonSchemaHelper.getSafeValue("deprecated", rows)); - component.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - component.setConsumerOnly(JSonSchemaHelper.getSafeValue("consumerOnly", rows)); - component.setProducerOnly(JSonSchemaHelper.getSafeValue("producerOnly", rows)); - component.setJavaType(JSonSchemaHelper.getSafeValue("javaType", rows)); - component.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - component.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - component.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); - - return component; - } - - 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.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", rows)); - other.setGroupId(JSonSchemaHelper.getSafeValue("groupId", rows)); - other.setArtifactId(JSonSchemaHelper.getSafeValue("artifactId", rows)); - other.setVersion(JSonSchemaHelper.getSafeValue("version", rows)); - - return other; - } - - private DataFormatModel generateDataFormatModel(String json, boolean coreOnly) { - List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("dataformat", json, false); - - DataFormatModel dataFormat = new DataFormatModel(coreOnly); - 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.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", 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; - } - - private LanguageModel generateLanguageModel(String json, boolean coreOnly) { - List<Map<String, String>> rows = JSonSchemaHelper.parseJsonSchema("language", json, false); - - LanguageModel language = new LanguageModel(coreOnly); - 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.setDeprecationNote(JSonSchemaHelper.getSafeValue("deprecationNote", 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; - } - } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java index de98f36..e1d58ba 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java @@ -724,7 +724,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix); Set<JavaClassSource> nestedTypes = new HashSet<>(); - for (ComponentOptionModel option : model.getComponentOptions()) { + for (ComponentOptionModel option : model.getOptions()) { if (skipComponentOption(model, option)) { // some component options should be skipped @@ -1159,7 +1159,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { javaClass.addAnnotation(Generated.class).setStringValue("value", SpringBootAutoConfigurationMojo.class.getName()); javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix); - for (DataFormatOptionModel option : model.getDataFormatOptions()) { + for (DataFormatOptionModel option : model.getOptions()) { // skip option with name id in data format as we do not need that if ("id".equals(option.getName())) { continue; @@ -1248,7 +1248,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { javaClass.addAnnotation(Generated.class).setStringValue("value", SpringBootAutoConfigurationMojo.class.getName()); javaClass.addAnnotation("org.springframework.boot.context.properties.ConfigurationProperties").setStringValue("prefix", prefix); - for (LanguageOptionModel option : model.getLanguageOptions()) { + for (LanguageOptionModel option : model.getOptions()) { // 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; @@ -1982,7 +1982,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { option.setDescription(getSafeValue("description", row)); option.setDefaultValue(getSafeValue("defaultValue", row)); option.setEnums(getSafeValue("enum", row)); - component.addComponentOption(option); + component.addOption(option); } rows = JSonSchemaHelper.parseJsonSchema("properties", json, true); @@ -2039,7 +2039,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { option.setDescription(getSafeValue("description", row)); option.setDefaultValue(getSafeValue("defaultValue", row)); option.setEnumValues(getSafeValue("enum", row)); - dataFormat.addDataFormatOption(option); + dataFormat.addOption(option); } return dataFormat; @@ -2075,7 +2075,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { option.setDescription(getSafeValue("description", row)); option.setDefaultValue(getSafeValue("defaultValue", row)); option.setEnumValues(getSafeValue("enum", row)); - language.addLanguageOption(option); + language.addOption(option); } return language; @@ -2110,7 +2110,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo { option.setDescription(getSafeValue("description", row)); option.setEnums(getSafeValue("enums", row)); - model.addOptionModel(option); + model.addOption(option); } return model; diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java index 992b0ca..3b0788f 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/UpdateReadmeMojo.java @@ -21,27 +21,14 @@ import java.io.FileInputStream; import java.io.IOException; import java.io.InputStream; import java.nio.file.Paths; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Set; -import java.util.TreeSet; +import java.util.*; import java.util.stream.Collectors; -import org.apache.camel.maven.packaging.model.ComponentModel; -import org.apache.camel.maven.packaging.model.ComponentOptionModel; -import org.apache.camel.maven.packaging.model.DataFormatModel; -import org.apache.camel.maven.packaging.model.DataFormatOptionModel; -import org.apache.camel.maven.packaging.model.EipModel; -import org.apache.camel.maven.packaging.model.EipOptionModel; -import org.apache.camel.maven.packaging.model.EndpointOptionModel; -import org.apache.camel.maven.packaging.model.LanguageModel; -import org.apache.camel.maven.packaging.model.LanguageOptionModel; +import org.apache.camel.maven.packaging.model.*; import org.apache.maven.model.Resource; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; @@ -75,13 +62,40 @@ public class UpdateReadmeMojo extends AbstractMojo { protected File buildDir; /** - * The documentation directory + * The generic documentation directory * */ @Parameter(defaultValue = "${basedir}/src/main/docs") protected File docDir; /** + * The core dataformates documentation directory + * + */ + @Parameter(defaultValue = "${basedir}/src/main/docs/modules/dataformats/pages") + protected File dataformatsDocDirCore; + + /** + * The core languages documentation directory + * + */ + @Parameter(defaultValue = "${basedir}/src/main/docs/modules/languages/pages") + protected File languagesDocDirCore; + + /** + * The core others documentation directory + * + */ + @Parameter(defaultValue = "${basedir}/src/main/docs/modules/others/pages") + protected File othersDocDirCore; + + /** + * The core component documentation directory + */ + @Parameter(defaultValue = "${project.basedir}/src/main/docs/modules/ROOT/pages") + protected File componentDocDirCore; + + /** * The documentation directory * */ @@ -104,6 +118,7 @@ public class UpdateReadmeMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { executeComponent(); + executeOther(); executeDataFormat(); executeLanguage(); executeEips(); @@ -126,6 +141,11 @@ public class UpdateReadmeMojo extends AbstractMojo { componentName = asComponentName(componentName); File file = new File(docDir, componentName + "-component.adoc"); + boolean exists = file.exists(); + if (!exists) { + file = new File(componentDocDirCore, componentName + "-component.adoc"); + exists = file.exists(); + } ComponentModel model = generateComponentModel(json); String title = asComponentTitle(model.getScheme(), model.getTitle()); @@ -139,22 +159,22 @@ public class UpdateReadmeMojo extends AbstractMojo { } } - String docTitle = model.getTitle() + " Component"; - boolean deprecated = "true".equals(model.getDeprecated()); - if (deprecated) { - docTitle += " (deprecated)"; - } +// String docTitle = model.getTitle() + " Component"; +// boolean deprecated = "true".equals(model.getDeprecated()); +// if (deprecated) { +// docTitle += " (deprecated)"; +// } - boolean exists = file.exists(); - boolean updated; - updated = updateLink(file, componentName + "-component"); - updated |= updateTitles(file, docTitle); - updated |= updateAvailableFrom(file, model.getFirstVersion()); + boolean updated = updateHeader(componentName, file, model, " Component", "-component"); + checkSince(file, model); +// updated = updateLink(file, componentName + "-component"); +// updated |= updateTitles(file, docTitle); +// updated |= updateAvailableFrom(file, model.getFirstVersion()); // resolvePropertyPlaceholders is an option which only make sense to use if the component has other options - boolean hasOptions = model.getComponentOptions().stream().anyMatch(o -> !o.getName().equals("resolvePropertyPlaceholders")); + boolean hasOptions = model.getOptions().stream().anyMatch(o -> !o.getName().equals("resolvePropertyPlaceholders")); if (!hasOptions) { - model.getComponentOptions().clear(); + model.getOptions().clear(); } String options = evaluateTemplate("component-options.mvel", model); @@ -178,6 +198,48 @@ public class UpdateReadmeMojo extends AbstractMojo { } } + private void executeOther() throws MojoExecutionException { + final Set<File> jsonFiles = new TreeSet<>(); + PackageHelper.findJsonFiles(buildDir, jsonFiles, new PackageHelper.CamelOthersModelFilter()); + + if (!jsonFiles.isEmpty()) { + getLog().debug("Found " + jsonFiles.size() + "miscellaneous components"); + for (File jsonFile : jsonFiles) { + String json = loadJsonFrom(jsonFile, "other"); + if (json != null) { + OtherModel model = generateOtherModel(json); + String title = model.getTitle(); + model.setTitle(title); + + String componentName = asComponentName(model.getName()); + + File file = new File(docDir, componentName + ".adoc"); + boolean exists = file.exists(); + if (!exists) { + file = new File(othersDocDirCore, componentName + ".adoc"); + exists = file.exists(); + } + + + // we only want the first scheme as the alternatives do not + boolean updated = updateHeader(componentName, file, model, " Component", "-component"); + checkSince(file, model); + + if (updated) { + getLog().info("Updated doc file: " + file); + } else if (exists) { + getLog().debug("No changes to doc file: " + file); + } else { + getLog().warn("No component doc file: " + file); + if (isFailFast()) { + throw new MojoExecutionException("Failed build due failFast=true"); + } + } + } + } + } + } + private void executeDataFormat() throws MojoExecutionException { // find the dataformat names List<String> dataFormatNames = listDescriptorNamesOfType("dataformat"); @@ -195,22 +257,27 @@ public class UpdateReadmeMojo extends AbstractMojo { dataFormatName = asDataFormatName(dataFormatName); File file = new File(docDir, dataFormatName + "-dataformat.adoc"); + boolean exists = file.exists(); + if (!exists) { + file = new File(dataformatsDocDirCore, dataFormatName + "-dataformat.adoc"); + exists = file.exists(); + } 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)"; - } +// String docTitle = model.getTitle() + " DataFormat"; +// boolean deprecated = "true".equals(model.getDeprecated()); +// if (deprecated) { +// docTitle += " (deprecated)"; +// } - boolean exists = file.exists(); - boolean updated; - updated = updateLink(file, dataFormatName + "-dataformat"); - updated |= updateTitles(file, docTitle); - updated |= updateAvailableFrom(file, model.getFirstVersion()); + boolean updated = updateHeader(dataFormatName, file, model, " DataFormat", "-dataformat"); + checkSince(file, model); +// updated = updateLink(file, dataFormatName + "-dataformat"); +// updated |= updateTitles(file, docTitle); +// updated |= updateAvailableFrom(file, model.getFirstVersion()); String options = evaluateTemplate("dataformat-options.mvel", model); updated |= updateOptionsIn(file, "dataformat", options); @@ -253,20 +320,27 @@ public class UpdateReadmeMojo extends AbstractMojo { String json = loadJsonFrom(jsonFiles, "language", languageName); if (json != null) { File file = new File(docDir, languageName + "-language.adoc"); + boolean exists = file.exists(); + if (!exists) { + file = new File(languagesDocDirCore, languageName + "-language.adoc"); + exists = file.exists(); + } LanguageModel model = generateLanguageModel(json); - String docTitle = model.getTitle() + " Language"; - boolean deprecated = "true".equals(model.getDeprecated()); - if (deprecated) { - docTitle += " (deprecated)"; - } +// String docTitle = model.getTitle() + " Language"; +// boolean deprecated = "true".equals(model.getDeprecated()); +// if (deprecated) { +// docTitle += " (deprecated)"; +// } - boolean exists = file.exists(); - boolean updated; - updated = updateLink(file, languageName + "-language"); - updated |= updateTitles(file, docTitle); - updated |= updateAvailableFrom(file, model.getFirstVersion()); + String titleSuffix = " Language"; + String linkSuffix = "-language"; + boolean updated = updateHeader(languageName, file, model, titleSuffix, linkSuffix); + checkSince(file, model); +// updated = updateLink(file, languageName + "-language"); +// updated |= updateTitles(file, docTitle); +// updated |= updateAvailableFrom(file, model.getFirstVersion()); String options = evaluateTemplate("language-options.mvel", model); updated |= updateOptionsIn(file, "language", options); @@ -302,11 +376,11 @@ public class UpdateReadmeMojo extends AbstractMojo { PackageHelper.findJsonFiles(target, jsonFiles, new PackageHelper.CamelComponentsModelFilter()); } - // only if there is dataformat we should update the documentation files + // only if there is eip we should update the documentation files if (!jsonFiles.isEmpty()) { getLog().debug("Found " + jsonFiles.size() + " eips"); for (File jsonFile : jsonFiles) { - String json = loadEipJson(jsonFile); + String json = loadJsonFrom(jsonFile, "model"); if (json != null) { EipModel model = generateEipModel(json); String title = model.getTitle(); @@ -321,16 +395,16 @@ public class UpdateReadmeMojo extends AbstractMojo { File file = new File(eipDocDir, eipName + "-eip.adoc"); - String docTitle = model.getTitle() + " EIP"; - boolean deprecated = model.isDeprecated(); - if (deprecated) { - docTitle += " (deprecated)"; - } +// String docTitle = model.getTitle() + " EIP"; +// boolean deprecated = model.isDeprecated(); +// if (deprecated) { +// docTitle += " (deprecated)"; +// } boolean exists = file.exists(); - boolean updated; - updated = updateLink(file, eipName + "-eip"); - updated |= updateTitles(file, docTitle); + boolean updated = updateHeader(eipName, file, model, " EIP", "-eip"); +// updated = updateLink(file, eipName + "-eip"); +// updated |= updateTitles(file, docTitle); String options = evaluateTemplate("eip-options.mvel", model); updated |= updateOptionsIn(file, "eip", options); @@ -377,104 +451,85 @@ public class UpdateReadmeMojo extends AbstractMojo { return title; } - private static boolean updateLink(File file, String link) throws MojoExecutionException { - if (!file.exists()) { + private boolean updateHeader(String name, final File file, final BaseModel<?> model, String titleSuffix, String linkSuffix) throws MojoExecutionException { + getLog().debug("updateHeader " + file); + + if (model == null || !file.exists()) { return false; } boolean updated = false; - try (InputStream fileStream = new FileInputStream(file)) { - List<String> newLines = new ArrayList<>(); - String text = loadText(fileStream); + String[] lines = text.split("\n"); - for (int i = 0; i < lines.length; i++) { - String line = lines[i]; - if (i == 0) { - // first line is the link - String newLine = "[[" + link + "]]"; - newLines.add(newLine); - updated = !line.equals(newLine); - if (updated) { - // its some old text so keep it - newLines.add(line); - } - } else { - newLines.add(line); - } + // check first if it is a standard documentation file, we expect at + // least five lines + if (lines.length < 5) { + return false; } - if (updated) { - // build the new updated text - String newText = newLines.stream().collect(Collectors.joining("\n")); - writeText(file, newText); - } - } catch (Exception e) { - throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); - } - - return updated; - } + List<String> newLines = new ArrayList<>(lines.length + 8); - private static boolean updateTitles(File file, String title) throws MojoExecutionException { - if (!file.exists()) { - return false; - } + //link + newLines.add("[[" + name + linkSuffix + "]]"); - boolean updated = false; - - try (InputStream fileStream = new FileInputStream(file)) { - List<String> newLines = new ArrayList<>(); + //title + String title = model.getTitle() + titleSuffix; + if (model.isDeprecated()) { + title += " (deprecated)"; + } + newLines.add("= " + title); + newLines.add(":docTitle: " + model.getTitle()); - String text = loadText(fileStream); - String[] lines = text.split("\n"); - // line 0 is the link - for (int i = 1; i < lines.length; i++) { - String line = lines[i]; - - if (i == 1) { - // first line is the title to make the text less noisy we use level 2 - String newLine = "= " + title; - newLines.add(newLine); - updated = !line.equals(newLine); - continue; + if (model instanceof ArtifactModel<?>) { + newLines.add(":artifactId: " + ((ArtifactModel<?>)model).getArtifactId()); + } + newLines.add(":description: " + model.getDescription()); + newLines.add(":since: " + model.getFirstVersionShort()); + //TODO put the deprecation into the actual support level. +// newLines.add(":supportLevel: " + model.getSupportLevel().toString() + (model.isDeprecated() ? "-deprecated" : "")); + if (model.isDeprecated()) { + newLines.add(":deprecated: *deprecated*"); + } + if (model instanceof ComponentModel) { + newLines.add(":component-header: " + generateComponentHeader((ComponentModel)model)); + if (Arrays.asList(model.getLabel().split(",")).contains("core")) { + newLines.add(":core:"); } + } - // use single line headers with # as level instead of the cumbersome adoc weird style - if (line.startsWith("^^^") || line.startsWith("~~~") || line.startsWith("+++")) { - String level = line.startsWith("+++") ? "===" : "=="; - - // transform legacy heading into new style - int idx = newLines.size() - 1; - String prev = newLines.get(idx); - - newLines.set(idx, level + " " + prev); - - // okay if 2nd-prev line is a [[title]] we need to remove that too - // so we have nice clean sub titles - idx = newLines.size() - 2; - if (idx >= 0) { - prev = newLines.get(idx); - if (prev.startsWith("[[")) { - // remove - newLines.remove(idx); - } - } + newLines.add(""); + for (int i = 0; i < lines.length; i++) { + if (i == newLines.size() || newLines.get(i) != lines[i]) { updated = true; - } else { - // okay normal text so just add it - newLines.add(line); + break; } } + boolean copy = false; + if (updated) { + for (int i = 0; i < lines.length; i++) { + if (!copy && lines[i].isEmpty()) { + copy = true; + } else if (copy) { + newLines.add(lines[i]); + } + } + } + if (!copy) { + throw new MojoFailureException("File " + file + " has unexpected structure with no empty line."); + } if (updated) { // build the new updated text - String newText = newLines.stream().collect(Collectors.joining("\n")); - writeText(file, newText); + if (!newLines.get(newLines.size() - 1).isEmpty()) { + newLines.add(""); + } + String newText = String.join("\n", newLines); + PackageHelper.writeText(file, newText); } } catch (Exception e) { throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); @@ -483,63 +538,226 @@ public class UpdateReadmeMojo extends AbstractMojo { return updated; } - private static boolean updateAvailableFrom(final File file, final String firstVersion) throws MojoExecutionException { - if (firstVersion == null || !file.exists()) { - return false; - } - - String version = firstVersion; - // cut last digit so its not 2.18.0 but 2.18 - String[] parts = firstVersion.split("\\."); - if (parts.length == 3 && parts[2].equals("0")) { - version = parts[0] + "." + parts[1]; +// private static boolean updateLink(File file, String link) throws MojoExecutionException { +// if (!file.exists()) { +// return false; +// } +// +// boolean updated = false; +// +// try (InputStream fileStream = new FileInputStream(file)) { +// List<String> newLines = new ArrayList<>(); +// +// String text = loadText(fileStream); +// String[] lines = text.split("\n"); +// for (int i = 0; i < lines.length; i++) { +// String line = lines[i]; +// +// if (i == 0) { +// // first line is the link +// String newLine = "[[" + link + "]]"; +// newLines.add(newLine); +// updated = !line.equals(newLine); +// if (updated) { +// // its some old text so keep it +// newLines.add(line); +// } +// } else { +// newLines.add(line); +// } +// } +// +// if (updated) { +// // build the new updated text +// String newText = newLines.stream().collect(Collectors.joining("\n")); +// writeText(file, newText); +// } +// } catch (Exception e) { +// throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); +// } +// +// return updated; +// } +// +// private static boolean updateTitles(File file, String title) throws MojoExecutionException { +// if (!file.exists()) { +// return false; +// } +// +// boolean updated = false; +// +// try (InputStream fileStream = new FileInputStream(file)) { +// List<String> newLines = new ArrayList<>(); +// +// String text = loadText(fileStream); +// String[] lines = text.split("\n"); +// // line 0 is the link +// for (int i = 1; i < lines.length; i++) { +// String line = lines[i]; +// +// if (i == 1) { +// // first line is the title to make the text less noisy we use level 2 +// String newLine = "= " + title; +// newLines.add(newLine); +// updated = !line.equals(newLine); +// continue; +// } +// +// // use single line headers with # as level instead of the cumbersome adoc weird style +// if (line.startsWith("^^^") || line.startsWith("~~~") || line.startsWith("+++")) { +// String level = line.startsWith("+++") ? "===" : "=="; +// +// // transform legacy heading into new style +// int idx = newLines.size() - 1; +// String prev = newLines.get(idx); +// +// newLines.set(idx, level + " " + prev); +// +// // okay if 2nd-prev line is a [[title]] we need to remove that too +// // so we have nice clean sub titles +// idx = newLines.size() - 2; +// if (idx >= 0) { +// prev = newLines.get(idx); +// if (prev.startsWith("[[")) { +// // remove +// newLines.remove(idx); +// } +// } +// +// updated = true; +// } else { +// // okay normal text so just add it +// newLines.add(line); +// } +// } +// +// +// if (updated) { +// // build the new updated text +// String newText = newLines.stream().collect(Collectors.joining("\n")); +// writeText(file, newText); +// } +// } catch (Exception e) { +// throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); +// } +// +// return updated; +// } +// +// private static boolean updateAvailableFrom(final File file, final String firstVersion) throws MojoExecutionException { +// if (firstVersion == null || !file.exists()) { +// return false; +// } +// +// String version = firstVersion; +// // cut last digit so its not 2.18.0 but 2.18 +// String[] parts = firstVersion.split("\\."); +// if (parts.length == 3 && parts[2].equals("0")) { +// version = parts[0] + "." + parts[1]; +// } +// +// boolean updated = false; +// +// try (InputStream fileStream = new FileInputStream(file)) { +// String text = loadText(fileStream); +// +// String[] lines = text.split("\n"); +// +// List<String> newLines = new ArrayList<>(); +// +// // copy over to all new lines +// newLines.addAll(Arrays.asList(lines)); +// +// // check the first four lines +// boolean title = lines[1].startsWith("#") || lines[1].startsWith("="); +// boolean empty = lines[2].trim().isEmpty(); +// boolean availableFrom = lines[3].trim().contains("Available as of") || lines[3].trim().contains("Available in"); +// boolean empty2 = lines[4].trim().isEmpty(); +// +// if (title && empty && availableFrom) { +// String newLine = "*Available as of Camel version " + version + "*"; +// if (!newLine.equals(lines[3])) { +// newLines.set(3, newLine); +// updated = true; +// } +// if (!empty2) { +// newLines.add(4, ""); +// updated = true; +// } +// } else if (!availableFrom) { +// String newLine = "*Available as of Camel version " + version + "*"; +// newLines.add(3, newLine); +// newLines.add(4, ""); +// updated = true; +// } +// +// if (updated) { +// // build the new updated text +// String newText = newLines.stream().collect(Collectors.joining("\n")); +// writeText(file, newText); +// } +// } catch (Exception e) { +// throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); +// } +// +// return updated; +// } + + private void checkSince(final File file, final ArtifactModel<?> model) throws MojoExecutionException { + if (!file.exists()) { + return; } - boolean updated = false; + final String sinceText = "*Since Camel {since}*"; + String loadedText; try (InputStream fileStream = new FileInputStream(file)) { - String text = loadText(fileStream); - - String[] lines = text.split("\n"); - - List<String> newLines = new ArrayList<>(); - - // copy over to all new lines - newLines.addAll(Arrays.asList(lines)); + loadedText = loadText(fileStream); + //change '*Available as of Camel' to since text + String[] lines = loadedText.split("\n"); - // check the first four lines - boolean title = lines[1].startsWith("#") || lines[1].startsWith("="); - boolean empty = lines[2].trim().isEmpty(); - boolean availableFrom = lines[3].trim().contains("Available as of") || lines[3].trim().contains("Available in"); - boolean empty2 = lines[4].trim().isEmpty(); - - if (title && empty && availableFrom) { - String newLine = "*Available as of Camel version " + version + "*"; - if (!newLine.equals(lines[3])) { - newLines.set(3, newLine); - updated = true; - } - if (!empty2) { - newLines.add(4, ""); - updated = true; - } - } else if (!availableFrom) { - String newLine = "*Available as of Camel version " + version + "*"; - newLines.add(3, newLine); - newLines.add(4, ""); + List<String> newLines = new ArrayList<>(lines.length + 1); + boolean updated = false; + for (String line: lines) { + if (line.startsWith("*Available as of Camel")) { + line = sinceText; updated = true; } + newLines.add(line); + } - if (updated) { - // build the new updated text - String newText = newLines.stream().collect(Collectors.joining("\n")); - writeText(file, newText); + + if (updated) { + // build the new updated text + if (!newLines.get(newLines.size() - 1).isEmpty()) { + newLines.add(""); } + String newText = String.join("\n", newLines); + PackageHelper.writeText(file, newText); + } + //end update code } catch (Exception e) { throw new MojoExecutionException("Error reading file " + file + " Reason: " + e, e); } + //TODO uncomment!! +// if (!loadedText.contains(sinceText)) { +// throw new MojoExecutionException("File " + file + " does not contain required string '" + sinceText + "'"); +// } + } + + private static String generateComponentHeader(final ComponentModel model) { + final boolean consumerOnly = model.isConsumerOnly(); + final boolean producerOnly = model.isProducerOnly(); + // if we have only producer support + if (!consumerOnly && producerOnly) { + return "Only producer is supported"; + } + // if we have only consumer support + if (consumerOnly && !producerOnly) { + return "Only consumer is supported"; + } - return updated; + return "Both producer and consumer are supported"; } private boolean updateOptionsIn(final File file, final String kind, final String changed) throws MojoExecutionException { @@ -597,10 +815,10 @@ public class UpdateReadmeMojo extends AbstractMojo { return null; } - private static String loadEipJson(File file) { + private static String loadJsonFrom(File file, String kind) { try (InputStream fileStream = new FileInputStream(file)) { String json = loadText(fileStream); - boolean isEip = json.contains("\"kind\": \"model\""); + boolean isEip = json.contains("\"kind\": \"" + kind + "\""); if (isEip) { return json; } @@ -667,7 +885,7 @@ public class UpdateReadmeMojo extends AbstractMojo { option.setDescription(desc); } } - component.addComponentOption(option); + component.addOption(option); // group separate between different options if (oldGroup == null || !oldGroup.equals(option.getGroup())) { @@ -731,6 +949,122 @@ public class UpdateReadmeMojo extends AbstractMojo { return component; } + private OtherModel generateOtherModel(String json) { + List<Map<String, String>> rows = parseJsonSchema("other", json, false); + + OtherModel component = new OtherModel(); + component.setName(getSafeValue("name", rows)); + component.setTitle(getSafeValue("title", rows)); + component.setDescription(getSafeValue("description", rows)); + component.setFirstVersion(getSafeValue("firstVersion", rows)); + component.setLabel(getSafeValue("label", rows)); + component.setDeprecated(getSafeValue("deprecated", rows)); + component.setDeprecationNote(getSafeValue("deprecationNote", rows)); + component.setJavaType(getSafeValue("javaType", rows)); + component.setGroupId(getSafeValue("groupId", rows)); + component.setArtifactId(getSafeValue("artifactId", rows)); + component.setVersion(getSafeValue("version", rows)); + + String oldGroup = null; + rows = parseJsonSchema("componentProperties", json, true); + for (Map<String, String> row : rows) { + OtherOptionModel option = new OtherOptionModel(); + option.setName(getSafeValue("name", row)); + option.setDisplayName(getSafeValue("displayName", row)); + option.setKind(getSafeValue("kind", row)); + option.setGroup(getSafeValue("group", row)); + option.setRequired(getSafeValue("required", row)); + option.setType(getSafeValue("type", row)); + option.setJavaType(getSafeValue("javaType", row)); + option.setEnums(getSafeValue("enum", row)); + option.setDeprecated(getSafeValue("deprecated", row)); + option.setDeprecationNote(getSafeValue("deprecationNote", row)); + option.setSecret(getSafeValue("secret", row)); + option.setDefaultValue(getSafeValue("defaultValue", row)); + option.setDescription(getSafeValue("description", row)); + // lets put required in the description + if ("true".equals(option.getRequired())) { + String desc = "*Required* " + option.getDescription(); + option.setDescription(desc); + } + // is the option deprecated then include that as well in the description + if ("true".equals(option.getDeprecated())) { + String desc = "*Deprecated* " + option.getDescription(); + option.setDescription(desc); + if (!StringHelper.isEmpty(option.getDeprecationNote())) { + desc = option.getDescription(); + if (!desc.endsWith(".")) { + desc = desc + ". Deprecation note: " + option.getDeprecationNote(); + } else { + desc = desc + " Deprecation note: " + option.getDeprecationNote(); + } + option.setDescription(desc); + } + } + component.addOption(option); + + // group separate between different options + if (oldGroup == null || !oldGroup.equals(option.getGroup())) { + option.setNewGroup(true); + } + oldGroup = option.getGroup(); + } + +// oldGroup = null; +// rows = parseJsonSchema("properties", json, true); +// for (Map<String, String> row : rows) { +// EndpointOptionModel option = new EndpointOptionModel(); +// option.setName(getSafeValue("name", row)); +// option.setDisplayName(getSafeValue("displayName", row)); +// option.setKind(getSafeValue("kind", row)); +// option.setGroup(getSafeValue("group", row)); +// option.setRequired(getSafeValue("required", row)); +// option.setType(getSafeValue("type", row)); +// option.setJavaType(getSafeValue("javaType", row)); +// option.setEnums(getSafeValue("enum", row)); +// option.setPrefix(getSafeValue("prefix", row)); +// option.setMultiValue(getSafeValue("multiValue", row)); +// option.setDeprecated(getSafeValue("deprecated", row)); +// option.setDeprecationNote(getSafeValue("deprecationNote", row)); +// option.setSecret(getSafeValue("secret", row)); +// option.setDefaultValue(getSafeValue("defaultValue", row)); +// option.setDescription(getSafeValue("description", row)); +// // lets put required in the description +// if ("true".equals(option.getRequired())) { +// String desc = "*Required* " + option.getDescription(); +// option.setDescription(desc); +// } +// // is the option deprecated then include that as well in the description +// if ("true".equals(option.getDeprecated())) { +// String desc = "*Deprecated* " + option.getDescription(); +// option.setDescription(desc); +// if (!StringHelper.isEmpty(option.getDeprecationNote())) { +// desc = option.getDescription(); +// if (!desc.endsWith(".")) { +// desc = desc + ". Deprecation note: " + option.getDeprecationNote(); +// } else { +// desc = desc + " Deprecation note: " + option.getDeprecationNote(); +// } +// option.setDescription(desc); +// } +// } +// // separate the options in path vs parameter so we can generate two different tables +// if ("path".equals(option.getKind())) { +// component.addOption(option); +// } else { +// component.addEndpointOption(option); +// } +// +// // group separate between different options +// if (oldGroup == null || !oldGroup.equals(option.getGroup())) { +// option.setNewGroup(true); +// } +// oldGroup = option.getGroup(); +// } + + return component; + } + private DataFormatModel generateDataFormatModel(String dataFormatName, String json) { List<Map<String, String>> rows = parseJsonSchema("dataformat", json, false); @@ -788,7 +1122,7 @@ public class UpdateReadmeMojo extends AbstractMojo { if ("id".equals(option.getName())) { getLog().debug("Skipping option: " + option.getName()); } else { - dataFormat.addDataFormatOption(option); + dataFormat.addOption(option); } } @@ -845,7 +1179,7 @@ public class UpdateReadmeMojo extends AbstractMojo { if ("id".equals(option.getName()) || "expression".equals(option.getName())) { getLog().debug("Skipping option: " + option.getName()); } else { - language.addLanguageOption(option); + language.addOption(option); } } @@ -906,7 +1240,7 @@ public class UpdateReadmeMojo extends AbstractMojo { || "expression".equals(option.getName()) || "outputs".equals(option.getName())) { getLog().debug("Skipping option: " + option.getName()); } else { - eip.addEipOptionModel(option); + eip.addOption(option); } } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ArtifactModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ArtifactModel.java new file mode 100644 index 0000000..c834381 --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ArtifactModel.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.maven.packaging.model; + +/** + * A {@link BaseModel} with Maven coordinates. + * + * @param <O> the type of option mode. + */ +public abstract class ArtifactModel<O extends Object> extends BaseModel<O> { + + protected String groupId; + protected String artifactId; + protected String version; + + public String getGroupId() { + return groupId; + } + + public void setGroupId(String groupId) { + this.groupId = groupId; + } + + public String getArtifactId() { + return artifactId; + } + + public void setArtifactId(String artifactId) { + this.artifactId = artifactId; + } + + public String getVersion() { + return version; + } + + public void setVersion(String version) { + this.version = version; + } + +} diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/BaseModel.java similarity index 58% copy from tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java copy to tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/BaseModel.java index 8f1a0f1..fab22c6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/BaseModel.java @@ -1,4 +1,4 @@ -/** +/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. @@ -17,43 +17,28 @@ package org.apache.camel.maven.packaging.model; import java.util.ArrayList; +import java.util.Comparator; import java.util.List; -import org.apache.camel.maven.packaging.StringHelper; +public abstract class BaseModel<O extends Object> { -import static org.apache.camel.maven.packaging.StringHelper.cutLastZeroDigit; + protected String name; + protected String title; + protected String description; + protected String firstVersion; + protected String javaType; + protected String label; + protected boolean deprecated; + protected String deprecationNote; + protected final List<O> options = new ArrayList<>(); +// protected SupportLevel supportLevel; + protected boolean nativeSupported; -public class OtherModel { - - private String kind; - private String name; - private String title; - private String description; - private String firstVersion; - private String label; - private String deprecated; - private String deprecationNote; - private String groupId; - private String artifactId; - private String version; - private String javaType; - private final List<OtherOptionModel> options = new ArrayList<>(); - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getKind() { - return kind; + public static Comparator<BaseModel<?>> compareTitle() { + return (m1, m2) -> m1.getTitle().compareToIgnoreCase(m2.getTitle()); } - public void setKind(String kind) { - this.kind = kind; - } + public abstract String getKind(); public String getName() { return name; @@ -95,11 +80,11 @@ public class OtherModel { this.label = label; } - public String getDeprecated() { + public boolean isDeprecated() { return deprecated; } - public void setDeprecated(String deprecated) { + public void setDeprecated(boolean deprecated) { this.deprecated = deprecated; } @@ -111,47 +96,51 @@ public class OtherModel { this.deprecationNote = deprecationNote; } - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; + public String getJavaType() { + return javaType; } - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; + public void setJavaType(String javaType) { + this.javaType = javaType; } - public String getVersion() { - return version; + public List<O> getOptions() { + return options; } - public void setVersion(String version) { - this.version = version; + public void addOption(O option) { + options.add(option); } - public String getDocLink() { - return artifactId + "/src/main/docs"; + public String getShortJavaType() { + return Strings.getClassShortName(javaType); } public String getFirstVersionShort() { - return cutLastZeroDigit(firstVersion); + return !Strings.isNullOrEmpty(firstVersion) ? Strings.cutLastZeroDigit(firstVersion) : ""; } - public List<OtherOptionModel> getOptions() { - return options; - } +// public SupportLevel getSupportLevel() { +// return supportLevel; +// } +// +// public void setSupportLevel(SupportLevel supportLevel) { +// this.supportLevel = supportLevel; +// } - public void addOptionModel(OtherOptionModel option) { - options.add(option); + /** + * @return {@code true} if the part represented by this model supports compilation to native code; {@code false} + * otherwise + */ + public boolean isNativeSupported() { + return nativeSupported; } - public String getShortJavaType() { - return StringHelper.getClassShortName(javaType); + /** + * @param nativeSupported see {@link #isNativeSupported()} + */ + public void setNativeSupported(boolean nativeSupported) { + this.nativeSupported = nativeSupported; } + } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java index d3e5a8d..921d1f6 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/ComponentModel.java @@ -23,7 +23,7 @@ import org.apache.camel.maven.packaging.StringHelper; import static org.apache.camel.maven.packaging.StringHelper.cutLastZeroDigit; -public class ComponentModel { +public class ComponentModel extends ArtifactModel<ComponentOptionModel> { private final boolean coreOnly; @@ -32,19 +32,9 @@ public class ComponentModel { private String syntax; private String alternativeSyntax; private String alternativeSchemes; - private String title; - private String description; - private String firstVersion; - private String label; - private String deprecated; - private String deprecationNote; - private String consumerOnly; - private String producerOnly; - private String javaType; - private String groupId; - private String artifactId; - private String version; - private final List<ComponentOptionModel> componentOptions = new ArrayList<>(); + private boolean consumerOnly; + private boolean producerOnly; +// private final List<ComponentOptionModel> componentOptions = new ArrayList<>(); private final List<EndpointOptionModel> endpointPathOptions = new ArrayList<>(); private final List<EndpointOptionModel> endpointOptions = new ArrayList<>(); @@ -92,108 +82,36 @@ public class ComponentModel { this.alternativeSchemes = alternativeSchemes; } - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getFirstVersion() { - return firstVersion; - } - - public void setFirstVersion(String firstVersion) { - this.firstVersion = firstVersion; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getDeprecated() { - return deprecated; - } +// public String getDeprecated() { +// return deprecated; +// } public void setDeprecated(String deprecated) { - this.deprecated = deprecated; + setDeprecated("true".equalsIgnoreCase(deprecated)); } - public String getDeprecationNote() { - return deprecationNote; - } - - public void setDeprecationNote(String deprecationNote) { - this.deprecationNote = deprecationNote; - } - - public String getConsumerOnly() { + public boolean isConsumerOnly() { return consumerOnly; } public void setConsumerOnly(String consumerOnly) { - this.consumerOnly = consumerOnly; + this.consumerOnly = "true".equals(consumerOnly); } - public String getProducerOnly() { + public boolean isProducerOnly() { return producerOnly; } public void setProducerOnly(String producerOnly) { - this.producerOnly = producerOnly; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; + this.producerOnly = "true".equalsIgnoreCase(producerOnly); } public List<ComponentOptionModel> getComponentOptions() { - return componentOptions; + return super.getOptions(); } public void addComponentOption(ComponentOptionModel option) { - componentOptions.add(option); + super.addOption(option); } public List<EndpointOptionModel> getEndpointOptions() { @@ -212,10 +130,6 @@ public class ComponentModel { endpointPathOptions.add(option); } - public String getShortJavaType() { - return StringHelper.getClassShortName(javaType); - } - public String getDocLink() { // special for these components if ("camel-as2".equals(artifactId)) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/DataFormatModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/DataFormatModel.java index babf9cd..ae3e9c2 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/DataFormatModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/DataFormatModel.java @@ -19,28 +19,15 @@ package org.apache.camel.maven.packaging.model; import java.util.ArrayList; import java.util.List; -import org.apache.camel.maven.packaging.StringHelper; - import static org.apache.camel.maven.packaging.StringHelper.cutLastZeroDigit; -public class DataFormatModel { +public class DataFormatModel extends ArtifactModel<DataFormatOptionModel> { private final boolean coreOnly; private String kind; - private String name; private String modelName; - private String title; - private String description; - private String firstVersion; - private String label; - private String deprecated; - private String deprecationNote; - private String javaType; - private String groupId; - private String artifactId; - private String version; - private final List<DataFormatOptionModel> dataFormatOptions = new ArrayList<>(); +// private final List<DataFormatOptionModel> dataFormatOptions = new ArrayList<>(); public DataFormatModel() { this(false); @@ -58,14 +45,6 @@ public class DataFormatModel { this.kind = kind; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getModelName() { return modelName; } @@ -74,98 +53,18 @@ public class DataFormatModel { this.modelName = modelName; } - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getFirstVersion() { - return firstVersion; - } - - public void setFirstVersion(String firstVersion) { - this.firstVersion = firstVersion; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getDeprecated() { - return deprecated; - } - public void setDeprecated(String deprecated) { - this.deprecated = deprecated; - } - - public String getDeprecationNote() { - return deprecationNote; - } - - public void setDeprecationNote(String deprecationNote) { - this.deprecationNote = deprecationNote; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public List<DataFormatOptionModel> getDataFormatOptions() { - return dataFormatOptions; - } - - public void addDataFormatOption(DataFormatOptionModel option) { - dataFormatOptions.add(option); - } - - public String getShortJavaType() { - return StringHelper.getClassShortName(javaType); + setDeprecated("true".equals(deprecated)); } +// public List<DataFormatOptionModel> getDataFormatOptions() { +// return dataFormatOptions; +// } +// +// public void addDataFormatOption(DataFormatOptionModel option) { +// dataFormatOptions.add(option); +// } +// public String getDocLink() { // special for these components if ("camel-fhir".equals(artifactId)) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EipModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EipModel.java index 970288b..c36ad46 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EipModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/EipModel.java @@ -19,73 +19,15 @@ package org.apache.camel.maven.packaging.model; import java.util.ArrayList; import java.util.List; -public class EipModel { +public class EipModel extends BaseModel<EipOptionModel> { - private String name; - private String title; - private String javaType; - private String label; - private String description; - private boolean deprecated; - private String deprecationNote; private boolean input; private boolean output; - private final List<EipOptionModel> eipOptions = new ArrayList<>(); +// private final List<EipOptionModel> eipOptions = new ArrayList<>(); - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public boolean isDeprecated() { - return deprecated; - } - - public void setDeprecated(boolean deprecated) { - this.deprecated = deprecated; - } - - public String getDeprecationNote() { - return deprecationNote; - } - - public void setDeprecationNote(String deprecationNote) { - this.deprecationNote = deprecationNote; + @Override + public String getKind() { + return "model"; } public boolean isInput() { @@ -112,13 +54,13 @@ public class EipModel { return output ? "true" : "false"; } - public List<EipOptionModel> getEipOptions() { - return eipOptions; - } - - public void addEipOptionModel(EipOptionModel option) { - eipOptions.add(option); - } +// public List<EipOptionModel> getEipOptions() { +// return eipOptions; +// } +// +// public void addEipOptionModel(EipOptionModel option) { +// eipOptions.add(option); +// } public String getDocLink() { // lets store EIP docs in a sub-folder as we have many EIPs diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/LanguageModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/LanguageModel.java index 655df8e..c17b0c1 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/LanguageModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/LanguageModel.java @@ -23,24 +23,17 @@ import org.apache.camel.maven.packaging.StringHelper; import static org.apache.camel.maven.packaging.StringHelper.cutLastZeroDigit; -public class LanguageModel { +public class LanguageModel extends ArtifactModel<LanguageOptionModel> { private final boolean coreOnly; private String kind; - private String name; private String modelName; private String title; private String description; private String firstVersion; private String label; - private String deprecated; - private String deprecationNote; - private String javaType; - private String groupId; - private String artifactId; - private String version; - private final List<LanguageOptionModel> languageOptions = new ArrayList<>(); +// private final List<LanguageOptionModel> languageOptions = new ArrayList<>(); public LanguageModel() { this(false); @@ -58,14 +51,6 @@ public class LanguageModel { this.kind = kind; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - public String getModelName() { return modelName; } @@ -106,65 +91,17 @@ public class LanguageModel { this.label = label; } - public String getDeprecated() { - return deprecated; - } - public void setDeprecated(String deprecated) { - this.deprecated = deprecated; - } - - public String getDeprecationNote() { - return deprecationNote; - } - - public void setDeprecationNote(String deprecationNote) { - this.deprecationNote = deprecationNote; - } - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } - - public String getGroupId() { - return groupId; + setDeprecated("true".equals(deprecated)); } - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; - } - - public List<LanguageOptionModel> getLanguageOptions() { - return languageOptions; - } - - public void addLanguageOption(LanguageOptionModel option) { - languageOptions.add(option); - } - - public String getShortJavaType() { - return StringHelper.getClassShortName(javaType); - } +// public List<LanguageOptionModel> getLanguageOptions() { +// return languageOptions; +// } +// +// public void addLanguageOption(LanguageOptionModel option) { +// languageOptions.add(option); +// } public String getDocLink() { if ("camel-core".equals(artifactId)) { diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java index 8f1a0f1..deb637d 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/OtherModel.java @@ -23,29 +23,9 @@ import org.apache.camel.maven.packaging.StringHelper; import static org.apache.camel.maven.packaging.StringHelper.cutLastZeroDigit; -public class OtherModel { +public class OtherModel extends ArtifactModel<OtherOptionModel> { private String kind; - private String name; - private String title; - private String description; - private String firstVersion; - private String label; - private String deprecated; - private String deprecationNote; - private String groupId; - private String artifactId; - private String version; - private String javaType; - private final List<OtherOptionModel> options = new ArrayList<>(); - - public String getJavaType() { - return javaType; - } - - public void setJavaType(String javaType) { - this.javaType = javaType; - } public String getKind() { return kind; @@ -55,103 +35,12 @@ public class OtherModel { this.kind = kind; } - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getTitle() { - return title; - } - - public void setTitle(String title) { - this.title = title; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String getFirstVersion() { - return firstVersion; - } - - public void setFirstVersion(String firstVersion) { - this.firstVersion = firstVersion; - } - - public String getLabel() { - return label; - } - - public void setLabel(String label) { - this.label = label; - } - - public String getDeprecated() { - return deprecated; - } - public void setDeprecated(String deprecated) { - this.deprecated = deprecated; - } - - public String getDeprecationNote() { - return deprecationNote; - } - - public void setDeprecationNote(String deprecationNote) { - this.deprecationNote = deprecationNote; - } - - public String getGroupId() { - return groupId; - } - - public void setGroupId(String groupId) { - this.groupId = groupId; - } - - public String getArtifactId() { - return artifactId; - } - - public void setArtifactId(String artifactId) { - this.artifactId = artifactId; - } - - public String getVersion() { - return version; - } - - public void setVersion(String version) { - this.version = version; + setDeprecated("true".equals(deprecated)); } public String getDocLink() { return artifactId + "/src/main/docs"; } - public String getFirstVersionShort() { - return cutLastZeroDigit(firstVersion); - } - - public List<OtherOptionModel> getOptions() { - return options; - } - - public void addOptionModel(OtherOptionModel option) { - options.add(option); - } - - public String getShortJavaType() { - return StringHelper.getClassShortName(javaType); - } } diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/Strings.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/Strings.java new file mode 100644 index 0000000..01dc96b --- /dev/null +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/model/Strings.java @@ -0,0 +1,170 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.maven.packaging.model; + +/** + * Some String helper methods + */ +public final class Strings { + + private Strings() { + //Helper class + } + + /** + * Returns true if the given text is null or empty string or has <tt>null</tt> as the value + */ + public static boolean isNullOrEmpty(String text) { + return text == null || text.length() == 0 || "null".equals(text); + } + + public static String cutLastZeroDigit(String version) { + String answer = version; + // cut last digit so its not 2.18.0 but 2.18 + String[] parts = version.split("\\."); + if (parts.length == 3 && parts[2].equals("0")) { + answer = parts[0] + "." + parts[1]; + } + return answer; + } + + /** + * To wrap long camel cased texts by words. + * + * @param option the option which is camel cased. + * @param watermark a watermark to denote the size to cut after + * @param lineSep the new line to use when breaking into a new line + */ + public static String wrapCamelCaseWords(String option, int watermark, String lineSep) { + String text = option.replaceAll("(?=[A-Z][a-z])", " "); + text = wrapWords(text, "", lineSep, watermark, false); + return Character.toUpperCase(text.charAt(0)) + text.substring(1); + } + + /** + * To wrap a big line by words. + * @param line the big line + * @param wordSep the word separator + * @param lineSep the new line to use when breaking into a new line + * @param watermark a watermark to denote the size to cut after + * @param wrapLongWords whether to wrap long words + */ + public static String wrapWords(String line, String wordSep, String lineSep, int watermark, boolean wrapLongWords) { + if (line == null) { + return null; + } else { + if (lineSep == null) { + lineSep = System.lineSeparator(); + } + if (wordSep == null) { + wordSep = ""; + } + + if (watermark < 1) { + watermark = 1; + } + + int inputLineLength = line.length(); + int offset = 0; + StringBuilder sb = new StringBuilder(inputLineLength + 32); + int currentLength = 0; + while (offset < inputLineLength) { + if (line.charAt(offset) == ' ') { + offset++; + continue; + } + int next = line.indexOf(' ', offset); + if (next < 0) { + next = inputLineLength; + if (wrapLongWords && inputLineLength - offset > watermark) { + if (currentLength > 0) { + sb.append(wordSep); + currentLength += wordSep.length(); + } + sb.append(line, offset, watermark - currentLength); + sb.append(lineSep); + offset += watermark - currentLength; + } + } + if (currentLength + (currentLength > 0 ? wordSep.length() : 0) + next - offset <= watermark) { + if (currentLength > 0) { + sb.append(wordSep); + currentLength += wordSep.length(); + } + sb.append(line, offset, next); + currentLength += next - offset; + offset = next + 1; + } else { + sb.append(lineSep); + sb.append(line, offset, next); + currentLength = next - offset; + offset = next + 1; + } + } + /* + while (inputLineLength - offset > watermark) { + if (line.charAt(offset) == ' ') { + ++offset; + } else { + int spaceToWrapAt = line.lastIndexOf(' ', watermark + offset); + int spaces = 0; + for (int i = offset; i < spaceToWrapAt; i++) { + spaces += line.charAt(i) == ' ' ? 1 : 0; + } + if (spaceToWrapAt >= offset) { + sb.append(line, offset, spaceToWrapAt); + sb.append(newLine); + offset = spaceToWrapAt + 1; + } else if (wrapLongWords) { + sb.append(line, offset, watermark + offset); + sb.append(newLine); + offset += watermark; + } else { + spaceToWrapAt = line.indexOf(' ', watermark + offset); + if (spaceToWrapAt >= 0) { + sb.append(line, offset, spaceToWrapAt); + sb.append(newLine); + offset = spaceToWrapAt + 1; + } else { + sb.append(line, offset, line.length()); + offset = inputLineLength; + } + } + } + } + + sb.append(line, offset, line.length()); + */ + return sb.toString(); + } + } + + /** + * Returns the base class name, i.e. without package and generic related + * information. + * + * @param className The class name which base class is to be computed. + * @return the base class name, i.e. without package and generic related + * information. + */ + public static String getClassShortName(String className) { + if (className != null) { + return className.replaceAll("<.*>", "").replaceAll(".*[.]([^.]+)", "$1"); + } + return className; + } +} diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/dataformat-options.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/dataformat-options.mvel index 5942392..650ae78 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/dataformat-options.mvel +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/dataformat-options.mvel @@ -1,13 +1,13 @@ -@if{dataFormatOptions.isEmpty()} +@if{options.isEmpty()} The @{title} dataformat has no options. @else{} -The @{title} dataformat supports @{dataFormatOptions.size()} options, which are listed below. +The @{title} dataformat supports @{options.size()} options, which are listed below. @end{} -@if{!dataFormatOptions.isEmpty()} +@if{!options.isEmpty()} [width="100%",cols="2s,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -@foreach{row : dataFormatOptions}| @{row.name} | @{row.defaultValue} | @{row.shortJavaType} | @{util.escape(row.description)} +@foreach{row : options}| @{row.name} | @{row.defaultValue} | @{row.shortJavaType} | @{util.escape(row.description)} @end{}|=== @end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/eip-options.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/eip-options.mvel index a11511a..2d32f79 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/eip-options.mvel +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/eip-options.mvel @@ -1,11 +1,11 @@ -@if{eipOptions.isEmpty()} +@if{options.isEmpty()} The @{title} EIP has no options. @else{} -The @{title} EIP supports @{eipOptions.size()} options which are listed below: +The @{title} EIP supports @{options.size()} options which are listed below: [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type -@foreach{row : eipOptions}| *@{row.getShortName(30)}* | @{util.escape(row.description)} | @{row.getShortDefaultValue(20)} | @{row.getShortJavaType(25)} +@foreach{row : options}| *@{row.getShortName(30)}* | @{util.escape(row.description)} | @{row.getShortDefaultValue(20)} | @{row.getShortJavaType(25)} @end{}|=== @end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/language-options.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/language-options.mvel index 498d338..52267f4 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/language-options.mvel +++ b/tooling/maven/camel-package-maven-plugin/src/main/resources/language-options.mvel @@ -1,13 +1,13 @@ -@if{languageOptions.isEmpty()} +@if{options.isEmpty()} The @{title} language has no options. @else{} -The @{title} language supports @{languageOptions.size()} options, which are listed below. +The @{title} language supports @{options.size()} options, which are listed below. @end{} -@if{!languageOptions.isEmpty()} +@if{!options.isEmpty()} [width="100%",cols="2,1m,1m,6",options="header"] |=== | Name | Default | Java Type | Description -@foreach{row : languageOptions}| @{row.name} | @{row.defaultValue} | @{row.shortJavaType} | @{util.escape(row.description)} +@foreach{row : options}| @{row.name} | @{row.defaultValue} | @{row.shortJavaType} | @{util.escape(row.description)} @end{}|=== @end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-components.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-components.mvel deleted file mode 100644 index 16d3573..0000000 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-components.mvel +++ /dev/null @@ -1,14 +0,0 @@ -@if{!components.isEmpty()} - -Number of Components: @{components.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) - -[width="100%",cols="4,1,5",options="header"] -|=== -| Component | Available From | Description -@foreach{row : components} -| link:@{row.docLink}/${row.scheme}-component.adoc[@{row.title}] (@{row.artifactId}) + -`@{row.syntax}` | @{row.firstVersionShort} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} -@end{} -|=== - -@end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel deleted file mode 100644 index 72d12c1..0000000 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-dataformats.mvel +++ /dev/null @@ -1,12 +0,0 @@ -@if{!dataformats.isEmpty()} - -Number of Data Formats: @{dataformats.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) - -[width="100%",cols="4,1,5",options="header"] -|=== -| Data Format | Available From | Description -@foreach{row : dataformats} -| link:@{row.docLink}/${row.name}-dataformat.adoc[@{row.title}] (@{row.artifactId}) | @{row.firstVersionShort} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} -@end{}|=== - -@end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-languages.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-languages.mvel deleted file mode 100644 index ba0e1ca..0000000 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-languages.mvel +++ /dev/null @@ -1,12 +0,0 @@ -@if{!languages.isEmpty()} - -Number of Languages: @{languages.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) - -[width="100%",cols="4,1,5",options="header"] -|=== -| Language | Available From | Description -@foreach{row : languages} -| link:@{row.docLink}/${row.name}-language.adoc[@{row.title}] (@{row.artifactId}) | @{row.firstVersionShort} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} -@end{}|=== - -@end{} \ No newline at end of file diff --git a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-others.mvel b/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-others.mvel deleted file mode 100644 index cbd06ce..0000000 --- a/tooling/maven/camel-package-maven-plugin/src/main/resources/readme-others.mvel +++ /dev/null @@ -1,12 +0,0 @@ -@if{!others.isEmpty()} - -Number of Miscellaneous Components: @{others.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) - -[width="100%",cols="4,1,5",options="header"] -|=== -| Component | Available From | Description -@foreach{row : others} -| link:@{row.docLink}/${row.name}.adoc[@{row.title}] (@{row.artifactId}) | @{row.firstVersionShort} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} -@end{}|=== - -@end{} \ No newline at end of file