attributes;
+ /**
+ * Parser configurations (per matching Doxia markup source file path patterns).
+ * Each configuration item has the following format:
+ *
+ *
+ * <patterns>
+ * <pattern>glob:**/*.md</pattern><!-- is either glob or regex syntax with the according prefix -->
+ * </patterns>
+ * <emitComments>true</emitComments><!-- false by default -->
+ * <emitAnchorsForIndexableEntries>false</emitAnchorsForIndexableEntries><!-- true by default -->
+ *
+ * The configuration is only applied if one of the given patterns matches the Doxia markup source file path.
+ * The first matching configuration wins (i.e. is applied).
+ * @since 4.0.0
+ * @see java.nio.file.FileSystem#getPathMatcher(String) FileSystem.getPathMatcher(String) for the supported patterns
+ */
+ @Parameter
+ private List parserConfigurations;
+
/**
* Site renderer.
*/
@@ -329,7 +348,7 @@ protected SiteRenderingContext createSiteRenderingContext(Locale locale)
context.setProcessedContentOutput(processedDir);
}
}
-
+ context.setParserConfigurationRetriever(new ParserConfigurationRetrieverImpl(parserConfigurations));
return context;
}
diff --git a/src/main/java/org/apache/maven/plugins/site/render/ParserConfiguration.java b/src/main/java/org/apache/maven/plugins/site/render/ParserConfiguration.java
new file mode 100644
index 00000000..c48abda9
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/site/render/ParserConfiguration.java
@@ -0,0 +1,119 @@
+/*
+ * 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.plugins.site.render;
+
+import java.nio.file.FileSystem;
+import java.nio.file.Path;
+import java.nio.file.PathMatcher;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+
+import org.apache.maven.doxia.parser.Parser;
+
+/** Configuration for a Doxia {@link Parser} (bound to a specific markup source path pattern)
+ * @since 4.0.0
+ **/
+public class ParserConfiguration implements org.apache.maven.doxia.siterenderer.ParserConfiguration {
+
+ /**
+ * List of patterns in the format described at {@link FileSystem#getPathMatcher(String)}, i.e. {@code :}
+ * where {@code patterns;
+
+ /**
+ * List of {@link PathMatcher}s for all of the {@link #patterns}. Lazily populated via {@link FileSystem#getPathMatcher(String)}.
+ */
+ private List matchers;
+
+ private boolean emitComments;
+
+ private boolean emitAnchorsForIndexableEntries;
+
+ public ParserConfiguration() {
+ patterns = new LinkedList<>();
+ matchers = null;
+ }
+
+ /**
+ * Switches the feature {@link Parser#setEmitComments(boolean)} either on or off.
+ * Default (for Doxia Sitetools) is off.
+ *
+ * @param emitComments {@code true} to switch it on, otherwise leave it off
+ * @see Parser#setEmitComments(boolean)
+ */
+ public void setEmitComments(boolean emitComments) {
+ this.emitComments = emitComments;
+ }
+
+ /**
+ * Switches the feature {@link Parser#setEmitAnchorsForIndexableEntries(boolean)} either on or off.
+ * Default (for Doxia Sitetools) is on.
+ *
+ * @param emitAnchorsForIndexableEntries {@code true} to switch it on, otherwise leave it off
+ * @see Parser#setEmitAnchorsForIndexableEntries(boolean)
+ */
+ public void setEmitAnchorsForIndexableEntries(boolean emitAnchorsForIndexableEntries) {
+ this.emitAnchorsForIndexableEntries = emitAnchorsForIndexableEntries;
+ }
+
+ /**
+ * A pattern in the format described at {@link FileSystem#getPathMatcher(String)}, i.e. {@code :}
+ * where {@code filePath.getFileSystem().getPathMatcher(p))
+ .collect(Collectors.toList());
+ }
+ return matchers.stream().anyMatch(m -> m.matches(filePath));
+ }
+
+ @Override
+ public void configure(Parser parser) {
+ parser.setEmitComments(emitComments);
+ parser.setEmitAnchorsForIndexableEntries(emitAnchorsForIndexableEntries);
+ }
+}
diff --git a/src/main/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImpl.java b/src/main/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImpl.java
new file mode 100644
index 00000000..93765951
--- /dev/null
+++ b/src/main/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImpl.java
@@ -0,0 +1,42 @@
+/*
+ * 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.plugins.site.render;
+
+import java.nio.file.Path;
+import java.util.Collection;
+import java.util.Optional;
+
+import org.apache.maven.doxia.siterenderer.ParserConfigurationRetriever;
+
+public class ParserConfigurationRetrieverImpl implements ParserConfigurationRetriever {
+
+ private final Collection parserConfigurations;
+
+ public ParserConfigurationRetrieverImpl(Collection parserConfigurations) {
+ this.parserConfigurations = parserConfigurations;
+ }
+
+ @Override
+ public Optional retrieve(Path filePath) {
+ return parserConfigurations.stream()
+ .filter(c -> c.matches(filePath))
+ .findFirst()
+ .map(c -> c);
+ }
+}
diff --git a/src/test/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImplTest.java b/src/test/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImplTest.java
new file mode 100644
index 00000000..df80ea16
--- /dev/null
+++ b/src/test/java/org/apache/maven/plugins/site/render/ParserConfigurationRetrieverImplTest.java
@@ -0,0 +1,88 @@
+/*
+ * 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.plugins.site.render;
+
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.Optional;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertThrows;
+
+public class ParserConfigurationRetrieverImplTest {
+
+ @Test
+ public void testEmptyConfigurations() {
+ ParserConfiguration config1 = new ParserConfiguration();
+ ParserConfiguration config2 = new ParserConfiguration();
+ assertEquals(
+ Optional.empty(),
+ new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
+ .retrieve(Paths.get("some", "file")));
+ }
+
+ @Test
+ public void testConfigurationWithInvalidPattern() {
+ ParserConfiguration config1 = new ParserConfiguration();
+ config1.addPattern("invalidprefix:*");
+ ParserConfigurationRetrieverImpl parserConfigurationRetrieverImpl =
+ new ParserConfigurationRetrieverImpl(Arrays.asList(config1));
+ assertThrows(RuntimeException.class, () -> {
+ parserConfigurationRetrieverImpl.retrieve(Paths.get("some", "file"));
+ });
+ }
+
+ @Test
+ public void testNonMatchingConfigurations() {
+ ParserConfiguration config1 = new ParserConfiguration();
+ config1.addPattern("glob:**/*.md");
+ ParserConfiguration config2 = new ParserConfiguration();
+ config2.addPattern("regex:.*\\.apt");
+ assertEquals(
+ Optional.empty(),
+ new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
+ .retrieve(Paths.get("some", "file")));
+ }
+
+ @Test
+ public void testNonOverlappingConfigurations() {
+ ParserConfiguration config1 = new ParserConfiguration();
+ config1.addPattern("regex:.*\\.apt");
+ ParserConfiguration config2 = new ParserConfiguration();
+ config2.addPattern("glob:**/*");
+ assertEquals(
+ Optional.of(config2),
+ new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
+ .retrieve(Paths.get("some", "file")));
+ }
+
+ @Test
+ public void testOverlappingConfigurations() {
+ ParserConfiguration config1 = new ParserConfiguration();
+ config1.addPattern("glob:**/*");
+ ParserConfiguration config2 = new ParserConfiguration();
+ config2.addPattern("regex:.*");
+ assertEquals(
+ Optional.of(config1),
+ new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
+ .retrieve(Paths.get("some", "file")));
+ }
+}