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: introduce ChangeDetection strategy for file copy by gnodet · Pull Request #397 · apache/maven-filtering

Conversation

@gnodet

@gnodet gnodet commented Sep 24, 2026 •
edited
Loading

Uh oh!

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

Copy link
Copy Markdown
Contributor

Summary

Port of the ChangeDetection strategy from the maven-filtering-3.x branch (commit d9bc10a) to the master branch (Maven 4 / Path-based API).

Instead of jumping between ways to perform change detection — deciding whether an existing target file needs to be overwritten — make it a configurable strategy. Before 3.4.0 it was timestamp-based, post 3.4.0 it switched to content-based via CachingOutputStream, but in any case users were left with no control.

Changes

New ChangeDetection enum

Five strategies:

Strategy Behaviour
TIMESTAMP Overwrite only when source is newer (pre-3.4.0 default)
CONTENT Overwrite only when content differs — via CachingOutputStream/CachingWriter (current default)
TIMESTAMP_AND_CONTENT Check timestamp first, then content if needed
ALWAYS Always overwrite (replaces overwrite=true)
NEVER Never overwrite an existing file

API changes

  • AbstractMavenFilteringRequest — new changeDetection field (default CONTENT) with getter/setter
  • FilteringUtils — new copyFile(Path, Path, String, FilterWrapper[], ChangeDetection) overload returning boolean (true=written, false=skipped); old boolean overwrite signature deprecated
  • MavenFileFilter — new copyFile(…, ChangeDetection) and copyFileWithResult(…, ChangeDetection) methods; old signature deprecated
  • DefaultMavenFileFilter — implements new interface methods, returns boolean indicating whether the destination was written
  • DefaultMavenResourcesFiltering — uses getChangeDetection() from the request instead of isOverwrite(); per-resource override takes precedence over request-level setting; emits "Copying file X" or "Skipping file X (up to date)" based on the actual copy outcome
  • MavenResourcesExecution — isOverwrite() / setOverwrite() deprecated, now delegate through ChangeDetection
  • Resource — new changeDetection field so individual <resource> elements can declare their own strategy, overriding the request-level default

Implementation details

  • CONTENT / TIMESTAMP_AND_CONTENT use CachingOutputStream / CachingWriter (existing behaviour)
  • ALWAYS / TIMESTAMP / NEVER bypass caching and write unconditionally via Files.newOutputStream / Files.newBufferedWriter
  • TIMESTAMP uses Files.getLastModifiedTime(path).toMillis() for Path-based comparison
  • Per-resource changeDetection wins when set; falls back to the request-level value otherwise
  • buildContext.refresh() is always called for processed outputs so incremental build contexts (m2e / Eclipse) correctly track them regardless of whether the file was skipped

Fixes

  • Destination file overwritten even with overwrite false in 3.4.0 maven-resources-plugin#453
  • [MRESOURCES-274] set overwrite per resource maven-resources-plugin#286 (per-resource changeDetection on Resource)
  • [MRESOURCES-313] Debug says 'copy' but does not do that when overwrite = false maven-resources-plugin#316 — debug log said "Copying file" even when the file was skipped by change-detection (fixed: log is now emitted after the copy, showing "Copying" or "Skipping (up to date)" based on the actual outcome)

Related

Plugin-side companion PR: apache/maven-resources-plugin#527

Origin

Ported from maven-filtering-3.x commit d9bc10a by Tamas Cservenak.

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 20:49
@gnodet
gnodet force-pushed the feat/change-detection branch from 464fca5 to 2b00a7e Compare September 25, 2026 06:37
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.

Well-structured refactor — the ChangeDetection enum is a clean replacement for the boolean overwrite flag, and the split into copyUnconditionally / copyIfContentsChanged makes the intent clear. The gracefulBinaryHandling migration from DefaultMavenFileFilter to DefaultMavenResourcesFiltering is correct (no double-handling). A few items 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/FilteringUtils.java Resolved

Uh oh!

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

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

Uh oh!

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

@gnodet gnodet mentioned this pull request Sep 25, 2026
[MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397 apache/maven-resources-plugin#527
Merged
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 4fcc417 — both previous findings are addressed:

  1. FilteringUtils.java @param overwrite — Javadoc now accurately documents the mapping (true → ALWAYS, false → CONTENT). ✅
  2. MavenResourcesExecution.java dead overwrite field — removed entirely; isOverwrite()/setOverwrite() now delegate through ChangeDetection. ✅

Full re-review of the current diff found no new issues. The switch-based dispatch in FilteringUtils.copyFile handles all five strategies correctly with a defensive default branch. The gracefulBinaryHandling migration from DefaultMavenFileFilter to DefaultMavenResourcesFiltering is clean — the caller catches MavenFilteringException wrapping MalformedInputException and falls back to unfiltered copy with the same ChangeDetection mode. API backward compat is preserved via deprecated method delegation.

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 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 9a3e681 (per-resource changeDetection override).

Previous findings (from first review): both addressed in 4fcc417 ✅

  1. FilteringUtils.java — inaccurate @param overwrite Javadoc → fixed, now documents the true→ALWAYS / false→CONTENT mapping.
  2. MavenResourcesExecution.java — dead overwrite field → removed entirely, getters/setters delegate through ChangeDetection.

New commit 9a3e681: Clean. The per-resource changeDetection override in Resource.java is nullable (null = inherit from request-level), and DefaultMavenResourcesFiltering resolves it correctly across all three call sites (flatten check, primary copy, binary-fallback copy). Field visibility is package-private, consistent with other Resource fields. Javadoc is accurate with @since 4.0.0-beta-2.

No new issues found.

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 gnodet mentioned this pull request Sep 25, 2026
[MRESOURCES-274] set overwrite per resource apache/maven-resources-plugin#286
Closed
@gnodet-bot gnodet-bot mentioned this pull request Sep 25, 2026
fix: restore first resource entry wins for overlapping declarations #398
Merged
gnodet added a commit to gnodet/maven-filtering that referenced this pull request Sep 25, 2026
@gnodet
Address review: remove forward reference to ChangeDetection.ALWAYS fr…
be9bc56
…om PR apache#397
@gnodet gnodet mentioned this pull request Sep 25, 2026
[MRESOURCES-313] Debug says 'copy' but does not do that when overwrite = false apache/maven-resources-plugin#316
Closed
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 a25457e (accurate copy/skip debug logging).

Previous findings (from first two reviews): all addressed ✅

  1. FilteringUtils.java — inaccurate @param overwrite Javadoc → fixed in 4fcc417.
  2. MavenResourcesExecution.java — dead overwrite field → removed in 4fcc417.

New commit a25457e: adds copyFileWithResult() to MavenFileFilter (returns boolean), refactors DefaultMavenFileFilter.doCopyFile() to propagate the result, and updates DefaultMavenResourcesFiltering to log "Copying file X" vs "Skipping file X (up to date)" based on the actual copy outcome — fixing the pre-existing issue where the debug log always said "Copying" even when the file was skipped by change detection.

The gracefulBinaryHandling catch is correctly moved up to DefaultMavenResourcesFiltering for the copyFileWithResult path (retries with filtering=false), while the old doCopyFile path still handles it for backward-compatible callers via copyFile(MavenFileFilterRequest). No double-handling.

No new issues found.

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
gnodet force-pushed the feat/change-detection branch from a25457e to dec4590 Compare September 25, 2026 15:10
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 rebase/squash (dec4590). Tree SHA is identical to previously approved a25457e — code unchanged, all prior findings remain addressed. Clean rebase onto updated master.

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
This was referenced Sep 25, 2026
Add separate input/output encoding support for resource filtering (MRESOURCES-232) #407
Closed
[MRESOURCES-232] Resource copy filtering should use different encoding for source and output apache/maven-resources-plugin#335
Closed
slawekjaranowski
slawekjaranowski approved these changes Sep 26, 2026
View reviewed changes
@slawekjaranowski slawekjaranowski mentioned this pull request Sep 26, 2026
Add per-resource encoding support (MRESOURCES-281) #406
Merged
@gnodet gnodet added enhancement New feature or request java Pull requests that update Java code labels Sep 26, 2026
@gnodet
feat: introduce ChangeDetection strategy for resource copy (MRESOURCE…
4baf4b4
…S-397)

Replace the boolean overwrite parameter with a ChangeDetection enum that
supports ALWAYS, NEVER, TIMESTAMP, CONTENT, and TIMESTAMP_AND_CONTENT modes.

- Add ChangeDetection enum with five strategies
- Add MavenResourcesExecution.changeDetection field (default: CONTENT)
- Add per-resource Resource.changeDetection override
- Adapt MavenFileFilter / DefaultMavenFileFilter APIs (boolean overwrite overloads deprecated)
- FilteringUtils.copyFile: return boolean (was copied or skipped)
- Fix debug log to report actual copy/skip outcome per file
@gnodet
gnodet force-pushed the feat/change-detection branch from dec4590 to 4baf4b4 Compare September 26, 2026 17:11
@gnodet
gnodet merged commit e5c3765 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 added this to the 4.0.0-beta-2 milestone Sep 26, 2026
@github-actions github-actions Bot assigned gnodet Sep 26, 2026
gnodet added a commit to apache/maven-resources-plugin that referenced this pull request Sep 26, 2026
@gnodet
[MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
bf89b3c
Replace the deprecated boolean 'overwrite' parameter with a 'changeDetection'
strategy enum (CONTENT / TIMESTAMP / TIMESTAMP_AND_CONTENT / ALWAYS / NEVER),
forwarded from maven-filtering 4.0.0-beta-2-SNAPSHOT (PR apache/maven-filtering#397).

- Add 'changeDetection' @parameter (default CONTENT, i.e. current behaviour)
- Deprecate 'overwrite'; bridge: overwrite=true maps to ALWAYS, overwrite=false
  keeps the declared changeDetection value (backward-compat)
- Add IT MRESOURCES-453: verifies that changeDetection=NEVER leaves an existing
  destination file untouched even when source content differs

Fixes: #453
Depends on: apache/maven-filtering#397
gnodet added a commit to apache/maven-resources-plugin that referenced this pull request Sep 27, 2026
@gnodet
[MRESOURCES-453] Leverage ChangeDetection from maven-filtering #397
ed570e3
Replace the deprecated boolean 'overwrite' parameter with a 'changeDetection'
strategy enum (CONTENT / TIMESTAMP / TIMESTAMP_AND_CONTENT / ALWAYS / NEVER),
forwarded from maven-filtering 4.0.0-beta-2-SNAPSHOT (PR apache/maven-filtering#397).

- Add 'changeDetection' @parameter (default CONTENT, i.e. current behaviour)
- Deprecate 'overwrite'; bridge: overwrite=true maps to ALWAYS, overwrite=false
  keeps the declared changeDetection value (backward-compat)
- Add IT MRESOURCES-453: verifies that changeDetection=NEVER leaves an existing
  destination file untouched even when source content differs

Fixes: #453
Depends on: apache/maven-filtering#397
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.

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.