diff --git a/pom.xml b/pom.xml
index de7b2889..1715047f 100644
--- a/pom.xml
+++ b/pom.xml
@@ -670,6 +670,27 @@
+
+
+ org.apache.logging.log4j
+ log4j-api
+ 2.9.1
+ test
+
+
+
+ org.apache.logging.log4j
+ log4j-core
+ 2.9.1
+ test
+
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ 2.9.1
+ test
+
diff --git a/redback-common/redback-common-configuration/redback-common-configuration-acc2/pom.xml b/redback-common/redback-common-configuration/redback-common-configuration-acc2/pom.xml
index 0073e84a..dcc2fd09 100644
--- a/redback-common/redback-common-configuration/redback-common-configuration-acc2/pom.xml
+++ b/redback-common/redback-common-configuration/redback-common-configuration-acc2/pom.xml
@@ -106,6 +106,22 @@
org.apache.commons
commons-lang3
+
+
+ org.apache.logging.log4j
+ log4j-api
+ test
+
+
+ org.apache.logging.log4j
+ log4j-core
+ test
+
+
+ org.apache.logging.log4j
+ log4j-slf4j-impl
+ test
+
diff --git a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/main/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistry.java b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/main/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistry.java
index 910f4fe4..4d3f7587 100644
--- a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/main/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistry.java
+++ b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/main/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistry.java
@@ -52,6 +52,8 @@ import java.net.URL;
import java.nio.file.Path;
import java.util.*;
import java.util.regex.Pattern;
+import java.util.stream.Collectors;
+import java.util.stream.StreamSupport;
/**
* Implementation of the registry component using
@@ -67,6 +69,8 @@ import java.util.regex.Pattern;
public class CommonsConfigurationRegistry
implements ConfigRegistry
{
+ private static final Pattern DOT_NAME_PATTERN = Pattern.compile( "([^.]+)(\\..*)*" );
+
/**
* The combined configuration instance that houses the registry.
*/
@@ -81,6 +85,7 @@ public class CommonsConfigurationRegistry
private String propertyDelimiter = ".";
+ private boolean addSystemProperties = false;
/**
* The configuration properties for the registry. This should take the format of an input to the Commons
@@ -261,35 +266,18 @@ public class CommonsConfigurationRegistry
public Collection getKeys()
{
- Set keys = new HashSet( );
+ Iterable iterable = () -> configuration.getKeys( );
+ return StreamSupport.stream( iterable.spliterator( ), false )
+ .map( k -> DOT_NAME_PATTERN.matcher( k ) )
+ .filter( k -> k.matches( ) )
+ .map( k -> k.group( 1 ) ).collect( Collectors.toSet( ) );
- for ( Iterator i = configuration.getKeys( ); i.hasNext( ); )
- {
- String key = i.next( );
-
- int index = key.indexOf( '.' );
- if ( index < 0 )
- {
- keys.add( key );
- } else
- {
- keys.add( key.substring( 0, index ) );
- }
- }
-
- return keys;
}
public Collection getFullKeys()
{
- Set keys = new HashSet( );
-
- for ( Iterator i = configuration.getKeys( ); i.hasNext( ); )
- {
- keys.add( i.next( ) );
- }
-
- return keys;
+ Iterable iterable = () -> configuration.getKeys( );
+ return StreamSupport.stream( iterable.spliterator( ), false ).collect( Collectors.toSet( ) );
}
public void remove(String key)
@@ -491,7 +479,8 @@ public class CommonsConfigurationRegistry
this.content = content;
}
- StringFileSystem(String encoding, String content) {
+ StringFileSystem(String encoding, String content)
+ {
this.encoding = encoding;
this.content = content;
}
@@ -579,9 +568,7 @@ public class CommonsConfigurationRegistry
CombinedConfiguration configuration;
if ( StringUtils.isNotBlank( combinedConfigurationDefinition ) )
{
-
- // This part is mainly for backwards compatibility.
- // It allows to use system properties in the XML declaration.
+ String interpolatedProps;
Parameters params = new Parameters( );
DefaultExpressionEngineSymbols symbols = new DefaultExpressionEngineSymbols.Builder( DefaultExpressionEngineSymbols.DEFAULT_SYMBOLS )
.setPropertyDelimiter( propertyDelimiter )
@@ -590,8 +577,11 @@ public class CommonsConfigurationRegistry
.setEscapedDelimiter( "\\" + propertyDelimiter )
.create( );
DefaultExpressionEngine expressionEngine = new DefaultExpressionEngine( symbols );
+
+ // It allows to use system properties in the XML declaration.
+
ConfigurationInterpolator interpolator = ConfigurationInterpolator.fromSpecification( new InterpolatorSpecification.Builder( ).withDefaultLookup( DefaultLookups.SYSTEM_PROPERTIES.getLookup( ) ).create( ) );
- String interpolatedProps = interpolator.interpolate( combinedConfigurationDefinition ).toString( );
+ interpolatedProps = interpolator.interpolate( combinedConfigurationDefinition ).toString( );
logger.debug( "Loading configuration into commons-configuration, xml {}", interpolatedProps );
// This is the builder configuration for the XML declaration, that contains the definition
// for the sources that are used for the CombinedConfiguration.
@@ -600,7 +590,6 @@ public class CommonsConfigurationRegistry
new FileBasedConfigurationBuilder<>(
XMLConfiguration.class )
.configure( params.xml( )
- .setInterpolator( interpolator )
.setFileSystem( fs )
.setFileName( "config.xml" )
.setListDelimiterHandler(
@@ -624,14 +613,17 @@ public class CommonsConfigurationRegistry
}
// In the end, we add the system properties to the combined configuration
- configuration.addConfiguration( new SystemConfiguration( ), "SystemProperties" );
+ if ( addSystemProperties )
+ {
+ configuration.addConfiguration( new SystemConfiguration( ), "SystemProperties" );
+ }
this.configuration = configuration;
}
catch ( ConfigurationException e )
{
- logger.error("Fatal error, while reading the configuration definition: "+e.getMessage());
- logger.error("The definition was:");
+ logger.error( "Fatal error, while reading the configuration definition: " + e.getMessage( ) );
+ logger.error( "The definition was:" );
logger.error( combinedConfigurationDefinition );
throw new RuntimeException( e.getMessage( ), e );
}
@@ -662,4 +654,26 @@ public class CommonsConfigurationRegistry
{
this.configurationBuilder = configurationBuilder;
}
+
+ /**
+ * Returns true, if the system properties are added to the base configuration. Otherwise system properties
+ * can be interpolated by ${sys:var} syntax.
+ *
+ * @return
+ */
+ public boolean isAddSystemProperties()
+ {
+ return addSystemProperties;
+ }
+
+ /**
+ * Set to true, if the system properties should be added to the base configuration.
+ * If set to false, system properties are no direct part of the configuration.
+ *
+ * @param addSystemProperties
+ */
+ public void setAddSystemProperties(boolean addSystemProperties)
+ {
+ this.addSystemProperties = addSystemProperties;
+ }
}
diff --git a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/AbstractRegistryTest.java b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/AbstractRegistryTest.java
index fa6d6371..a51ff779 100644
--- a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/AbstractRegistryTest.java
+++ b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/AbstractRegistryTest.java
@@ -52,10 +52,16 @@ public abstract class AbstractRegistryTest
return getRegistry( getRoleHint() );
}
- public ConfigRegistry getRegistry( String name )
+ public ConfigRegistry getRegistry( String name ) throws Exception
+ {
+ return getRegistry(name, false);
+ }
+
+ public ConfigRegistry getRegistry( String name , boolean addSysProps )
throws Exception
{
- ConfigRegistry registry = applicationContext.getBean( name, ConfigRegistry.class );
+ CommonsConfigurationRegistry registry = applicationContext.getBean( name, CommonsConfigurationRegistry.class );
+ registry.setAddSystemProperties( addSysProps );
registry.initialize();
return registry;
}
diff --git a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistryTest.java b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistryTest.java
index 57d55cde..778dc457 100644
--- a/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistryTest.java
+++ b/redback-common/redback-common-configuration/redback-common-configuration-acc2/src/test/java/org/apache/archiva/redback/common/config/acc2/CommonsConfigurationRegistryTest.java
@@ -33,11 +33,7 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.nio.file.StandardCopyOption;
import java.rmi.registry.Registry;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.List;
-import java.util.Map;
-import java.util.NoSuchElementException;
+import java.util.*;
/**
* Test the commons configuration registry.
@@ -70,7 +66,7 @@ public class CommonsConfigurationRegistryTest
public void testDefaultConfiguration()
throws Exception
{
- registry = getRegistry( "default" );
+ registry = getRegistry( "default" , true);
assertEquals( "Check system property override", System.getProperty( "user.dir" ),
registry.getString( "user.dir" ) );
@@ -78,11 +74,36 @@ public class CommonsConfigurationRegistryTest
assertNull( "Check other properties are not loaded", registry.getString( "test.value" ) );
}
+ @Test
+ public void testGetKeys() throws Exception
+ {
+ registry = getRegistry( "builder" );
+ Collection keys = registry.getKeys( );
+ HashSet