Skip to content
Open
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
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ under the License.
<javaVersion>17</javaVersion>

<guiceVersion>7.0.0</guiceVersion>
<mavenFilteringVersion>4.0.0-beta-1</mavenFilteringVersion>
<mavenFilteringVersion>4.0.0-beta-2-SNAPSHOT</mavenFilteringVersion>
<mavenPluginPluginVersion>4.0.0-beta-2</mavenPluginPluginVersion>
<mavenPluginTestingVersion>4.0.0-beta-4</mavenPluginTestingVersion>
<plexusBuildApiVersion>0.0.7</plexusBuildApiVersion>
Expand Down
51 changes: 51 additions & 0 deletions src/it/MRESOURCES-232/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
<?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 xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.apache.maven.plugins.maven-resources-plugin.its</groupId>
<artifactId>MRESOURCES-232</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>MRESOURCES-232: separate input and output encoding for resource filtering</name>

<properties>
<world>World</world>
</properties>

<build>
<resources>
<resource>
<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>
<!-- Read resources as ISO-8859-1, write as UTF-8 -->
<encoding>ISO-8859-1</encoding>
<outputEncoding>UTF-8</outputEncoding>
</configuration>
</plugin>
</plugins>
</build>
</project>
1 change: 1 addition & 0 deletions src/it/MRESOURCES-232/src/main/resources/message.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Bonjour ${world}! café
38 changes: 38 additions & 0 deletions src/it/MRESOURCES-232/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* 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.
*/
// MRESOURCES-232: Verify that outputEncoding enables encoding conversion during filtering.
// The source file (message.txt) is ISO-8859-1-encoded and contains a filter token and an
// é character (0xE9 in Latin-1). After filtering with encoding=ISO-8859-1 and
// outputEncoding=UTF-8 the output file must:
// 1. Have the token expanded (${world} → World)
// 2. Encode é as UTF-8 (0xC3 0xA9)

File output = new File( basedir, 'target/classes/message.txt' );
assert output.exists() : "message.txt was not copied";

// Read as UTF-8 — if the file were still Latin-1 this would produce garbage for é
String content = output.getText( 'UTF-8' );
assert content.trim() == 'Bonjour World! caf\u00e9' : "Unexpected content: '${content.trim()}'"

// Also verify the raw bytes: é should be the two-byte UTF-8 sequence 0xC3 0xA9
byte[] bytes = output.bytes;
String hex = bytes.collect { String.format('%02x', it & 0xFF) }.join(' ');
assert hex.contains('c3 a9') : "Expected UTF-8 é (c3 a9) in output bytes, got: ${hex}"

return true;
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,26 @@ public class ResourcesMojo implements org.apache.maven.api.plugin.Mojo {
@Parameter(defaultValue = "${project.build.sourceEncoding}")
protected String encoding;

/**
* The character encoding to use when writing filtered resources.
* When set, enables encoding conversion during filtering: resources are read with {@link #encoding}
* and written with this encoding. Useful to convert legacy EBCDIC or Latin-1 source files to UTF-8
* (or vice-versa) as part of the build.
* <p>
* When not set (the default), the same encoding is used for reading and writing, preserving
* backward compatibility.
* </p>
* <p>
* This parameter is ignored when filtering is disabled (i.e. when no resource has
* {@code &lt;filtering&gt;true&lt;/filtering&gt;}), because non-filtered files are always copied
* as raw bytes.
* </p>
*
* @since 3.4.1

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

⚠️ Inaccurate @since tag — version 3.4.1 was never released (releases went 3.4.0 → 3.5.0 → 3.5.1). Since this PR targets master (the 4.x line), this should be:

Suggested change
* @since 3.4.1
* @since 4.0.0-beta-2

If backporting to the 3.x line as well, use the future 3.x release version there.

*/
@Parameter(property = "maven.resources.outputEncoding")
protected String outputEncoding;

/**
* The character encoding to use when reading and writing filtered properties files.
* If not specified, it will default to the value of the "encoding" parameter.
Expand Down Expand Up @@ -357,6 +377,11 @@ protected void doExecute() throws MojoException {
// Handle MRESOURCES-171
mavenResourcesExecution.setPropertiesEncoding(propertiesEncoding);

// Handle MRESOURCES-232: separate input/output encoding for encoding conversion
if (outputEncoding != null) {
mavenResourcesExecution.setOutputEncoding(outputEncoding);
}

if (nonFilteredFileExtensions != null) {
mavenResourcesExecution.setNonFilteredFileExtensions(nonFilteredFileExtensions);
}
Expand Down
Loading