This is an automated email from the ASF dual-hosted git repository.

slachiewicz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/maven-resources-plugin.git

commit b90db90ec38fc6fb2e88b1ce49df4fce4811a49c
Author: Sylwester Lachiewicz <[email protected]>
AuthorDate: Thu Nov 26 06:52:43 2026 +0000

    Add unit tests for delimiters, basedir, escapeString and build special 
properties
    
    Fixtures and assertions mirror the MRESOURCES-105, -106, -231 and -99 
integration tests.
---
 .../resources/ResourcesMojoFilteringTest.java      | 99 ++++++++++++++++++++++
 .../resources/unit/MRESOURCES-105/my.properties    | 19 +++++
 .../unit/MRESOURCES-105/resources/test.txt         | 22 +++++
 .../unit/MRESOURCES-106/filter.properties          | 19 +++++
 src/test/resources/unit/MRESOURCES-231/test.txt    | 20 +++++
 .../resources/unit/MRESOURCES-99/SomeResource.txt  | 28 ++++++
 6 files changed, 207 insertions(+)

diff --git 
a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoFilteringTest.java
 
b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoFilteringTest.java
index 3fc546f..8f69186 100644
--- 
a/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoFilteringTest.java
+++ 
b/src/test/java/org/apache/maven/plugins/resources/ResourcesMojoFilteringTest.java
@@ -22,6 +22,8 @@ import javax.inject.Inject;
 
 import java.io.File;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.Reader;
 import java.net.URISyntaxException;
 import java.nio.charset.StandardCharsets;
 import java.nio.file.Files;
@@ -32,6 +34,7 @@ import java.util.Arrays;
 import java.util.Collections;
 import java.util.LinkedHashSet;
 import java.util.List;
+import java.util.Properties;
 
 import org.apache.maven.api.di.Provides;
 import org.apache.maven.api.plugin.testing.InjectMojo;
@@ -399,4 +402,100 @@ class ResourcesMojoFilteringTest {
             assertContains(content, "1.0-SNAPSHOT");
         }
     }
+
+    @Test
+    @InjectMojo(goal = "resources")
+    @MojoParameter(name = "encoding", value = "UTF-8")
+    @MojoParameter(name = "useDefaultDelimiters", value = "false")
+    void 
customDelimitersReplaceTheDefaultsAndFilterFileValuesApply(ResourcesMojo mojo) 
throws Exception {
+        resource("MRESOURCES-105/resources", true);
+        setVariableValueToObject(mojo, "buildFilters", 
filters("../../MRESOURCES-105/my.properties"));
+        mojo.setDelimiters(new LinkedHashSet<>(Arrays.asList("$", "@", "#", 
"${*}")));
+
+        mojo.execute();
+
+        List<String> lines = Arrays.asList(output("test.txt").split("\\R"));
+        // the first line has to survive: it is the reason for the bug report
+        assertTrue(lines.contains("#init test value (true|false) LINE IS 
essential for this bug report.#"));
+        // $toto.value$ is replaced
+        assertTrue(lines.contains("toto.value=foo"));
+        // #test.value# and @test.value@ are replaced; ${test.value} is not, 
because the $ delimiter takes its
+        // opening $ and finds no closing $ on the line
+        List<String> testValue = new ArrayList<>();
+        for (String line : lines) {
+            if (line.startsWith("test.value=")) {
+                testValue.add(line);
+            }
+        }
+        assertEquals(Arrays.asList("test.value=true", "test.value=true", 
"test.value=${test.value}"), testValue);
+    }
+
+    @Test
+    @InjectMojo(goal = "resources")
+    @MojoParameter(name = "encoding", value = "UTF-8")
+    void basedirInsideAPropertyValueIsResolvedOnce(ResourcesMojo mojo) throws 
Exception {
+        project().addProperty("location", 
"${basedir}/src/main/resources/file.txt");
+        resource("MRESOURCES-106", true);
+
+        mojo.execute();
+
+        Properties filtered = new Properties();
+        try (InputStream in =
+                Files.newInputStream(new File(project().getOutputDirectory(), 
"filter.properties").toPath())) {
+            filtered.load(in);
+        }
+        String basedir = project().getBasedir().getAbsolutePath();
+        assertEquals(basedir, filtered.getProperty("basedir"));
+        // not prefixed twice: the path is the base directory plus the 
relative part, nothing else
+        assertEquals(new File(basedir, "src/main/resources/file.txt"), new 
File(filtered.getProperty("location")));
+    }
+
+    @Test
+    @InjectMojo(goal = "resources")
+    @MojoParameter(name = "encoding", value = "UTF-8")
+    @MojoParameter(name = "escapeString", value = "")
+    void emptyEscapeStringIsNotAnEscape(ResourcesMojo mojo) throws Exception {
+        project().addProperty("project.build.sourceEncoding", "UTF-8");
+        resource("MRESOURCES-231", true);
+
+        mojo.execute();
+
+        assertContains(
+                output("test.txt"),
+                
"something\\with\\default\\escape\\string\\and\\a\\property\\like\\UTF-8\\in\\between");
+    }
+
+    @Test
+    @InjectMojo(goal = "resources")
+    @MojoParameter(name = "encoding", value = "UTF-8")
+    void buildTimestampBaseUriAndBasedirExpressions(ResourcesMojo mojo) throws 
Exception {
+        project().setGroupId("org.apache.maven.plugins");
+        resource("MRESOURCES-99", true);
+
+        mojo.execute();
+
+        Properties props = new Properties();
+        try (Reader in = Files.newBufferedReader(
+                new File(project().getOutputDirectory(), 
"SomeResource.txt").toPath(), StandardCharsets.ISO_8859_1)) {
+            props.load(in);
+        }
+        // ${maven.build.timestamp} and @maven.build.timestamp@ are replaced 
by the plugin
+        String timestamp = props.getProperty("timestamp");
+        assertTrue(
+                
timestamp.matches("\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}Z"),
+                () -> "${maven.build.timestamp} was not replaced: " + 
timestamp);
+        assertEquals(timestamp, props.getProperty("at.timestamp"));
+        // only these expressions are replaced
+        String basedir = project().getBasedir().getAbsolutePath();
+        
assertEquals(project().getBasedir().getAbsoluteFile().toURI().toString(), 
props.getProperty("project.baseUri"));
+        assertEquals("org.apache.maven.plugins", props.getProperty("groupId"));
+        assertEquals(basedir, props.getProperty("basedir"));
+        assertEquals(basedir, props.getProperty("project.basedir"));
+        // these have no value in the filtering context and stay as they are
+        assertEquals("${build.timestamp}", 
props.getProperty("build.timestamp"));
+        assertEquals("${project.build.timestamp}", 
props.getProperty("project.build.timestamp"));
+        assertEquals("${baseUri}", props.getProperty("baseUri"));
+        assertEquals("${pom.baseUri}", props.getProperty("pom.baseUri"));
+        assertEquals("@baseUri@", props.getProperty("at.baseUri"));
+    }
 }
diff --git a/src/test/resources/unit/MRESOURCES-105/my.properties 
b/src/test/resources/unit/MRESOURCES-105/my.properties
new file mode 100644
index 0000000..207f663
--- /dev/null
+++ b/src/test/resources/unit/MRESOURCES-105/my.properties
@@ -0,0 +1,19 @@
+# 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.
+
+test.value=true
+toto.value=foo
diff --git a/src/test/resources/unit/MRESOURCES-105/resources/test.txt 
b/src/test/resources/unit/MRESOURCES-105/resources/test.txt
new file mode 100644
index 0000000..9903054
--- /dev/null
+++ b/src/test/resources/unit/MRESOURCES-105/resources/test.txt
@@ -0,0 +1,22 @@
+# 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.
+
+#init test value (true|false) LINE IS essential for this bug report.#
+toto.value=$toto.value$
+test.value=#test.value#
[email protected]@
+test.value=${test.value}
diff --git a/src/test/resources/unit/MRESOURCES-106/filter.properties 
b/src/test/resources/unit/MRESOURCES-106/filter.properties
new file mode 100644
index 0000000..3ff12b7
--- /dev/null
+++ b/src/test/resources/unit/MRESOURCES-106/filter.properties
@@ -0,0 +1,19 @@
+# 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.
+
+location=${location}
+basedir=${basedir}
diff --git a/src/test/resources/unit/MRESOURCES-231/test.txt 
b/src/test/resources/unit/MRESOURCES-231/test.txt
new file mode 100644
index 0000000..4fca97b
--- /dev/null
+++ b/src/test/resources/unit/MRESOURCES-231/test.txt
@@ -0,0 +1,20 @@
+<!--
+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.
+-->
+
+something\with\default\escape\string\and\a\property\like\${project.build.sourceEncoding}\in\between
diff --git a/src/test/resources/unit/MRESOURCES-99/SomeResource.txt 
b/src/test/resources/unit/MRESOURCES-99/SomeResource.txt
new file mode 100644
index 0000000..74a7ae9
--- /dev/null
+++ b/src/test/resources/unit/MRESOURCES-99/SomeResource.txt
@@ -0,0 +1,28 @@
+# 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.
+
+timestamp=${maven.build.timestamp}
[email protected]@
+build.timestamp=${build.timestamp}
+project.build.timestamp=${project.build.timestamp}
+baseUri=${baseUri}
+project.baseUri=${project.baseUri}
+pom.baseUri=${pom.baseUri}
+at.baseUri=@baseUri@
+groupId=${project.groupId}
+basedir=${basedir}
+project.basedir=${project.basedir}

Reply via email to