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/03/20 16:07:45 UTC
(maven-doxia-sitetools) branch feature/configure-with-plexus-configurator created (now 0c1d1a9)
This is an automated email from the ASF dual-hosted git repository.
kwin pushed a change to branch feature/configure-with-plexus-configurator
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
at 0c1d1a9 [MSITE-1000] Allow parametrisation of parsers
This branch includes the following new commits:
new 0c1d1a9 [MSITE-1000] Allow parametrisation of parsers
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: [MSITE-1000] Allow parametrisation of parsers
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-with-plexus-configurator
in repository https://gitbox.apache.org/repos/asf/maven-doxia-sitetools.git
commit 0c1d1a90ab0c2a09d374dba4dc83c0ee9ee479c8
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Mar 20 17:07:35 2024 +0100
[MSITE-1000] Allow parametrisation of parsers
Introduce interface ParserConfigurator which can be passed to
SiteRenderingContext
---
.../doxia/siterenderer/DefaultSiteRenderer.java | 14 ++++++--
.../doxia/siterenderer/ParserConfigurator.java | 38 ++++++++++++++++++++++
.../doxia/siterenderer/SiteRenderingContext.java | 20 ++++++++++++
3 files changed, 69 insertions(+), 3 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 c37562e..8db7382 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
@@ -33,6 +33,7 @@ import java.io.StringWriter;
import java.io.Writer;
import java.net.URL;
import java.net.URLClassLoader;
+import java.nio.file.Paths;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
@@ -320,9 +321,16 @@ 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);
- parser.setEmitAnchorsForIndexableEntries(true);
+ ParserConfigurator configurator = siteContext.getParserConfigurator();
+ boolean isConfigured = false;
+ if (configurator != null) {
+ isConfigured = configurator.configure(docRenderingContext.getParserId(), doc.toPath(), parser);
+ }
+ if (!isConfigured) {
+ // DOXIASITETOOLS-146 don't render comments from source markup
+ parser.setEmitComments(false);
+ parser.setEmitAnchorsForIndexableEntries(true);
+ }
// TODO: DOXIA-111: the filter used here must be checked generally.
if (docRenderingContext.getAttribute("velocity") != null) {
diff --git a/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurator.java b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurator.java
new file mode 100644
index 0000000..d7ac268
--- /dev/null
+++ b/doxia-site-renderer/src/main/java/org/apache/maven/doxia/siterenderer/ParserConfigurator.java
@@ -0,0 +1,38 @@
+/*
+ * 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 org.apache.maven.doxia.parser.Parser;
+
+/**
+ * Interface which allows to configure a particular {@link Parser} before it is being used.
+ */
+public interface ParserConfigurator {
+
+ /**
+ * Configures the given parser, which is afterwards used to parse the given source file.
+ * @param parserId the parser id
+ * @param filePath the absolute path of the file to parse
+ * @param parser the parser to configure
+ * @return {@code true} if the parser has been configured, otherwise {@code false}
+ */
+ boolean configure(String parserId, Path filePath, Parser parser);
+}
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..73561a3 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
@@ -72,6 +72,8 @@ public class SiteRenderingContext {
private File processedContentOutput;
+ private ParserConfigurator parserConfigurator;
+
/**
* If input documents should be validated before parsing.
* By default no validation is performed.
@@ -388,4 +390,22 @@ public class SiteRenderingContext {
public void setRootDirectory(File rootDirectory) {
this.rootDirectory = rootDirectory;
}
+
+ /**
+ * Return the configurator for {@link Parser} objects.
+ * @return the parser configurator (may be {@code null}) in which case the default configuration is applied
+ * @since 4.0
+ */
+ public ParserConfigurator getParserConfigurator() {
+ return parserConfigurator;
+ }
+
+ /**
+ * Set the configurator to use for parsers.
+ * @param parserConfigurator
+ * @since 4.0
+ */
+ public void setParserConfigurator(ParserConfigurator parserConfigurator) {
+ this.parserConfigurator = parserConfigurator;
+ }
}