GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Support String properties being converted to Enums in a case insensitive by kwin · Pull Request #2220 · apache/maven-resolver

Support String properties being converted to Enums in a case insensitive #2220

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
kwin merged 6 commits into master from feature/case-insensitive-enum-conversion
Oct 21, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Support String properties being converted to Enums in a case insensitive #2220

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
6 commits
Select commit Hold shift + click to select a range
0d532f4
Support String properties being converted to Enums in a case insensitive
kwin Oct 21, 2026
b742f70
Update maven-resolver-util/src/main/java/org/eclipse/aether/util/Conf…
kwin Oct 21, 2026
ec6c94f
Update maven-resolver-util/src/main/java/org/eclipse/aether/util/Conf…
kwin Oct 21, 2026
79ee5c6
Update maven-resolver-tools/src/main/resources/configuration.md.vm
kwin Oct 21, 2026
3b959f1
Update maven-resolver-util/src/main/java/org/eclipse/aether/util/Conf…
kwin Oct 21, 2026
f2d09ea
Apply batched suggestions from code review
kwin Oct 21, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 2 additions & 2 deletions 4 maven-resolver-tools/src/main/resources/configuration.md.vm
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,13 @@ All properties which have `yes` in the column `Supports Repo ID Suffix` can be o

If the value is not given in the target type the following conversions are applied.

From | To | With
From | To | How
--- | --- | ---
`String` | `boolean` | [`Boolean.parseBoolean(...)`](https://docs.oracle.com/javase/7/docs/api/java/lang/Boolean.html#parseBoolean(java.lang.String))
`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

Expand Down
24 changes: 20 additions & 4 deletions 24 maven-resolver-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -352,19 +352,33 @@ public static List<?> getList(RepositorySystemSession session, List<?> defaultVa
* @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 (compared case-insensitively against enum constant names;
* if no constant matches, an {@link IllegalArgumentException} is thrown) is found.
Comment thread
kwin marked this conversation as resolved.
Resolved

Uh oh!

There was an error while loading. Please reload this page.

* @return the property value or {@code defaultValue} if none found
* @throws IllegalArgumentException if a property value is found but cannot be converted to the specified enum type
* @since 2.0.21
*/
public static <T extends Enum<T>> T getEnum(
Map<?, ?> properties, Class<T> enumClass, T defaultValue, String... keys) {
for (String key : keys) {
Object value = properties.get(key);

if (value == null) {
continue;
}
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;
}
}
throw new IllegalArgumentException("Invalid enum value '" + enumName + "' for key '" + key
+ "' in enum class " + enumClass.getName());
} else {
throw new IllegalArgumentException("Invalid value type for key '" + key + "' in enum class "
+ enumClass.getName() + ": " + value.getClass().getName());
}
}
return defaultValue;
Expand All @@ -379,7 +393,9 @@ public static <T extends Enum<T>> T getEnum(
* @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 (compared case-insensitively against enum constant names;
* if no constant matches, an {@link IllegalArgumentException} is thrown) is found.
* @throws IllegalArgumentException if a property value is found but cannot be converted to the specified enum type
* @return the property value or {@code defaultValue} if none found
* @since 2.0.21
*/
Expand Down
6 changes: 5 additions & 1 deletion 6 maven-resolver-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -215,11 +215,15 @@ void testGetEnum() {
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");
config.put("some-enum", "third");
assertThrows(
IllegalArgumentException.class,
() -> ConfigUtils.getEnum(config, TestEnum.class, TestEnum.FIRST, "some-enum"));
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.