Skip to content

Commit 99ae8e0

Browse files
committed
[MSITE-1000] Introduce parser configuration parameter
1 parent d78b8da commit 99ae8e0

File tree

5 files changed

+159
-2
lines changed

5 files changed

+159
-2
lines changed

pom.xml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ under the License.
199199
<!-- for dependencies -->
200200
<jettyVersion>9.4.53.v20231009</jettyVersion>
201201
<doxiaVersion>2.0.0-M8</doxiaVersion>
202-
<doxiaSitetoolsVersion>2.0.0-M16</doxiaSitetoolsVersion>
202+
<doxiaSitetoolsVersion>2.0.0-M17-SNAPSHOT</doxiaSitetoolsVersion>
203203
<wagonVersion>3.5.3</wagonVersion>
204204
<slf4jVersion>1.7.36</slf4jVersion>
205205
<!-- for ITs -->
@@ -513,6 +513,17 @@ under the License.
513513
<build>
514514
<pluginManagement>
515515
<plugins>
516+
<plugin>
517+
<groupId>org.apache.maven.plugins</groupId>
518+
<artifactId>maven-plugin-plugin</artifactId>
519+
<configuration>
520+
<externalJavadocBaseUrls>
521+
<externalJavadocBaseUrl>https://maven.apache.org/doxia/doxia/doxia-core/apidocs/</externalJavadocBaseUrl>
522+
<externalJavadocBaseUrl>https://maven.apache.org/doxia/doxia-sitetools/doxia-site-renderer/apidocs/</externalJavadocBaseUrl>
523+
<externalJavadocBaseUrl>https://docs.oracle.com/javase/8/docs/api/</externalJavadocBaseUrl>
524+
</externalJavadocBaseUrls>
525+
</configuration>
526+
</plugin>
516527
<plugin>
517528
<groupId>org.apache.maven.plugins</groupId>
518529
<artifactId>maven-plugin-report-plugin</artifactId>

src/main/java/org/apache/maven/plugins/site/render/AbstractSiteRenderingMojo.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,24 @@ public abstract class AbstractSiteRenderingMojo extends AbstractSiteDescriptorMo
9494
@Parameter
9595
private Map<String, Object> attributes;
9696

97+
/**
98+
* Parser configurations (per Doxia markup source file paths).
99+
* Each entry has the following format
100+
* <p/>
101+
* <pre>
102+
* &lt;patterns&gt;
103+
* &lt;pattern&gt;glob:**&#47;*.md&lt;/pattern&gt;&lt;!-- is either glob or regex syntax --&gt;
104+
* &lt;/patterns&gt;
105+
* &lt;emitComments&gt;true&lt;/emitComments&gt;&lt;!-- false by default --&gt;
106+
* &lt;emitAnchorsForIndexableEntries&gt;false&lt;/emitAnchorsForIndexableEntries&gt;&lt;!-- true by default --&gt;
107+
* </pre>
108+
*
109+
* @since 4.0.0
110+
* @see java.nio.file.FileSystem#getPathMatcher(String) FileSystem.getPathMatcher(String) for the supported patterns
111+
*/
112+
@Parameter
113+
private List<ParserConfiguration> parserConfigurations;
114+
97115
/**
98116
* Site renderer.
99117
*/
@@ -329,7 +347,7 @@ protected SiteRenderingContext createSiteRenderingContext(Locale locale)
329347
context.setProcessedContentOutput(processedDir);
330348
}
331349
}
332-
350+
context.setParserConfigurationRetriever(new ParserConfigurationRetrieverImpl(parserConfigurations));
333351
return context;
334352
}
335353

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.plugins.site.render;
20+
21+
import java.nio.file.FileSystem;
22+
import java.nio.file.Path;
23+
import java.nio.file.PathMatcher;
24+
import java.util.HashMap;
25+
import java.util.Map;
26+
import java.util.Map.Entry;
27+
import java.util.regex.Pattern;
28+
29+
import org.apache.maven.doxia.parser.Parser;
30+
31+
/** Configuration for a Doxia {@link Parser} (bound to a specific markup source path pattern) **/
32+
public class ParserConfiguration implements org.apache.maven.doxia.siterenderer.ParserConfiguration {
33+
34+
/**
35+
* Map of patterns and {@link PathMatcher}s.
36+
* The key contains the pattern in the format described at {@link FileSystem#getPathMatcher(String)}, i.e. {@code <syntax>:<pattern>}
37+
* where {@code <syntax} is either {@code glob} or {@code regex}. The value represents the according {@link PathMatcher} which is set
38+
* lazily.
39+
* If one of the patterns matches the file being parsed this configuration is applied.
40+
* @see FileSystem#getPathMatcher(String)
41+
* @see Pattern
42+
*/
43+
private final Map<String, PathMatcher> patterns;
44+
45+
/**
46+
* @see {@link Parser#setEmitComments(boolean)}
47+
*/
48+
private boolean emitComments;
49+
50+
/**
51+
* @see {@link Parser#setEmitAnchorsForIndexableEntries(boolean)}
52+
*/
53+
private boolean emitAnchorsForIndexableEntries;
54+
55+
public ParserConfiguration() {
56+
patterns = new HashMap<>();
57+
}
58+
59+
public void setEmitComments(boolean emitComments) {
60+
this.emitComments = emitComments;
61+
}
62+
63+
public void setEmitAnchorsForIndexableEntries(boolean emitAnchorsForIndexableEntries) {
64+
this.emitAnchorsForIndexableEntries = emitAnchorsForIndexableEntries;
65+
}
66+
67+
public void addPattern(String pattern) {
68+
patterns.put(pattern, null);
69+
}
70+
71+
public boolean matches(Path filePath) {
72+
for (Entry<String, PathMatcher> patternWithMatcher : patterns.entrySet()) {
73+
if (patternWithMatcher.getValue() == null) {
74+
patternWithMatcher.setValue(filePath.getFileSystem().getPathMatcher(patternWithMatcher.getKey()));
75+
}
76+
if (patternWithMatcher.getValue().matches(filePath)) {
77+
return true;
78+
}
79+
}
80+
return false;
81+
}
82+
83+
@Override
84+
public void accept(Parser parser) {
85+
parser.setEmitComments(emitComments);
86+
// parser.setEmitAnchorsForIndexableEntries(emitAnchorsForIndexableEntries);
87+
}
88+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
package org.apache.maven.plugins.site.render;
20+
21+
import java.nio.file.Path;
22+
import java.util.Collection;
23+
import java.util.Optional;
24+
25+
import org.apache.maven.doxia.siterenderer.ParserConfigurationRetriever;
26+
27+
public class ParserConfigurationRetrieverImpl implements ParserConfigurationRetriever {
28+
29+
private final Collection<ParserConfiguration> parserConfigurations;
30+
31+
public ParserConfigurationRetrieverImpl(Collection<ParserConfiguration> parserConfigurations) {
32+
this.parserConfigurations = parserConfigurations;
33+
}
34+
35+
@Override
36+
public Optional<ParserConfiguration> apply(Path filePath) {
37+
return parserConfigurations.stream().filter(c -> c.matches(filePath)).findFirst();
38+
}
39+
}

src/main/java/org/apache/maven/plugins/site/render/ReportDocumentRenderer.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@ public Sink createSink(File outputDirectory, String outputName) {
131131
docRenderingContext.getBasedirRelativePath(),
132132
document,
133133
docRenderingContext.getParserId(),
134+
docRenderingContext.getParserConfiguration(), // TODO: use another config?
134135
docRenderingContext.getExtension(),
135136
docRenderingContext.isEditable(),
136137
docRenderingContext.getGenerator());

0 commit comments

Comments
 (0)