Skip to content

Commit 4e3f180

Browse files
authored
Merge pull request #47 from SWAT-engineering/improved-macos-support/small-fixes
Improved macOS support: Small fixes
2 parents e21382d + da4156c commit 4e3f180

File tree

4 files changed

+28
-18
lines changed

4 files changed

+28
-18
lines changed

.github/workflows/build.yaml

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,17 @@ jobs:
1212
test:
1313
strategy:
1414
matrix:
15-
os: [ubuntu-latest, macos-latest, windows-latest]
15+
os:
16+
- image: ubuntu-latest
17+
- image: macos-latest
18+
mac-backend: jdk
19+
- image: macos-latest
20+
mac-backend: jna
21+
- image: windows-latest
1622
jdk: [11, 17, 21]
23+
1724
fail-fast: false
18-
runs-on: ${{ matrix.os }}
25+
runs-on: ${{ matrix.os.image }}
1926
steps:
2027
- uses: actions/checkout@v4
2128
- run: echo " " >> pom.xml # make sure the cache is slightly different for these runners
@@ -27,7 +34,7 @@ jobs:
2734
cache: 'maven'
2835

2936
- name: test
30-
run: mvn -B clean test
37+
run: mvn -B clean test -DargLine="-Dengineering.swat.java-watch.mac=${{ matrix.os.mac-backend }}"
3138
env:
3239
DELAY_FACTOR: 3
3340

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,13 @@ try(var active = watcherSetup.start()) {
5757
// no new events will be scheduled on the threadpool
5858
```
5959

60-
## Internals
60+
## Backends
6161

6262
On all platforms except macOS, the library internally uses the JDK default implementation of the Java NIO [`WatchService`](https://docs.oracle.com/javase/8/docs/api/java/nio/file/WatchService.html) API.
6363

6464
On macOS, the library internally uses our custom `WatchService` implementation based on macOS's native [file system event streams](https://developer.apple.com/documentation/coreservices/file_system_events?language=objc) (using JNA).
6565
Generally, it offers better performance than the JDK default implementation (because the latter uses a polling loop to detect changes only once every two seconds).
66-
To force the library to use the JDK default implementation on macOS, set system property `engineering.swat.watch.impl` to `default`.
66+
To force the library to use the JDK default implementation on macOS, set system property `engineering.swat.java-watch.mac` to `jdk`.
6767

6868
## Related work
6969

pom.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@
7474
<checkerframework.version>3.49.2</checkerframework.version>
7575
<junit.version>5.12.2</junit.version>
7676
<log4j.version>2.24.3</log4j.version>
77+
<jna.version>5.16.0</jna.version>
7778
<maven.compiler.source>11</maven.compiler.source>
7879
<maven.compiler.target>11</maven.compiler.target>
7980
</properties>
@@ -226,12 +227,12 @@
226227
<dependency>
227228
<groupId>net.java.dev.jna</groupId>
228229
<artifactId>jna</artifactId>
229-
<version>5.16.0</version>
230+
<version>${jna.version}</version>
230231
</dependency>
231232
<dependency>
232233
<groupId>net.java.dev.jna</groupId>
233234
<artifactId>jna-platform</artifactId>
234-
<version>5.16.0</version>
235+
<version>${jna.version}</version>
235236
</dependency>
236237
</dependencies>
237238

src/main/java/engineering/swat/watch/impl/jdk/JDKPoller.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,20 +190,22 @@ public Watchable newWatchable(Path path) {
190190
static final Platform CURRENT = current(); // Assumption: the platform doesn't change
191191

192192
private static Platform current() {
193-
var key = "engineering.swat.watch.impl";
194-
var val = System.getProperty(key);
195-
if (val != null) {
196-
if (val.equals("mac")) {
197-
return MAC;
198-
} else if (val.equals("default")) {
199-
return DEFAULT;
200-
} else {
201-
logger.warn("Unexpected value \"{}\" for system property \"{}\". Using value \"default\" instead.", val, key);
202-
return DEFAULT;
193+
if (com.sun.jna.Platform.isMac()) {
194+
var key = "engineering.swat.java-watch.mac";
195+
var val = System.getProperty(key);
196+
if (val != null) {
197+
if (val.equals("jna")) {
198+
return MAC;
199+
} else if (val.equals("jdk")) {
200+
return DEFAULT;
201+
} else {
202+
logger.warn("Unexpected value \"{}\" for system property \"{}\". Using value \"jdk\" instead.", val, key);
203+
return DEFAULT;
204+
}
203205
}
204206
}
205207

206-
return com.sun.jna.Platform.isMac() ? MAC : DEFAULT;
208+
return DEFAULT;
207209
}
208210

209211
static Platform get() {

0 commit comments

Comments
 (0)