Skip to content

Commit 34e7507

Browse files
committed
Dependency Updates + Match Upstream
Added registerShutdownHook to match upstream and updated all dependencies to the latest versions.
1 parent 0a5e4dd commit 34e7507

9 files changed

Lines changed: 52 additions & 32 deletions

File tree

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ And the following to your `gradle/libs.versions.toml`:
3434
```toml
3535
[versions]
3636
# Check this on https://central.sonatype.com/artifact/com.smushytaco/embedded-postgres/
37-
embeddedPostgres = "3.0.3"
37+
embeddedPostgres = "3.1.0"
3838

3939
[libraries]
4040
embeddedPostgres = { group = "com.smushytaco", name = "embedded-postgres", version.ref = "embeddedPostgres" }
4141
```
4242

43-
The default version of the embedded postgres is `PostgreSQL 18.1.0`, but you can change it by following the instructions described in [Postgres version](#postgres-version).
43+
The default version of the embedded postgres is `PostgreSQL 18.3.0`, but you can change it by following the instructions described in [Postgres version](#postgres-version).
4444

4545
## Basic Usage
4646

@@ -78,7 +78,7 @@ independent databases gives you.
7878

7979
## Postgres version
8080

81-
The default version of the embedded postgres is `PostgreSQL 18.1.0`, but it can be changed by importing `embedded-postgres-binaries-bom`.
81+
The default version of the embedded postgres is `PostgreSQL 18.3.0`, but it can be changed by importing `embedded-postgres-binaries-bom`.
8282

8383
Add the following to your `build.gradle.kts`;
8484
```kotlin
@@ -91,7 +91,7 @@ And the following to your `gradle/libs.versions.toml`:
9191
```toml
9292
[versions]
9393
# Check this on https://central.sonatype.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom/
94-
postgresql = "18.1.0"
94+
postgresql = "18.3.0"
9595

9696
[libraries]
9797
postgresql = { group = "io.zonky.test.postgres", name = "embedded-postgres-binaries-bom", version.ref = "postgresql" }

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ tasks {
7575
targetCompatibility = javaVersion.get().toString()
7676
if (javaVersion.get() > 8) options.release = javaVersion
7777
}
78-
named<UpdateDaemonJvm>("updateDaemonJvm") {
78+
withType<UpdateDaemonJvm>().configureEach {
7979
languageVersion = libs.versions.gradleJava.map { JavaLanguageVersion.of(it.toInt()) }
8080
vendor = JvmVendorSpec.ADOPTIUM
8181
}

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ org.gradle.configuration-cache = true
77
# Maven Properties
88
group = com.smushytaco
99
name = embedded-postgres
10-
version = 3.0.3
10+
version = 3.1.0
1111
description = Embedded PostgreSQL Server
1212
##########################################################################
1313
# Publishing Properties
Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
#This file is generated by updateDaemonJvm
2-
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
3-
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
4-
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
5-
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
6-
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/e1118b4c7c2858d28154d086dbff010e/redirect
7-
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/59a9771cad43219260d9aac9a8ec4d6a/redirect
8-
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/c5ee947fbfb70bc347d8d531e3a578c4/redirect
9-
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/5ee463876563a46fff651cce1bc53a4c/redirect
10-
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/b96cb7670c095245220e7d01d5927b58/redirect
2+
toolchainUrl.FREE_BSD.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
3+
toolchainUrl.FREE_BSD.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
4+
toolchainUrl.LINUX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
5+
toolchainUrl.LINUX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
6+
toolchainUrl.MAC_OS.AARCH64=https\://api.foojay.io/disco/v3.0/ids/d4fd992c9557644e637ebe98263e0ae7/redirect
7+
toolchainUrl.MAC_OS.X86_64=https\://api.foojay.io/disco/v3.0/ids/faa12903720d410b387cc69ccafb1a74/redirect
8+
toolchainUrl.UNIX.AARCH64=https\://api.foojay.io/disco/v3.0/ids/1630f7ebef05444cb27a2709ea0249b3/redirect
9+
toolchainUrl.UNIX.X86_64=https\://api.foojay.io/disco/v3.0/ids/cd495626d2ee49a75447e3fdc6afb287/redirect
10+
toolchainUrl.WINDOWS.X86_64=https\://api.foojay.io/disco/v3.0/ids/8e1d9ee5d0f13e442218f6884a306da1/redirect
1111
toolchainVendor=ADOPTIUM
1212
toolchainVersion=25

gradle/libs.versions.toml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
##########################################################################
33
# Plugins
44
# Check this on https://github.com/Kotlin/dokka/releases/latest/
5-
dokka = "2.1.0"
5+
dokka = "2.2.0"
66
# Check this on https://plugins.gradle.org/plugin/dev.yumi.gradle.licenser/
7-
yumiGradleLicenser = "2.2.2"
7+
yumiGradleLicenser = "3.0.1"
88
# Check this on https://plugins.gradle.org/plugin/co.uzzu.dotenv.gradle/
99
dotenv = "4.0.0"
1010
# Check this on https://github.com/GradleUp/nmcp/releases/latest/
@@ -18,21 +18,21 @@ gradleJava = "25"
1818
##########################################################################
1919
# Dependencies
2020
# Check this on https://central.sonatype.com/artifact/io.zonky.test.postgres/embedded-postgres-binaries-bom/
21-
embeddedPostgresBinaries = "18.1.0"
21+
embeddedPostgresBinaries = "18.3.0"
2222
# Check this on https://central.sonatype.com/artifact/org.apache.commons/commons-compress/
2323
commonsCompress = "1.28.0"
2424
# Check this on https://central.sonatype.com/artifact/org.flywaydb/flyway-database-postgresql/
25-
flyway = "12.0.0"
25+
flyway = "12.3.0"
2626
# Check this on https://central.sonatype.com/artifact/org.junit.jupiter/junit-jupiter-api/
27-
junit = "6.0.2"
27+
junit = "6.0.3"
2828
# Check this on https://central.sonatype.com/artifact/org.liquibase/liquibase-core/
29-
liquibase = "5.0.1"
29+
liquibase = "5.0.2"
3030
# Check this on https://central.sonatype.com/artifact/org.postgresql/postgresql/
31-
postgresql = "42.7.9"
31+
postgresql = "42.7.10"
3232
# Check this on https://central.sonatype.com/artifact/org.slf4j/slf4j-api/
3333
slf4j = "2.0.17"
3434
# Check this on https://central.sonatype.com/artifact/org.tukaani/xz/
35-
xz = "1.11"
35+
xz = "1.12"
3636
##########################################################################
3737

3838
[libraries]

gradle/wrapper/gradle-wrapper.jar

3.43 KB
Binary file not shown.

gradle/wrapper/gradle-wrapper.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
# Check this on https://gradle.org/releases/
12
distributionBase=GRADLE_USER_HOME
23
distributionPath=wrapper/dists
3-
distributionUrl=https\://services.gradle.org/distributions/gradle-9.3.1-all.zip
4+
distributionUrl=https\://services.gradle.org/distributions/gradle-9.4.1-all.zip
45
networkTimeout=10000
56
validateDistributionUrl=true
67
zipStoreBase=GRADLE_USER_HOME

gradlew

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/com/smushytaco/postgres/embedded/EmbeddedPostgres.java

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,26 @@ public class EmbeddedPostgres implements Closeable {
8787
private final FileChannel lockChannel;
8888
private final FileLock lock;
8989
private final boolean cleanDataDirectory;
90+
private final boolean registerShutdownHook;
9091

9192
private final ProcessBuilder.Redirect errorRedirector;
9293
private final ProcessBuilder.Redirect outputRedirector;
9394

9495
@SuppressWarnings("unused")
95-
EmbeddedPostgres(final Path parentDirectory, final Path dataDirectory, final boolean cleanDataDirectory,
96+
EmbeddedPostgres(final Path parentDirectory, final Path dataDirectory, final boolean cleanDataDirectory, boolean registerShutdownHook,
9697
final Map<String, String> postgresConfig, final Map<String, String> localeConfig, final int port, final Map<String, String> connectConfig,
9798
final PgBinaryResolver pgBinaryResolver, final ProcessBuilder.Redirect errorRedirector, final ProcessBuilder.Redirect outputRedirector) throws IOException {
98-
this(parentDirectory, dataDirectory, cleanDataDirectory, postgresConfig, localeConfig, port, connectConfig,
99+
this(parentDirectory, dataDirectory, cleanDataDirectory, registerShutdownHook, postgresConfig, localeConfig, port, connectConfig,
99100
pgBinaryResolver, errorRedirector, outputRedirector, DEFAULT_PG_STARTUP_WAIT, null, null);
100101
}
101102

102-
EmbeddedPostgres(final Path parentDirectory, final Path dataDirectory, final boolean cleanDataDirectory,
103+
EmbeddedPostgres(final Path parentDirectory, final Path dataDirectory, final boolean cleanDataDirectory, boolean registerShutdownHook,
103104
final Map<String, String> postgresConfig, final Map<String, String> localeConfig, final int port, final Map<String, String> connectConfig,
104105
final PgBinaryResolver pgBinaryResolver, final ProcessBuilder.Redirect errorRedirector,
105106
final ProcessBuilder.Redirect outputRedirector, final Duration pgStartupWait,
106107
final Path overrideWorkingDirectory, final Consumer<Path> dataDirectoryCustomizer) throws IOException {
107108
this.cleanDataDirectory = cleanDataDirectory;
109+
this.registerShutdownHook = registerShutdownHook;
108110
this.postgresConfig = new HashMap<>(postgresConfig);
109111
this.localeConfig = new HashMap<>(localeConfig);
110112
this.connectConfig = new HashMap<>(connectConfig);
@@ -283,7 +285,7 @@ private void startPostmaster() {
283285
"-w", "start"
284286
));
285287

286-
Runtime.getRuntime().addShutdownHook(newCloserThread());
288+
if (registerShutdownHook) Runtime.getRuntime().addShutdownHook(newCloserThread());
287289

288290
system(pgCtl, args, pgStartupWait);
289291

@@ -463,6 +465,7 @@ public static class Builder {
463465
private final Map<String, String> config = new HashMap<>();
464466
private final Map<String, String> localeConfig = new HashMap<>();
465467
private boolean builderCleanDataDirectory = true;
468+
private boolean builderRegisterShutdownHook = true;
466469
private int builderPort = 0;
467470
private final Map<String, String> connectConfig = new HashMap<>();
468471
private PgBinaryResolver pgBinaryResolver = DefaultPostgresBinaryResolver.INSTANCE;
@@ -509,6 +512,20 @@ public Builder setCleanDataDirectory(final boolean cleanDataDirectory) {
509512
return this;
510513
}
511514

515+
/**
516+
* Configures whether a JVM shutdown hook should be registered to
517+
* automatically close the embedded PostgreSQL instance on shutdown.
518+
*
519+
* @param registerShutdownHook {@code true} to register a shutdown hook,
520+
* {@code false} to disable it
521+
* @return this builder instance for chaining
522+
*/
523+
@SuppressWarnings("unused")
524+
public Builder setRegisterShutdownHook(final boolean registerShutdownHook) {
525+
builderRegisterShutdownHook = registerShutdownHook;
526+
return this;
527+
}
528+
512529
/**
513530
* Sets a fixed data directory for PostgreSQL to use instead of a
514531
* randomly generated temporary directory.
@@ -653,7 +670,7 @@ public Builder setDataDirectoryCustomizer(final Consumer<Path> dataDirectoryCust
653670
public EmbeddedPostgres start() throws IOException {
654671
if (builderPort == 0) builderPort = detectFreePort();
655672
if (builderDataDirectory == null) builderDataDirectory = Files.createTempDirectory("epg");
656-
return new EmbeddedPostgres(parentDirectory, builderDataDirectory, builderCleanDataDirectory, config,
673+
return new EmbeddedPostgres(parentDirectory, builderDataDirectory, builderCleanDataDirectory, builderRegisterShutdownHook, config,
657674
localeConfig, builderPort, connectConfig, pgBinaryResolver, errRedirector, outRedirector,
658675
pgStartupWait, overrideWorkingDirectory, dataDirectoryCustomizer);
659676
}
@@ -673,6 +690,7 @@ public boolean equals(final Object o) {
673690
if (o == null || getClass() != o.getClass()) return false;
674691
final Builder builder = (Builder) o;
675692
return builderCleanDataDirectory == builder.builderCleanDataDirectory &&
693+
builderRegisterShutdownHook == builder.builderRegisterShutdownHook &&
676694
builderPort == builder.builderPort &&
677695
Objects.equals(parentDirectory, builder.parentDirectory) &&
678696
Objects.equals(builderDataDirectory, builder.builderDataDirectory) &&
@@ -689,7 +707,7 @@ public boolean equals(final Object o) {
689707

690708
@Override
691709
public int hashCode() {
692-
return Objects.hash(parentDirectory, builderDataDirectory, config, localeConfig, builderCleanDataDirectory, builderPort, connectConfig, pgBinaryResolver, pgStartupWait, errRedirector, outRedirector);
710+
return Objects.hash(parentDirectory, builderDataDirectory, config, localeConfig, builderCleanDataDirectory, builderRegisterShutdownHook, builderPort, connectConfig, pgBinaryResolver, pgStartupWait, errRedirector, outRedirector);
693711
}
694712
}
695713

@@ -768,6 +786,7 @@ private static String getArchitecture() {
768786
* @param stream A stream with the postgres binaries.
769787
* @param targetDir The directory to extract the content to.
770788
*/
789+
@SuppressWarnings("java:S2612")
771790
private static void extractTxz(final InputStream stream, final Path targetDir) throws IOException {
772791
try (final XZInputStream xzIn = new XZInputStream(stream);
773792
final TarArchiveInputStream tarIn = new TarArchiveInputStream(xzIn)) {
@@ -845,7 +864,7 @@ private void closeChannel(final Channel channel) {
845864
}
846865
}
847866

848-
@SuppressWarnings("java:S1141")
867+
@SuppressWarnings({"java:S1141", "java:S2612"})
849868
private static Path prepareBinaries(final PgBinaryResolver pgBinaryResolver, final Path overrideWorkingDirectory) {
850869
PREPARE_BINARIES_LOCK.lock();
851870
try {

0 commit comments

Comments
 (0)