This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-karaf.git
commit 4b9cc442e17f0670cd89e381b009ab064241147e Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Mar 23 14:04:07 2020 +0100 Added tooling for Karaf --- pom.xml | 3 +- tooling/camel-karaf-docs-maven-plugin/pom.xml | 204 +++++++ .../apache/camel/karaf/maven/ExtMvelHelper.java | 86 +++ .../karaf/maven/UpdateDocComponentsListMojo.java | 634 +++++++++++++++++++++ .../src/main/resources/META-INF/LICENSE.txt | 203 +++++++ .../src/main/resources/META-INF/NOTICE.txt | 11 + .../src/main/resources/readme-components.mvel | 14 + .../src/main/resources/readme-dataformats.mvel | 13 + .../src/main/resources/readme-languages.mvel | 13 + .../src/main/resources/readme-others.mvel | 13 + tooling/pom.xml | 92 +++ 11 files changed, 1285 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1b26b60..11c86c8 100644 --- a/pom.xml +++ b/pom.xml @@ -72,7 +72,7 @@ </prerequisites> <modules> - <!--<module>tooling</module>--> + <module>tooling</module> <module>core</module> <module>components</module> <module>catalog</module> @@ -143,6 +143,7 @@ <arquillian-container-se-managed-version>1.0.2.Final</arquillian-container-se-managed-version> <arquillian-version>1.6.0.Final</arquillian-version> <arquillian-weld-embedded-version>2.0.0.Final</arquillian-weld-embedded-version> + <asciidoctorj-version>2.1.0</asciidoctorj-version> <asm-version>5.0.4</asm-version> <aspectj-version>1.9.5</aspectj-version> <assertj-version>3.15.0</assertj-version> diff --git a/tooling/camel-karaf-docs-maven-plugin/pom.xml b/tooling/camel-karaf-docs-maven-plugin/pom.xml new file mode 100644 index 0000000..164416a --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/pom.xml @@ -0,0 +1,204 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>tooling</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + + <artifactId>camel-karaf-docs-maven-plugin</artifactId> + <packaging>jar</packaging> + <name>Camel Karaf Tooling :: Docs Maven Plugin</name> + + <properties> + <maven-version>3.6.3</maven-version> + </properties> + + <dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>tooling-parent</artifactId> + <version>${camel-version}</version> + <type>pom</type> + <scope>import</scope> + </dependency> + </dependencies> + </dependencyManagement> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-package-maven-plugin</artifactId> + <version>${camel-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-tooling-util</artifactId> + <version>${camel-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-tooling-model</artifactId> + <version>${camel-version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>bom-generator-maven-plugin</artifactId> + <version>${camel-version}</version> + </dependency> + + <dependency> + <groupId>jakarta.xml.bind</groupId> + <artifactId>jakarta.xml.bind-api</artifactId> + <version>${jakarta-jaxb-version}</version> + </dependency> + + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-util-json</artifactId> + <version>${camel-version}</version> + </dependency> + + <dependency> + <groupId>org.mvel</groupId> + <artifactId>mvel2</artifactId> + <version>${mvel-version}</version> + </dependency> + + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-core</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-artifact</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-plugin-api</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.plugin-tools</groupId> + <artifactId>maven-plugin-annotations</artifactId> + <version>3.6.0</version> + </dependency> + <dependency> + <groupId>org.apache.maven</groupId> + <artifactId>maven-compat</artifactId> + <version>${maven-version}</version> + </dependency> + <dependency> + <groupId>org.apache.maven.shared</groupId> + <artifactId>maven-dependency-tree</artifactId> + <version>3.0.1</version> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-container-default</artifactId> + </dependency> + <dependency> + <groupId>org.codehaus.plexus</groupId> + <artifactId>plexus-utils</artifactId> + </dependency> + <dependency> + <groupId>org.sonatype.plexus</groupId> + <artifactId>plexus-build-api</artifactId> + </dependency> + + <dependency> + <groupId>commons-io</groupId> + <artifactId>commons-io</artifactId> + </dependency> + + <dependency> + <groupId>com.google.code.gson</groupId> + <artifactId>gson</artifactId> + <version>${gson-version}</version> + </dependency> + + <!-- asciidoc to convert adoc to html files --> + <dependency> + <groupId>org.asciidoctor</groupId> + <artifactId>asciidoctorj</artifactId> + <version>${asciidoctorj-version}</version> + </dependency> + + <dependency> + <groupId>org.ow2.asm</groupId> + <artifactId>asm-tree</artifactId> + <version>7.0</version> + </dependency> + + <!-- logging --> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-api</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.logging.log4j</groupId> + <artifactId>log4j-slf4j-impl</artifactId> + <scope>test</scope> + </dependency> + + <!-- camel --> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>spi-annotations</artifactId> + </dependency> + + <!-- testing --> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-api</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-engine</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.junit.jupiter</groupId> + <artifactId>junit-jupiter-params</artifactId> + <version>${junit-jupiter-version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + </dependency> + </dependencies> + +</project> diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/ExtMvelHelper.java b/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/ExtMvelHelper.java new file mode 100644 index 0000000..b91829e --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/ExtMvelHelper.java @@ -0,0 +1,86 @@ +/* + * 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.karaf.maven; + +import java.nio.file.Path; + +import org.apache.camel.maven.packaging.MvelHelper; +import org.apache.camel.tooling.model.OtherModel; +import org.apache.camel.tooling.util.Strings; +import org.apache.camel.tooling.model.ComponentModel; +import org.apache.camel.tooling.model.DataFormatModel; +import org.apache.camel.tooling.model.LanguageModel; + +public class ExtMvelHelper { + + private final Path extensionsDocPath; + + public ExtMvelHelper(Path extensionsDocPath) { + this.extensionsDocPath = extensionsDocPath; + } + + public static String escape(final String raw) { + return MvelHelper.escape(raw); + } + + public String getFirstVersionShort(Object model) { + String version = (String) invokeGetter(model, "getFirstVersion"); + return org.apache.camel.tooling.model.Strings.cutLastZeroDigit(version); + } + + public String getDocLink(Object model) { + if (localDocExists(model)) { + return getLocalDocLink(model); + } else if (model instanceof ComponentModel) { + return String.format("link:https://camel.apache.org/%s/latest/%s", "components", + invokeGetter(model, "getScheme") + "-component.html"); + } else if (model instanceof DataFormatModel) { + return String.format("link:https://camel.apache.org/%s/latest/%s", "components", + invokeGetter(model, "getName") + "-dataformat.html"); + } else if (model instanceof LanguageModel) { + return String.format("link:https://camel.apache.org/%s/latest/%s", "components", + invokeGetter(model, "getName") + "-language.html"); + } else if (model instanceof OtherModel) { + return String.format("link:https://camel.apache.org/%s/latest/%s", "components", + invokeGetter(model, "getName") + ".html"); + } else { + return null; + } + } + + private Object invokeGetter(Object model, String method) { + try { + return model.getClass().getMethod(method) + .invoke(model); + } catch (Exception e) { + throw new RuntimeException("Unable to access " + method + " from " + model, e); + } + } + + private boolean localDocExists(Object model) { + Path path = extensionsDocPath.resolve(getSpringBootDocName(model)); + return path.toFile().exists(); + } + + private String getLocalDocLink(Object model) { + return "xref:components-starter/" + getSpringBootDocName(model); + } + + private String getSpringBootDocName(Object model) { + return Strings.after((String) invokeGetter(model, "getArtifactId"), "camel-") + ".adoc"; + } +} diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/UpdateDocComponentsListMojo.java b/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/UpdateDocComponentsListMojo.java new file mode 100644 index 0000000..e0b32c2 --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/java/org/apache/camel/karaf/maven/UpdateDocComponentsListMojo.java @@ -0,0 +1,634 @@ +/* + * 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.karaf.maven; + +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.TreeSet; + +import org.apache.camel.tooling.model.ComponentModel; +import org.apache.camel.tooling.model.DataFormatModel; +import org.apache.camel.tooling.model.JsonMapper; +import org.apache.camel.tooling.model.LanguageModel; +import org.apache.camel.tooling.model.OtherModel; +import org.apache.camel.tooling.util.Strings; +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; +import org.apache.maven.project.MavenProject; +import org.apache.maven.project.MavenProjectHelper; +import org.mvel2.templates.TemplateRuntime; + + +import static java.util.stream.Collectors.toSet; +import static org.apache.camel.tooling.util.PackageHelper.loadText; +import static org.apache.camel.tooling.util.PackageHelper.writeText; + +/** + * Updates the documentation in: + * + * - component-starter/readme.adoc + * + * to be up to date with all the component starters that Apache Camel Spring Boot ships. + */ +@Mojo(name = "update-doc-components-list", threadSafe = true) +public class UpdateDocComponentsListMojo extends AbstractMojo { + + /** + * The maven project. + */ + @Parameter(property = "project", required = true, readonly = true) + protected MavenProject project; + + /** + * The directory for components catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/karaf/catalog/components") + protected File componentsDir; + + /** + * The directory for data formats catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/karaf/catalog/dataformats") + protected File dataFormatsDir; + + /** + * The directory for languages catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/karaf/catalog/languages") + protected File languagesDir; + + /** + * The directory for others catalog + */ + @Parameter(defaultValue = "${project.build.directory}/classes/org/apache/camel/karaf/catalog/others") + protected File othersDir; + + /** + * The directory for components starter + */ + @Parameter(defaultValue = "${project.directory}/../../../components") + protected File readmeComponentsStarterDir; + + /** + * The website doc base directory + */ + @Parameter(defaultValue = "${project.directory}/../../../docs/modules/ROOT/pages") + protected File websiteDocBaseDir; + + /** + * Maven ProjectHelper. + */ + @Component + private MavenProjectHelper projectHelper; + + /** + * Execute goal. + * + * @throws MojoExecutionException execution of the main class or one of the + * threads it generated failed. + * @throws MojoFailureException something bad happened... + */ + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + executeComponentsReadme(); + executeDataFormatsReadme(); + executeLanguagesReadme(); + executeOthersReadme(); + } + + protected void executeComponentsReadme() 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); + + // filter out alternative schemas which reuses documentation + boolean add = true; + if (model.getAlternativeSchemes() != null && !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) { + 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(ComponentModel::isDeprecated) + .count(); + + // update the big readme file in the extensions dir + File file = new File(readmeComponentsStarterDir, "readme.adoc"); + 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 executeDataFormatsReadme() 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); + + // 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(DataFormatModel::isDeprecated) + .count(); + + // filter out camel-core + List<DataFormatModel> dataFormats = new ArrayList<>(); + for (DataFormatModel model : models) { + dataFormats.add(model); + } + + // update the big readme file in the extensions dir + File file = new File(readmeComponentsStarterDir, "readme.adoc"); + 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() throws MojoExecutionException, MojoFailureException { + Set<File> languageFiles = new TreeSet<>(); + + if (languagesDir != null && languagesDir.isDirectory()) { + File[] files = languagesDir.listFiles(); + if (files != null) { + languageFiles.addAll(Arrays.asList(files)); + } + } + + try { + List<LanguageModel> models = new ArrayList<>(); + for (File file : languageFiles) { + String json = loadText(new FileInputStream(file)); + LanguageModel model = generateLanguageModel(json); + models.add(model); + } + + // sort the models + Collections.sort(models, new LanguageComparator()); + + // filter out camel-core + List<LanguageModel> languages = new ArrayList<>(); + for (LanguageModel model : models) { + 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(LanguageModel::isDeprecated) + .count(); + + // update the big readme file in the extensions dir + File file = new File(readmeComponentsStarterDir, "readme.adoc"); + 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); + } + } + + 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(OtherModel::isDeprecated) + .count(); + + // update the big readme file in the extensions dir + File file = new File(readmeComponentsStarterDir, "readme.adoc"); + 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); + } + } + + private String templateComponents(List<ComponentModel> models, int artifacts, long deprecated) + throws MojoExecutionException { + try { + String template = loadText( + UpdateDocComponentsListMojo.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", new ExtMvelHelper(getComponentsStarterDocPath()))); + 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( + UpdateDocComponentsListMojo.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", new ExtMvelHelper(getComponentsStarterDocPath()))); + 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( + UpdateDocComponentsListMojo.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", new ExtMvelHelper(getComponentsStarterDocPath()))); + 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( + UpdateDocComponentsListMojo.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", new ExtMvelHelper(getComponentsStarterDocPath()))); + return out; + } catch (Exception e) { + throw new MojoExecutionException("Error processing mvel template. Reason: " + e, e); + } + } + + private boolean updateComponents(File file, String changed) throws MojoExecutionException { + if (!file.exists()) { + return false; + } + + try { + String text = loadText(new FileInputStream(file)); + + String existing = Strings.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 = Strings.before(text, "// components: START"); + String after = Strings.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 updateDataFormats(File file, String changed) throws MojoExecutionException { + if (!file.exists()) { + return false; + } + + try { + String text = loadText(new FileInputStream(file)); + + String existing = Strings.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 = Strings.before(text, "// dataformats: START"); + String after = Strings.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 = Strings.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 = Strings.before(text, "// languages: START"); + String after = Strings.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 boolean updateOthers(File file, String changed) throws MojoExecutionException { + if (!file.exists()) { + return false; + } + + try { + String text = loadText(new FileInputStream(file)); + + String existing = Strings.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 = Strings.before(text, "// others: START"); + String after = Strings.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 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 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 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 ComponentModel generateComponentModel(String json) { + return JsonMapper.generateComponentModel(json); + } + + private DataFormatModel generateDataFormatModel(String json) { + return JsonMapper.generateDataFormatModel(json); + } + + private LanguageModel generateLanguageModel(String json) { + return JsonMapper.generateLanguageModel(json); + } + + private OtherModel generateOtherModel(String json) { + return JsonMapper.generateOtherModel(json); + } + + private String getJSonValue(String key, List<Map<String, String>> rows) { + for (Map<String, String> row : rows) { + if (row.containsKey(key)) { + return row.get(key); + } + } + return ""; + } + + private Path getComponentsStarterDocPath() { + return Paths.get(websiteDocBaseDir.toString(), "components-starter"); + } + +} diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/LICENSE.txt b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/LICENSE.txt new file mode 100644 index 0000000..6b0b127 --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/LICENSE.txt @@ -0,0 +1,203 @@ + + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed 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. + diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/NOTICE.txt b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/NOTICE.txt new file mode 100644 index 0000000..2e215bf --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/META-INF/NOTICE.txt @@ -0,0 +1,11 @@ + ========================================================================= + == NOTICE file corresponding to the section 4 d of == + == the Apache License, Version 2.0, == + == in this case for the Apache Camel distribution. == + ========================================================================= + + This product includes software developed by + The Apache Software Foundation (http://www.apache.org/). + + Please read the different LICENSE files present in the licenses directory of + this distribution. diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-components.mvel b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-components.mvel new file mode 100644 index 0000000..fe78049 --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-components.mvel @@ -0,0 +1,14 @@ +@if{!components.isEmpty()} + +Number of Camel components: @{components.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) + +[width="100%",cols="4,1,5",options="header"] +|=== +| Component | Since | Description +@foreach{row : components} +| @{util.getDocLink(row)}[@{row.title}] (@{row.artifactId}) + +`@{row.syntax}` | @{util.getFirstVersionShort(row)} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} +@end{} +|=== + +@end{} \ No newline at end of file diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-dataformats.mvel b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-dataformats.mvel new file mode 100644 index 0000000..f2c0a4d --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-dataformats.mvel @@ -0,0 +1,13 @@ +@if{!dataformats.isEmpty()} + +Number of Camel data formats: @{dataformats.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) + +[width="100%",cols="4,1,5",options="header"] +|=== +| Data Format | Since | Description +@foreach{row : dataformats} +| @{util.getDocLink(row)}[@{row.title}] + +(@{row.artifactId}) | @{util.getFirstVersionShort(row)} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} +@end{}|=== + +@end{} \ No newline at end of file diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-languages.mvel b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-languages.mvel new file mode 100644 index 0000000..95b5281 --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-languages.mvel @@ -0,0 +1,13 @@ +@if{!languages.isEmpty()} + +Number of Camel languages: @{languages.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) + +[width="100%",cols="4,1,5",options="header"] +|=== +| Language | Since | Description +@foreach{row : languages} +| @{util.getDocLink(row)}[@{row.title}] + +(@{row.artifactId}) | @{util.getFirstVersionShort(row)} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} +@end{}|=== + +@end{} \ No newline at end of file diff --git a/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-others.mvel b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-others.mvel new file mode 100644 index 0000000..d59897b --- /dev/null +++ b/tooling/camel-karaf-docs-maven-plugin/src/main/resources/readme-others.mvel @@ -0,0 +1,13 @@ +@if{!others.isEmpty()} + +Number of miscellaneous extensions: @{others.size} in @{numberOfArtifacts} JAR artifacts (@{numberOfDeprecated} deprecated) + +[width="100%",cols="4,1,5",options="header"] +|=== +| Extension | Since | Description +@foreach{row : others} +| @{util.getDocLink(row)}[@{row.title}] + +(@{row.artifactId}) | @{util.getFirstVersionShort(row)} | @if{row.deprecated == "true"}*deprecated* @end{}@{util.escape(row.description)} +@end{}|=== + +@end{} \ No newline at end of file diff --git a/tooling/pom.xml b/tooling/pom.xml new file mode 100644 index 0000000..86e90c9 --- /dev/null +++ b/tooling/pom.xml @@ -0,0 +1,92 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + 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. + +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel.karaf</groupId> + <artifactId>karaf</artifactId> + <version>3.2.0-SNAPSHOT</version> + </parent> + + <artifactId>tooling</artifactId> + <packaging>pom</packaging> + <name>Camel Karaf Tooling</name> + + <modules> + <module>camel-karaf-docs-maven-plugin</module> + </modules> + + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <version>${maven-compiler-plugin-version}</version> + <configuration> + <source>${jdk.version}</source> + <target>${jdk.version}</target> + <maxmem>512M</maxmem> + <fork>${compiler.fork}</fork> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-javadoc-plugin</artifactId> + <configuration> + <attach>true</attach> + <source>${jdk.version}</source> + <quiet>true</quiet> + <bottom>Apache Camel</bottom> + <detectOfflineLinks>false</detectOfflineLinks> + <javadocVersion>1.8.0</javadocVersion> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-resources-plugin</artifactId> + <configuration> + <encoding>UTF-8</encoding> + </configuration> + </plugin> + <plugin> + <groupId>org.apache.camel</groupId> + <artifactId>camel-bundle-plugin</artifactId> + <version>${project.version}</version> + <configuration> + <instructions> + </instructions> + </configuration> + <executions> + <execution> + <id>bundle-manifest</id> + <phase>prepare-package</phase> + <goals> + <goal>manifest</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + +</project>