From b50521ae26999b71634062a2a4cca5d4333f23aa Mon Sep 17 00:00:00 2001 From: Konrad Windszus Date: Tue, 23 Jun 2020 12:42:42 +0200 Subject: [PATCH] [MRESOLVER-126] support conversion from String to Map for config properties --- .../org/eclipse/aether/util/ConfigUtils.java | 16 ++++++++++++++++ .../org/eclipse/aether/util/ConfigUtilsTest.java | 10 ++++++++++ src/site/markdown/configuration.md | 3 +++ 3 files changed, 29 insertions(+) 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 b55ad57b8..77977d049 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 @@ -19,11 +19,14 @@ * under the License. */ +import java.io.IOException; +import java.io.StringReader; import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; import java.util.Map; +import java.util.Properties; import org.eclipse.aether.RepositorySystemSession; @@ -369,6 +372,19 @@ public static List getList( RepositorySystemSession session, List defaultV { return (Map) value; } + else if ( value instanceof String ) + { + Properties props = new Properties( ); + try + { + props.load( new StringReader( (String) value ) ); + return props; + } + catch ( IOException e ) + { + // try next key + } + } } return defaultValue; 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 440a7c1ca..35420fdc0 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 @@ -66,6 +66,16 @@ public void testGetMap_AlternativeKeys() assertSame( val, ConfigUtils.getMap( config, null, "no-object", "some-map" ) ); } + @Test + public void testGetMap_StringConversion() + { + Map val = new HashMap<>(); + val.put("key1", "value1"); + val.put("key:=2", "value2"); + config.put( "some-map", "#comment\nkey1=value1\nkey\\:\\=2=value2"); + assertEquals( val, ConfigUtils.getMap( config, null, "no-object", "some-map" ) ); + } + @Test public void testGetList_Default() { diff --git a/src/site/markdown/configuration.md b/src/site/markdown/configuration.md index d67a2fe59..e7f50e8f9 100644 --- a/src/site/markdown/configuration.md +++ b/src/site/markdown/configuration.md @@ -67,8 +67,11 @@ 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` | `Map` | [`Properties.load(...)`](https://docs.oracle.com/javase/7/docs/api/java/util/Properties.html#load(java.io.Reader)) ## Set Configuration from Apache Maven To set one of the configuration options from above just use system variables. As system variables only support String values the type conversion mentioned above needs to be leveraged. Sometimes Maven uses different default values than the Maven Resolver itself or tries to extract certain values from the `server.xml`. For details refer to . + +Maven does only ship with the Wagon Transporter (not the Http Transporter), therefore some properties might not be applicable.