You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kw...@apache.org on 2024/01/04 10:53:19 UTC
(maven-doxia-sitetools) branch feature/configure-parser created (now 8537db0)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch feature/configure-parser
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
at 8537db0 [DOXIASITETOOLS-324] Allow configuration of Doxia parser
This branch includes the following new commits:
new 8537db0 [DOXIASITETOOLS-324] Allow configuration of Doxia parser
The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
(maven-doxia-sitetools) 01/01: [DOXIASITETOOLS-324] Allow configuration of Doxia parser
Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a commit to branch feature/configure-parser
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 8537db01d9449460036e1c9e33262bf95ced8270
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Thu Jan 4 11:53:12 2024 +0100
[DOXIASITETOOLS-324] Allow configuration of Doxia parser
---
.../doxia/siterenderer/DefaultSiteRenderer.java | 31 +++++++++++++---
.../siterenderer/DocumentRenderingContext.java | 42 ++++++++++++++++++++++
.../doxia/siterenderer/ParserConfiguration.java | 37 +++++++++++++++++++
.../siterenderer/ParserConfigurationRetriever.java | 39 ++++++++++++++++++++
.../doxia/siterenderer/SiteRenderingContext.java | 19 ++++++++++
5 files changed, 163 insertions(+), 5 deletions(-)
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
index 9c532ac..c80a653 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java
@@ -168,7 +168,13 @@ public class DefaultSiteRenderer implements Renderer {
String excludes = (moduleExcludes == null) ? null : moduleExcludes.get(module.getParserId());
addModuleFiles(
- siteRenderingContext.getRootDirectory(), moduleBasedir, module, excludes, files, editable);
+ siteRenderingContext.getParserConfigurationRetriever(),
+ siteRenderingContext.getRootDirectory(),
+ moduleBasedir,
+ module,
+ excludes,
+ files,
+ editable);
}
}
}
@@ -190,6 +196,7 @@ public class DefaultSiteRenderer implements Renderer {
}
private void addModuleFiles(
+ ParserConfigurationRetriever parserConfigurationRetriever,
File rootDir,
File moduleBasedir,
ParserModule module,
@@ -217,8 +224,18 @@ public class DefaultSiteRenderer implements Renderer {
docs.addAll(velocityFiles);
for (String doc : docs) {
+ ParserConfiguration parserConfiguration = parserConfigurationRetriever
+ .apply(moduleBasedir.toPath().resolve(doc))
+ .orElse(null);
DocumentRenderingContext docRenderingContext = new DocumentRenderingContext(
- moduleBasedir, moduleRelativePath, doc, module.getParserId(), extension, editable);
+ moduleBasedir,
+ moduleRelativePath,
+ doc,
+ module.getParserId(),
+ parserConfiguration,
+ extension,
+ editable,
+ null);
// TODO: DOXIA-111: we need a general filter here that knows how to alter the context
if (endsWithIgnoreCase(doc, ".vm")) {
@@ -320,9 +337,13 @@ public class DefaultSiteRenderer implements Renderer {
String resource = doc.getAbsolutePath();
Parser parser = doxia.getParser(docRenderingContext.getParserId());
- // DOXIASITETOOLS-146 don't render comments from source markup
- parser.setEmitComments(false);
-
+ ParserConfiguration parserConfiguration = docRenderingContext.getParserConfiguration();
+ if (parserConfiguration != null) {
+ parserConfiguration.accept(parser);
+ } else {
+ // DOXIASITETOOLS-146 don't render comments from source markup
+ parser.setEmitComments(false);
+ }
// TODO: DOXIA-111: the filter used here must be checked generally.
if (docRenderingContext.getAttribute("velocity") != null) {
LOGGER.debug("Processing Velocity for " + docRenderingContext.getDoxiaSourcePath());
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DocumentRenderingContext.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DocumentRenderingContext.java
index b176c83..a8bd267 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DocumentRenderingContext.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/DocumentRenderingContext.java
@@ -42,6 +42,8 @@ public class DocumentRenderingContext {
private final String parserId;
+ private final ParserConfiguration parserConfiguration;
+
private final String relativePath;
private final String extension;
@@ -101,8 +103,39 @@ public class DocumentRenderingContext {
String extension,
boolean editable,
String generator) {
+ this(basedir, basedirRelativePath, document, parserId, null, extension, editable, generator);
+ }
+
+ /**
+ * <p>
+ * Constructor for document rendering context.
+ * </p>
+ *
+ * @param basedir the source base directory (not null, pseudo value when not a Doxia source).
+ * @param basedirRelativePath the relative path from root (null if not Doxia source)
+ * @param document the source document path.
+ * @param parserId the Doxia module parser id associated to this document, may be null if document not rendered from
+ * a Doxia markup source.
+ * @param parserConfiguration the configuration to use for the Doxia parser, may be {@null} if default should be used or if
+ * document is not rendered from a Doxia markup source
+ * @param extension the source document filename extension, may be null if document not rendered from
+ * a Doxia source.
+ * @param editable is the document editable as source, i.e. not generated?
+ * @param generator the generator (in general a reporting goal: <code>groupId:artifactId:version:goal</code>)
+ * @since 2.0
+ */
+ public DocumentRenderingContext(
+ File basedir,
+ String basedirRelativePath,
+ String document,
+ String parserId,
+ ParserConfiguration parserConfiguration,
+ String extension,
+ boolean editable,
+ String generator) {
this.basedir = basedir;
this.parserId = parserId;
+ this.parserConfiguration = parserConfiguration;
this.extension = extension;
this.generator = generator;
this.attributes = new HashMap<>();
@@ -286,4 +319,13 @@ public class DocumentRenderingContext {
public String getDoxiaSourcePath(String base) {
return PathTool.calculateLink(getDoxiaSourcePath(), base);
}
+
+ /**
+ * Get the configuration to use for the parsing the document or {@code null} if the default configuration should be used (or if this context
+ * is not for a Doxia markup source, i.e. not parsing is involved).
+ * @return the parser configuration or {@code null}.
+ */
+ public ParserConfiguration getParserConfiguration() {
+ return parserConfiguration;
+ }
}
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfiguration.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfiguration.java
new file mode 100644
index 0000000..f506528
--- /dev/null
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfiguration.java
@@ -0,0 +1,37 @@
+/*
+ * 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.maven.doxia.siterenderer;
+
+import java.util.function.Consumer;
+
+import org.apache.maven.doxia.parser.Parser;
+
+/**
+ * Configures a Doxia {@link Parser}.
+ * @since 2.0.0
+ */
+@FunctionalInterface
+public interface ParserConfiguration extends Consumer<Parser> {
+
+ /**
+ * Applies the configuration to the given parser
+ */
+ @Override
+ void accept(Parser t);
+}
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurationRetriever.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurationRetriever.java
new file mode 100644
index 0000000..fd45748
--- /dev/null
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurationRetriever.java
@@ -0,0 +1,39 @@
+/*
+ * 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.maven.doxia.siterenderer;
+
+import java.nio.file.Path;
+import java.util.Optional;
+import java.util.function.Function;
+
+/**
+ * Retrieves a {@link ParserConfiguration} for a particular Doxia markup source path.
+ * @since 2.0.0
+ */
+@FunctionalInterface
+public interface ParserConfigurationRetriever extends Function<Path, Optional<? extends ParserConfiguration>> {
+
+ /**
+ * Retrieves the parser configuration applicable for the given path
+ * @param filePath the source file path
+ * @param
+ */
+ @Override
+ Optional<? extends ParserConfiguration> apply(Path filePath);
+}
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
index 12733d0..9d4840e 100644
--- a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/SiteRenderingContext.java
@@ -25,6 +25,7 @@ import java.util.Date;
import java.util.List;
import java.util.Locale;
import java.util.Map;
+import java.util.Optional;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.doxia.site.SiteModel;
@@ -72,6 +73,8 @@ public class SiteRenderingContext {
private File processedContentOutput;
+ private ParserConfigurationRetriever parserConfigurationRetriever;
+
/**
* If input documents should be validated before parsing.
* By default no validation is performed.
@@ -388,4 +391,20 @@ public class SiteRenderingContext {
public void setRootDirectory(File rootDirectory) {
this.rootDirectory = rootDirectory;
}
+
+ /**
+ *
+ * @return the retriever for parser configurations (only relevant for Doxia sources)
+ * @since 2.0.0
+ */
+ public ParserConfigurationRetriever getParserConfigurationRetriever() {
+ if (parserConfigurationRetriever == null) {
+ return p -> Optional.empty();
+ }
+ return parserConfigurationRetriever;
+ }
+
+ public void setParserConfigurationRetriever(ParserConfigurationRetriever parserConfigurationRetriever) {
+ this.parserConfigurationRetriever = parserConfigurationRetriever;
+ }
}