From d44d76ea03aca7490a11e9a1d9c52fdc669feb1c Mon Sep 17 00:00:00 2001 From: Andrea Bollini Date: Thu, 23 May 2024 16:32:56 +0200 Subject: [PATCH] Create a temporary version of the ConfigurationPlaceholderConfigurer to overcome bu in 2.10 --- .../util/DSpaceConfigurationInitializer.java | 6 +-- ...aceConfigurationPlaceholderConfigurer.java | 5 +- .../DSpaceConfigurationPropertySource.java | 54 +++++++++++++++++++ 3 files changed, 59 insertions(+), 6 deletions(-) create mode 100644 dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPropertySource.java diff --git a/dspace-api/src/test/java/org/dspace/util/DSpaceConfigurationInitializer.java b/dspace-api/src/test/java/org/dspace/util/DSpaceConfigurationInitializer.java index e2e0355f12..e5a8adb2fd 100644 --- a/dspace-api/src/test/java/org/dspace/util/DSpaceConfigurationInitializer.java +++ b/dspace-api/src/test/java/org/dspace/util/DSpaceConfigurationInitializer.java @@ -8,7 +8,7 @@ package org.dspace.util; import org.apache.commons.configuration2.Configuration; -import org.apache.commons.configuration2.spring.ConfigurationPropertySource; +import org.dspace.servicemanager.config.DSpaceConfigurationPropertySource; import org.dspace.services.ConfigurationService; import org.dspace.services.factory.DSpaceServicesFactory; import org.springframework.context.ApplicationContextInitializer; @@ -38,8 +38,8 @@ public class DSpaceConfigurationInitializer Configuration configuration = configurationService.getConfiguration(); // Create an Apache Commons Configuration Property Source from our configuration - ConfigurationPropertySource apacheCommonsConfigPropertySource = - new ConfigurationPropertySource(configuration.getClass().getName(), configuration); + DSpaceConfigurationPropertySource apacheCommonsConfigPropertySource = + new DSpaceConfigurationPropertySource(configuration.getClass().getName(), configuration); // Prepend it to the Environment's list of PropertySources // NOTE: This is added *first* in the list so that settings in DSpace's diff --git a/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPlaceholderConfigurer.java b/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPlaceholderConfigurer.java index b85450dcd0..caa715e21b 100644 --- a/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPlaceholderConfigurer.java +++ b/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPlaceholderConfigurer.java @@ -8,7 +8,6 @@ package org.dspace.servicemanager.config; import org.apache.commons.configuration2.Configuration; -import org.apache.commons.configuration2.spring.ConfigurationPropertySource; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.env.MutablePropertySources; @@ -27,8 +26,8 @@ import org.springframework.core.env.MutablePropertySources; public class DSpaceConfigurationPlaceholderConfigurer extends PropertySourcesPlaceholderConfigurer { public DSpaceConfigurationPlaceholderConfigurer(Configuration configuration) { - ConfigurationPropertySource apacheCommonsConfigPropertySource = - new ConfigurationPropertySource(configuration.getClass().getName(), configuration); + DSpaceConfigurationPropertySource apacheCommonsConfigPropertySource = + new DSpaceConfigurationPropertySource(configuration.getClass().getName(), configuration); MutablePropertySources propertySources = new MutablePropertySources(); propertySources.addLast(apacheCommonsConfigPropertySource); setPropertySources(propertySources); diff --git a/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPropertySource.java b/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPropertySource.java new file mode 100644 index 0000000000..9bbf821766 --- /dev/null +++ b/dspace-services/src/main/java/org/dspace/servicemanager/config/DSpaceConfigurationPropertySource.java @@ -0,0 +1,54 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.dspace.servicemanager.config; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.configuration2.Configuration; +import org.apache.commons.lang3.ArrayUtils; +import org.springframework.core.env.EnumerablePropertySource; + +/** + * Allow use of Apache Commons Configuration Objects as Spring PropertySources. + * This class is a copy of the ConfigurationPropertySource class in the Apache Commons Configuration + * project needed until to fix the issue https://issues.apache.org/jira/browse/CONFIGURATION-846 + */ +public class DSpaceConfigurationPropertySource extends EnumerablePropertySource { + + protected DSpaceConfigurationPropertySource(final String name) { + super(name); + } + + public DSpaceConfigurationPropertySource(final String name, final Configuration source) { + super(name, source); + } + + @Override + public Object getProperty(final String name) { + final String[] propValue = source.getStringArray(name); + return propValue != null && propValue.length == 1 ? propValue[0] : propValue; + } + + @Override + public String[] getPropertyNames() { + final List keys = new ArrayList<>(); + source.getKeys().forEachRemaining(keys::add); + return keys.toArray(ArrayUtils.EMPTY_STRING_ARRAY); + } +}