@Test public void testLoadConfigFile() throws Exception { ConfigObject config = LeoUtils.loadConfigFile("simple", "conf/common.groovy", "conf/bob.groovy"); String commonVariable = (String) config.get("myCommonVariable"); String bobVariable = (String) config.get("myBobVariable"); boolean isSimple = (Boolean) config.get("isSimple"); boolean isHappy = (Boolean) config.get("isHappy"); assertEquals(commonVariable, "common1234567"); assertEquals(bobVariable, "bob123"); assertTrue(isSimple); assertTrue(isHappy); config = LeoUtils.loadConfigFile("sad", "conf/common.groovy", "conf/bob.groovy"); commonVariable = (String) config.get("myCommonVariable"); bobVariable = (String) config.get("myBobVariable"); isSimple = (Boolean) config.get("isSimple"); isHappy = (Boolean) config.get("isHappy"); assertEquals(commonVariable, "common1234567"); assertEquals(bobVariable, "bob123"); assertFalse(isSimple); assertFalse(isHappy); }
public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); for (String filePath : configFilePaths) { Resource resource = loader.getResource(filePath); if(!resource.exists()) { log.warn("File " + filePath + " not found. Loading other configuration files..."); continue; } String resourceString = IOUtils.toString(resource.getInputStream()); config.merge(slurper.parse(resourceString)); log.info("Loaded file: " + resource.getURI()); } return config; }
LeoUtils { public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); for (String filePath : configFilePaths) { Resource resource = loader.getResource(filePath); if(!resource.exists()) { log.warn("File " + filePath + " not found. Loading other configuration files..."); continue; } String resourceString = IOUtils.toString(resource.getInputStream()); config.merge(slurper.parse(resourceString)); log.info("Loaded file: " + resource.getURI()); } return config; } }
LeoUtils { public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); for (String filePath : configFilePaths) { Resource resource = loader.getResource(filePath); if(!resource.exists()) { log.warn("File " + filePath + " not found. Loading other configuration files..."); continue; } String resourceString = IOUtils.toString(resource.getInputStream()); config.merge(slurper.parse(resourceString)); log.info("Loaded file: " + resource.getURI()); } return config; }  }
LeoUtils { public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); for (String filePath : configFilePaths) { Resource resource = loader.getResource(filePath); if(!resource.exists()) { log.warn("File " + filePath + " not found. Loading other configuration files..."); continue; } String resourceString = IOUtils.toString(resource.getInputStream()); config.merge(slurper.parse(resourceString)); log.info("Loaded file: " + resource.getURI()); } return config; }  static String getTimestampDateDotTime(); static String getTimestampDateUnderscoreTime(); static String getUUID(); static URL createURL(String name); static String getFileURI(File f); static List<File> listFiles(File src, FileFilter filter, boolean recurse); static String extractPearFile(File installDir, File pearFile, boolean doVerification, boolean cleanInstallDir); static Class<?> getRuntimeClass(); static ConfigObject loadConfigFile(String environment, String... configFilePaths); static String filterText(String input, List<TextFilter> filters); static Set<ConfigurationParameter> getStaticConfigurationParameters(Class c); static Parameter getParameter(String name, Parameter[] parameters); static Parameter[] addParameter(Parameter p, Parameter[] parameters); static Map<String, String> parseMappingString(String jsonString); static String getHeaderManipulationSafeString(Object object); }
LeoUtils { public static ConfigObject loadConfigFile(String environment, String... configFilePaths) throws IOException { ConfigSlurper slurper = new ConfigSlurper(environment); ConfigObject config = new ConfigObject(); ClassLoader cl = ClassLoader.getSystemClassLoader(); DefaultResourceLoader loader = new DefaultResourceLoader(cl); for (String filePath : configFilePaths) { Resource resource = loader.getResource(filePath); if(!resource.exists()) { log.warn("File " + filePath + " not found. Loading other configuration files..."); continue; } String resourceString = IOUtils.toString(resource.getInputStream()); config.merge(slurper.parse(resourceString)); log.info("Loaded file: " + resource.getURI()); } return config; }  static String getTimestampDateDotTime(); static String getTimestampDateUnderscoreTime(); static String getUUID(); static URL createURL(String name); static String getFileURI(File f); static List<File> listFiles(File src, FileFilter filter, boolean recurse); static String extractPearFile(File installDir, File pearFile, boolean doVerification, boolean cleanInstallDir); static Class<?> getRuntimeClass(); static ConfigObject loadConfigFile(String environment, String... configFilePaths); static String filterText(String input, List<TextFilter> filters); static Set<ConfigurationParameter> getStaticConfigurationParameters(Class c); static Parameter getParameter(String name, Parameter[] parameters); static Parameter[] addParameter(Parameter p, Parameter[] parameters); static Map<String, String> parseMappingString(String jsonString); static String getHeaderManipulationSafeString(Object object);  }