Skip to content

Package: EnvFriendlyConfiguration

EnvFriendlyConfiguration

nameinstructionbranchcomplexitylinemethod
EnvFriendlyConfiguration()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
containsKey(String)
M: 16 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
envKey(String)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getKeys()
M: 28 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%
getProperty(String)
M: 20 C: 0
0%
M: 4 C: 0
0%
M: 3 C: 0
0%
M: 7 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2016, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech - initial API and implementation
12: *******************************************************************************/
13: package org.eclipse.kapua.commons.setting;
14:
15: import java.util.ArrayList;
16: import java.util.Iterator;
17: import java.util.List;
18: import java.util.stream.Collectors;
19:
20: import org.apache.commons.configuration.CompositeConfiguration;
21:
22: import com.google.common.collect.ImmutableList;
23:
24: public class EnvFriendlyConfiguration extends CompositeConfiguration {
25:
26: @Override
27: public Iterator<String> getKeys() {
28: List<String> keys = ImmutableList.copyOf(super.getKeys());
29: List<String> envKeys = keys.stream().map(this::envKey).collect(Collectors.toList());
30: List<String> result = new ArrayList<>();
31: result.addAll(keys);
32: result.addAll(envKeys);
33: return result.iterator();
34: }
35:
36: @Override
37: public Object getProperty(String key) {
38: Object property = super.getProperty(key);
39:• if(property != null) {
40: return property;
41: }
42: property = super.getProperty(envKey(key));
43:• if(property != null) {
44: return property;
45: } else {
46: return null;
47: }
48: }
49:
50: @Override
51: public boolean containsKey(String key) {
52: boolean contains = super.containsKey(key);
53:• return contains || super.containsKey(envKey(key));
54: }
55:
56: private String envKey(String key) {
57: return key.toUpperCase().replaceAll("\\.", "_");
58: }
59:
60: }