This is an automated email from the ASF dual-hosted git repository. ppalaga pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/master by this push: new 786c86b Fix #1232 Per-extension documentation pages 786c86b is described below commit 786c86b18ab5ab9a3b053578b883e639253537e5 Author: Peter Palaga <ppal...@redhat.com> AuthorDate: Wed May 20 16:01:40 2020 +0200 Fix #1232 Per-extension documentation pages --- docs/modules/ROOT/pages/extensions/activemq.adoc | 27 ++++ docs/modules/ROOT/pages/extensions/ahc.adoc | 25 ++-- .../pages/list-of-camel-quarkus-extensions.adoc | 2 +- extensions-core/xml-io/deployment/pom.xml | 2 +- extensions-core/xml-io/pom.xml | 2 +- extensions-core/xml-io/runtime/pom.xml | 2 +- extensions-core/xml-jaxb/deployment/pom.xml | 2 +- extensions-core/xml-jaxb/pom.xml | 2 +- extensions-core/xml-jaxb/runtime/pom.xml | 2 +- extensions-core/xml-jaxp/deployment/pom.xml | 2 +- extensions-core/xml-jaxp/pom.xml | 2 +- extensions-core/xml-jaxp/runtime/pom.xml | 2 +- extensions/activemq/runtime/pom.xml | 18 +++ extensions/ahc/runtime/pom.xml | 18 +++ .../ahc/runtime/src/main/doc/configuration.adoc | 2 + .../quarkus/maven/AbstractDocGeneratorMojo.java | 73 ++++++++++ .../camel/quarkus/maven/CamelQuarkusExtension.java | 153 +++++++++++++++++++++ .../org/apache/camel/quarkus/maven/CqCatalog.java | 16 ++- .../org/apache/camel/quarkus/maven/CqUtils.java | 63 ++++++++- .../quarkus/maven/PrepareCatalogQuarkusMojo.java | 139 +------------------ .../quarkus/maven/UpdateDocExtensionsListMojo.java | 45 +----- .../quarkus/maven/UpdateExtensionDocPageMojo.java | 113 +++++++++++++++ .../doc-templates/extension-doc-page.adoc | 38 +++++ .../readme-components.ftl | 0 .../readme-dataformats.ftl | 0 .../readme-languages.ftl | 0 .../readme-others.ftl | 0 27 files changed, 550 insertions(+), 200 deletions(-) diff --git a/docs/modules/ROOT/pages/extensions/activemq.adoc b/docs/modules/ROOT/pages/extensions/activemq.adoc new file mode 100644 index 0000000..927405c --- /dev/null +++ b/docs/modules/ROOT/pages/extensions/activemq.adoc @@ -0,0 +1,27 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page + +[[activemq]] += ActiveMQ + +*Since Camel Quarkus 1.0.0-M5, JVM and native* + +Send messages to (or consume from) Apache ActiveMQ. This component extends the Camel JMS component. + +== What's inside + +* https://camel.apache.org/components/latest/activemq-component.html[ActiveMQ component] + +Please refer to the above links for usage details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-activemq</artifactId> +</dependency> +---- + +Check the xref:user-guide.adoc[User guide] for more information about writing Camel Quarkus applications. diff --git a/docs/modules/ROOT/pages/extensions/ahc.adoc b/docs/modules/ROOT/pages/extensions/ahc.adoc index 45fc877..711d196 100644 --- a/docs/modules/ROOT/pages/extensions/ahc.adoc +++ b/docs/modules/ROOT/pages/extensions/ahc.adoc @@ -1,13 +1,20 @@ +// Do not edit directly! +// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page + [[ahc]] -= Async HTTP Client (AHC) Extension += AHC (Async Http Client) + +*Since Camel Quarkus 1.0.0-M3, JVM and native* + +Call external HTTP services using Async Http Client. + +== What's inside -*Since Camel Quarkus 1.0.0-M3* +* https://camel.apache.org/components/latest/ahc-component.html[AHC component] -The AHC component provides HTTP based endpoints for consuming external HTTP resources (as a client to call external -servers using HTTP). It is using the https://github.com/AsyncHttpClient/async-http-client[Async Http Client library] -under the hood. +Please refer to the above links for usage details. -Maven users will need to add the following dependency to their `pom.xml` for this extension. +== Maven coordinates [source,xml] ---- @@ -17,12 +24,10 @@ Maven users will need to add the following dependency to their `pom.xml` for thi </dependency> ---- -== Usage - -Please refer to the https://camel.apache.org/components/latest/ahc-component.html[AHC] component page. - +Check the xref:user-guide.adoc[User guide] for more information about writing Camel Quarkus applications. == Configuration * Check the xref:native-mode.adoc#charsets[Character encodings section] of the Native mode guide if you expect your application to send or receive requests using non-default encodings. + diff --git a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc index 6ca7f5a..6bdc5aa 100644 --- a/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc +++ b/docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc @@ -25,7 +25,7 @@ Number of Camel components: 148 in 113 JAR artifacts (0 deprecated) | Component | Target + Level | Since | Description -| link:https://camel.apache.org/components/latest/activemq-component.html[ActiveMQ] (camel-quarkus-activemq) + +| xref:extensions/activemq.adoc[ActiveMQ] (camel-quarkus-activemq) + `activemq:destinationType:destinationName` | Native + Stable | 1.0.0-M5 | Send messages to (or consume from) Apache ActiveMQ. This component extends the Camel JMS component. diff --git a/extensions-core/xml-io/deployment/pom.xml b/extensions-core/xml-io/deployment/pom.xml index ff2678c..13a3af7 100644 --- a/extensions-core/xml-io/deployment/pom.xml +++ b/extensions-core/xml-io/deployment/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-io-deployment</artifactId> - <name>Camel Quarkus :: XML :: IO :: Deployment</name> + <name>Camel Quarkus :: XML :: XML IO :: Deployment</name> <dependencyManagement> <dependencies> diff --git a/extensions-core/xml-io/pom.xml b/extensions-core/xml-io/pom.xml index 2813daf..80c0f56 100644 --- a/extensions-core/xml-io/pom.xml +++ b/extensions-core/xml-io/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-io-parent</artifactId> - <name>Camel Quarkus :: XML :: IO</name> + <name>Camel Quarkus :: XML IO</name> <packaging>pom</packaging> <modules> diff --git a/extensions-core/xml-io/runtime/pom.xml b/extensions-core/xml-io/runtime/pom.xml index 2d4d116..8a9ef53 100644 --- a/extensions-core/xml-io/runtime/pom.xml +++ b/extensions-core/xml-io/runtime/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-io</artifactId> - <name>Camel Quarkus :: XML :: Core XML IO :: Runtime</name> + <name>Camel Quarkus :: XML IO :: Runtime</name> <description>An XML stack for parsing XML route definitions. A fast an light weight alternative to camel-quarkus-xml-jaxp</description> <properties> diff --git a/extensions-core/xml-jaxb/deployment/pom.xml b/extensions-core/xml-jaxb/deployment/pom.xml index 789aea5..1722bf5 100644 --- a/extensions-core/xml-jaxb/deployment/pom.xml +++ b/extensions-core/xml-jaxb/deployment/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxb-deployment</artifactId> - <name>Camel Quarkus :: XML :: JAXB :: Deployment</name> + <name>Camel Quarkus :: XML JAXB :: Deployment</name> <dependencyManagement> <dependencies> diff --git a/extensions-core/xml-jaxb/pom.xml b/extensions-core/xml-jaxb/pom.xml index b415b8d..3075697 100644 --- a/extensions-core/xml-jaxb/pom.xml +++ b/extensions-core/xml-jaxb/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxb-parent</artifactId> - <name>Camel Quarkus :: XML :: JAXB</name> + <name>Camel Quarkus :: XML JAXB</name> <packaging>pom</packaging> <modules> diff --git a/extensions-core/xml-jaxb/runtime/pom.xml b/extensions-core/xml-jaxb/runtime/pom.xml index 0f1dc21..93d4608 100644 --- a/extensions-core/xml-jaxb/runtime/pom.xml +++ b/extensions-core/xml-jaxb/runtime/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxb</artifactId> - <name>Camel Quarkus :: XML :: JAXB :: Runtime</name> + <name>Camel Quarkus :: XML JAXB :: Runtime</name> <description>An XML stack for parsing XML route definitions. A legacy alternative to the fast an light weight camel-quarkus-xml-io</description> <properties> diff --git a/extensions-core/xml-jaxp/deployment/pom.xml b/extensions-core/xml-jaxp/deployment/pom.xml index b921e39..61c70fa 100644 --- a/extensions-core/xml-jaxp/deployment/pom.xml +++ b/extensions-core/xml-jaxp/deployment/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxp-deployment</artifactId> - <name>Camel Quarkus :: XML :: JAXP :: Deployment</name> + <name>Camel Quarkus :: XML JAXP :: Deployment</name> <dependencyManagement> <dependencies> diff --git a/extensions-core/xml-jaxp/pom.xml b/extensions-core/xml-jaxp/pom.xml index 7f26d92..686a12e 100644 --- a/extensions-core/xml-jaxp/pom.xml +++ b/extensions-core/xml-jaxp/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxp-parent</artifactId> - <name>Camel Quarkus :: XML :: JAXP</name> + <name>Camel Quarkus :: XML JAXP</name> <packaging>pom</packaging> <modules> diff --git a/extensions-core/xml-jaxp/runtime/pom.xml b/extensions-core/xml-jaxp/runtime/pom.xml index fb2d623..2c42adf 100644 --- a/extensions-core/xml-jaxp/runtime/pom.xml +++ b/extensions-core/xml-jaxp/runtime/pom.xml @@ -27,7 +27,7 @@ </parent> <artifactId>camel-quarkus-xml-jaxp</artifactId> - <name>Camel Quarkus :: XML :: Core JAXP :: Runtime</name> + <name>Camel Quarkus :: XML JAXP :: Runtime</name> <properties> <firstVersion>1.0.0-M5</firstVersion> diff --git a/extensions/activemq/runtime/pom.xml b/extensions/activemq/runtime/pom.xml index 3b57f68..d0b3c59 100644 --- a/extensions/activemq/runtime/pom.xml +++ b/extensions/activemq/runtime/pom.xml @@ -82,6 +82,24 @@ <build> <plugins> <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-package-maven-plugin</artifactId> + <version>${project.version}</version> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-catalog</artifactId> + <version>${camel.version}</version> + </dependency> + </dependencies> + <executions> + <execution> + <goals><goal>update-extension-doc-page</goal></goals> + <phase>process-resources</phase> + </execution> + </executions> + </plugin> + <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-bootstrap-maven-plugin</artifactId> </plugin> diff --git a/extensions/ahc/runtime/pom.xml b/extensions/ahc/runtime/pom.xml index e0aab5b..420afb0 100644 --- a/extensions/ahc/runtime/pom.xml +++ b/extensions/ahc/runtime/pom.xml @@ -68,6 +68,24 @@ <build> <plugins> <plugin> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-package-maven-plugin</artifactId> + <version>${project.version}</version> + <dependencies> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-catalog</artifactId> + <version>${camel.version}</version> + </dependency> + </dependencies> + <executions> + <execution> + <goals><goal>update-extension-doc-page</goal></goals> + <phase>process-resources</phase> + </execution> + </executions> + </plugin> + <plugin> <groupId>io.quarkus</groupId> <artifactId>quarkus-bootstrap-maven-plugin</artifactId> </plugin> diff --git a/extensions/ahc/runtime/src/main/doc/configuration.adoc b/extensions/ahc/runtime/src/main/doc/configuration.adoc new file mode 100644 index 0000000..1f97a7a --- /dev/null +++ b/extensions/ahc/runtime/src/main/doc/configuration.adoc @@ -0,0 +1,2 @@ +* Check the xref:native-mode.adoc#charsets[Character encodings section] of the Native mode guide if you expect + your application to send or receive requests using non-default encodings. diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractDocGeneratorMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractDocGeneratorMojo.java new file mode 100644 index 0000000..2a92aa8 --- /dev/null +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/AbstractDocGeneratorMojo.java @@ -0,0 +1,73 @@ +/* + * 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.quarkus.maven; + +import java.io.File; +import java.io.IOException; +import java.io.Writer; +import java.util.Map; + +import freemarker.template.Configuration; +import freemarker.template.Template; +import freemarker.template.TemplateException; +import org.apache.maven.plugin.AbstractMojo; +import org.apache.maven.plugins.annotations.Parameter; + +/** + * Base for {@link UpdateDocExtensionsListMojo} and {@link UpdateExtensionDocPageMojo}. + */ +abstract class AbstractDocGeneratorMojo extends AbstractMojo { + public static final String DEFAULT_TEMPLATES_URI_BASE = "classpath:/doc-templates"; + /** + */ + @Parameter(defaultValue = AbstractDocGeneratorMojo.DEFAULT_TEMPLATES_URI_BASE, required = true, property = "camel-quarkus.templatesUriBase") + String templatesUriBase; + /** + * Directory where the changes should be performed. Default is the current directory of the current Java process. + */ + @Parameter(property = "camel-quarkus.basedir", defaultValue = "${project.basedir}") + File baseDir; + + /** + * Encoding to read and write files in the current source tree + */ + @Parameter(defaultValue = "${project.build.sourceEncoding}", required = true, property = "camel-quarkus.encoding") + String encoding; + /** + * The root directory of the Camel Quarkus source tree. + * + * @since 1.0.0-M8 + */ + @Parameter(defaultValue = "${maven.multiModuleProjectDirectory}", required = true, property = "camel-quarkus.multiModuleProjectDirectory") + File multiModuleProjectDirectory; + + protected static <T extends Writer> T evalTemplate(Configuration cfg, String templateUri, Map<String, Object> model, + T out) { + try { + final Template template = cfg.getTemplate(templateUri); + try { + template.process(model, out); + } catch (TemplateException e) { + throw new RuntimeException("Could not process template " + templateUri + ":\n\n" + out.toString(), e); + } + return out; + } catch (IOException e) { + throw new RuntimeException("Could not evaluate template " + templateUri, e); + } + } + +} diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CamelQuarkusExtension.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CamelQuarkusExtension.java new file mode 100644 index 0000000..fe4014b --- /dev/null +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CamelQuarkusExtension.java @@ -0,0 +1,153 @@ +/* + * 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.quarkus.maven; + +import java.io.IOException; +import java.io.Reader; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.List; +import java.util.Optional; +import java.util.Properties; + +import org.apache.maven.model.Dependency; +import org.apache.maven.model.Model; +import org.apache.maven.model.io.xpp3.MavenXpp3Reader; +import org.codehaus.plexus.util.xml.pull.XmlPullParserException; + +/** + * A utility to extract some extension metadata from the Runtime module's POM. + */ +public class CamelQuarkusExtension { + + public static CamelQuarkusExtension read(Path runtimePomXmlPath) { + try (Reader runtimeReader = Files.newBufferedReader(runtimePomXmlPath, StandardCharsets.UTF_8)) { + final MavenXpp3Reader rxppReader = new MavenXpp3Reader(); + final Model runtimePom = rxppReader.read(runtimeReader); + final List<Dependency> deps = runtimePom.getDependencies(); + + final String aid = runtimePom.getArtifactId(); + String camelComponentArtifactId = null; + if (deps != null && !deps.isEmpty()) { + Optional<Dependency> artifact = deps.stream() + .filter(dep -> + + "org.apache.camel".equals(dep.getGroupId()) && + ("compile".equals(dep.getScope()) || dep.getScope() == null)) + .findFirst(); + if (artifact.isPresent()) { + camelComponentArtifactId = CqCatalog.toCamelComponentArtifactIdBase(artifact.get().getArtifactId()); + } + } + final Properties props = runtimePom.getProperties() != null ? runtimePom.getProperties() : new Properties(); + + String name = props.getProperty("title"); + if (name == null) { + name = CqUtils.getNameBase(runtimePom.getName()); + } + + final String version = CqUtils.getVersion(runtimePom); + + return new CamelQuarkusExtension( + runtimePomXmlPath, + camelComponentArtifactId, + (String) props.get("firstVersion"), + aid, + name, + runtimePom.getDescription(), + props.getProperty("label"), + version, + !runtimePomXmlPath.getParent().getParent().getParent().getFileName().toString().endsWith("-jvm")); + } catch (IOException | XmlPullParserException e) { + throw new RuntimeException("Could not read " + runtimePomXmlPath, e); + } + } + + private final String label; + private final String version; + private final String description; + private final String runtimeArtifactId; + private final Path runtimePomXmlPath; + private final String camelComponentArtifactId; + private final String firstVersion; + private final String name; + private final boolean nativeSupported; + + public CamelQuarkusExtension( + Path runtimePomXmlPath, + String camelComponentArtifactId, + String firstVersion, + String runtimeArtifactId, + String name, + String description, + String label, + String version, + boolean nativeSupported) { + super(); + this.runtimePomXmlPath = runtimePomXmlPath; + this.camelComponentArtifactId = camelComponentArtifactId; + this.firstVersion = firstVersion; + this.runtimeArtifactId = runtimeArtifactId; + this.name = name; + this.description = description; + this.label = label; + this.version = version; + this.nativeSupported = nativeSupported; + } + + public String getVersion() { + return version; + } + + public Optional<String> getFirstVersion() { + return Optional.ofNullable(firstVersion); + } + + public Path getRuntimePomXmlPath() { + return runtimePomXmlPath; + } + + public Optional<String> getLabel() { + return Optional.ofNullable(label); + } + + public Optional<String> getDescription() { + return Optional.ofNullable(description); + } + + public String getRuntimeArtifactIdBase() { + return CqUtils.getArtifactIdBase(runtimeArtifactId); + } + + public String getRuntimeArtifactId() { + return runtimeArtifactId; + } + + public String getCamelComponentArtifactId() { + return camelComponentArtifactId; + } + + public Optional<String> getName() { + return Optional.ofNullable(name); + } + + public boolean isNativeSupported() { + return nativeSupported; + } + +} diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java index f2d12bd..0091cc5 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqCatalog.java @@ -24,7 +24,6 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; -import java.util.stream.Collectors; import java.util.stream.Stream; import org.apache.camel.catalog.CamelCatalog; @@ -40,6 +39,12 @@ public class CqCatalog { private final DefaultCamelCatalog catalog; + private static final ThreadLocal<CqCatalog> threadLocalCamelCatalog = ThreadLocal.withInitial(CqCatalog::new); + + public static CqCatalog getThreadLocalCamelCatalog() { + return threadLocalCamelCatalog.get(); + } + public CqCatalog(Path baseDir) { super(); final DefaultCamelCatalog c = new DefaultCamelCatalog(true); @@ -53,7 +58,7 @@ public class CqCatalog { this.catalog = new DefaultCamelCatalog(true); } - public String toCamelComponentArtifactIdBase(String cqArtifactIdBase) { + public static String toCamelComponentArtifactIdBase(String cqArtifactIdBase) { if ("core".equals(cqArtifactIdBase)) { return "base"; } else if ("reactive-executor".equals(cqArtifactIdBase)) { @@ -63,7 +68,7 @@ public class CqCatalog { } } - public List<String> toCamelArtifactIdBase(String cqArtifactIdBase) { + public static List<String> toCamelArtifactIdBase(String cqArtifactIdBase) { if ("core".equals(cqArtifactIdBase)) { return Arrays.asList("camel-base", "camel-core-languages"); } else if ("reactive-executor".equals(cqArtifactIdBase)) { @@ -73,11 +78,10 @@ public class CqCatalog { } } - public List<ArtifactModel<?>> filterModels(String artifactIdBase) { + public Stream<ArtifactModel<?>> filterModels(String artifactIdBase) { List<String> camelArtifactIds = toCamelArtifactIdBase(artifactIdBase); return models() - .filter(model -> camelArtifactIds.contains(model.getArtifactId())) - .collect(Collectors.toList()); + .filter(model -> camelArtifactIds.contains(model.getArtifactId())); } public Stream<ArtifactModel<?>> models() { diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqUtils.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqUtils.java index 2122603..222adb6 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqUtils.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/CqUtils.java @@ -19,6 +19,10 @@ package org.apache.camel.quarkus.maven; import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; import java.util.stream.Stream; import freemarker.cache.ClassTemplateLoader; @@ -27,13 +31,15 @@ import freemarker.cache.MultiTemplateLoader; import freemarker.cache.TemplateLoader; import freemarker.template.Configuration; import freemarker.template.TemplateExceptionHandler; +import org.apache.camel.catalog.Kind; import org.apache.camel.tooling.model.ArtifactModel; import org.apache.maven.model.Model; +import org.apache.maven.plugin.logging.Log; public class CqUtils { public static final String CLASSPATH_PREFIX = "classpath:"; - public static final String FILE_PREFIX = "file:"; + private static final String NAME_SUFFIX = " :: Runtime"; static TemplateLoader createTemplateLoader(Path basePath, String defaultUriBase, String templatesUriBase) { final TemplateLoader defaultLoader = new ClassTemplateLoader(CqUtils.class, @@ -106,4 +112,59 @@ public class CqUtils { "Unexpected artifactId " + artifactId + "; expected one starting with camel-quarkus- or camel-"); } + public static String getArtifactIdBase(String cqArtifactId) { + if (cqArtifactId.startsWith("camel-quarkus-")) { + return cqArtifactId.substring("camel-quarkus-".length()); + } + throw new IllegalStateException( + "Unexpected artifactId " + cqArtifactId + "; expected one starting with camel-quarkus-"); + } + + public static String getNameBase(String name) { + if (!name.endsWith(NAME_SUFFIX)) { + throw new IllegalStateException( + "Unexpected Maven module name '" + name + "'; expected to end with " + NAME_SUFFIX); + } + final int startDelimPos = name.lastIndexOf(" :: ", name.length() - NAME_SUFFIX.length() - 1); + if (startDelimPos < 0) { + throw new IllegalStateException( + "Unexpected Maven module name '" + name + "'; expected to start with with '<whatever> :: '"); + } + return name.substring(startDelimPos + 4, name.length() - NAME_SUFFIX.length()); + } + + public static String humanReadableKind(Kind kind) { + switch (kind) { + case component: + return "component"; + case dataformat: + return "data format"; + case language: + return "languages"; + case other: + return null; + default: + throw new IllegalStateException("Unexpected kind " + kind); + } + } + + public static String getDescription(List<ArtifactModel<?>> models, String descriptionFromPom, Log log) { + if (descriptionFromPom != null) { + return descriptionFromPom; + } else if (models.size() == 1) { + return models.get(0).getDescription(); + } else { + final Set<String> uniqueDescriptions = models.stream() + .map(m -> m.getDescription()) + .collect(Collectors.toCollection(LinkedHashSet::new)); + final String description = uniqueDescriptions + .stream() + .collect(Collectors.joining(" ")); + if (uniqueDescriptions.size() > 1) { + log.warn("Consider adding and explicit <description> if you do not like the concatenated description: " + + description); + } + return description; + } + } } diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java index 0445271..f3d4d69 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/PrepareCatalogQuarkusMojo.java @@ -18,7 +18,6 @@ package org.apache.camel.quarkus.maven; import java.io.File; import java.io.IOException; -import java.io.Reader; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; @@ -26,8 +25,6 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Optional; -import java.util.Properties; import java.util.Set; import java.util.TreeSet; import java.util.stream.Collectors; @@ -40,15 +37,11 @@ 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.model.SupportLevel; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; /** * Prepares the Quarkus provider camel catalog to include component it supports @@ -87,17 +80,19 @@ public class PrepareCatalogQuarkusMojo extends AbstractMojo { final Map<String, Set<String>> schemesByKind = new LinkedHashMap<>(); CqCatalog.kinds().forEach(kind -> schemesByKind.put(kind.name(), new TreeSet<>())); - final CqCatalog catalog = new CqCatalog(); + final CqCatalog catalog = CqCatalog.getThreadLocalCamelCatalog(); extensionDirectories.stream() .map(File::toPath) .forEach(extDir -> { CqUtils.findExtensionArtifactIdBases(extDir) .filter(artifactIdBase -> !skipArtifactIdBases.contains(artifactIdBase)) .forEach(artifactIdBase -> { - final List<ArtifactModel<?>> models = catalog.filterModels(artifactIdBase); - final CamelQuarkusExtension ext = CamelQuarkusExtension - .read(extDir.resolve(artifactIdBase).resolve("pom.xml"), catalog); - final boolean nativeSupported = !extDir.getFileName().toString().endsWith("-jvm"); + final List<ArtifactModel<?>> models = catalog.filterModels(artifactIdBase) + .collect(Collectors.toList()); + final Path runtimePomXmlPath = extDir.resolve(artifactIdBase).resolve("runtime/pom.xml") + .toAbsolutePath().normalize(); + final CamelQuarkusExtension ext = CamelQuarkusExtension.read(runtimePomXmlPath); + final boolean nativeSupported = ext.isNativeSupported(); if (models.isEmpty()) { final OtherModel model = new OtherModel(); final String name = ext.getRuntimeArtifactId().replace("camel-quarkus-", ""); @@ -187,124 +182,4 @@ public class PrepareCatalogQuarkusMojo extends AbstractMojo { } - static class CamelQuarkusExtension { - - public static CamelQuarkusExtension read(Path parentPomXmlPath, CqCatalog catalog) { - final Path runtimePomXmlPath = parentPomXmlPath.getParent().resolve("runtime/pom.xml").toAbsolutePath().normalize(); - try (Reader parentReader = Files.newBufferedReader(parentPomXmlPath, StandardCharsets.UTF_8); - Reader runtimeReader = Files.newBufferedReader(runtimePomXmlPath, StandardCharsets.UTF_8)) { - final MavenXpp3Reader rxppReader = new MavenXpp3Reader(); - final Model parentPom = rxppReader.read(parentReader); - final Model runtimePom = rxppReader.read(runtimeReader); - final List<Dependency> deps = runtimePom.getDependencies(); - - final String aid = runtimePom.getArtifactId(); - String camelComponentArtifactId = null; - if (deps != null && !deps.isEmpty()) { - Optional<Dependency> artifact = deps.stream() - .filter(dep -> - - "org.apache.camel".equals(dep.getGroupId()) && - ("compile".equals(dep.getScope()) || dep.getScope() == null)) - .findFirst(); - if (artifact.isPresent()) { - camelComponentArtifactId = catalog.toCamelComponentArtifactIdBase(artifact.get().getArtifactId()); - } - } - final Properties props = runtimePom.getProperties() != null ? runtimePom.getProperties() : new Properties(); - - String name = props.getProperty("title"); - if (name == null) { - name = parentPom.getName().replace("Camel Quarkus :: ", ""); - } - - final String version = CqUtils.getVersion(runtimePom); - - return new CamelQuarkusExtension( - parentPomXmlPath, - runtimePomXmlPath, - camelComponentArtifactId, - (String) props.get("firstVersion"), - aid, - name, - runtimePom.getDescription(), - props.getProperty("label"), - version); - } catch (IOException | XmlPullParserException e) { - throw new RuntimeException("Could not read " + parentPomXmlPath, e); - } - } - - private final String label; - private final String version; - - private final String description; - - private final String runtimeArtifactId; - - private final Path parentPomXmlPath; - private final Path runtimePomXmlPath; - private final String camelComponentArtifactId; - private final String firstVersion; - private final String name; - - public CamelQuarkusExtension( - Path pomXmlPath, - Path runtimePomXmlPath, - String camelComponentArtifactId, - String firstVersion, - String runtimeArtifactId, - String name, - String description, - String label, String version) { - super(); - this.parentPomXmlPath = pomXmlPath; - this.runtimePomXmlPath = runtimePomXmlPath; - this.camelComponentArtifactId = camelComponentArtifactId; - this.firstVersion = firstVersion; - this.runtimeArtifactId = runtimeArtifactId; - this.name = name; - this.description = description; - this.label = label; - this.version = version; - } - - public String getVersion() { - return version; - } - - public Path getParentPomXmlPath() { - return parentPomXmlPath; - } - - public Optional<String> getFirstVersion() { - return Optional.ofNullable(firstVersion); - } - - public Path getRuntimePomXmlPath() { - return runtimePomXmlPath; - } - - public Optional<String> getLabel() { - return Optional.ofNullable(label); - } - - public Optional<String> getDescription() { - return Optional.ofNullable(description); - } - - public String getRuntimeArtifactId() { - return runtimeArtifactId; - } - - public String getCamelComponentArtifactId() { - return camelComponentArtifactId; - } - - public Optional<String> getName() { - return Optional.ofNullable(name); - } - - } - } diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java index b0e2490..7b9078b 100644 --- a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateDocExtensionsListMojo.java @@ -19,7 +19,6 @@ package org.apache.camel.quarkus.maven; import java.io.File; import java.io.IOException; import java.io.StringWriter; -import java.io.Writer; import java.nio.file.Files; import java.nio.file.Path; import java.util.HashMap; @@ -32,8 +31,6 @@ import java.util.stream.Collectors; import freemarker.ext.beans.StringModel; import freemarker.template.Configuration; -import freemarker.template.Template; -import freemarker.template.TemplateException; import freemarker.template.TemplateMethodModelEx; import freemarker.template.TemplateModelException; import freemarker.template.utility.DeepUnwrap; @@ -43,7 +40,6 @@ import org.apache.camel.tooling.model.BaseModel; import org.apache.camel.tooling.model.ComponentModel; import org.apache.camel.tooling.model.DataFormatModel; import org.apache.camel.tooling.model.SupportLevel; -import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Mojo; @@ -54,14 +50,12 @@ import static java.util.stream.Collectors.toSet; /** * Updates the documentation in: * - * - extensions/readme.adoc * - docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc * * to be up to date with all the extensions that Apache Camel Quarkus ships. */ @Mojo(name = "update-doc-extensions-list", threadSafe = true) -public class UpdateDocExtensionsListMojo extends AbstractMojo { - static final String DEFAULT_TEMPLATES_URI_BASE = "classpath:/extension-list-templates"; +public class UpdateDocExtensionsListMojo extends AbstractDocGeneratorMojo { /** * The directory relative to which the catalog data is read. */ @@ -75,22 +69,6 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { File extensionListFile; /** - */ - @Parameter(defaultValue = DEFAULT_TEMPLATES_URI_BASE, required = true, property = "camel-quarkus.templatesUriBase") - String templatesUriBase; - /** - * Directory where the changes should be performed. Default is the current directory of the current Java process. - */ - @Parameter(property = "camel-quarkus.basedir", defaultValue = "${project.basedir}") - File baseDir; - - /** - * Encoding to read and write files in the current source tree - */ - @Parameter(defaultValue = "${project.build.sourceEncoding}", required = true, property = "camel-quarkus.encoding") - String encoding; - - /** * Execute goal. * * @throws MojoExecutionException execution of the main class or one of the @@ -103,7 +81,8 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { final Path basePath = baseDir.toPath(); final Path extensionListPath = extensionListFile.toPath(); - final Configuration cfg = CqUtils.getTemplateConfig(basePath, DEFAULT_TEMPLATES_URI_BASE, templatesUriBase, encoding); + final Configuration cfg = CqUtils.getTemplateConfig(basePath, AbstractDocGeneratorMojo.DEFAULT_TEMPLATES_URI_BASE, + templatesUriBase, encoding); AtomicReference<String> document; try { @@ -168,7 +147,7 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { model.put("getSupportLevel", getSupportLevel); model.put("getTarget", getTarget); - final String extList = evalTemplate(cfg, "readme-" + kind.name() + "s.ftl", model); + final String extList = evalTemplate(cfg, "readme-" + kind.name() + "s.ftl", model, new StringWriter()).toString(); replace(document, extensionListPath, extList, kind); }); @@ -197,22 +176,6 @@ public class UpdateDocExtensionsListMojo extends AbstractMojo { ref.set(sb.toString()); } - static String evalTemplate(Configuration cfg, String templateUri, Map<String, Object> model) { - try { - final Template template = cfg.getTemplate(templateUri); - try (Writer out = new StringWriter()) { - try { - template.process(model, out); - } catch (TemplateException e) { - throw new RuntimeException("Could not process template " + templateUri + ":\n\n" + out.toString(), e); - } - return out.toString(); - } - } catch (IOException e) { - throw new RuntimeException("Could not evaluate template " + templateUri, e); - } - } - static class GetDocLink implements TemplateMethodModelEx { private final Path extensionsDocPath; diff --git a/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateExtensionDocPageMojo.java b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateExtensionDocPageMojo.java new file mode 100644 index 0000000..5164208 --- /dev/null +++ b/tooling/package-maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateExtensionDocPageMojo.java @@ -0,0 +1,113 @@ +/* + * 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.quarkus.maven; + +import java.io.IOException; +import java.io.StringWriter; +import java.nio.charset.Charset; +import java.nio.file.Files; +import java.nio.file.Path; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import freemarker.template.Configuration; +import freemarker.template.TemplateMethodModelEx; +import freemarker.template.TemplateModelException; +import org.apache.camel.catalog.Kind; +import org.apache.camel.tooling.model.ArtifactModel; +import org.apache.camel.tooling.model.BaseModel; +import org.apache.maven.plugin.MojoExecutionException; +import org.apache.maven.plugin.MojoFailureException; +import org.apache.maven.plugins.annotations.Mojo; + +@Mojo(name = "update-extension-doc-page", threadSafe = true) +public class UpdateExtensionDocPageMojo extends AbstractDocGeneratorMojo { + + @Override + public void execute() throws MojoExecutionException, MojoFailureException { + final Charset charset = Charset.forName(encoding); + final Path basePath = baseDir.toPath(); + + if (!"runtime".equals(basePath.getFileName().toString())) { + getLog().info("Skipping a module that is not a Quarkus extension runtime module"); + return; + } + + final CqCatalog catalog = CqCatalog.getThreadLocalCamelCatalog(); + + final Path multiModuleProjectDirectoryPath = multiModuleProjectDirectory.toPath(); + final CamelQuarkusExtension ext = CamelQuarkusExtension.read(basePath.resolve("pom.xml")); + + final Configuration cfg = CqUtils.getTemplateConfig(basePath, AbstractDocGeneratorMojo.DEFAULT_TEMPLATES_URI_BASE, + templatesUriBase, encoding); + + final List<ArtifactModel<?>> models = catalog.filterModels(ext.getRuntimeArtifactIdBase()) + .sorted(BaseModel.compareTitle()) + .collect(Collectors.toList()); + + final Map<String, Object> model = new HashMap<>(); + model.put("artifactIdBase", ext.getRuntimeArtifactIdBase()); + model.put("firstVersion", ext.getFirstVersion().get()); + model.put("nativeSupported", ext.isNativeSupported()); + model.put("name", ext.getName().get()); + model.put("intro", loadSection(basePath, "intro.adoc", charset, + CqUtils.getDescription(models, ext.getDescription().orElse(null), getLog()))); + model.put("models", models); + model.put("configuration", loadSection(basePath, "configuration.adoc", charset, null)); + model.put("limitations", loadSection(basePath, "limitations.adoc", charset, null)); + model.put("humanReadableKind", new TemplateMethodModelEx() { + @Override + public Object exec(List arguments) throws TemplateModelException { + if (arguments.size() != 1) { + throw new TemplateModelException("Wrong argument count in toCamelCase()"); + } + return CqUtils.humanReadableKind(Kind.valueOf(String.valueOf(arguments.get(0)))); + } + }); + + final Path docPagePath = multiModuleProjectDirectoryPath + .resolve("docs/modules/ROOT/pages/extensions/" + ext.getRuntimeArtifactIdBase() + ".adoc"); + try { + Files.createDirectories(docPagePath.getParent()); + } catch (IOException e) { + throw new RuntimeException("Could not create directories " + docPagePath.getParent(), e); + } + String pageText = "// Do not edit directly!\n// This file was generated by camel-quarkus-package-maven-plugin:update-extension-doc-page\n\n" + + evalTemplate(cfg, "extension-doc-page.adoc", model, new StringWriter()).toString(); + try { + Files.write(docPagePath, pageText.getBytes(charset)); + } catch (IOException e) { + throw new RuntimeException("Could not write to " + docPagePath, e); + } + } + + private static String loadSection(Path basePath, String fileName, Charset charset, String default_) { + Path p = basePath.resolve("src/main/doc/" + fileName); + if (Files.exists(p)) { + try { + return new String(Files.readAllBytes(p), charset); + } catch (IOException e) { + throw new RuntimeException("Could not read " + p, e); + } + } else { + return default_; + } + } + +} diff --git a/tooling/package-maven-plugin/src/main/resources/doc-templates/extension-doc-page.adoc b/tooling/package-maven-plugin/src/main/resources/doc-templates/extension-doc-page.adoc new file mode 100644 index 0000000..2ce6640 --- /dev/null +++ b/tooling/package-maven-plugin/src/main/resources/doc-templates/extension-doc-page.adoc @@ -0,0 +1,38 @@ +[[[=artifactIdBase]]] += [=name] + +*Since Camel Quarkus [=firstVersion], [=nativeSupported?then('JVM and native','JVM only')]* + +[=intro] + +== What's inside + +[#list models as model] +* https://camel.apache.org/[=model.kind]s/latest/[=model.name]-[=model.kind].html[[=model.title][#if model.kind != "other" ] [=humanReadableKind(model.kind)][/#if]][#if model.kind != "component" ], URI syntax: `[=model.syntax]`[/#if] +[/#list] + +Please refer to the above links for usage details. + +== Maven coordinates + +[source,xml] +---- +<dependency> + <groupId>org.apache.camel.quarkus</groupId> + <artifactId>camel-quarkus-[=artifactIdBase]</artifactId> +</dependency> +---- + +Check the xref:user-guide.adoc[User guide] for more information about writing Camel Quarkus applications. +[#if configuration?? ] + +== Configuration + +[=configuration] +[/#if] +[#if limitations?? ] + +== Limitations + +[=limitations] +[/#if] diff --git a/tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-components.ftl b/tooling/package-maven-plugin/src/main/resources/doc-templates/readme-components.ftl similarity index 100% rename from tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-components.ftl rename to tooling/package-maven-plugin/src/main/resources/doc-templates/readme-components.ftl diff --git a/tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-dataformats.ftl b/tooling/package-maven-plugin/src/main/resources/doc-templates/readme-dataformats.ftl similarity index 100% rename from tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-dataformats.ftl rename to tooling/package-maven-plugin/src/main/resources/doc-templates/readme-dataformats.ftl diff --git a/tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-languages.ftl b/tooling/package-maven-plugin/src/main/resources/doc-templates/readme-languages.ftl similarity index 100% rename from tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-languages.ftl rename to tooling/package-maven-plugin/src/main/resources/doc-templates/readme-languages.ftl diff --git a/tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-others.ftl b/tooling/package-maven-plugin/src/main/resources/doc-templates/readme-others.ftl similarity index 100% rename from tooling/package-maven-plugin/src/main/resources/extension-list-templates/readme-others.ftl rename to tooling/package-maven-plugin/src/main/resources/doc-templates/readme-others.ftl