@Test public void shouldThrowExceptionWhenNoEnvFileIsFound() { thrown.expect(Error.class); env.searchConfigFileInClasspath("nonexistent.conf"); }
File searchConfigFileInClasspath(String filename) { final List<File> files; try (Stream<Path> paths = Files.walk(new File(ConfigConstants.PROJECT_DIR).toPath())) { files = paths.filter(p -> p.endsWith(filename)).filter(p -> !p.toString().contains(ConfigConstants.TARGET_DIR)).map(Path::toFile) .collect(Collectors.toList()); } catch (IOException e) { throw new Error(e); } if (files.size() == 0) throw new Error("Config file with name [" + filename + "] could not be found in your classpath."); if (files.size() > 1) log.warn("More than one file found for this environment with name [" + filename + "]"); if (!files.get(0).isFile()) throw new Error("The file [" + files.get(0).getAbsolutePath() + "] is not a normal file."); return files.get(0); }
Env { File searchConfigFileInClasspath(String filename) { final List<File> files; try (Stream<Path> paths = Files.walk(new File(ConfigConstants.PROJECT_DIR).toPath())) { files = paths.filter(p -> p.endsWith(filename)).filter(p -> !p.toString().contains(ConfigConstants.TARGET_DIR)).map(Path::toFile) .collect(Collectors.toList()); } catch (IOException e) { throw new Error(e); } if (files.size() == 0) throw new Error("Config file with name [" + filename + "] could not be found in your classpath."); if (files.size() > 1) log.warn("More than one file found for this environment with name [" + filename + "]"); if (!files.get(0).isFile()) throw new Error("The file [" + files.get(0).getAbsolutePath() + "] is not a normal file."); return files.get(0); } }
Env { File searchConfigFileInClasspath(String filename) { final List<File> files; try (Stream<Path> paths = Files.walk(new File(ConfigConstants.PROJECT_DIR).toPath())) { files = paths.filter(p -> p.endsWith(filename)).filter(p -> !p.toString().contains(ConfigConstants.TARGET_DIR)).map(Path::toFile) .collect(Collectors.toList()); } catch (IOException e) { throw new Error(e); } if (files.size() == 0) throw new Error("Config file with name [" + filename + "] could not be found in your classpath."); if (files.size() > 1) log.warn("More than one file found for this environment with name [" + filename + "]"); if (!files.get(0).isFile()) throw new Error("The file [" + files.get(0).getAbsolutePath() + "] is not a normal file."); return files.get(0); } Env();  Env(String env); }
Env { File searchConfigFileInClasspath(String filename) { final List<File> files; try (Stream<Path> paths = Files.walk(new File(ConfigConstants.PROJECT_DIR).toPath())) { files = paths.filter(p -> p.endsWith(filename)).filter(p -> !p.toString().contains(ConfigConstants.TARGET_DIR)).map(Path::toFile) .collect(Collectors.toList()); } catch (IOException e) { throw new Error(e); } if (files.size() == 0) throw new Error("Config file with name [" + filename + "] could not be found in your classpath."); if (files.size() > 1) log.warn("More than one file found for this environment with name [" + filename + "]"); if (!files.get(0).isFile()) throw new Error("The file [" + files.get(0).getAbsolutePath() + "] is not a normal file."); return files.get(0); } Env();  Env(String env); static Env env(); }
Env { File searchConfigFileInClasspath(String filename) { final List<File> files; try (Stream<Path> paths = Files.walk(new File(ConfigConstants.PROJECT_DIR).toPath())) { files = paths.filter(p -> p.endsWith(filename)).filter(p -> !p.toString().contains(ConfigConstants.TARGET_DIR)).map(Path::toFile) .collect(Collectors.toList()); } catch (IOException e) { throw new Error(e); } if (files.size() == 0) throw new Error("Config file with name [" + filename + "] could not be found in your classpath."); if (files.size() > 1) log.warn("More than one file found for this environment with name [" + filename + "]"); if (!files.get(0).isFile()) throw new Error("The file [" + files.get(0).getAbsolutePath() + "] is not a normal file."); return files.get(0); } Env();  Env(String env); static Env env(); static final Env INSTANCE; public Config config; }