From edc22b309aaa1d77577516a13ac8c7b6d979f58d Mon Sep 17 00:00:00 2001
From: Shaun Phillips <61982125+ShaPhi7@users.noreply.github.com>
Date: Thu, 9 Jun 2022 22:05:23 +0100
Subject: [PATCH] BAEL-4170 add Maven encoding examples (#12332)
* BAEL-4170 add Maven encoding examples
* GTSIS-4170 update name of test class
---
maven-modules/maven-properties/pom.xml | 27 ++++++++++++++++++-
.../maven/properties/NonAsciiString.java | 26 ++++++++++++++++++
.../properties/NonAsciiStringUnitTest.java | 20 ++++++++++++++
3 files changed, 72 insertions(+), 1 deletion(-)
create mode 100644 maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/NonAsciiString.java
create mode 100644 maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/NonAsciiStringUnitTest.java
diff --git a/maven-modules/maven-properties/pom.xml b/maven-modules/maven-properties/pom.xml
index 88e13a0fb8..0e9986e3ac 100644
--- a/maven-modules/maven-properties/pom.xml
+++ b/maven-modules/maven-properties/pom.xml
@@ -19,7 +19,7 @@
org.codehaus.mojo
properties-maven-plugin
- 1.0.0
+ 1.1.0
generate-resources
@@ -32,12 +32,37 @@
+
+
+ org.apache.maven.plugins
+ maven-resources-plugin
+ 3.2.0
+
+
+
+
+
+
+
+ org.apache.maven.plugins
+ maven-compiler-plugin
+
+
+
+
+
${project.name}
property-from-pom
+
+
+
+ UTF-8
+ UTF-8
\ No newline at end of file
diff --git a/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/NonAsciiString.java b/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/NonAsciiString.java
new file mode 100644
index 0000000000..48a82f93b0
--- /dev/null
+++ b/maven-modules/maven-properties/src/main/java/com/baeldung/maven/properties/NonAsciiString.java
@@ -0,0 +1,26 @@
+package com.baeldung.maven.properties;
+
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/*
+ * Simple class to demonstrate the importance of Maven encoding when dealing with NonAscii characters
+ */
+public class NonAsciiString {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NonAsciiString.class);
+
+ public static String getNonAsciiString() {
+
+ String nonAsciiStr = "ÜÝÞßàæç";
+ LOGGER.info(nonAsciiStr);
+ return nonAsciiStr;
+
+ /*We can even use non-ASCII characters as Java variables names.
+ The below will run fine when built using Maven UTF-8 encoding,
+ but not when using US-ASCII. Give it a go!*/
+ /*String nonAsciiŞŧř = "ÜÝÞßàæç";
+ LOGGER.info(nonAsciiŞŧř);
+ return nonAsciiŞŧř;*/
+ }
+}
diff --git a/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/NonAsciiStringUnitTest.java b/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/NonAsciiStringUnitTest.java
new file mode 100644
index 0000000000..d6cc9908d3
--- /dev/null
+++ b/maven-modules/maven-properties/src/test/java/com/baeldung/maven/properties/NonAsciiStringUnitTest.java
@@ -0,0 +1,20 @@
+package com.baeldung.maven.properties;
+
+import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class NonAsciiStringUnitTest {
+
+ private static final Logger LOGGER = LoggerFactory.getLogger(NonAsciiStringUnitTest.class);
+
+ /**
+ * Sanity check to ensure that the code is still able to compile and run
+ */
+ @Test
+ public void whenNonAsciiStringIsUsed_thenCodeRuns() {
+ String nonAsciiStr = NonAsciiString.getNonAsciiString();
+ LOGGER.info(nonAsciiStr);
+ }
+
+}