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:22:04 UTC

(maven-doxia-sitetools) branch feature/configure-with-plexus-configurator updated (891592d -> adc2018)

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


    omit 891592d  [DOXIASITETOOLS-324] Allow configuration of parsers
     new adc2018  [DOXIASITETOOLS-324] Allow configuration of parsers

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (891592d)
            \
             N -- N -- N   refs/heads/feature/configure-with-plexus-configurator (adc2018)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

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.


Summary of changes:
 .../java/org/apache/maven/doxia/siterenderer/DefaultSiteRenderer.java   | 1 -
 .../java/org/apache/maven/doxia/siterenderer/ParserConfigurator.java    | 2 +-
 2 files changed, 1 insertion(+), 2 deletions(-)


(maven-doxia-sitetools) 01/01: [DOXIASITETOOLS-324] Allow configuration 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 adc20189c7cb7cc890d3aecf0fe05022d5977379
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Mar 20 17:07:35 2024 +0100

    [DOXIASITETOOLS-324] Allow configuration of parsers
    
    Introduce interface ParserConfigurator which can be passed to
    SiteRenderingContext
---
 .../doxia/siterenderer/DefaultSiteRenderer.java    | 13 ++++++--
 .../doxia/siterenderer/ParserConfigurator.java     | 38 ++++++++++++++++++++++
 .../doxia/siterenderer/SiteRenderingContext.java   | 20 ++++++++++++
 3 files changed, 68 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..cfec91a 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
@@ -320,9 +320,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..4475da7
--- /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 source file with the given path.
+     * @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;
+    }
 }