Skip to content

Commit 50e52a7

Browse files
committed
Merge branch 'main' into fix-log-level-of-overflow-rescanner
2 parents 022046f + c482cb0 commit 50e52a7

26 files changed

Lines changed: 1168 additions & 819 deletions

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,3 +15,6 @@ end_of_line = lf
1515
[*.java]
1616
indent_size = 4
1717
max_line_length = 120
18+
19+
[*.rs]
20+
indent_size = 4

.github/workflows/build.yaml

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
name: Build and Test
2+
permissions:
3+
contents: read
4+
pull-requests: write
25
on:
36
push:
47
branches:
@@ -18,20 +21,24 @@ jobs:
1821
mac-backend: jdk
1922
- image: macos-latest
2023
mac-backend: fsevents
24+
- image: macos-15-intel
25+
mac-backend: fsevents
2126
- image: windows-latest
22-
jdk: [11, 17, 21]
27+
jdk: [11, 21]
2328

2429
fail-fast: false
2530
runs-on: ${{ matrix.os.image }}
2631
steps:
27-
- uses: actions/checkout@v4
32+
- uses: actions/checkout@v6
2833
- run: echo " " >> pom.xml # make sure the cache is slightly different for these runners
2934
- name: Set up JDK
30-
uses: actions/setup-java@v4
35+
uses: actions/setup-java@v5
3136
with:
3237
java-version: ${{ matrix.jdk }}
3338
distribution: 'temurin'
3439
cache: 'maven'
40+
- run: ./update-rust-jni-libs.sh -r
41+
if: startsWith(matrix.os.image, 'macos-')
3542

3643
- name: test
3744
run: mvn -B clean test "-Dwatch.mac.backend=${{ matrix.os.mac-backend }}"
@@ -46,10 +53,10 @@ jobs:
4653
checker-framework:
4754
runs-on: ubuntu-latest
4855
steps:
49-
- uses: actions/checkout@v4
56+
- uses: actions/checkout@v6
5057
- run: echo " " >> pom.xml # make sure the cache is slightly different for the checker framework
5158
- name: Set up JDK 11
52-
uses: actions/setup-java@v4
59+
uses: actions/setup-java@v5
5360
with:
5461
java-version: 11
5562
distribution: 'temurin'
@@ -60,9 +67,9 @@ jobs:
6067
lint:
6168
runs-on: ubuntu-latest
6269
steps:
63-
- uses: actions/checkout@v4
70+
- uses: actions/checkout@v6
6471
- name: Set up JDK 11
65-
uses: actions/setup-java@v4
72+
uses: actions/setup-java@v5
6673
with:
6774
java-version: 11
6875
distribution: 'temurin'

.github/workflows/release.yaml

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
name: Publish package maven
2+
permissions:
3+
contents: read
4+
pull-requests: read
25
on:
36
release:
47
types: [created]
58
jobs:
69
publish:
7-
runs-on: ubuntu-latest
10+
runs-on: macos-latest # for now build on macos for the jni
811
steps:
9-
- uses: actions/checkout@v4
10-
- uses: actions/setup-java@v4
12+
- uses: actions/checkout@v6
13+
14+
# build jni libs on osx
15+
- run: ./update-rust-jni-libs.sh -r
16+
17+
- uses: actions/setup-java@v5
1118
with:
1219
java-version: '11'
1320
distribution: 'temurin'
@@ -22,4 +29,4 @@ jobs:
2229
env:
2330
MAVEN_USERNAME: ${{ secrets.MAVEN_CENTRAL_USER }}
2431
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_PASSWORD }}
25-
GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSPHRASE }}
32+
GPG_PASSPHRASE: ${{ secrets.GPG_SIGNING_KEY_PASSPHRASE }}

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,4 +27,4 @@ replay_pid*
2727

2828
# release plugin state files
2929
/pom.xml.releaseBackup
30-
/release.properties
30+
/release.properties

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Features:
1313
- monitor a directory for changes to its direct children
1414
- monitor a directory for changes for all its descendants (aka recursive directory watch)
1515
- high-resolution events (on macOS we use the native [FSEvents](https://developer.apple.com/documentation/coreservices/file_system_events) API to circumvent the polling behavior of the JDK [WatchService](https://docs.oracle.com/javase/8/docs/api/java/nio/file/WatchService.html))
16+
- Java 11 and higher are supported
1617
- edge cases dealt with:
1718
- recursive watches will also continue in new directories
1819
- multiple watches for the same directory are merged to avoid overloading the kernel
@@ -25,8 +26,6 @@ Planned features:
2526
- Support single file watches natively in linux (see [#11](https://github.com/SWAT-engineering/java-watch/issues/11))
2627
- Monitor only specific events (such as only CREATE events)
2728

28-
29-
3029
## Usage
3130

3231
Import dependency in pom.xml:

pom.xml

Lines changed: 34 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
<groupId>engineering.swat</groupId>
3434
<artifactId>java-watch</artifactId>
35-
<version>0.9.2-SNAPSHOT</version>
35+
<version>0.9.6-SNAPSHOT</version>
3636
<packaging>jar</packaging>
3737

3838
<name>${project.groupId}:${project.artifactId}</name>
@@ -66,26 +66,33 @@
6666
<connection>scm:git:git://github.com/SWAT-engineering/java-watch.git</connection>
6767
<developerConnection>scm:git:ssh://git@github.com/SWAT-engineering/java-watch.git</developerConnection>
6868
<url>https://github.com/SWAT-engineering/java-watch/tree/main/</url>
69-
<tag>v0.5.0-RC3</tag>
69+
<tag>v0.9.2</tag>
7070
</scm>
7171

7272
<properties>
7373
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
74-
<checkerframework.version>3.49.3</checkerframework.version>
75-
<junit.version>5.13.0</junit.version>
76-
<log4j.version>2.24.3</log4j.version>
77-
<jna.version>5.17.0</jna.version>
74+
<checkerframework.version>3.52.0</checkerframework.version>
75+
<junit.version>5.14.1</junit.version>
76+
<log4j.version>2.25.2</log4j.version>
7877
<maven.compiler.source>11</maven.compiler.source>
7978
<maven.compiler.target>11</maven.compiler.target>
8079
<watch.mac.backend>fsevents</watch.mac.backend>
8180
</properties>
8281

8382
<build>
83+
<resources>
84+
<resource>
85+
<directory>src/main/resources</directory>
86+
<excludes>
87+
<exclude>src/main/rust/**/*.*</exclude>
88+
</excludes>
89+
</resource>
90+
</resources>
8491
<plugins>
8592
<plugin> <!-- configure java compiler -->
8693
<groupId>org.apache.maven.plugins</groupId>
8794
<artifactId>maven-compiler-plugin</artifactId>
88-
<version>3.14.0</version>
95+
<version>3.14.1</version>
8996
<configuration>
9097
<release>11</release>
9198
<compilerArgument>-parameters</compilerArgument>
@@ -94,25 +101,26 @@
94101
<plugin> <!-- automate release commits -->
95102
<groupId>org.apache.maven.plugins</groupId>
96103
<artifactId>maven-release-plugin</artifactId>
97-
<version>3.1.1</version>
104+
<version>3.2.0</version>
98105
<configuration>
99106
<tagNameFormat>v@{project.version}</tagNameFormat>
107+
<arguments>-DskipTests</arguments> <!-- when doing a local release, don't wait for tests, they're long and slow -->
100108
<!-- do not use the build in release profile, we invoke it later -->
101109
<releaseProfiles />
102110
</configuration>
103111
</plugin>
104112
<plugin> <!-- unit test integration -->
105113
<groupId>org.apache.maven.plugins</groupId>
106114
<artifactId>maven-surefire-plugin</artifactId>
107-
<version>3.5.3</version>
115+
<version>3.5.4</version>
108116
<configuration>
109117
<argLine>@{argLine} -Dengineering.swat.java-watch.mac=${watch.mac.backend}</argLine>
110118
</configuration>
111119
</plugin>
112120
<plugin> <!-- code coverage -->
113121
<groupId>org.jacoco</groupId>
114122
<artifactId>jacoco-maven-plugin</artifactId>
115-
<version>0.8.13</version>
123+
<version>0.8.14</version>
116124
<executions>
117125
<execution>
118126
<goals>
@@ -146,6 +154,9 @@
146154
</excludes>
147155
</licenseSet>
148156
</licenseSets>
157+
<mapping>
158+
<rs>DOUBLESLASH_STYLE</rs> <!-- Use same style for license headers in Rust files as in https://github.com/rust-lang/style-team/blob/main/example/lists.rs -->
159+
</mapping>
149160
</configuration>
150161
<executions>
151162
<execution>
@@ -158,7 +169,7 @@
158169
<plugin> <!-- enforce editor config on the files -->
159170
<groupId>org.ec4j.maven</groupId>
160171
<artifactId>editorconfig-maven-plugin</artifactId>
161-
<version>0.1.3</version>
172+
<version>0.1.17</version>
162173
<!-- run mvn editorconfig:format to fix errors reported-->
163174
<executions>
164175
<execution>
@@ -169,11 +180,16 @@
169180
</goals>
170181
</execution>
171182
</executions>
183+
<configuration>
184+
<excludes>
185+
<exclude>src/main/resources/**</exclude>
186+
</excludes>
187+
</configuration>
172188
</plugin>
173189
<plugin> <!-- use a new version of maven -->
174190
<groupId>org.apache.maven.plugins</groupId>
175191
<artifactId>maven-enforcer-plugin</artifactId>
176-
<version>3.5.0</version>
192+
<version>3.6.2</version>
177193
<executions>
178194
<execution>
179195
<id>enforce-maven</id>
@@ -228,16 +244,6 @@
228244
<version>${log4j.version}</version>
229245
<scope>test</scope>
230246
</dependency>
231-
<dependency>
232-
<groupId>net.java.dev.jna</groupId>
233-
<artifactId>jna</artifactId>
234-
<version>${jna.version}</version>
235-
</dependency>
236-
<dependency>
237-
<groupId>net.java.dev.jna</groupId>
238-
<artifactId>jna-platform</artifactId>
239-
<version>${jna.version}</version>
240-
</dependency>
241247
</dependencies>
242248

243249
<profiles>
@@ -248,7 +254,7 @@
248254
<plugin><!-- uploading to maven central-->
249255
<groupId>org.sonatype.central</groupId>
250256
<artifactId>central-publishing-maven-plugin</artifactId>
251-
<version>0.7.0</version>
257+
<version>0.9.0</version>
252258
<extensions>true</extensions>
253259
<configuration>
254260
<publishingServerId>central</publishingServerId>
@@ -258,7 +264,7 @@
258264
<plugin> <!-- sign jar for maven central-->
259265
<groupId>org.apache.maven.plugins</groupId>
260266
<artifactId>maven-gpg-plugin</artifactId>
261-
<version>3.2.7</version>
267+
<version>3.2.8</version>
262268
<executions>
263269
<execution>
264270
<id>sign-artifacts</id>
@@ -272,7 +278,7 @@
272278
<plugin> <!-- generate java-doc -->
273279
<groupId>org.apache.maven.plugins</groupId>
274280
<artifactId>maven-javadoc-plugin</artifactId>
275-
<version>3.11.2</version>
281+
<version>3.12.0</version>
276282
<executions>
277283
<execution>
278284
<id>attach-javadocs</id>
@@ -288,7 +294,7 @@
288294
<plugin> <!-- generate sources jar -->
289295
<groupId>org.apache.maven.plugins</groupId>
290296
<artifactId>maven-source-plugin</artifactId>
291-
<version>3.3.1</version>
297+
<version>3.4.0</version>
292298
<executions>
293299
<execution>
294300
<id>attach-sources</id>
@@ -311,7 +317,7 @@
311317
<!-- This plugin will set properties values using dependency information -->
312318
<groupId>org.apache.maven.plugins</groupId>
313319
<artifactId>maven-dependency-plugin</artifactId>
314-
<version>3.8.1</version>
320+
<version>3.9.0</version>
315321
<executions>
316322
<execution>
317323
<goals>
@@ -323,7 +329,7 @@
323329
<plugin>
324330
<groupId>org.apache.maven.plugins</groupId>
325331
<artifactId>maven-compiler-plugin</artifactId>
326-
<version>3.14.0</version>
332+
<version>3.14.1</version>
327333
<configuration>
328334
<fork>true</fork>
329335
<release>11</release>

src/main/checkerframework/nio-file.astub

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ public interface WatchService {
1212
public interface WatchEvent<T> {
1313
@Nullable T context();
1414
}
15+
16+
public class NoSuchFileException extends FileSystemException {
17+
public NoSuchFileException(String file, @Nullable String other, String reason);
18+
}
19+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
/*
2+
* BSD 2-Clause License
3+
*
4+
* Copyright (c) 2023, Swat.engineering
5+
*
6+
* Redistribution and use in source and binary forms, with or without
7+
* modification, are permitted provided that the following conditions are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice, this
10+
* list of conditions and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice,
13+
* this list of conditions and the following disclaimer in the documentation
14+
* and/or other materials provided with the distribution.
15+
*
16+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19+
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22+
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23+
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24+
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25+
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26+
*/
27+
package engineering.swat.watch;
28+
29+
import java.util.concurrent.ExecutorService;
30+
import java.util.concurrent.LinkedBlockingQueue;
31+
import java.util.concurrent.ThreadFactory;
32+
import java.util.concurrent.ThreadPoolExecutor;
33+
import java.util.concurrent.TimeUnit;
34+
import java.util.concurrent.atomic.AtomicInteger;
35+
36+
/**
37+
* Build thread pools that even when not properly shutdown, will still not prevent the termination of the JVM.
38+
*/
39+
public class DaemonThreadPool {
40+
private DaemonThreadPool() {}
41+
42+
/**
43+
* Generate a thread pool that will reuse threads, clear them after a while, but constrain the total amount of threads.
44+
* @param name name of the thread pool
45+
* @param maxThreads the maximum amount of threads to start in this pool, after this things will get queued.
46+
* @return an exectutor with deamon threads and constainted to a certain maximum
47+
*/
48+
public static ExecutorService buildConstrainedCached(String name, int maxThreads) {
49+
if (maxThreads <= 0) {
50+
throw new IllegalArgumentException("maxThreads should be higher than 0");
51+
}
52+
var pool = new ThreadPoolExecutor(maxThreads, maxThreads,
53+
60, TimeUnit.SECONDS,
54+
new LinkedBlockingQueue<>(),
55+
buildFactory(name)
56+
);
57+
pool.allowCoreThreadTimeOut(true);
58+
return pool;
59+
}
60+
61+
private static ThreadFactory buildFactory(String name) {
62+
return new ThreadFactory() {
63+
private final AtomicInteger id = new AtomicInteger(0);
64+
private final ThreadGroup group = new ThreadGroup(name);
65+
@Override
66+
public Thread newThread(Runnable r) {
67+
var t = new Thread(group, r, name + "-" + id.getAndIncrement());
68+
t.setDaemon(true);
69+
return t;
70+
}
71+
};
72+
}
73+
74+
75+
76+
}

0 commit comments

Comments
 (0)