Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
kwin committed Jan 8, 2024
1 parent 8a87442 commit 2da5f8c
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 18 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ under the License.
<javaVersion>8</javaVersion>
<!-- for dependencies -->
<jettyVersion>9.4.53.v20231009</jettyVersion>
<doxiaVersion>2.0.0-M8</doxiaVersion>
<doxiaVersion>2.0.0-M9-SNAPSHOT</doxiaVersion>
<doxiaSitetoolsVersion>2.0.0-M17-SNAPSHOT</doxiaSitetoolsVersion>
<wagonVersion>3.5.3</wagonVersion>
<slf4jVersion>1.7.36</slf4jVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,17 +95,18 @@ public abstract class AbstractSiteRenderingMojo extends AbstractSiteDescriptorMo
private Map<String, Object> attributes;

/**
* Parser configurations (per Doxia markup source file paths).
* Each entry has the following format
* Parser configurations (per matching Doxia markup source file path patterns).
* Each configuration item has the following format:
* <p/>
* <pre>
* &lt;patterns&gt;
* &lt;pattern&gt;glob:**&#47;*.md&lt;/pattern&gt;&lt;!-- is either glob or regex syntax --&gt;
* &lt;pattern&gt;glob:**&#47;*.md&lt;/pattern&gt;&lt;!-- is either glob or regex syntax with the according prefix --&gt;
* &lt;/patterns&gt;
* &lt;emitComments&gt;true&lt;/emitComments&gt;&lt;!-- false by default --&gt;
* &lt;emitAnchorsForIndexableEntries&gt;false&lt;/emitAnchorsForIndexableEntries&gt;&lt;!-- true by default --&gt;
* </pre>
*
* 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
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@

import org.apache.maven.doxia.parser.Parser;

/** Configuration for a Doxia {@link Parser} (bound to a specific markup source path pattern) **/
/** 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 {

/**
Expand Down Expand Up @@ -56,7 +58,7 @@ public ParserConfiguration() {

/**
* Switches the feature {@link Parser#setEmitComments(boolean)} either on or off.
* Default is off.
* Default (for Doxia Sitetools) is off.
*
* @param emitComments {@code true} to switch it on, otherwise leave it off
* @see Parser#setEmitComments(boolean)
Expand All @@ -67,7 +69,7 @@ public void setEmitComments(boolean emitComments) {

/**
* Switches the feature {@link Parser#setEmitAnchorsForIndexableEntries(boolean)} either on or off.
* Default is on.
* Default (for Doxia Sitetools) is on.
*
* @param emitAnchorsForIndexableEntries {@code true} to switch it on, otherwise leave it off
* @see Parser#setEmitAnchorsForIndexableEntries(boolean)
Expand Down Expand Up @@ -110,8 +112,8 @@ public boolean matches(Path filePath) {
}

@Override
public void accept(Parser parser) {
public void configure(Parser parser) {
parser.setEmitComments(emitComments);
// parser.setEmitAnchorsForIndexableEntries(emitAnchorsForIndexableEntries);
parser.setEmitAnchorsForIndexableEntries(emitAnchorsForIndexableEntries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ public ParserConfigurationRetrieverImpl(Collection<ParserConfiguration> parserCo
}

@Override
public Optional<ParserConfiguration> apply(Path filePath) {
return parserConfigurations.stream().filter(c -> c.matches(filePath)).findFirst();
public Optional<org.apache.maven.doxia.siterenderer.ParserConfiguration> retrieve(Path filePath) {
return parserConfigurations.stream()
.filter(c -> c.matches(filePath))
.findFirst()
.map(c -> c);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ public Sink createSink(File outputDirectory, String outputName) {
docRenderingContext.getBasedirRelativePath(),
document,
docRenderingContext.getParserId(),
docRenderingContext.getParserConfiguration(), // TODO: use another config?
docRenderingContext.getExtension(),
docRenderingContext.isEditable(),
docRenderingContext.getGenerator());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ public void testEmptyConfigurations() {
ParserConfiguration config2 = new ParserConfiguration();
assertEquals(
Optional.empty(),
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2)).apply(Paths.get("some", "file")));
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
.retrieve(Paths.get("some", "file")));
}

@Test
Expand All @@ -45,7 +46,7 @@ public void testConfigurationWithInvalidPattern() {
ParserConfigurationRetrieverImpl parserConfigurationRetrieverImpl =
new ParserConfigurationRetrieverImpl(Arrays.asList(config1));
assertThrows(RuntimeException.class, () -> {
parserConfigurationRetrieverImpl.apply(Paths.get("some", "file"));
parserConfigurationRetrieverImpl.retrieve(Paths.get("some", "file"));
});
}

Expand All @@ -57,7 +58,8 @@ public void testNonMatchingConfigurations() {
config2.addPattern("regex:.*\\.apt");
assertEquals(
Optional.empty(),
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2)).apply(Paths.get("some", "file")));
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
.retrieve(Paths.get("some", "file")));
}

@Test
Expand All @@ -68,7 +70,8 @@ public void testNonOverlappingConfigurations() {
config2.addPattern("glob:**/*");
assertEquals(
Optional.of(config2),
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2)).apply(Paths.get("some", "file")));
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
.retrieve(Paths.get("some", "file")));
}

@Test
Expand All @@ -79,6 +82,7 @@ public void testOverlappingConfigurations() {
config2.addPattern("regex:.*");
assertEquals(
Optional.of(config1),
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2)).apply(Paths.get("some", "file")));
new ParserConfigurationRetrieverImpl(Arrays.asList(config1, config2))
.retrieve(Paths.get("some", "file")));
}
}

0 comments on commit 2da5f8c

Please sign in to comment.