Skip to content

Commit c312718

Browse files
authored
Merge pull request #300 from Philippus/adopt-sbt-java-formatter
Adopt sbt-java-formatter
2 parents f47c15e + fc6013b commit c312718

4 files changed

Lines changed: 65 additions & 64 deletions

File tree

.git-blame-ignore-revs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,6 @@ d9ed5546c4de868b176b13b9b04bb8caf3543926
99

1010
# Scala Steward: Reformat with scalafmt 3.10.4
1111
73984fb901d347e84b6331981b225f74cbdb3fed
12+
13+
# Reformat with sbt-java-formatter 0.10.0
14+
3a2e6552f80f743fa5cc16c78c5fed2280768849

.sbtopts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
-J--add-exports=jdk.compiler/com.sun.tools.javac.parser=ALL-UNNAMED
2+
-J--add-exports=jdk.compiler/com.sun.tools.javac.util=ALL-UNNAMED
3+
-J--add-exports=jdk.compiler/com.sun.tools.javac.file=ALL-UNNAMED
4+
-J--add-exports=jdk.compiler/com.sun.tools.javac.tree=ALL-UNNAMED
5+
-J--add-exports=jdk.compiler/com.sun.tools.javac.api=ALL-UNNAMED

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
addSbtPlugin("org.scalameta" % "sbt-scalafmt" % "2.5.6")
22

3+
addSbtPlugin("com.github.sbt" % "sbt-java-formatter" % "0.10.0")
4+
35
addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.11.2")
Lines changed: 55 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -1,92 +1,83 @@
11
package au.com.onegeek.sbtdotenv;
22

3-
import java.util.Map;
4-
53
import com.sun.jna.Library;
64
import com.sun.jna.Native;
75
import com.sun.jna.Platform;
6+
import java.util.Map;
87

98
/**
109
* Change the actual program environment so that changes propagate to child processes
1110
*
12-
* Taken from: http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java/7201825#7201825
11+
* <p>Taken from:
12+
* http://stackoverflow.com/questions/318239/how-do-i-set-environment-variables-from-java/7201825#7201825
1313
*
14-
* Created by mfellows on 20/07/2014.
14+
* <p>Created by mfellows on 20/07/2014.
1515
*/
1616
public abstract class NativeEnvironmentManager {
17-
public abstract void setEnv(String key, String value);
17+
public abstract void setEnv(String key, String value);
1818

19-
static class EnvironmentException extends RuntimeException {
20-
EnvironmentException(String key) {
21-
super("Failed to set environment variable: " + key);
22-
}
19+
static class EnvironmentException extends RuntimeException {
20+
EnvironmentException(String key) {
21+
super("Failed to set environment variable: " + key);
2322
}
23+
}
2424

25-
static class WindowsNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
26-
public interface WindowsEnvironmentLibC extends Library {
27-
WindowsEnvironmentLibC INSTANCE = (
28-
(WindowsEnvironmentLibC) Native.load("msvcrt",
29-
WindowsEnvironmentLibC.class)
30-
);
25+
static class WindowsNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
26+
public interface WindowsEnvironmentLibC extends Library {
27+
WindowsEnvironmentLibC INSTANCE =
28+
((WindowsEnvironmentLibC) Native.load("msvcrt", WindowsEnvironmentLibC.class));
3129

32-
int _putenv(String name);
33-
}
30+
int _putenv(String name);
31+
}
3432

35-
private WindowsEnvironmentLibC libc = WindowsEnvironmentLibC.INSTANCE;
33+
private WindowsEnvironmentLibC libc = WindowsEnvironmentLibC.INSTANCE;
3634

37-
@Override
38-
public void setEnv(String name, String value) {
39-
String s = name + "=";
40-
if (value != null)
41-
s += value;
35+
@Override
36+
public void setEnv(String name, String value) {
37+
String s = name + "=";
38+
if (value != null) s += value;
4239

43-
if (libc._putenv(s) != 0)
44-
throw new EnvironmentException(name);
45-
}
40+
if (libc._putenv(s) != 0) throw new EnvironmentException(name);
4641
}
42+
}
43+
44+
static class PosixNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
45+
public interface PosixEnvironmentLibC extends Library {
46+
PosixEnvironmentLibC INSTANCE =
47+
((PosixEnvironmentLibC) Native.load("c", PosixEnvironmentLibC.class));
48+
49+
int setenv(String name, String value, int overwrite);
4750

48-
static class PosixNativeEnvironmentManagerImpl extends NativeEnvironmentManager {
49-
public interface PosixEnvironmentLibC extends Library {
50-
PosixEnvironmentLibC INSTANCE = (
51-
(PosixEnvironmentLibC) Native.load("c",
52-
PosixEnvironmentLibC.class)
53-
);
54-
55-
int setenv(String name, String value, int overwrite);
56-
int unsetenv(String name);
57-
}
58-
59-
private PosixEnvironmentLibC libc = PosixEnvironmentLibC.INSTANCE;
60-
61-
@Override
62-
public void setEnv(String name, String value) {
63-
int result;
64-
if (value != null)
65-
result = libc.setenv(name, value, 1);
66-
else
67-
result = libc.unsetenv(name);
68-
69-
if (result != 0)
70-
throw new EnvironmentException(name);
71-
}
51+
int unsetenv(String name);
7252
}
7353

74-
private static NativeEnvironmentManager instance = null;
75-
private static NativeEnvironmentManager getInstance() {
76-
if (instance == null) {
77-
if (Platform.isWindows())
78-
instance = new WindowsNativeEnvironmentManagerImpl();
79-
else
80-
instance = new PosixNativeEnvironmentManagerImpl();
81-
}
54+
private PosixEnvironmentLibC libc = PosixEnvironmentLibC.INSTANCE;
8255

83-
return instance;
56+
@Override
57+
public void setEnv(String name, String value) {
58+
int result;
59+
if (value != null) result = libc.setenv(name, value, 1);
60+
else result = libc.unsetenv(name);
61+
62+
if (result != 0) throw new EnvironmentException(name);
8463
}
64+
}
65+
66+
private static NativeEnvironmentManager instance = null;
67+
68+
private static NativeEnvironmentManager getInstance() {
69+
if (instance == null) {
70+
if (Platform.isWindows()) instance = new WindowsNativeEnvironmentManagerImpl();
71+
else instance = new PosixNativeEnvironmentManagerImpl();
72+
}
73+
74+
return instance;
75+
}
8576

86-
public static void setEnv(Map<String, String> env) {
87-
NativeEnvironmentManager envManager = NativeEnvironmentManager.getInstance();
88-
for (Map.Entry<String, String> entry : env.entrySet()) {
89-
envManager.setEnv(entry.getKey(), entry.getValue());
90-
}
77+
public static void setEnv(Map<String, String> env) {
78+
NativeEnvironmentManager envManager = NativeEnvironmentManager.getInstance();
79+
for (Map.Entry<String, String> entry : env.entrySet()) {
80+
envManager.setEnv(entry.getKey(), entry.getValue());
9181
}
82+
}
9283
}

0 commit comments

Comments
 (0)