You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ol...@apache.org on 2016/05/01 12:56:37 UTC
[35/50] [abbrv] maven-aether git commit: Bug 447810 - Make
ConfigUtils.getString() recognize booleans and numbers as valid values
Bug 447810 - Make ConfigUtils.getString() recognize booleans and numbers as valid values
Project: http://git-wip-us.apache.org/repos/asf/maven-aether/repo
Commit: http://git-wip-us.apache.org/repos/asf/maven-aether/commit/32267bff
Tree: http://git-wip-us.apache.org/repos/asf/maven-aether/tree/32267bff
Diff: http://git-wip-us.apache.org/repos/asf/maven-aether/diff/32267bff
Branch: refs/heads/master
Commit: 32267bff2a22be45fc94f7854d36a275a224e49c
Parents: 0db0dcc
Author: Benjamin Bentmann <be...@sonatype.com>
Authored: Sun Oct 19 16:08:11 2014 +0200
Committer: Benjamin Bentmann <be...@sonatype.com>
Committed: Sun Oct 19 16:08:11 2014 +0200
----------------------------------------------------------------------
.../org/eclipse/aether/util/ConfigUtils.java | 12 ++++++------
.../eclipse/aether/util/ConfigUtilsTest.java | 20 +++++++++++++++++++-
2 files changed, 25 insertions(+), 7 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/32267bff/aether-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
----------------------------------------------------------------------
diff --git a/aether-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java b/aether-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
index 1f52a76..2bcd958 100644
--- a/aether-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
+++ b/aether-util/src/main/java/org/eclipse/aether/util/ConfigUtils.java
@@ -74,8 +74,8 @@ public final class ConfigUtils
* Gets the specified configuration property as a string value.
*
* @param properties The configuration properties 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 string, may be
- * {@code null}.
+ * @param defaultValue The default value to return in case none of the property keys is set to a
+ * string/boolean/number, may be {@code null}.
* @param keys The property keys to read, must not be {@code null}. The specified keys are read one after one until
* a string value is found.
* @return The property value or {@code null} if none.
@@ -86,9 +86,9 @@ public final class ConfigUtils
{
Object value = properties.get( key );
- if ( value instanceof String )
+ if ( value instanceof String || value instanceof Boolean || value instanceof Number )
{
- return (String) value;
+ return value.toString();
}
}
@@ -100,8 +100,8 @@ public final class ConfigUtils
*
* @param session The repository system session from which to read the configuration property, must not be
* {@code null}.
- * @param defaultValue The default value to return in case none of the property keys is set to a string, may be
- * {@code null}.
+ * @param defaultValue The default value to return in case none of the property keys is set to a
+ * string/boolean/number, may be {@code null}.
* @param keys The property keys to read, must not be {@code null}. The specified keys are read one after one until
* a string value is found.
* @return The property value or {@code null} if none.
http://git-wip-us.apache.org/repos/asf/maven-aether/blob/32267bff/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
----------------------------------------------------------------------
diff --git a/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java b/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
index 6be0476..8bd1147 100644
--- a/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
+++ b/aether-util/src/test/java/org/eclipse/aether/util/ConfigUtilsTest.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2013 Sonatype, Inc.
+ * Copyright (c) 2013, 2014 Sonatype, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -97,6 +97,24 @@ public class ConfigUtilsTest
}
@Test
+ public void testGetString_BooleanConversion()
+ {
+ config.put( "some-string", Boolean.TRUE );
+ assertEquals( "true", ConfigUtils.getString( config, "default", "some-string" ) );
+ config.put( "some-string", Boolean.FALSE );
+ assertEquals( "false", ConfigUtils.getString( config, "default", "some-string" ) );
+ }
+
+ @Test
+ public void testGetString_NumberConversion()
+ {
+ config.put( "some-string", Integer.valueOf( -7 ) );
+ assertEquals( "-7", ConfigUtils.getString( config, "default", "some-string" ) );
+ config.put( "some-string", new Float( -1.5f ) );
+ assertEquals( "-1.5", ConfigUtils.getString( config, "default", "some-string" ) );
+ }
+
+ @Test
public void testGetBoolean_Default()
{
config.put( "no-boolean", new Object() );