gnodet commented on code in PR #406:
URL: https://github.com/apache/maven-filtering/pull/406#discussion_r4103068851
##########
src/test/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFilteringTest.java:
##########
@@ -1041,6 +1041,47 @@ void filterPropertiesFiles() throws Exception {
assertTrue(contentEquals(Paths.get(unitFilesDir, "test.txt"),
targetPathFile.resolve("test.txt")));
}
+ /**
+ * MRESOURCES-281: Allow per-resource encoding override via {@link
Resource#setEncoding(String)}.
+ */
+ @Test
+ void filterResourcesWithPerResourceEncoding() throws Exception {
+ String unitFilesDir = getBasedir() +
"/src/test/units-files/resource-encoding";
+
+ // Resource 1: read and copy the UTF-8 encoded file
+ Resource utf8Resource = new Resource();
+ utf8Resource.setDirectory(unitFilesDir);
+ utf8Resource.setFiltering(false);
Review Comment:
Fixed in bd24ef7. Changed to `filtering=true` +
`useDefaultFilterWrappers=true`, added a `${project.name}` placeholder to both
fixture files, and updated the assertions to verify placeholder resolution and
non-ASCII content round-trip for both UTF-8 and windows-1252.
##########
src/main/java/org/apache/maven/shared/filtering/DefaultMavenResourcesFiltering.java:
##########
@@ -273,9 +273,15 @@ public void filterResources(MavenResourcesExecution
mavenResourcesExecution) thr
propertiesFiles.add(source);
}
- // Determine which encoding to use when filtering this file
- String encoding = getEncoding(
- source, mavenResourcesExecution.getEncoding(),
mavenResourcesExecution.getPropertiesEncoding());
+ // Determine which encoding to use when filtering this file.
+ // A per-resource encoding overrides the global encoding and
propertiesEncoding.
+ String resourceEncoding = resource.getEncoding();
+ String encoding = (resourceEncoding != null)
+ ? resourceEncoding
+ : getEncoding(
+ source,
+ mavenResourcesExecution.getEncoding(),
+
mavenResourcesExecution.getPropertiesEncoding());
Review Comment:
Already addressed in bd24ef7 (parent commit already had the comment `// A
per-resource encoding overrides the global encoding and propertiesEncoding.` at
that exact location). The bypass is documented.
--
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]