gnodet opened a new issue, #394:
URL: https://github.com/apache/maven-filtering/issues/394

   ## Problem
   
   When a project keeps both filterable and binary resources under a single 
`<resource>` block with `<filtering>true</filtering>` (e.g. `.properties` 
alongside `.p12`, `.jks`, or extension-less binary fixtures), 
`FilteringUtils.copyFile()` opens the binary with the project charset, hits 
`MalformedInputException`, and crashes the build.
   
   The existing `nonFilteredFileExtensions` mechanism is insufficient because:
   - It only matches on file extension — extension-less binaries (e.g. test 
keystores, generated binary fixtures) are not covered
   - It cannot express path-based exclusions (e.g. "all files under `certs/`")
   - It is global — users cannot be surgical about which `<resource>` block is 
affected
   
   See apache/maven-resources-plugin#303 for a concrete example.
   
   ## Proposed Solution
   
   ### 1. Per-resource glob exclusions (primary mechanism)
   
   Add `List<String> nonFilteredFiles` (Ant-style glob patterns) to `Resource`, 
with getter/setter.
   
   In `DefaultMavenResourcesFiltering.filterResources()`, alongside the 
existing `filteredFileExtension()` check, evaluate the globs:
   
   ```java
   boolean filteredGlob = resource.getNonFilteredFiles() == null
       || resource.getNonFilteredFiles().stream()
              .noneMatch(glob -> matchesGlob(name, glob));
   // Combined: resource.isFiltering() && filteredExt && filteredGlob
   ```
   
   The glob matching can reuse `org.codehaus.plexus.util.DirectoryScanner` / 
`SelectorUtils.matchPath()` already on the classpath, so no new dependency is 
needed.
   
   Plugin config surface (exposed by maven-resources-plugin in a companion 
issue):
   
   ```xml
   <resource>
     <directory>src/main/resources</directory>
     <filtering>true</filtering>
     <nonFilteredFiles>
       <nonFilteredFile>**/*.p12</nonFilteredFile>
       <nonFilteredFile>**/*.jks</nonFilteredFile>
       <nonFilteredFile>**/certs/**</nonFilteredFile>
       <nonFilteredFile>binary-file</nonFilteredFile>   <!-- extension-less -->
     </nonFilteredFiles>
   </resource>
   ```
   
   ### 2. Opt-in graceful binary fallback (safety net)
   
   Add a boolean `gracefulBinaryHandling` flag (default `false`) to 
`MavenResourcesExecution`.
   
   When `true`, catch `MalformedInputException` in `FilteringUtils.copyFile()` 
and:
   - Log a `WARN`: `"File '<path>' could not be filtered 
(MalformedInputException) — file appears to be binary and will be copied 
without filtering. Consider adding it to nonFilteredFiles or 
nonFilteredFileExtensions."`
   - Fall back to a direct `Files.copy()` (not a recursive `copyFile()` call)
   
   This is **opt-in** (default `false`) to avoid silently swallowing real 
encoding errors, and always emits a warning so the user knows filtering was 
skipped.
   
   ## Relationship to existing mechanism
   
   `nonFilteredFileExtensions` continues to work as-is for standard binary 
types (`jpg`, `png`, etc.). The new glob support is additive, for 
project-specific cases. The graceful fallback is a last resort for projects 
that cannot enumerate their binaries upfront.
   
   ## See also
   
   - apache/maven-resources-plugin#303 — original PR (to be replaced by this 
feature)
   - Companion issue in maven-resources-plugin to expose the new 
`nonFilteredFiles` config
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to