You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by kw...@apache.org on 2026/10/21 13:48:04 UTC

(maven-resolver) branch feature/case-insensitive-enum-conversion created (now 56ff8373e)

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

kwin pushed a change to branch feature/case-insensitive-enum-conversion
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git


      at 56ff8373e Support String properties being converted to Enums in a case insensitive manner.

This branch includes the following new commits:

     new 56ff8373e Support String properties being converted to Enums in a case insensitive manner.

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(maven-resolver) 01/01: Support String properties being converted to Enums in a case insensitive manner.

Posted by kw...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

kwin pushed a commit to branch feature/case-insensitive-enum-conversion
in repository https://gitbox.apache.org/repos/asf/maven-resolver.git

commit 56ff8373efb367521e5c4f7003bd0fc44eaa47d0
Author: Konrad Windszus <kw...@apache.org>
AuthorDate: Wed Oct 21 15:47:53 2026 +0200

    Support String properties being converted to Enums in a case insensitive
    manner.
---
 .../src/main/resources/configuration.md.vm                |  2 +-
 .../main/java/org/eclipse/aether/util/ConfigUtils.java    | 15 +++++++++++----
 .../java/org/eclipse/aether/util/ConfigUtilsTest.java     | 12 +++++++-----
 3 files changed, 19 insertions(+), 10 deletions(-)

diff --git a/maven-resolver-tools/src/main/resources/configuration.md.vm b/maven-resolver-tools/src/main/resources/configuration.md.vm
index 9109438d3..09e4920cf 100644
--- a/maven-resolver-tools/src/main/resources/configuration.md.vm
+++ b/maven-resolver-tools/src/main/resources/configuration.md.vm
@@ -68,7 +68,7 @@ From | To | With
 `String` | `int` | [`Integer.parseInt(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Integer.html#parseInt(java.lang.String))
 `String` | `long` | [`Long.parseLong(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Long.html#parseLong(java.lang.String))
 `String` | `float` | [`Float.parseFloat(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Float.html#parseFloat(java.lang.String))
-`String` | `T extends Enum<T>` | [`Enum.valueOf(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#valueOf(java.lang.Class,%20java.lang.String))
+`String` | `T extends Enum<T>` | Each [`Enum.name(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Enum.html#name()) compared with `String.equalsIgnoreCase(...)` until a match is found. If no match is found an `IllegalArgumentException` is thrown.
 
 ## Set Configuration from Apache Maven
 
diff --git a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
index b065a0cff..a45fac5e7 100644
--- a/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
+++ b/maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
@@ -352,7 +352,8 @@ public final class ConfigUtils {
      * @param enumClass the enum class to read, must not be {@code null}
      * @param defaultValue the default value to return in case none of the property keys is set to a convertible String or T.
      * @param keys the property keys to read, must not be {@code null}. The specified keys are read one after one until
-     *            a enum type {@code T} or a string (parsed using {@link Enum#valueOf(Class, String)} is found.
+     *            a enum type {@code T} or a string (parsed using {@link Enum#valueOf(Class, String)} in a case-insensitive
+     *            manner) is found.
      * @return the property value or {@code defaultValue} if none found
      * @since 2.0.21
      */
@@ -364,7 +365,12 @@ public final class ConfigUtils {
             if (enumClass.isInstance(value)) { // validate type
                 return enumClass.cast(value);
             } else if (value instanceof String) {
-                return Enum.valueOf(enumClass, (String) value);
+                String enumName = (String) value;
+                for (T enumConstant : enumClass.getEnumConstants()) {
+                    if (enumConstant.name().equalsIgnoreCase(enumName)) {
+                        return enumConstant;
+                    }
+                }
             }
         }
         return defaultValue;
@@ -379,7 +385,8 @@ public final class ConfigUtils {
      * @param enumClass the enum class to read, must not be {@code null}
      * @param defaultValue the default value to return in case none of the property keys is set to a convertible String or T.
      * @param keys the property keys to read, must not be {@code null}. The specified keys are read one after one until
-     *            a enum type {@code T} or a string (parsed using {@link Enum#valueOf(Class, String)} is found.
+     *            a enum type {@code T} or a string (parsed using {@link Enum#valueOf(Class, String)} in a case-insensitive
+     *            manner) is found.
      * @return the property value or {@code defaultValue} if none found
      * @since 2.0.21
      */
@@ -412,4 +419,4 @@ public final class ConfigUtils {
     public static List<String> parseCommaSeparatedUniqueNames(String commaSeparatedNames) {
         return parseCommaSeparatedNames(commaSeparatedNames).stream().distinct().collect(toList());
     }
-}
+}
\ No newline at end of file
diff --git a/maven-resolver-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java b/maven-resolver-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
index 480fbafc8..2c6e17166 100644
--- a/maven-resolver-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
+++ b/maven-resolver-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
@@ -215,13 +215,15 @@ public class ConfigUtilsTest {
     void testGetEnum_StringConversion() {
         config.put("some-enum", "SECOND");
         assertEquals(TestEnum.SECOND, ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
+        config.put("some-enum", "second");
+        assertEquals(TestEnum.SECOND, ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
+        config.put("some-enum", "SeCoNd");
+        assertEquals(TestEnum.SECOND, ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
     }
 
     @Test
     void testGetEnum_StringInvalidValue() {
-        config.put("some-enum", "second");
-        assertThrows(
-                IllegalArgumentException.class,
-                () -> ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
+        config.put("some-enum", "third");
+        assertEquals(TestEnum.FIRST, ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
     }
-}
+}
\ No newline at end of file