Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/it/MRESOURCES-graceful-binary/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals=clean process-resources
52 changes: 52 additions & 0 deletions src/it/MRESOURCES-graceful-binary/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Licensed to the Apache Software Foundation (ASF) under one
~ or more contributor license agreements. See the NOTICE file
~ distributed with this work for additional information
~ regarding copyright ownership. The ASF licenses this file
~ to you under the Apache License, Version 2.0 (the
~ "License"); you may not use this file except in compliance
~ with the License. You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing,
~ software distributed under the License is distributed on an
~ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
~ KIND, either express or implied. See the License for the
~ specific language governing permissions and limitations
~ under the License.
-->
<project>
<modelVersion>4.0.0</modelVersion>

<groupId>org.apache.maven.plugins.resources.its</groupId>
<artifactId>MRESOURCES-graceful-binary</artifactId>
<version>1.0</version>
<packaging>jar</packaging>

<description>Integration test for gracefulBinaryHandling: when a binary file is included in a
filtered resource directory and gracefulBinaryHandling=true, the build should succeed
and the binary file should be copied as-is (byte-for-byte identical to the source).</description>

<build>
<resources>
<resource>
<!-- filtering=true on the whole resource dir; the .p12 would normally cause
a MalformedInputException. gracefulBinaryHandling silences it and copies as-is. -->
<filtering>true</filtering>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>@project.version@</version>
<configuration>
<gracefulBinaryHandling>true</gracefulBinaryHandling>
</configuration>
</plugin>
</plugins>
</build>
</project>
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# A simple text resource with a filter token — should be filtered normally
app.name=${project.artifactId}
app.version=${project.version}
24 changes: 24 additions & 0 deletions src/it/MRESOURCES-graceful-binary/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Verify gracefulBinaryHandling: the binary .p12 must be copied byte-for-byte,
// and the text .properties must be filtered normally.

import java.nio.file.*

def outputDir = new File(basedir, 'target/classes')

// 1. Binary file must exist and be byte-for-byte identical to the source
def srcBinary = new File(basedir, 'src/main/resources/certs/keystore.p12')
def dstBinary = new File(outputDir, 'certs/keystore.p12')
assert dstBinary.exists() : "Binary file was not copied: ${dstBinary}"
assert Arrays.equals(srcBinary.bytes, dstBinary.bytes) : \
"Binary file content was altered by filtering (gracefulBinaryHandling did not copy it as-is)"

// 2. Text properties file must exist and have filtered values
def props = new File(outputDir, 'config.properties')
assert props.exists() : "config.properties was not copied: ${props}"
def content = props.text
assert content.contains('MRESOURCES-graceful-binary') : \
"config.properties does not contain filtered artifactId: ${content}"
assert content.contains('1.0') : \
"config.properties does not contain filtered version: ${content}"
assert !content.contains('${project.') : \
"config.properties still contains unresolved placeholders: ${content}"
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,24 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
@Parameter(property = "maven.resources.failOnMissingFilterValue", defaultValue = "false")
private boolean failOnMissingFilterValue;

/**
* When set to {@code true}, files that trigger a {@code MalformedInputException} during filtering
* (i.e. binary files whose encoding cannot be read as text) are skipped and copied as-is
* instead of failing the build. A {@code WARN}-level log entry is emitted for each skipped file.
* <p>
* Use this as a last-resort fallback when it is not practical to enumerate every binary extension
* in {@code nonFilteredFileExtensions} or to exempt files via per-resource {@code nonFilteredFiles}
* glob patterns. Prefer those targeted approaches when possible.
* </p>
* <p>
* Defaults to {@code false} so that real encoding errors are not silently swallowed.
* </p>
*
* @since 4.0.0-beta-2
*/
@Parameter(property = "maven.resources.gracefulBinaryHandling", defaultValue = "false")
private boolean gracefulBinaryHandling;

@Inject
private Log logger;

Expand Down Expand Up @@ -522,6 +540,7 @@ protected void doExecute() throws MojoException {
mavenResourcesExecution.setNonFilteredFileExtensions(ADDITIONAL_DEFAULT_NON_FILTERED_EXTENSIONS);
}
mavenResourcesExecution.setFailOnMissingFilterValue(failOnMissingFilterValue);
mavenResourcesExecution.setGracefulBinaryHandling(gracefulBinaryHandling);
mavenResourcesFiltering.filterResources(mavenResourcesExecution);

executeUserFilterComponents(mavenResourcesExecution);
Expand Down
Loading