Skip to content
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.

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

[MRESOLVER-126] support conversion from String to Map for config #63

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@ public void testGetMap_AlternativeKeys()
assertSame( val, ConfigUtils.getMap( config, null, "no-object", "some-map" ) );
}

@Test
public void testGetMap_StringConversion()
{
Map<String, String> 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()
{
Expand Down
3 changes: 3 additions & 0 deletions src/site/markdown/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <https://github.com/apache/maven/blob/master/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java>.

Maven does only ship with the Wagon Transporter (not the Http Transporter), therefore some properties might not be applicable.