Skip to content

Experiment: migrate to Maven 4 BuildContext API - #363

Draft
gnodet wants to merge 5 commits into
masterfrom
experiment/maven4-build-context
Draft

Experiment: migrate to Maven 4 BuildContext API#363
gnodet wants to merge 5 commits into
masterfrom
experiment/maven4-build-context

Conversation

@gnodet

@gnodet gnodet commented Jul 29, 2026

Copy link
Copy Markdown
Contributor

Summary

Experimental branch migrating maven-filtering from the legacy plexus-build-api to the new Maven 4 BuildContext API (from apache/maven#12576).

  • Replace plexus-build-api with org.apache.maven.api.build.context.BuildContext from maven-api-core
  • Incremental per-file processing: use registerAndProcessInputs() to only process changed/new files and clean up stale outputs automatically
  • Use PathMatcherFactory for Ant-style include/exclude pattern matching instead of hand-rolled glob conversion
  • Fix edge cases: path normalization for mixed relative/absolute paths, skip associateOutput() when flattening (multiple inputs → same output)
  • Add 9 incremental tests (IncrementalResourceFilteringTest) exercising: initial build, no-change skip, modified input, deleted input cleanup, include/exclude patterns, new file detection, filtering, and subdirectory structure
  • All 77 tests pass (68 existing + 9 new)

Depends on

Test plan

  • All 77 maven-filtering tests pass (including 9 new incremental tests)
  • maven-resources-plugin tests pass with this version installed
  • Integration test with a real Maven build using the resources plugin

🤖 Generated with Claude Code

gnodet and others added 4 commits July 29, 2026 13:45
Replace the old Scanner-based plexus BuildContext with the new Maven 4
BuildContext API (org.apache.maven.api.build.context.BuildContext) from
maven-api-core 4.1.0-SNAPSHOT (PR apache/maven#12576).

Key changes:
- DefaultMavenResourcesFiltering: replace buildContext.newScanner() and
  newDeleteScanner() with buildContext.registerAndProcessInputs() which
  returns Input objects with change status tracking
- DefaultMavenFileFilter: remove buildContext.refresh() — output tracking
  is now handled by the BuildContext output association in the mojo
- Remove plexus-build-api dependency from pom.xml
- Delete old TestIncrementalBuildContext and IncrementalResourceFilteringTest
  (these tested the old Scanner-based API)

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add proper per-file incremental processing using Maven 4 BuildContext:
- registerAndProcessInputs() for all resource files
- Separate changed (NEW/MODIFIED) from unchanged (UNMODIFIED) inputs
- Only copy/filter changed files in incremental mode
- input.associateOutput() for stale output cleanup on file removal
- Informative logging: "Copying N of M resources (Z unchanged)"
- @nullable BuildContext for backward compat (tests without DI)
- Ant-style pattern matching fallback using PathMatcher with proper
  escaping of glob metacharacters ({, }, [, ]) and leading **/
  zero-directory matching

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…sion

Replace custom Ant-to-glob pattern conversion (escapeGlobMetachars,
toPathMatchers, matchesAny) with Maven 4's PathMatcherFactory service.
PathSelector already handles all the nuances:
- Escaping {, }, [, ] as literals
- Leading **/ matching zero directories
- **/** normalization
- Comprehensive default SCM excludes

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add IncrementalResourceFilteringTest (9 tests) exercising the Maven 4
  BuildContext incremental code path: initial build, no-change skip,
  modified input re-processing, stale output cleanup, include/exclude
  patterns, new file detection, filtering, and subdirectory structure.

- Fix path normalization: normalize resourceDirectory to absolute path
  after existence check so relativize() works correctly with
  BuildContext's canonicalized paths.

- Fix flatten + associateOutput: skip associateOutput() when flattening
  since multiple inputs can map to the same output, violating the
  BuildContext's one-input-to-one-output constraint.

- Update Providers.java: provide real BuildContext and PathMatcherFactory
  for test DI with @priority(10) to override auto-discovered
  MavenBuildContext from maven-core.

- Remove stale plexusBuildApiVersion property from pom.xml.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The dependency was already removed; this just cleans up the leftover
comment marker.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant