Skip to content

Commit bd94e57

Browse files
authored
Upgrade to dotenv-java v3.0.0 (#69)
* Update Java to 11 - Use Java 11 for maven compiler release - Bump dependency versions * Migrate tests to junit 5 - Refactor tests - Remove deprecations * Update docs - Making requirements clear * Switch to github actions - Remove .travis.yml * Add maven-compiler-plugin * Migrate DotEnvDslTest to jupiter * Update docs - Revert back to initial versions for now * Add dsl tests for systemProperties
1 parent f375008 commit bd94e57

File tree

8 files changed

+139
-129
lines changed

8 files changed

+139
-129
lines changed

.github/workflows/build.yml

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
name: Build with Maven
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
pull_request:
7+
branches: [ "master" ]
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
17+
- name: Set up JDK 11
18+
uses: actions/setup-java@v3
19+
with:
20+
java-version: '11'
21+
distribution: 'temurin'
22+
cache: maven
23+
24+
- name: Build with Maven
25+
run: mvn clean package dokka:javadocJar jacoco:report
26+
27+
- name: Report Coveralls
28+
uses: coverallsapp/github-action@v2

.travis.yml

-9
This file was deleted.

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ Contributors are not responsible for pushing packages to mavencentral and jcente
4545
mvn clean package dokka:javadocJar
4646
```
4747

48-
### Publish to Github Packages
48+
### Publish to GitHub Packages
4949

5050
Add `distributionManagement` to `pom.xml`
5151

README.md

+5-5
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ With **Java**
6666
import io.github.cdimascio.dotenv.Dotenv;
6767

6868
Dotenv dotenv = Dotenv.load();
69-
dotenv.get("MY_ENV_VAR1")
69+
dotenv.get("MY_ENV_VAR1");
7070
```
7171

7272
or with **Kotlin**
@@ -217,7 +217,7 @@ for (e in dotenv.entries()) {
217217
Dotenv
218218
.configure()
219219
.filename("myenv")
220-
.load()
220+
.load();
221221
```
222222
**Kotlin Dsl example**
223223

@@ -237,7 +237,7 @@ for (e in dotenv.entries()) {
237237
Dotenv
238238
.configure()
239239
.ignoreIfMalformed()
240-
.load()
240+
.load();
241241
```
242242
**Kotlin Dsl example**
243243

@@ -257,7 +257,7 @@ for (e in dotenv.entries()) {
257257
Dotenv
258258
.configure()
259259
.ignoreIfMissing()
260-
.load()
260+
.load();
261261
```
262262
**Kotlin Dsl example**
263263

@@ -277,7 +277,7 @@ for (e in dotenv.entries()) {
277277
Dotenv
278278
.configure()
279279
.systemProperties()
280-
.load()
280+
.load();
281281
```
282282
**Kotlin Dsl example**
283283

pom.xml

+23-48
Original file line numberDiff line numberDiff line change
@@ -48,36 +48,25 @@
4848
</developer>
4949
</developers>
5050

51-
5251
<properties>
53-
<dotenv.version>2.3.2</dotenv.version>
54-
<kotlin.compiler.jvmTarget>1.8</kotlin.compiler.jvmTarget>
55-
<maven.compiler.target>1.8</maven.compiler.target>
56-
<maven.compiler.source>1.8</maven.compiler.source>
57-
<kotlin.version>1.6.0</kotlin.version>
52+
<dotenv.version>3.0.0</dotenv.version>
53+
<maven.compiler.release>11</maven.compiler.release>
54+
<kotlin.version>1.9.22</kotlin.version>
5855
<main.class>io.cdimascio.DotenvKt</main.class>
59-
<junit.version>4.13.1</junit.version>
56+
<junit.version>5.10.1</junit.version>
6057
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
61-
<maven.source.plugin>3.0.1</maven.source.plugin>
62-
<maven.javadoc.plugin>3.0.0</maven.javadoc.plugin>
63-
<maven.jar.plugin>2.6</maven.jar.plugin>
64-
<maven.jacoco.plugin>0.8.4</maven.jacoco.plugin>
65-
<maven.coveralls.plugin>4.3.0</maven.coveralls.plugin>
66-
<maven.surefire.plugin>2.22.0</maven.surefire.plugin>
67-
<dokka.version>1.4.0</dokka.version>
58+
<maven.compiler.plugin>3.12.1</maven.compiler.plugin>
59+
<maven.source.plugin>3.3.0</maven.source.plugin>
60+
<maven.javadoc.plugin>3.6.3</maven.javadoc.plugin>
61+
<maven.jar.plugin>3.3.0</maven.jar.plugin>
62+
<maven.jacoco.plugin>0.8.11</maven.jacoco.plugin>
63+
<maven.surefire.plugin>3.2.3</maven.surefire.plugin>
64+
<dokka.version>1.9.10</dokka.version>
6865
<bintray.subject>cdimascio</bintray.subject>
6966
<bintray.repo>maven</bintray.repo>
7067
<bintray.package>dotenv-kotlin</bintray.package>
7168
</properties>
7269

73-
<pluginRepositories>
74-
<pluginRepository>
75-
<id>jcenter</id>
76-
<name>JCenter</name>
77-
<url>https://jcenter.bintray.com/</url>
78-
</pluginRepository>
79-
</pluginRepositories>
80-
8170
<dependencies>
8271
<dependency>
8372
<groupId>org.jetbrains.kotlin</groupId>
@@ -94,8 +83,8 @@
9483
</dependency>
9584

9685
<dependency>
97-
<groupId>junit</groupId>
98-
<artifactId>junit</artifactId>
86+
<groupId>org.junit.jupiter</groupId>
87+
<artifactId>junit-jupiter</artifactId>
9988
<version>${junit.version}</version>
10089
<scope>test</scope>
10190
</dependency>
@@ -111,6 +100,13 @@
111100
<build>
112101
<sourceDirectory>${project.basedir}/src/main/kotlin</sourceDirectory>
113102
<plugins>
103+
104+
<plugin>
105+
<groupId>org.apache.maven.plugins</groupId>
106+
<artifactId>maven-compiler-plugin</artifactId>
107+
<version>${maven.compiler.plugin}</version>
108+
</plugin>
109+
114110
<plugin>
115111
<artifactId>kotlin-maven-plugin</artifactId>
116112
<groupId>org.jetbrains.kotlin</groupId>
@@ -119,6 +115,7 @@
119115
<executions>
120116
<execution>
121117
<id>compile</id>
118+
<phase>process-sources</phase>
122119
<goals>
123120
<goal>compile</goal>
124121
</goals>
@@ -156,13 +153,6 @@
156153
<groupId>org.apache.maven.plugins</groupId>
157154
<artifactId>maven-surefire-plugin</artifactId>
158155
<version>${maven.surefire.plugin}</version>
159-
<dependencies>
160-
<dependency>
161-
<groupId>org.apache.maven.surefire</groupId>
162-
<artifactId>surefire-junit4</artifactId>
163-
<version>2.22.0</version>
164-
</dependency>
165-
</dependencies>
166156
<configuration>
167157
<includes>
168158
<include>**/*.java</include>
@@ -246,25 +236,10 @@
246236
</execution>
247237
</executions>
248238
</plugin>
249-
<plugin>
250-
<groupId>org.eluder.coveralls</groupId>
251-
<artifactId>coveralls-maven-plugin</artifactId>
252-
<version>${maven.coveralls.plugin}</version>
253-
<configuration>
254-
<repoToken>DTE7449Zg7tuwgrV6HeE0et1YB6JPPfeY</repoToken>
255-
</configuration>
256-
<dependencies>
257-
<dependency>
258-
<groupId>javax.xml.bind</groupId>
259-
<artifactId>jaxb-api</artifactId>
260-
<version>2.2.3</version>
261-
</dependency>
262-
</dependencies>
263-
</plugin>
264239
<plugin>
265240
<groupId>org.sonatype.plugins</groupId>
266241
<artifactId>nexus-staging-maven-plugin</artifactId>
267-
<version>1.6.7</version>
242+
<version>1.6.13</version>
268243
<extensions>true</extensions>
269244
<configuration>
270245
<serverId>ossrh</serverId>
@@ -305,7 +280,7 @@
305280
<plugin>
306281
<groupId>org.apache.maven.plugins</groupId>
307282
<artifactId>maven-gpg-plugin</artifactId>
308-
<version>1.5</version>
283+
<version>3.1.0</version>
309284
<executions>
310285
<execution>
311286
<id>sign-artifacts</id>

src/test/java/tests/JavaTests.java

+26-40
Original file line numberDiff line numberDiff line change
@@ -3,39 +3,32 @@
33
import io.github.cdimascio.dotenv.Dotenv;
44
import io.github.cdimascio.dotenv.DotenvEntry;
55
import io.github.cdimascio.dotenv.DotenvException;
6-
import org.junit.Before;
7-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
87

9-
import java.util.HashMap;
108
import java.util.Iterator;
119
import java.util.Map;
1210
import java.util.Set;
1311

14-
import static org.junit.Assert.*;
12+
import static org.junit.jupiter.api.Assertions.*;
1513

1614
public class JavaTests {
17-
private Map<String, String> envVars;
18-
19-
@Before
20-
public void setUp() {
21-
envVars = new HashMap<>();
22-
envVars.put("MY_TEST_EV1", "my test ev 1");
23-
envVars.put("MY_TEST_EV2", "my test ev 2");
24-
envVars.put("WITHOUT_VALUE", "");
25-
}
15+
private final Map<String, String> envVars = Map.of(
16+
"MY_TEST_EV1", "my test ev 1",
17+
"MY_TEST_EV2", "my test ev 2",
18+
"WITHOUT_VALUE", ""
19+
);
2620

27-
@Test(expected = DotenvException.class)
21+
@Test
2822
public void throwIfMalconfigured() {
29-
Dotenv.configure().load();
23+
assertThrows(DotenvException.class, () -> Dotenv.configure().load());
3024
}
3125

32-
@Test(expected = DotenvException.class)
26+
@Test
3327
public void load() {
34-
Dotenv dotenv = Dotenv.load();
35-
36-
for (String envName : envVars.keySet()) {
37-
assertEquals(envVars.get(envName), dotenv.get(envName));
38-
}
28+
assertThrows(DotenvException.class, () -> {
29+
Dotenv dotenv = Dotenv.load();
30+
envVars.keySet().forEach(envName -> assertEquals(envVars.get(envName), dotenv.get(envName)));
31+
});
3932
}
4033

4134
@Test
@@ -44,13 +37,7 @@ public void iteratorOverDotenv() {
4437
.ignoreIfMalformed()
4538
.load();
4639

47-
dotenv
48-
.entries()
49-
.forEach(e -> assertEquals(dotenv.get(e.getKey()), e.getValue()));
50-
51-
for (DotenvEntry e : dotenv.entries()) {
52-
assertEquals(dotenv.get(e.getKey()), e.getValue());
53-
}
40+
dotenv.entries().forEach(e -> assertEquals(dotenv.get(e.getKey()), e.getValue()));
5441
}
5542

5643
@Test
@@ -63,32 +50,31 @@ public void iteratorOverDotenvWithFilter() {
6350
Set<DotenvEntry> entriesAll = dotenv.entries();
6451
assertTrue(entriesInFile.size() < entriesAll.size());
6552

66-
for (Map.Entry<String, String> e: envVars.entrySet()) {
67-
assertEquals(dotenv.get(e.getKey()), e.getValue());
68-
}
53+
envVars.forEach((key, value) -> assertEquals(dotenv.get(key), value));
6954
}
7055

71-
@Test(expected = UnsupportedOperationException.class)
56+
@Test
7257
public void failToRemoveFromDotenv() {
7358
Dotenv dotenv = Dotenv.configure()
7459
.ignoreIfMalformed()
7560
.load();
7661

77-
Iterator<DotenvEntry> iter = dotenv.entries().iterator();
78-
while (iter.hasNext()) {
79-
iter.next();
80-
iter.remove();
81-
}
62+
assertThrows(UnsupportedOperationException.class, () -> {
63+
Iterator<DotenvEntry> iter = dotenv.entries().iterator();
64+
while (iter.hasNext()) {
65+
iter.next();
66+
iter.remove();
67+
}
68+
});
8269
}
8370

84-
@Test(expected = UnsupportedOperationException.class)
71+
@Test
8572
public void failToAddToDotenv() {
86-
8773
Dotenv dotenv = Dotenv.configure()
8874
.ignoreIfMalformed()
8975
.load();
9076

91-
dotenv.entries().add(new DotenvEntry("new", "value"));
77+
assertThrows(UnsupportedOperationException.class, () -> dotenv.entries().add(new DotenvEntry("new", "value")));
9278
}
9379

9480
@Test

src/test/kotlin/tests/BasicTests.kt

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
package tests
22

3-
import io.github.cdimascio.dotenv.DotenvException
43
import io.github.cdimascio.dotenv.Dotenv
4+
import io.github.cdimascio.dotenv.DotenvException
55
import kotlin.test.assertEquals
6+
import kotlin.test.assertFailsWith
67
import kotlin.test.assertNotNull
78
import kotlin.test.assertNull
8-
import org.junit.Test as test
9+
import org.junit.jupiter.api.Test as test
910

1011
class DotEnvTest {
1112
private val envVars = mapOf(
@@ -15,11 +16,13 @@ class DotEnvTest {
1516
"MULTI_LINE" to "hello\\nworld"
1617
)
1718

18-
@test(expected = DotenvException::class)
19+
@test
1920
fun dotenvMalformed() {
20-
Dotenv.configure()
21-
.directory("./src/test/resources")
22-
.load()
21+
assertFailsWith<DotenvException> {
22+
Dotenv.configure()
23+
.directory("./src/test/resources")
24+
.load()
25+
}
2326
}
2427

2528
@test
@@ -113,11 +116,13 @@ class DotEnvTest {
113116
}
114117
}
115118

116-
@test(expected = DotenvException::class)
119+
@test
117120
fun dotenvMissing() {
118-
Dotenv.configure()
119-
.directory("/missing/.env")
120-
.load()
121+
assertFailsWith<DotenvException> {
122+
Dotenv.configure()
123+
.directory("/missing/.env")
124+
.load()
125+
}
121126
}
122127

123128
@test
@@ -133,7 +138,7 @@ class DotEnvTest {
133138
}
134139

135140
private fun assertHostEnvVar(env: Dotenv) {
136-
val isWindows = System.getProperty("os.name").toLowerCase().indexOf("win") >= 0
141+
val isWindows = System.getProperty("os.name").lowercase().indexOf("win") >= 0
137142
if (isWindows) {
138143
val path = env["PATH"]
139144
assertNotNull(path)

0 commit comments

Comments
 (0)