GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: support glob patterns in filter file paths by gnodet · Pull Request #400 · apache/maven-filtering

Conversation

@gnodet

@gnodet gnodet commented Sep 24, 2026

Copy link
Copy Markdown
Contributor

Summary

Maven's <filters> configuration only accepts literal file paths. When a project has many environment-specific property files under a common directory (e.g. env/dev/), users must enumerate each file individually — even when the set is dynamic or grows over time.

This PR adds glob pattern support to filter file paths, allowing configurations like:

<filters>
  <filter>env/dev/*.properties</filter>
</filters>

Root Cause

BaseFilter.loadProperties() passes each filter path directly to FilteringUtils.resolveFile(), which treats it as a literal file system path. No glob expansion is performed.

Fix

Added glob detection (*, ?, {, [ characters) and expansion via java.nio.file.Files.walk() + PathMatcher in BaseFilter.loadProperties():

  • Glob patterns are expanded to matching files, sorted for reproducibility
  • Each matched file is loaded in turn (same property inheritance semantics as explicit paths)
  • A glob that matches no files emits a WARN rather than failing the build, since the absence of environment-specific files can be intentional
  • Literal paths (no glob characters) are unchanged — fully backward-compatible

Tests

Three new unit tests in DefaultMavenFileFilterTest:

  • globFilterFilesMatchMultipleFiles: a **/*.properties glob loads all matched files
  • globFilterFilesScopedToSubdirectory: a directory-scoped glob does not bleed into sibling directories
  • globFilterFilesNoMatchEmitsWarning: a non-matching glob emits a warning and loads nothing

Fixes #254

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet
gnodet marked this pull request as ready for review September 24, 2026 21:28
gnodet-bot
gnodet-bot reviewed Sep 25, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice feature — glob support for filter file paths is a useful addition. I have a few concerns around security, backward compatibility, and minor code style.

Security: path traversal via .. in glob prefix

FilteringUtils.resolveFile() calls baseFile.resolve(filename).toAbsolutePath().normalize() — it happily resolves .. segments but never checks that the result stays within basedir. A filter like ../../../etc/*.properties would walk and load properties files from /etc/ (or wherever .. leads). Since filter file paths can come from POM <filters> which may be pulled from parent POMs or profiles, this should be constrained. The fix is to verify searchRoot.startsWith(basedir.toAbsolutePath().normalize()) and reject or warn if it escapes.

Backward compatibility: literal filenames with glob metacharacters

File names like filter[1].properties, cache.{backup}.properties, or what?.properties are legal on Unix. This change silently reinterprets them as glob patterns, which is a breaking change. Consider:

  • Adding escaping guidance in the Javadoc
  • Or only opting in to glob mode when an explicit glob: prefix is used (similar to PathMatcher's own convention)
  • Or falling back to literal loading when the glob matches nothing and a literal file exists at that path

Minor: Files.walk() depth

Files.walk() without a maxDepth will recurse arbitrarily deep. For patterns like env/dev/*.properties (single *), the glob only matches one level deep but the walker traverses the entire subtree. Consider passing a maxDepth derived from the pattern's remaining segments to avoid unnecessary I/O on large directory trees.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot approved these changes Sep 25, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-reviewed after commit 9d1e0cd. All three findings from the previous review are addressed:

  1. Path traversal guard — ✅ searchRoot.startsWith(normalizedBase) check added with IOException on escape. Files.walk() does not follow symlinks by default, so symlink-based traversal is also not a concern.
  2. Backward-compat fallback — ✅ When the glob matches nothing, the code falls back to loading the path as a literal file if it exists (handles filter[1].properties correctly).
  3. Parameterized logging — ✅ Switched to SLF4J {} placeholder. Test assertion updated accordingly.

No new issues introduced by the fix commit. Solid.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
gnodet-bot
gnodet-bot reviewed Sep 25, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after 9d1e0cd — all three previous findings are addressed:

Finding Status
Path traversal guard ✅ Fixed — searchRoot.startsWith(normalizedBase) check added
Backward-compat fallback for literal filenames with glob chars ✅ Fixed — falls back to literal path when glob matches nothing
Parameterized logging ✅ Fixed — uses '{}' placeholder

Two minor items remain below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot reviewed Sep 25, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after 21f72b5 — the InvalidPathException handling for Windows is solid. Two items from the previous review remain unaddressed.

Previous Finding Status
InvalidPathException on Windows in backward-compat fallback ✅ Fixed — try/catch around resolveFile() with appropriate fallback to warn
Javadoc {@code {} syntax ❌ Not addressed (see inline)
Files.walk() unbounded depth ❌ Not addressed (see inline)

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread src/main/java/org/apache/maven/shared/filtering/BaseFilter.java Resolved

Uh oh!

There was an error while loading. Please reload this page.

gnodet-bot
gnodet-bot approved these changes Sep 25, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after 7f75651 — both remaining items from the previous review are now addressed:

Finding Status
Javadoc {@code {} broken syntax ✅ Fixed — uses <code>{</code>
Files.walk() unbounded depth ✅ Fixed — maxDepth derived from pattern suffix (1 for flat globs, MAX_VALUE for ** or multi-segment)

All five findings across three review rounds are resolved. Code is solid.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
slawekjaranowski
slawekjaranowski approved these changes Sep 26, 2026
View reviewed changes
@gnodet gnodet added enhancement New feature or request java Pull requests that update Java code labels Sep 26, 2026
@gnodet
gnodet force-pushed the fix/254-glob-filter-files branch from 7f75651 to 05608dd Compare September 26, 2026 17:08
gnodet-bot
gnodet-bot approved these changes Sep 26, 2026
View reviewed changes

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Re-review after rebase-squash (05608dd) — the multi-commit history has been squashed into a single clean commit. The glob-support code in BaseFilter.java and the three test cases in DefaultMavenFileFilterTest.java are identical to the previously approved state. All five findings from the three prior review rounds remain addressed.

No new issues.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@gnodet
feat: support glob patterns in filter file paths (MRESOURCES-254)
6f57f03
- Add glob pattern expansion in BaseFilter.loadProperties() via java.nio.file.Files.walk() + PathMatcher
- Patterns containing *, ?, {, [ are expanded to matching files sorted for reproducibility
- Non-matching glob emits WARN instead of failing the build
- Guard against path traversal: glob root must remain under project base directory
- Backward-compatible: literal paths (no glob characters) unchanged
- Fix Windows compatibility: use relative path matching in expandGlob
- Fixes apache#254
@gnodet
gnodet force-pushed the fix/254-glob-filter-files branch from 05608dd to 6f57f03 Compare September 26, 2026 17:17
@gnodet
gnodet merged commit aacb334 into apache:master Sep 26, 2026
1 of 2 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@github-actions github-actions Bot assigned gnodet Sep 26, 2026
@github-actions github-actions Bot added this to the 4.0.0-beta-2 milestone Sep 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@slawekjaranowski slawekjaranowski slawekjaranowski approved these changes
+1 more reviewer
@gnodet-bot gnodet-bot gnodet-bot approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@gnodet gnodet

Labels

enhancement New feature or request java Pull requests that update Java code

Projects

None yet

Milestone

4.0.0-beta-2

Development

Successfully merging this pull request may close these issues.

[MSHARED-995] Documents of patterns used for filtering

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@gnodet @slawekjaranowski @gnodet-bot
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.