Skip to content

Commit 55d90af

Browse files
authoredOct 2, 2020
support for java 8 (#15)
* java 8 support * update pom * update pom.xml * update javadoc * update pom.xml
1 parent ae3ac10 commit 55d90af

File tree

5 files changed

+77
-49
lines changed

5 files changed

+77
-49
lines changed
 

‎pom.xml

+49-25
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.0.0</version>
14+
<version>2.1.0</version>
1515

1616
<licenses>
1717
<license>
@@ -51,14 +51,24 @@
5151

5252

5353
<properties>
54-
<maven.compiler.target>11</maven.compiler.target>
55-
<maven.compiler.source>11</maven.compiler.source>
5654
<main.class>io.github.cdimascio.dotenv.Dotenv</main.class>
57-
<junit.version>4.12</junit.version>
5855
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
56+
57+
<compile.source>1.8</compile.source>
58+
<compile.test.source>11</compile.test.source>
59+
<compile.javadoc.source>8</compile.javadoc.source>
60+
5961
<javadoc.dir>docs/javadoc</javadoc.dir>
62+
63+
<junit.version>4.12</junit.version>
64+
6065
<maven.source.plugin>3.0.1</maven.source.plugin>
6166
<maven.javadoc.plugin>3.2.0</maven.javadoc.plugin>
67+
<maven.surefire.plugin>2.22.0</maven.surefire.plugin>
68+
<maven.jacoco.plugin>0.8.6</maven.jacoco.plugin>
69+
<maven.coveralls.plugin>4.3.0</maven.coveralls.plugin>
70+
<maven.copy.rename.plugin>1.0.1</maven.copy.rename.plugin>
71+
6272
<bintray.subject>cdimascio</bintray.subject>
6373
<bintray.repo>maven</bintray.repo>
6474
<bintray.package>dotenv-java</bintray.package>
@@ -85,6 +95,19 @@
8595
<sourceDirectory>${project.basedir}/src/main/java</sourceDirectory>
8696
<plugins>
8797

98+
<!-- compile java 1.8 for lib and java 11 for tests-->
99+
<plugin>
100+
<groupId>org.apache.maven.plugins</groupId>
101+
<artifactId>maven-compiler-plugin</artifactId>
102+
<version>3.5.1</version>
103+
<configuration>
104+
<source>${compile.source}</source>
105+
<target>${compile.source}</target>
106+
<testSource>${compile.test.source}</testSource>
107+
<testTarget>${compile.test.source}</testTarget>
108+
</configuration>
109+
</plugin>
110+
88111
<!-- delete the javadoc dir -->
89112
<plugin>
90113
<groupId>org.apache.maven.plugins</groupId>
@@ -106,11 +129,11 @@
106129
</executions>
107130
</plugin>
108131

109-
<!-- compile sources -->
132+
<!-- plugin for tests -->
110133
<plugin>
111134
<groupId>org.apache.maven.plugins</groupId>
112135
<artifactId>maven-surefire-plugin</artifactId>
113-
<version>2.22.0</version>
136+
<version>${maven.surefire.plugin}</version>
114137
<dependencies>
115138
<dependency>
116139
<groupId>org.apache.maven.surefire</groupId>
@@ -146,6 +169,7 @@
146169
<artifactId>maven-javadoc-plugin</artifactId>
147170
<version>${maven.javadoc.plugin}</version>
148171
<configuration>
172+
<source>${compile.javadoc.source}</source>
149173
</configuration>
150174
<executions>
151175
<execution>
@@ -162,7 +186,7 @@
162186
<plugin>
163187
<groupId>org.jacoco</groupId>
164188
<artifactId>jacoco-maven-plugin</artifactId>
165-
<version>0.8.6</version>
189+
<version>${maven.jacoco.plugin}</version>
166190
<executions>
167191
<execution>
168192
<id>prepare-agent</id>
@@ -177,7 +201,7 @@
177201
<plugin>
178202
<groupId>org.eluder.coveralls</groupId>
179203
<artifactId>coveralls-maven-plugin</artifactId>
180-
<version>4.3.0</version>
204+
<version>${maven.coveralls.plugin}</version>
181205
<configuration>
182206
<repoToken>r92OLg0S3kCJakLAMW6HlLsDgNSMaolGS</repoToken>
183207
</configuration>
@@ -194,7 +218,7 @@
194218
<plugin>
195219
<groupId>com.coderplus.maven.plugins</groupId>
196220
<artifactId>copy-rename-maven-plugin</artifactId>
197-
<version>1.0.1</version>
221+
<version>${maven.copy.rename.plugin}</version>
198222
<executions>
199223
<execution>
200224
<id>copy-file</id>
@@ -206,26 +230,26 @@
206230
<fileSets>
207231
<fileSet>
208232
<sourceFile>${project.basedir}/pom.xml</sourceFile>
209-
<destinationFile>${project.build.directory}/dotenv-java-2.0.0.pom</destinationFile>
233+
<destinationFile>${project.build.directory}/dotenv-java-2.1.0.pom</destinationFile>
210234
</fileSet>
211235
</fileSets>
212236
</configuration>
213237
</execution>
214-
<!-- <execution>-->
215-
<!-- <id>rename-dir</id>-->
216-
<!-- <phase>install</phase>-->
217-
<!-- <goals>-->
218-
<!-- <goal>rename</goal>-->
219-
<!-- </goals>-->
220-
<!-- <configuration>-->
221-
<!-- <fileSets>-->
222-
<!-- <fileSet>-->
223-
<!-- <sourceFile>${project.build.directory}/apidocs/</sourceFile>-->
224-
<!-- <destinationFile>${project.basedir}/docs/javadoc/</destinationFile>-->
225-
<!-- </fileSet>-->
226-
<!-- </fileSets>-->
227-
<!-- </configuration>-->
228-
<!-- </execution>-->
238+
<!-- <execution>-->
239+
<!-- <id>rename-dir</id>-->
240+
<!-- <phase>install</phase>-->
241+
<!-- <goals>-->
242+
<!-- <goal>rename</goal>-->
243+
<!-- </goals>-->
244+
<!-- <configuration>-->
245+
<!-- <fileSets>-->
246+
<!-- <fileSet>-->
247+
<!-- <sourceFile>${project.build.directory}/apidocs/</sourceFile>-->
248+
<!-- <destinationFile>${project.basedir}/docs/javadoc/</destinationFile>-->
249+
<!-- </fileSet>-->
250+
<!-- </fileSets>-->
251+
<!-- </configuration>-->
252+
<!-- </execution>-->
229253
</executions>
230254
</plugin>
231255
</plugins>

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public Dotenv load() throws DotenvException {
7878
new DotenvReader(directoryPath, filename),
7979
throwIfMissing,
8080
throwIfMalformed);
81-
var env = reader.parse();
81+
List<DotenvEntry> env = reader.parse();
8282
if (systemProperties) {
8383
env.forEach(it -> System.setProperty(it.getKey(), it.getValue()));
8484
}
@@ -117,13 +117,13 @@ public Set<DotenvEntry> entries(Dotenv.Filter filter) {
117117

118118
@Override
119119
public String get(String key) {
120-
var value = System.getenv(key);
120+
String value = System.getenv(key);
121121
return value != null ? value : envVars.get(key);
122122
}
123123

124124
@Override
125125
public String get(String key, String defaultValue) {
126-
var value = this.get(key);
126+
String value = this.get(key);
127127
return value != null ? value : defaultValue;
128128
}
129129
}

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

+5-3
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,16 @@
22

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

5+
import java.io.InputStream;
56
import java.util.ArrayList;
7+
import java.util.List;
68
import java.util.Scanner;
79
import java.util.stream.Stream;
810

911
public class ClasspathHelper {
1012
static Stream<String> loadFileFromClasspath(String location) {
1113
Class<ClasspathHelper> loader = ClasspathHelper.class;
12-
var inputStream = loader.getResourceAsStream(location);
14+
InputStream inputStream = loader.getResourceAsStream(location);
1315
if (inputStream == null) {
1416
inputStream = loader.getResourceAsStream(location);
1517
}
@@ -20,8 +22,8 @@ static Stream<String> loadFileFromClasspath(String location) {
2022
if (inputStream == null) {
2123
throw new DotenvException("Could not find "+location+" on the classpath");
2224
}
23-
var scanner = new Scanner(inputStream, "utf-8");
24-
var lines = new ArrayList<String>();
25+
Scanner scanner = new Scanner(inputStream, "utf-8");
26+
List<String> lines = new ArrayList<>();
2527
while (scanner.hasNext()) {
2628
lines.add(scanner.nextLine());
2729
}

‎src/main/java/io/github/cdimascio/dotenv/internal/DotenvParser.java

+13-12
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88
import java.util.List;
99
import java.util.function.Function;
10+
import java.util.regex.Matcher;
1011
import java.util.regex.Pattern;
1112

1213
public class DotenvParser {
@@ -26,18 +27,18 @@ public DotenvParser(DotenvReader reader, boolean throwIfMissing, boolean throwIf
2627
}
2728

2829
public List<DotenvEntry> parse() throws DotenvException {
29-
var entries = new ArrayList<DotenvEntry>();
30-
for (var line : lines()) {
31-
var l = line.trim();
30+
List<DotenvEntry> entries = new ArrayList<>();
31+
for (String line : lines()) {
32+
String l = line.trim();
3233
if (isWhiteSpace.apply(l) || isComment.apply(l) || l.isBlank()) continue;
3334

34-
var entry = parseLine.apply(l);
35+
DotenvEntry entry = parseLine.apply(l);
3536
if (entry == null) {
3637
if (throwIfMalformed) throw new DotenvException("Malformed entry "+ l);
3738
continue;
3839
}
39-
var key = entry.getKey();
40-
var value = normalizeValue(entry.getValue());
40+
String key = entry.getKey();
41+
String value = normalizeValue(entry.getValue());
4142
entries.add(new DotenvEntry(key, value));
4243
}
4344
return entries;
@@ -55,22 +56,22 @@ private List<String> lines() throws DotenvException {
5556
}
5657

5758
private String normalizeValue(String value) {
58-
var tr = value.trim();
59+
String tr = value.trim();
5960
return isQuoted.apply(tr)
6061
? tr.substring(1, value.length() -1)
6162
: tr;
6263
}
6364

6465
private static boolean matches(String regex, String text) {
65-
var pattern = Pattern.compile(regex);
66-
var matcher = pattern.matcher(text);
66+
Pattern pattern = Pattern.compile(regex);
67+
Matcher matcher = pattern.matcher(text);
6768
return matcher.matches();
6869
}
6970

7071
private static DotenvEntry matchEntry(String regex, String text) {
71-
var pattern = Pattern.compile(regex);
72-
var matcher = pattern.matcher(text);
73-
var result = matcher.matches();
72+
Pattern pattern = Pattern.compile(regex);
73+
Matcher matcher = pattern.matcher(text);
74+
boolean result = matcher.matches();
7475
if (!result || matcher.groupCount() < 3) return null;
7576
return new DotenvEntry(matcher.group(1), matcher.group(3));
7677
}

‎src/main/java/io/github/cdimascio/dotenv/internal/DotenvReader.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import java.net.URI;
77
import java.nio.file.FileSystems;
88
import java.nio.file.Files;
9+
import java.nio.file.Path;
910
import java.nio.file.Paths;
1011
import java.util.List;
1112
import java.util.stream.Collectors;
@@ -20,14 +21,14 @@ public DotenvReader(String directory, String filename) {
2021
}
2122

2223
public List<String> read() throws DotenvException, IOException {
23-
var dir = directory
24+
String dir = directory
2425
.replaceAll("\\\\", "/")
2526
.replaceFirst("\\.env$", "")
2627
.replaceFirst("/$", "");
2728

28-
var location = dir + "/" + filename;
29-
var lowerLocation = location.toLowerCase();
30-
var path = lowerLocation.startsWith("file:") || lowerLocation.startsWith("android.resource:")
29+
String location = dir + "/" + filename;
30+
String lowerLocation = location.toLowerCase();
31+
Path path = lowerLocation.startsWith("file:") || lowerLocation.startsWith("android.resource:")
3132
? Paths.get(URI.create(location))
3233
: Paths.get(location);
3334

@@ -42,8 +43,8 @@ public List<String> read() throws DotenvException, IOException {
4243
.loadFileFromClasspath(location.replaceFirst("./", "/"))
4344
.collect(Collectors.toList());
4445
} catch (DotenvException e) {
45-
var cwd = FileSystems.getDefault().getPath(".").toAbsolutePath().normalize();
46-
var cwdMessage = !path.isAbsolute() ? "(working directory: " + cwd + ")" : "";
46+
Path cwd = FileSystems.getDefault().getPath(".").toAbsolutePath().normalize();
47+
String cwdMessage = !path.isAbsolute() ? "(working directory: " + cwd + ")" : "";
4748
e.addSuppressed(new DotenvException("Could not find " + path + " on the file system " + cwdMessage));
4849
throw e;
4950
}

0 commit comments

Comments
 (0)
Please sign in to comment.