4141 * Created by gupele on 5/25/2015.
4242 */
4343public final class ConfigurationFileLocator {
44+
45+ /** name of property containing path to directory with configuration file */
46+ public static final String CONFIG_DIR_PROPERTY = "insights.configurationDirectory" ;
47+
4448 private final String configurationFileName ;
4549
4650 public ConfigurationFileLocator (String configurationFileName ) {
@@ -49,22 +53,34 @@ public ConfigurationFileLocator(String configurationFileName) {
4953 }
5054
5155 public InputStream getConfigurationFile () {
52- InputStream inputStream = ConfigurationFileLocator .class .getClassLoader ().getResourceAsStream (configurationFileName );
53- if (inputStream != null ) {
54- InternalLogger .INSTANCE .logAlways (InternalLogger .LoggingLevel .INFO , "Configuration file has been successfully found as resource" );
55- return inputStream ;
56- }
5756
58- // Trying to load configuration as a resource.
59- String configurationFile = getConfigurationFromCurrentClassLoader () ;
57+ String configurationFile ;
58+ InputStream inputStream ;
6059
61- // If not found as a resource, trying to load from the executing jar directory
62- if (configurationFile == null ) {
63- configurationFile = getConfigurationFromLibraryLocation ();
60+ // first try to get from dir defined explicitly in system property insights.configurationFile
61+ String configDirFromProperty = System .getProperty (CONFIG_DIR_PROPERTY );
62+ if (configDirFromProperty != null ) {
63+ configurationFile = getConfigurationAbsolutePath (configDirFromProperty );
64+ } else {
6465
65- // If still not found try to get it from the class path
66+ inputStream = ConfigurationFileLocator .class .getClassLoader ().getResourceAsStream (configurationFileName );
67+ if (inputStream != null ) {
68+ InternalLogger .INSTANCE .logAlways (InternalLogger .LoggingLevel .INFO ,
69+ "Configuration file has been successfully found as resource" );
70+ return inputStream ;
71+ }
72+
73+ // Trying to load configuration as a resource.
74+ configurationFile = getConfigurationFromCurrentClassLoader ();
75+
76+ // If not found as a resource, trying to load from the executing jar directory
6677 if (configurationFile == null ) {
67- configurationFile = getConfFromClassPath ();
78+ configurationFile = getConfigurationFromLibraryLocation ();
79+
80+ // If still not found try to get it from the class path
81+ if (configurationFile == null ) {
82+ configurationFile = getConfFromClassPath ();
83+ }
6884 }
6985 }
7086
0 commit comments