apache / apache/maven-site-plugin

[MSITE-869] Options to preprocess site sources and resources through Maven filtering

Open
#1,003 10 comments 0 reactions 0 assignees View on GitHub
enhancement help wanted priority:major
Dominant language
Java
Stars
55
Forks
50
Avg merge
2d 7h
Merged PRs (30d)
11

Description

**[Bertrand Martin](https://issues.apache.org/jira/secure/ViewProfile.jspa?name=bertrandmartin)** opened **[MSITE-869](https://issues.apache.org/jira/browse/MSITE-869?redirect=false)** and commented

# Use Case

User has source files or resources files where Maven properties like ${project.version} or ${project.name} need to be replaced with their actual value.

Examples:
* a [REST API specification](https://swagger.io/specification/) in **src/site/resource/openapi.yaml**
* the title of a Markdown document describing the project (like [Maven Site Plugin](https://maven.apache.org/plugins/maven-site-plugin/index.html)'s own documentation)

# Workaround

Usually, [it is recommended to add the .vm suffix](https://stackoverflow.com/questions/7111000/resource-filtering-with-maven-site-plugin) to the files that need filtering, so that they are processed as a Velocity template.

But this workaround has several drawbacks:
* [Velocity and Markdown formats are highly incompatible](https://github.com/apache/maven-archetypes/blob/master/maven-archetype-plugin-site/src/main/resources/archetype-resources/src/site/markdown/markdown-velocity.md.vm) because of the headings format
* Velocity has 1000 times more features than just filtering, which is great, but also which can unexpectedly conflict with source files and with resource files (which may be from external sources, like JS libraries, YAML, etc.)
* .vm files are handled as Velocity templates in most code editors (VSCode, etc.), which prevents any other advanced features from working (especially on openapi.yaml, where you can have linting, validation, autosuggest, etc.)

Basically, Velocity templates is a great feature that needs to stay, but it's overkill for just replacing ${project.version} in a bunch of files.

# Specifications

Add options to filter site source files and resource files:
* `boolean sourceFiltering` (default: false)
* `boolean resourceFiltering` (default: false)
* `List nonFilteredFileExtensions` (default: jpg, jpeg, gif, bmp, png)
* `boolean fileNameFiltering` (default: false)

Use Maven's filtering component:

```java
@Component(role = MavenResourcesFiltering.class, hint = "default")
private MavenResourcesFiltering mavenResourcesFiltering;
```

.vm files don't need to be filtered. There are therefore 3 cases:
* no filtering
* simple filtering (like [Maven Resource Plugin](https://maven.apache.org/plugins/maven-resources-plugin/examples/filter.html))
* advanced templating

---

**Issue Links:**
- [DOXIA-677](https://issues.apache.org/jira/browse/DOXIA-677) Macro for printing project properties
(_**"duplicates"**_)

**Backported to:** [wontfix-candidate](https://github.com/apache/maven-site-plugin/milestone/53?closed=1)

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by tracing how site source files and resource files are processed, then examine the specified MavenResourcesFiltering component and the example src/site/resource/openapi.yaml. Done means supporting the requested sourceFiltering, resourceFiltering, nonFilteredFileExtensions, and fileNameFiltering options while preserving the existing .vm templating behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
build-system
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.