From 4c864dbfe7373a89029c7f43f846346a8c581ee8 Mon Sep 17 00:00:00 2001 From: Carmine DiMascio Date: Fri, 18 Sep 2020 23:54:11 -0400 Subject: [PATCH] add support for default value --- .travis.yml | 2 +- pom.xml | 51 ++++++++++--------- .../io/github/cdimascio/dotenv/Dotenv.java | 1 + .../cdimascio/dotenv/DotenvBuilder.java | 6 +++ 4 files changed, 36 insertions(+), 24 deletions(-) diff --git a/.travis.yml b/.travis.yml index 49cfe83..8d7b2c5 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,4 +7,4 @@ script: mvn clean test sudo: false after_success: # - mvn clean test jacoco:report coveralls:report - - mvn clean test + - mvn clean test jacoco:report diff --git a/pom.xml b/pom.xml index b40560d..05ee3d3 100644 --- a/pom.xml +++ b/pom.xml @@ -10,7 +10,7 @@ io.github.cdimascio dotenv-java - 1.0.0 + 1.0.1 @@ -57,7 +57,7 @@ UTF-8 3.0.1 - 3.0.0 + 3.2.0 cdimascio maven dotenv-java @@ -113,10 +113,13 @@ + org.apache.maven.plugins maven-javadoc-plugin ${maven.javadoc.plugin} + + attach-javadocs @@ -126,27 +129,29 @@ - - - - - - - - - - - - - - - - - - - - - + + + org.jacoco + jacoco-maven-plugin + 0.8.6 + + + prepare-agent + + prepare-agent + + + + + + + + + + + + + diff --git a/src/main/java/io/github/cdimascio/dotenv/Dotenv.java b/src/main/java/io/github/cdimascio/dotenv/Dotenv.java index ae31471..2809316 100644 --- a/src/main/java/io/github/cdimascio/dotenv/Dotenv.java +++ b/src/main/java/io/github/cdimascio/dotenv/Dotenv.java @@ -19,4 +19,5 @@ static Dotenv load() { Set entries(); Set entries(EntriesFilter filter); String get(String key); + String get(String key, String defaultValue); } diff --git a/src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java b/src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java index f7a8d5e..cff45cd 100644 --- a/src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java +++ b/src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java @@ -102,6 +102,12 @@ public String get(String key) { return value != null ? value : map.get(key); } + @Override + public String get(String key, String defaultValue) { + var value = this.get(key); + return value != null ? value : defaultValue; + } + private Map buildEntries() { var envMap = new HashMap(); System.getenv().forEach(envMap::put);