in tooling/maven-plugin/src/main/java/org/apache/camel/quarkus/maven/UpdateExtensionDocPageMojo.java [104:309]
public void execute() throws MojoExecutionException, MojoFailureException {
if (skip) {
getLog().info("Skipping per user request");
return;
}
final Charset charset = Charset.forName(encoding);
final Path currentModuleDir = baseDir.toPath();
final Path runtimeModuleDir;
final Path deploymentModuleDir;
if ("runtime".equals(currentModuleDir.getFileName().toString())) {
deploymentModuleDir = currentModuleDir.getParent().resolve("deployment");
if (session.getAllProjects().stream()
.anyMatch(p -> p.getBasedir().toPath().equals(deploymentModuleDir))) {
getLog().info("Skipping the execution in " + project.getArtifactId() + " and postponing it to "
+ project.getArtifactId() + "-deployment");
return;
}
runtimeModuleDir = currentModuleDir;
} else if ("deployment".equals(currentModuleDir.getFileName().toString())) {
runtimeModuleDir = currentModuleDir.getParent().resolve("runtime");
deploymentModuleDir = currentModuleDir;
} else {
getLog().info("Skipping a module that is nether Quarkus extension runtime nor deployment module");
return;
}
final CqCatalog catalog = new CqCatalog();
final Path multiModuleProjectDirectoryPath = multiModuleProjectDirectory.toPath();
final CamelQuarkusExtension ext = CamelQuarkusExtension.read(runtimeModuleDir.resolve("pom.xml"));
final Path pomRelPath = multiModuleProjectDirectoryPath.relativize(runtimeModuleDir).resolve("pom.xml");
if (ext.getJvmSince().isEmpty()) {
throw new IllegalStateException(
CamelQuarkusExtension.CAMEL_QUARKUS_JVM_SINCE + " property must defined in " + pomRelPath);
}
final String extensionsDir = runtimeModuleDir.getParent().getParent().getFileName().toString();
if (!"extensions-jvm".equals(extensionsDir) && ext.getNativeSince().isEmpty()) {
throw new IllegalStateException(
CamelQuarkusExtension.CAMEL_QUARKUS_NATIVE_SINCE + " property must defined in " + pomRelPath);
}
final Configuration cfg = CqUtils.getTemplateConfig(runtimeModuleDir,
AbstractDocGeneratorMojo.DEFAULT_TEMPLATES_URI_BASE,
templatesUriBase, encoding);
final List<ArtifactModel<?>> models = catalog.filterModels(ext.getRuntimeArtifactIdBase())
.filter(SUPPORTED_MODEL_KIND_FILTER)
.filter(artifactModel -> !artifactModel.getArtifactId().equals("camel-management"))
.filter(artifactModel -> !artifactModel.getArtifactId().equals("camel-yaml-io"))
.sorted(BaseModel.compareTitle())
.collect(Collectors.toList());
final Map<String, Object> model = new HashMap<>();
model.put("artifactIdBase", ext.getRuntimeArtifactIdBase());
final String jvmSince = ext.getJvmSince().get();
model.put("firstVersion", jvmSince);
model.put("nativeSupported", ext.isNativeSupported());
final String title = ext.getName().get();
model.put("name", title);
final String description = CqUtils.getDescription(models, ext.getDescription().orElse(null), getLog());
model.put("description", description);
model.put("status", ext.getStatus().getCapitalized());
final boolean deprecated = CqUtils.isDeprecated(title, models, ext.isDeprecated());
model.put("statusDeprecation",
deprecated ? ext.getStatus().getCapitalized() + " Deprecated" : ext.getStatus().getCapitalized());
model.put("deprecated", deprecated);
model.put("unlisted", ext.isUnlisted());
model.put("jvmSince", jvmSince);
model.put("nativeSince", ext.getNativeSince().orElse("n/a"));
if (lowerEqual_1_0_0(jvmSince)) {
model.put("pageAliases", "extensions/" + ext.getRuntimeArtifactIdBase() + ".adoc");
}
model.put("intro", loadSection(runtimeModuleDir, "intro.adoc", charset, description, ext));
model.put("models", models);
model.put("usage", loadSection(runtimeModuleDir, "usage.adoc", charset, null, ext));
model.put("usageAdvanced", loadSection(runtimeModuleDir, "usage-advanced.adoc", charset, null, ext));
model.put("configuration", loadSection(runtimeModuleDir, "configuration.adoc", charset, null, ext));
model.put("limitations", loadSection(runtimeModuleDir, "limitations.adoc", charset, null, ext));
model.put("activatesNativeSsl", ext.isNativeSupported() && detectNativeSsl(multiModuleProjectDirectory.toPath(),
runtimeModuleDir, ext.getRuntimeArtifactId(), ext.getDependencies(), nativeSslActivators));
model.put("activatesContextMapAll",
ext.isNativeSupported()
&& detectComponentOrEndpointOption(catalog, ext.getRuntimeArtifactIdBase(), "allowContextMapAll"));
model.put("activatesTransferException",
ext.isNativeSupported()
&& detectComponentOrEndpointOption(catalog, ext.getRuntimeArtifactIdBase(), "transferException"));
model.put("activatesQuarkusLangChain4jBom", ext.getRuntimeArtifactId().contains("langchain4j"));
final List<ConfigItem> configOptions = listConfigOptions(
runtimeModuleDir,
deploymentModuleDir,
multiModuleProjectDirectory.toPath(),
ext.getRuntimeArtifactIdBase());
model.put("configOptions", configOptions);
model.put("hasDurationOption", configOptions.stream().anyMatch(ConfigItem::isTypeDuration));
model.put("hasMemSizeOption", configOptions.stream().anyMatch(ConfigItem::isTypeMemSize));
model.put("configOptions", configOptions);
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))));
}
});
model.put("camelBitLink", new TemplateMethodModelEx() {
@Override
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 2) {
throw new TemplateModelException("Wrong argument count in camelBitLink()");
}
final ArtifactModel<?> model = (ArtifactModel<?>) DeepUnwrap.unwrap((TemplateModel) arguments.get(0));
if (CqCatalog.isFirstScheme(model)) {
return camelBitLink(model);
} else {
final List<ArtifactModel<?>> models = (List<ArtifactModel<?>>) DeepUnwrap
.unwrap((TemplateModel) arguments.get(1));
final ArtifactModel<?> firstModel = CqCatalog.findFirstSchemeModel(model, models);
return camelBitLink(firstModel);
}
}
private String camelBitLink(ArtifactModel<?> model) {
model = CqCatalog.toCamelDocsModel(model);
final String kind = model.getKind().name();
String name = model.getName();
String xrefPrefix = "xref:{cq-camel-components}:" + (!"component".equals(kind) ? kind + "s:" : ":");
if (name.equals("xml-io-dsl")) {
name = "java-xml-io-dsl";
}
if (name.equals("console")) {
xrefPrefix = "xref:manual::";
name = "camel-console";
}
return xrefPrefix + name + (!"other".equals(kind) ? "-" + kind : "") + ".adoc";
}
});
model.put("toAnchor", new TemplateMethodModelEx() {
@Override
public Object exec(List arguments) throws TemplateModelException {
if (arguments.size() != 1) {
throw new TemplateModelException("Wrong argument count in toAnchor()");
}
String string = String.valueOf(arguments.get(0));
string = Normalizer.normalize(string, Normalizer.Form.NFKC)
.replaceAll("[àáâãäåāąă]", "a")
.replaceAll("[çćčĉċ]", "c")
.replaceAll("[ďđð]", "d")
.replaceAll("[èéêëēęěĕė]", "e")
.replaceAll("[ƒſ]", "f")
.replaceAll("[ĝğġģ]", "g")
.replaceAll("[ĥħ]", "h")
.replaceAll("[ìíîïīĩĭįı]", "i")
.replaceAll("[ijĵ]", "j")
.replaceAll("[ķĸ]", "k")
.replaceAll("[łľĺļŀ]", "l")
.replaceAll("[ñńňņʼnŋ]", "n")
.replaceAll("[òóôõöøōőŏœ]", "o")
.replaceAll("[Þþ]", "p")
.replaceAll("[ŕřŗ]", "r")
.replaceAll("[śšşŝș]", "s")
.replaceAll("[ťţŧț]", "t")
.replaceAll("[ùúûüūůűŭũų]", "u")
.replaceAll("[ŵ]", "w")
.replaceAll("[ýÿŷ]", "y")
.replaceAll("[žżź]", "z")
.replaceAll("[æ]", "ae")
.replaceAll("[ÀÁÂÃÄÅĀĄĂ]", "A")
.replaceAll("[ÇĆČĈĊ]", "C")
.replaceAll("[ĎĐÐ]", "D")
.replaceAll("[ÈÉÊËĒĘĚĔĖ]", "E")
.replaceAll("[ĜĞĠĢ]", "G")
.replaceAll("[ĤĦ]", "H")
.replaceAll("[ÌÍÎÏĪĨĬĮİ]", "I")
.replaceAll("[Ĵ]", "J")
.replaceAll("[Ķ]", "K")
.replaceAll("[ŁĽĹĻĿ]", "L")
.replaceAll("[ÑŃŇŅŊ]", "N")
.replaceAll("[ÒÓÔÕÖØŌŐŎ]", "O")
.replaceAll("[ŔŘŖ]", "R")
.replaceAll("[ŚŠŞŜȘ]", "S")
.replaceAll("[ÙÚÛÜŪŮŰŬŨŲ]", "U")
.replaceAll("[Ŵ]", "W")
.replaceAll("[ÝŶŸ]", "Y")
.replaceAll("[ŹŽŻ]", "Z")
.replaceAll("[ß]", "ss");
// Apostrophes.
string = string.replaceAll("([a-z])'s([^a-z])", "$1s$2");
// Allow only letters, -, _, .
string = string.replaceAll("[^\\w-_]", "-").replaceAll("-{2,}", "-");
// Get rid of any - at the start and end.
string = string.replaceAll("-+$", "").replaceAll("^-+", "");
return string.toLowerCase();
}
});
final Path docPagePath = multiModuleProjectDirectoryPath
.resolve("docs/modules/ROOT/pages/reference/extensions/" + ext.getRuntimeArtifactIdBase() + ".adoc");
evalTemplate(charset, docPagePath, cfg, model, "extension-doc-page.adoc", "//");
camelBits(charset, cfg, models, multiModuleProjectDirectoryPath, model);
}