Skip to content

Commit d586bd3

Browse files
authored
Adds support to Java 11 (#51)
* Define automatic pom.xml name for the copy-rename-maven-plugin, using the project artifactId and version tags. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Upgrade to JDK 11 - Using Java 11 everywhere (instead of 1.8 for sources and 11 for tests) - Update dependency versions Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Remove maven.coveralls.plugin Since the project is already using https://codacy.com, they already provide coverage service which doesn't require a maven plugin. Uploading coverage reports can be done inside a GitHub Action workflow. This way, a single service can be used for code quality and coverage. The coveralls plugin is abandoned, has old dependencies and doesn't support new JDK versions. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Update pom to use JUnit 5 Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Migrate tests from JUnit 4 to JUnit 5 - Refactor tests - Organize test code Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Refactoring to use java var keyword where it makes code cleaner. - Define final variable and parameters. - Code organization. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Use afirmative conditions for clarity (without changing behaviour) Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Refactors DotenvParser.parse() extracting a new method to improve clarity. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Gets the number of lines from the env file inside the DotenvParser.parse() and creates an ArrayList with that exact size for memory improvement. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Version bump to 2.4.0 Signed-off-by: Manoel Campos <manoelcampos@gmail.com> * Removes .travis.yml file and adds GitHub Action workflow build.yml - Update build badge - Remove coveralls badge since the plugin was removed (since it's abandoned) and codacy can be configured to show code coverage. Signed-off-by: Manoel Campos <manoelcampos@gmail.com> --------- Signed-off-by: Manoel Campos <manoelcampos@gmail.com>
1 parent 10d4f06 commit d586bd3

File tree

9 files changed

+206
-235
lines changed

9 files changed

+206
-235
lines changed

.github/workflows/build.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: build
2+
3+
on:
4+
push:
5+
branches: [ "master", "main" ]
6+
pull_request:
7+
branches: [ "master", "main" ]
8+
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up JDK 11
16+
uses: actions/setup-java@v3
17+
with:
18+
java-version: '11'
19+
distribution: 'adopt'
20+
cache: maven
21+
- name: Build with Maven
22+
run: mvn clean package jacoco:report

.travis.yml

Lines changed: 0 additions & 10 deletions
This file was deleted.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# 🗝️ dotenv-java
22

3-
![](https://travis-ci.org/cdimascio/dotenv-java.svg?branch=master) [![Coverage Status](https://coveralls.io/repos/github/cdimascio/dotenv-java/badge.svg?branch=fixes)](https://coveralls.io/github/cdimascio/dotenv-java?branch=fixes) [![Maven Central](https://img.shields.io/maven-central/v/io.github.cdimascio/dotenv-java.svg?label=Maven%20Central)](https://search.maven.org/artifact/io.github.cdimascio/dotenv-java) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/66b8195f0da544f1ad9ed1352c0ea66f)](https://app.codacy.com/app/cdimascio/dotenv-java?utm_source=github.com&utm_medium=referral&utm_content=cdimascio/dotenv-java&utm_campaign=Badge_Grade_Dashboard) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-) [![](https://img.shields.io/badge/doc-javadoc-blue)](https://cdimascio.github.io/dotenv-java/docs/javadoc/index.html) ![](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
3+
![Build Status](https://github.com/cloudsimplus/cloudsimplus/actions/workflows/build.yml/badge.svg) [![Maven Central](https://img.shields.io/maven-central/v/io.github.cdimascio/dotenv-java.svg?label=Maven%20Central)](https://search.maven.org/artifact/io.github.cdimascio/dotenv-java) [![Codacy Badge](https://api.codacy.com/project/badge/Grade/66b8195f0da544f1ad9ed1352c0ea66f)](https://app.codacy.com/app/cdimascio/dotenv-java?utm_source=github.com&utm_medium=referral&utm_content=cdimascio/dotenv-java&utm_campaign=Badge_Grade_Dashboard) [![](https://img.shields.io/gitter/room/cdimascio-oss/community?color=%23eb205a)](https://gitter.im/cdimascio-oss/community) [![All Contributors](https://img.shields.io/badge/all_contributors-6-orange.svg?style=flat-square)](#contributors-) [![](https://img.shields.io/badge/doc-javadoc-blue)](https://cdimascio.github.io/dotenv-java/docs/javadoc/index.html) ![](https://img.shields.io/badge/license-Apache%202.0-blue.svg)
44

55
A no-dependency, pure Java port of the Ruby dotenv project. Load environment variables from a `.env` file.
66

pom.xml

Lines changed: 21 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>io.github.cdimascio</groupId>
1313
<artifactId>dotenv-java</artifactId>
14-
<version>2.3.2</version>
14+
<version>2.4.0</version>
1515

1616
<licenses>
1717
<license>
@@ -55,23 +55,20 @@
5555
<module.name>io.github.cdimascio.dotenv.java</module.name>
5656
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
5757

58-
<compile.source>1.8</compile.source>
59-
<compile.test.source>11</compile.test.source>
60-
<compile.javadoc.source>8</compile.javadoc.source>
58+
<maven.compiler.release>11</maven.compiler.release>
6159

6260
<javadoc.dir>docs/javadoc</javadoc.dir>
6361

64-
<junit.version>4.13.2</junit.version>
62+
<junit.version>5.9.2</junit.version>
6563

66-
<maven.enforcer.plugin>3.1.0</maven.enforcer.plugin>
67-
<maven.compiler.plugin>3.5.1</maven.compiler.plugin>
68-
<maven.source.plugin>3.0.1</maven.source.plugin>
69-
<maven.javadoc.plugin>3.2.0</maven.javadoc.plugin>
70-
<maven.surefire.plugin>2.22.0</maven.surefire.plugin>
71-
<maven.jacoco.plugin>0.8.6</maven.jacoco.plugin>
72-
<maven.coveralls.plugin>4.3.0</maven.coveralls.plugin>
64+
<maven.enforcer.plugin>3.3.0</maven.enforcer.plugin>
65+
<maven.compiler.plugin>3.11.0</maven.compiler.plugin>
66+
<maven.source.plugin>3.2.1</maven.source.plugin>
67+
<maven.javadoc.plugin>3.5.0</maven.javadoc.plugin>
68+
<maven.surefire.plugin>3.0.0</maven.surefire.plugin>
69+
<maven.jacoco.plugin>0.8.10</maven.jacoco.plugin>
7370
<maven.copy.rename.plugin>1.0.1</maven.copy.rename.plugin>
74-
<maven.moditect.plugin>1.0.0.RC2</maven.moditect.plugin>
71+
<maven.moditect.plugin>1.0.0.RC3</maven.moditect.plugin>
7572

7673
<bintray.subject>cdimascio</bintray.subject>
7774
<bintray.repo>maven</bintray.repo>
@@ -88,8 +85,14 @@
8885

8986
<dependencies>
9087
<dependency>
91-
<groupId>junit</groupId>
92-
<artifactId>junit</artifactId>
88+
<groupId>org.junit.jupiter</groupId>
89+
<artifactId>junit-jupiter-api</artifactId>
90+
<version>${junit.version}</version>
91+
<scope>test</scope>
92+
</dependency>
93+
<dependency>
94+
<groupId>org.junit.jupiter</groupId>
95+
<artifactId>junit-jupiter-engine</artifactId>
9396
<version>${junit.version}</version>
9497
<scope>test</scope>
9598
</dependency>
@@ -127,17 +130,10 @@
127130
</executions>
128131
</plugin>
129132

130-
<!-- compile java 1.8 for lib and java 11 for tests-->
131133
<plugin>
132134
<groupId>org.apache.maven.plugins</groupId>
133135
<artifactId>maven-compiler-plugin</artifactId>
134136
<version>${maven.compiler.plugin}</version>
135-
<configuration>
136-
<source>${compile.source}</source>
137-
<target>${compile.source}</target>
138-
<testSource>${compile.test.source}</testSource>
139-
<testTarget>${compile.test.source}</testTarget>
140-
</configuration>
141137
</plugin>
142138

143139
<!-- add module-info -->
@@ -194,13 +190,6 @@
194190
<groupId>org.apache.maven.plugins</groupId>
195191
<artifactId>maven-surefire-plugin</artifactId>
196192
<version>${maven.surefire.plugin}</version>
197-
<dependencies>
198-
<dependency>
199-
<groupId>org.apache.maven.surefire</groupId>
200-
<artifactId>surefire-junit4</artifactId>
201-
<version>2.22.0</version>
202-
</dependency>
203-
</dependencies>
204193
<configuration>
205194
<includes>
206195
<include>**/*.java</include>
@@ -257,23 +246,6 @@
257246
</executions>
258247
</plugin>
259248

260-
<!-- Send to coveralls -->
261-
<plugin>
262-
<groupId>org.eluder.coveralls</groupId>
263-
<artifactId>coveralls-maven-plugin</artifactId>
264-
<version>${maven.coveralls.plugin}</version>
265-
<configuration>
266-
<repoToken>r92OLg0S3kCJakLAMW6HlLsDgNSMaolGS</repoToken>
267-
</configuration>
268-
<dependencies>
269-
<dependency>
270-
<groupId>javax.xml.bind</groupId>
271-
<artifactId>jaxb-api</artifactId>
272-
<version>2.2.3</version>
273-
</dependency>
274-
</dependencies>
275-
</plugin>
276-
277249
<!-- copy pom to target -->
278250
<plugin>
279251
<groupId>com.coderplus.maven.plugins</groupId>
@@ -290,7 +262,7 @@
290262
<fileSets>
291263
<fileSet>
292264
<sourceFile>${project.basedir}/pom.xml</sourceFile>
293-
<destinationFile>${project.build.directory}/dotenv-java-2.2.4.pom</destinationFile>
265+
<destinationFile>${project.build.directory}/${project.artifactId}-${project.version}.pom</destinationFile>
294266
</fileSet>
295267
</fileSets>
296268
</configuration>
@@ -315,7 +287,7 @@
315287
<plugin>
316288
<groupId>org.sonatype.plugins</groupId>
317289
<artifactId>nexus-staging-maven-plugin</artifactId>
318-
<version>1.6.7</version>
290+
<version>1.6.13</version>
319291
<extensions>true</extensions>
320292
<configuration>
321293
<serverId>ossrh</serverId>
@@ -355,7 +327,7 @@
355327
<plugin>
356328
<groupId>org.apache.maven.plugins</groupId>
357329
<artifactId>maven-gpg-plugin</artifactId>
358-
<version>1.5</version>
330+
<version>3.0.1</version>
359331
<executions>
360332
<execution>
361333
<id>sign-artifacts</id>

src/main/java/io/github/cdimascio/dotenv/DotenvBuilder.java

Lines changed: 31 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class DotenvBuilder {
2323
* @param path the directory containing the .env file
2424
* @return this {@link DotenvBuilder}
2525
*/
26-
public DotenvBuilder directory(String path) {
26+
public DotenvBuilder directory(final String path) {
2727
this.directoryPath = path;
2828
return this;
2929
}
@@ -32,7 +32,7 @@ public DotenvBuilder directory(String path) {
3232
* @param name the filename
3333
* @return this {@link DotenvBuilder}
3434
*/
35-
public DotenvBuilder filename(String name) {
35+
public DotenvBuilder filename(final String name) {
3636
filename = name;
3737
return this;
3838
}
@@ -70,34 +70,40 @@ public DotenvBuilder systemProperties() {
7070
* @throws DotenvException when an error occurs
7171
*/
7272
public Dotenv load() throws DotenvException {
73-
DotenvParser reader = new DotenvParser(
74-
new DotenvReader(directoryPath, filename),
75-
throwIfMissing,
76-
throwIfMalformed);
77-
List<DotenvEntry> env = reader.parse();
73+
final var reader = new DotenvParser(
74+
new DotenvReader(directoryPath, filename),
75+
throwIfMissing, throwIfMalformed);
76+
final List<DotenvEntry> env = reader.parse();
7877
if (systemProperties) {
7978
env.forEach(it -> System.setProperty(it.getKey(), it.getValue()));
8079
}
80+
8181
return new DotenvImpl(env);
8282
}
8383

8484
static class DotenvImpl implements Dotenv {
8585
private final Map<String, String> envVars;
8686
private final Set<DotenvEntry> set;
8787
private final Set<DotenvEntry> setInFile;
88-
public DotenvImpl(List<DotenvEntry> envVars) {
89-
Map<String, String> envVarsInFile = envVars.stream()
90-
.collect(toMap(DotenvEntry::getKey, DotenvEntry::getValue));
88+
public DotenvImpl(final List<DotenvEntry> envVars) {
89+
final Map<String, String> envVarsInFile =
90+
envVars.stream()
91+
.collect(toMap(DotenvEntry::getKey, DotenvEntry::getValue));
92+
9193
this.envVars = new HashMap<>(envVarsInFile);
9294
this.envVars.putAll(System.getenv());
9395

94-
this.set = this.envVars.entrySet().stream()
95-
.map(it -> new DotenvEntry(it.getKey(), it.getValue()))
96-
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
97-
98-
this.setInFile = envVarsInFile.entrySet().stream()
99-
.map(it -> new DotenvEntry(it.getKey(), it.getValue()))
100-
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
96+
this.set =
97+
this.envVars.entrySet()
98+
.stream()
99+
.map(it -> new DotenvEntry(it.getKey(), it.getValue()))
100+
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
101+
102+
this.setInFile =
103+
envVarsInFile.entrySet()
104+
.stream()
105+
.map(it -> new DotenvEntry(it.getKey(), it.getValue()))
106+
.collect(collectingAndThen(toSet(), Collections::unmodifiableSet));
101107
}
102108

103109
@Override
@@ -106,21 +112,21 @@ public Set<DotenvEntry> entries() {
106112
}
107113

108114
@Override
109-
public Set<DotenvEntry> entries(Dotenv.Filter filter) {
110-
if (filter != null) return setInFile;
111-
return entries();
115+
public Set<DotenvEntry> entries(final Dotenv.Filter filter) {
116+
return filter == null ? entries() : setInFile;
117+
112118
}
113119

114120
@Override
115-
public String get(String key) {
116-
String value = System.getenv(key);
117-
return value != null ? value : envVars.get(key);
121+
public String get(final String key) {
122+
final String value = System.getenv(key);
123+
return value == null ? envVars.get(key) : value;
118124
}
119125

120126
@Override
121127
public String get(String key, String defaultValue) {
122-
String value = this.get(key);
123-
return value != null ? value : defaultValue;
128+
final String value = this.get(key);
129+
return value == null ? defaultValue : value;
124130
}
125131
}
126132
}

src/main/java/io/github/cdimascio/dotenv/internal/ClasspathHelper.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@
22

33
import io.github.cdimascio.dotenv.DotenvException;
44

5-
import java.io.InputStream;
5+
import java.nio.charset.StandardCharsets;
66
import java.util.ArrayList;
7-
import java.util.List;
87
import java.util.Scanner;
98
import java.util.stream.Stream;
109

@@ -13,8 +12,8 @@
1312
*/
1413
public class ClasspathHelper {
1514
static Stream<String> loadFileFromClasspath(String location) {
16-
Class<ClasspathHelper> loader = ClasspathHelper.class;
17-
InputStream inputStream = loader.getResourceAsStream(location);
15+
final var loader = ClasspathHelper.class;
16+
var inputStream = loader.getResourceAsStream(location);
1817
if (inputStream == null) {
1918
inputStream = loader.getResourceAsStream(location);
2019
}
@@ -25,11 +24,13 @@ static Stream<String> loadFileFromClasspath(String location) {
2524
if (inputStream == null) {
2625
throw new DotenvException("Could not find "+location+" on the classpath");
2726
}
28-
Scanner scanner = new Scanner(inputStream, "utf-8");
29-
List<String> lines = new ArrayList<>();
27+
28+
final var scanner = new Scanner(inputStream, StandardCharsets.UTF_8);
29+
final var lines = new ArrayList<String>();
3030
while (scanner.hasNext()) {
3131
lines.add(scanner.nextLine());
3232
}
33+
3334
return lines.stream();
3435
}
3536
}

0 commit comments

Comments
 (0)