@Test public void testLinesStartingWithHasAreIgnored() throws EnvFileErrorException { Map<String, String> result = parser.getEnvVars(Collections.emptyMap(), getFile("full-line-comments.env")); Assert.assertEquals(1, result.size()); Assert.assertEquals("value", result.get("key")); }
@NotNull @Override protected Map<String, String> getEnvVars(@NotNull Map<String, String> runConfigEnv, @NotNull String path) throws EnvFileErrorException { Map<String, String> result = new LinkedHashMap<>(); try { List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); for (String l: lines) { String strippedLine = l.trim(); if (!strippedLine.startsWith("#") && strippedLine.contains("=")) { String[] tokens = strippedLine.split("=", 2); String key = tokens[0]; String value = trim(tokens[1]); result.put(key, value); } } } catch (IOException ex) { throw new EnvFileErrorException(ex); } return result; }
DotEnvFileParser extends AbstractEnvVarsProvider { @NotNull @Override protected Map<String, String> getEnvVars(@NotNull Map<String, String> runConfigEnv, @NotNull String path) throws EnvFileErrorException { Map<String, String> result = new LinkedHashMap<>(); try { List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); for (String l: lines) { String strippedLine = l.trim(); if (!strippedLine.startsWith("#") && strippedLine.contains("=")) { String[] tokens = strippedLine.split("=", 2); String key = tokens[0]; String value = trim(tokens[1]); result.put(key, value); } } } catch (IOException ex) { throw new EnvFileErrorException(ex); } return result; } }
DotEnvFileParser extends AbstractEnvVarsProvider { @NotNull @Override protected Map<String, String> getEnvVars(@NotNull Map<String, String> runConfigEnv, @NotNull String path) throws EnvFileErrorException { Map<String, String> result = new LinkedHashMap<>(); try { List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); for (String l: lines) { String strippedLine = l.trim(); if (!strippedLine.startsWith("#") && strippedLine.contains("=")) { String[] tokens = strippedLine.split("=", 2); String key = tokens[0]; String value = trim(tokens[1]); result.put(key, value); } } } catch (IOException ex) { throw new EnvFileErrorException(ex); } return result; } DotEnvFileParser(boolean shouldSubstituteEnvVar); }
DotEnvFileParser extends AbstractEnvVarsProvider { @NotNull @Override protected Map<String, String> getEnvVars(@NotNull Map<String, String> runConfigEnv, @NotNull String path) throws EnvFileErrorException { Map<String, String> result = new LinkedHashMap<>(); try { List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); for (String l: lines) { String strippedLine = l.trim(); if (!strippedLine.startsWith("#") && strippedLine.contains("=")) { String[] tokens = strippedLine.split("=", 2); String key = tokens[0]; String value = trim(tokens[1]); result.put(key, value); } } } catch (IOException ex) { throw new EnvFileErrorException(ex); } return result; } DotEnvFileParser(boolean shouldSubstituteEnvVar);  }
DotEnvFileParser extends AbstractEnvVarsProvider { @NotNull @Override protected Map<String, String> getEnvVars(@NotNull Map<String, String> runConfigEnv, @NotNull String path) throws EnvFileErrorException { Map<String, String> result = new LinkedHashMap<>(); try { List<String> lines = Files.readAllLines(Paths.get(path), StandardCharsets.UTF_8); for (String l: lines) { String strippedLine = l.trim(); if (!strippedLine.startsWith("#") && strippedLine.contains("=")) { String[] tokens = strippedLine.split("=", 2); String key = tokens[0]; String value = trim(tokens[1]); result.put(key, value); } } } catch (IOException ex) { throw new EnvFileErrorException(ex); } return result; } DotEnvFileParser(boolean shouldSubstituteEnvVar);   }