@Test public void should_handle_valid_file() { System.setProperty(AgentConfigLocator.SYSPROP_CONFIG, "src/test/resources/codekvast1.conf"); assertThat(AgentConfigLocator.locateConfig(), not(nullValue())); outputCapture.expect(containsString("Found src/test/resources/codekvast1.conf")); }
public static File locateConfig() { List<String> explicitLocations = Arrays.asList(System.getProperty(SYSPROP_CONFIG), System.getenv(ENVVAR_CODEKVAST_CONFIG)); for (String location : explicitLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } logger.warning( String.format( "Invalid value of -D%s or %s: %s, Codekvast will not start.", SYSPROP_CONFIG, ENVVAR_CODEKVAST_CONFIG, location)); return null; } } List<String> automaticLocations = Arrays.asList( "./codekvast.conf", "./conf/codekvast.conf", constructLocation(System.getProperty(SYSPROP_CATALINA_HOME), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_HOME), "conf"), constructLocation(System.getProperty(SYSPROP_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_HOME), ".config"), "/etc/codekvast/codekvast.conf", "/etc/codekvast.conf"); for (String location : automaticLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } } } logger.warning("No configuration file found, Codekvast will not start."); return null; }
AgentConfigLocator { public static File locateConfig() { List<String> explicitLocations = Arrays.asList(System.getProperty(SYSPROP_CONFIG), System.getenv(ENVVAR_CODEKVAST_CONFIG)); for (String location : explicitLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } logger.warning( String.format( "Invalid value of -D%s or %s: %s, Codekvast will not start.", SYSPROP_CONFIG, ENVVAR_CODEKVAST_CONFIG, location)); return null; } } List<String> automaticLocations = Arrays.asList( "./codekvast.conf", "./conf/codekvast.conf", constructLocation(System.getProperty(SYSPROP_CATALINA_HOME), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_HOME), "conf"), constructLocation(System.getProperty(SYSPROP_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_HOME), ".config"), "/etc/codekvast/codekvast.conf", "/etc/codekvast.conf"); for (String location : automaticLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } } } logger.warning("No configuration file found, Codekvast will not start."); return null; } }
AgentConfigLocator { public static File locateConfig() { List<String> explicitLocations = Arrays.asList(System.getProperty(SYSPROP_CONFIG), System.getenv(ENVVAR_CODEKVAST_CONFIG)); for (String location : explicitLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } logger.warning( String.format( "Invalid value of -D%s or %s: %s, Codekvast will not start.", SYSPROP_CONFIG, ENVVAR_CODEKVAST_CONFIG, location)); return null; } } List<String> automaticLocations = Arrays.asList( "./codekvast.conf", "./conf/codekvast.conf", constructLocation(System.getProperty(SYSPROP_CATALINA_HOME), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_HOME), "conf"), constructLocation(System.getProperty(SYSPROP_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_HOME), ".config"), "/etc/codekvast/codekvast.conf", "/etc/codekvast.conf"); for (String location : automaticLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } } } logger.warning("No configuration file found, Codekvast will not start."); return null; } private  AgentConfigLocator(); }
AgentConfigLocator { public static File locateConfig() { List<String> explicitLocations = Arrays.asList(System.getProperty(SYSPROP_CONFIG), System.getenv(ENVVAR_CODEKVAST_CONFIG)); for (String location : explicitLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } logger.warning( String.format( "Invalid value of -D%s or %s: %s, Codekvast will not start.", SYSPROP_CONFIG, ENVVAR_CODEKVAST_CONFIG, location)); return null; } } List<String> automaticLocations = Arrays.asList( "./codekvast.conf", "./conf/codekvast.conf", constructLocation(System.getProperty(SYSPROP_CATALINA_HOME), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_HOME), "conf"), constructLocation(System.getProperty(SYSPROP_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_HOME), ".config"), "/etc/codekvast/codekvast.conf", "/etc/codekvast.conf"); for (String location : automaticLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } } } logger.warning("No configuration file found, Codekvast will not start."); return null; } private  AgentConfigLocator(); static File locateConfig(); }
AgentConfigLocator { public static File locateConfig() { List<String> explicitLocations = Arrays.asList(System.getProperty(SYSPROP_CONFIG), System.getenv(ENVVAR_CODEKVAST_CONFIG)); for (String location : explicitLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } logger.warning( String.format( "Invalid value of -D%s or %s: %s, Codekvast will not start.", SYSPROP_CONFIG, ENVVAR_CODEKVAST_CONFIG, location)); return null; } } List<String> automaticLocations = Arrays.asList( "./codekvast.conf", "./conf/codekvast.conf", constructLocation(System.getProperty(SYSPROP_CATALINA_HOME), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_HOME), "conf"), constructLocation(System.getProperty(SYSPROP_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_CATALINA_BASE), "conf"), constructLocation(System.getenv(ENVVAR_HOME), ".config"), "/etc/codekvast/codekvast.conf", "/etc/codekvast.conf"); for (String location : automaticLocations) { if (location != null) { File file = tryLocation(location); if (file != null) { return file; } } } logger.warning("No configuration file found, Codekvast will not start."); return null; } private  AgentConfigLocator(); static File locateConfig();  }