Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
HSEARCH-3827 Add a ConfigurationPropertySource for system properties
- Loading branch information
Showing
2 changed files
with
65 additions
and
0 deletions.
There are no files selected for viewing
57 changes: 57 additions & 0 deletions
57
...src/main/java/org/hibernate/search/engine/cfg/impl/SystemConfigurationPropertySource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* Hibernate Search, full-text search for your domain model | ||
* | ||
* License: GNU Lesser General Public License (LGPL), version 2.1 or later | ||
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>. | ||
*/ | ||
package org.hibernate.search.engine.cfg.impl; | ||
|
||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
import java.util.Set; | ||
|
||
import org.hibernate.search.engine.cfg.spi.AllAwareConfigurationPropertySource; | ||
|
||
public class SystemConfigurationPropertySource implements AllAwareConfigurationPropertySource { | ||
|
||
private static final SystemConfigurationPropertySource INSTANCE = new SystemConfigurationPropertySource(); | ||
|
||
public static AllAwareConfigurationPropertySource get() { | ||
return INSTANCE; | ||
} | ||
|
||
private SystemConfigurationPropertySource() { | ||
} | ||
|
||
@Override | ||
public Optional<?> get(String key) { | ||
Object value = System.getProperty( key ); | ||
return Optional.ofNullable( value ); | ||
} | ||
|
||
@Override | ||
public Optional<String> resolve(String key) { | ||
return Optional.of( key ); | ||
} | ||
|
||
@Override | ||
public Set<String> resolveAll(String prefix) { | ||
Set<String> prefixedPropertyKeys = new HashSet<>(); | ||
for ( Map.Entry<Object, Object> entry : System.getProperties().entrySet() ) { | ||
Object key = entry.getKey(); | ||
if ( key instanceof String ) { | ||
String stringKey = (String) key; | ||
if ( stringKey.startsWith( prefix ) ) { | ||
prefixedPropertyKeys.add( stringKey ); | ||
} | ||
} | ||
} | ||
return prefixedPropertyKeys; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getClass().getSimpleName(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters