Skip to content

Commit 36812b1

Browse files
committed
Make mongo-hibernate.jar a Java module
HIBERNATE-52
1 parent 100904b commit 36812b1

File tree

19 files changed

+193
-105
lines changed

19 files changed

+193
-105
lines changed

.evergreen/java-config.sh

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
# Java configurations for evergreen
44

55
export JDK17="/opt/java/jdk17"
6-
export JDK21="/opt/java/jdk21"
76

87
if [ -d "$JDK17" ]; then
98
export JAVA_HOME=$JDK17

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ instead of SQL. This product works by:
3535
- [Manual](https://www.mongodb.com/docs/languages/java/mongodb-hibernate/current)
3636
- [API](https://javadoc.io/doc/org.mongodb/mongodb-hibernate/latest/index.html)
3737

38-
[Standalone deployments](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-standalone) are not supported,
38+
MongoDB [standalone deployments](https://www.mongodb.com/docs/manual/reference/glossary/#std-term-standalone) are not supported,
3939
because they [do not support transactions](https://www.mongodb.com/docs/manual/core/transactions-production-consideration/).
4040
If you use one, you may [convert it to a replica set](https://www.mongodb.com/docs/manual/tutorial/convert-standalone-to-replica-set/).
4141

@@ -102,7 +102,7 @@ This project uses separate directories for unit and integration tests:
102102
- [`./src/test`](src/test)
103103
- [`./src/integrationTest`](src/integrationTest)
104104

105-
Integration tests require a MongoDB deployment with test commands enabled, which may be achieved with the
105+
Integration tests require a MongoDB deployment with test commands enabled, which may be achieved with the
106106
[`--setParameter enableTestCommands=1`](https://www.mongodb.com/docs/manual/reference/parameters/)
107107
command-line arguments.
108108

build.gradle.kts

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -39,20 +39,28 @@ java {
3939
}
4040

4141
tasks.withType<Javadoc> {
42-
exclude("/com/mongodb/hibernate/internal/**")
43-
exclude("com/mongodb/hibernate/dialect/**")
44-
exclude("com/mongodb/hibernate/jdbc/**")
45-
4642
val standardDocletOptions = options as StandardJavadocDocletOptions
4743
standardDocletOptions.apply {
44+
addBooleanOption("Werror", false)
45+
// TODO-HIBERNATE-129 addStringOption("-link-modularity-mismatch", "info")
46+
addBooleanOption("serialwarn", true)
47+
addBooleanOption("Xdoclint:all", true)
48+
addBooleanOption(
49+
"Xdoclint/package:-" +
50+
"com.mongodb.hibernate.internal.*" +
51+
",com.mongodb.hibernate.dialect.*" +
52+
",com.mongodb.hibernate.jdbc.*",
53+
true)
54+
addStringOption("-show-module-contents", "api")
55+
addStringOption("-show-packages", "exported")
56+
addStringOption("-show-types", "protected")
4857
author(true)
4958
version(true)
50-
encoding = "UTF-8"
59+
encoding("UTF-8")
5160
charSet("UTF-8")
5261
docEncoding("UTF-8")
5362
addBooleanOption("html5", true)
5463
addBooleanOption("-allow-script-in-comments", true)
55-
// TODO-HIBERNATE-129 addStringOption("-link-modularity-mismatch", "info")
5664
links =
5765
listOf(
5866
"https://docs.oracle.com/en/java/javase/17/docs/api/",
@@ -141,11 +149,15 @@ spotless {
141149
tasks.check { dependsOn(tasks.spotlessApply) }
142150

143151
tasks.withType<JavaCompile>().configureEach {
144-
options.compilerArgs.addAll(listOf("-Xlint:all", "-Werror"))
152+
options.compilerArgs.addAll(
153+
listOf("-Xlint:all", "-Xlint:-requires-automatic", "-Xlint:-requires-transitive-automatic", "-Werror"))
145154
when (this) {
146155
tasks.compileJava.get() ->
147156
options.errorprone {
148157
disableWarningsInGeneratedCode = true
158+
// Error Prone does not understand the `@hidden` standard tag
159+
disable("InvalidBlockTag")
160+
disable("AssignmentExpression")
149161
option("NullAway:AnnotatedPackages", "com.mongodb.hibernate")
150162
error("NullAway")
151163
}
@@ -159,6 +171,8 @@ tasks.withType<JavaCompile>().configureEach {
159171
buildConfig {
160172
useJavaOutput()
161173
packageName("com.mongodb.hibernate.internal")
174+
documentation.set(
175+
"Generated by the <a href=\"https://github.com/gmazzo/gradle-buildconfig-plugin\">BuildConfig</a> plugin.\n\n@hidden")
162176
buildConfigField("NAME", provider { project.name })
163177
buildConfigField("VERSION", provider { "${project.version}" })
164178
}
@@ -205,6 +219,9 @@ publishing {
205219
repositories {
206220
// publish to local build dir for testing
207221
// `./gradlew publishMavenPublicationToLocalBuildRepository`
222+
//
223+
// publish to the local Maven cache
224+
// `./gradlew publishToMavenLocal`
208225
maven {
209226
url = uri(localBuildRepo.get())
210227
name = "LocalBuild"
@@ -222,8 +239,8 @@ publishing {
222239
url = "https://www.mongodb.com/"
223240
licenses {
224241
license {
225-
name = "The Apache License, Version 2.0"
226-
url = "http://www.apache.org/licenses/LICENSE-2.0.txt"
242+
name = "Apache License, Version 2.0"
243+
url = "https://www.apache.org/licenses/LICENSE-2.0"
227244
}
228245
}
229246
developers {
@@ -234,8 +251,8 @@ publishing {
234251
}
235252
scm {
236253
url.set("https://github.com/mongodb/mongo-hibernate")
237-
connection.set("scm:https://github.com/mongodb/mongo-hibernate.git")
238-
developerConnection.set("scm:https://github.com/mongodb/mongo-hibernate.git")
254+
connection.set("scm:git:https://github.com/mongodb/mongo-hibernate.git")
255+
developerConnection.set("scm:git:https://github.com/mongodb/mongo-hibernate.git")
239256
}
240257
}
241258
}

gradle/libs.versions.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,19 @@
1515
[versions]
1616
junit-jupiter = "5.13.4"
1717
assertj = "3.27.3"
18-
google-errorprone-core = "2.36.0"
18+
google-errorprone-core = "2.42.0"
1919
nullaway = "0.12.4"
2020
jspecify = "1.0.0"
2121
hibernate-orm = "6.6.34.Final" # Remember to update javadoc links
2222
mongo-java-driver-sync = "5.6.1" # Remember to update javadoc links
2323
findbugs-jsr = "3.0.2"
24-
slf4j-api = "2.0.16"
25-
logback-classic = "1.5.16"
24+
slf4j-api = "2.0.17"
25+
logback-classic = "1.5.21"
2626
mockito = "5.16.0"
2727
checker-qual = "3.49.1"
2828

2929
plugin-spotless = "7.0.2"
30-
plugin-errorprone = "4.1.0"
30+
plugin-errorprone = "4.3.0"
3131
plugin-buildconfig = "5.5.4"
3232
plugin-palantir = "2.58.0"
3333
plugin-ktfmt = "0.54"

src/integrationTest/java/com/mongodb/hibernate/query/AbstractQueryIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
import com.mongodb.client.MongoCollection;
2828
import com.mongodb.hibernate.TestCommandListener;
29-
import com.mongodb.hibernate.dialect.MongoDialect;
29+
import com.mongodb.hibernate.internal.dialect.TestMongoDialect;
3030
import com.mongodb.hibernate.junit.MongoExtension;
3131
import java.util.Set;
3232
import java.util.function.Consumer;
@@ -251,7 +251,7 @@ private void assertAffectedCollections(Set<String> expectedAffectedCollections)
251251
.containsExactlyInAnyOrderElementsOf(expectedAffectedCollections);
252252
}
253253

254-
protected static final class TranslateResultAwareDialect extends MongoDialect {
254+
protected static final class TranslateResultAwareDialect extends TestMongoDialect {
255255
private AbstractJdbcOperationQuery capturedTranslateResult;
256256

257257
public TranslateResultAwareDialect(DialectResolutionInfo info) {

src/integrationTest/java/com/mongodb/hibernate/query/select/LimitOffsetFetchClauseIntegrationTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@
2323
import static org.hibernate.cfg.AvailableSettings.QUERY_PLAN_CACHE_ENABLED;
2424
import static org.junit.jupiter.params.provider.EnumSource.Mode.EXCLUDE;
2525

26-
import com.mongodb.hibernate.dialect.MongoDialect;
2726
import com.mongodb.hibernate.internal.FeatureNotSupportedException;
2827
import com.mongodb.hibernate.internal.MongoConstants;
28+
import com.mongodb.hibernate.internal.dialect.TestMongoDialect;
2929
import com.mongodb.hibernate.query.AbstractQueryIntegrationTests;
3030
import com.mongodb.hibernate.query.Book;
3131
import java.util.Arrays;
@@ -625,7 +625,7 @@ private void setQueryOptionsAndQuery(
625625
* the query plan cache is hit, not whether {@link SqlAstTranslator} is reused afterwards (e.g., incompatible
626626
* {@link org.hibernate.query.spi.QueryOptions QueryOptions}s will end up with new translator bing created).
627627
*/
628-
protected static final class TranslatingCacheTestingDialect extends MongoDialect {
628+
protected static final class TranslatingCacheTestingDialect extends TestMongoDialect {
629629
private final AtomicInteger selectTranslatingCounter = new AtomicInteger();
630630

631631
public TranslatingCacheTestingDialect(DialectResolutionInfo info) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
com.mongodb.hibernate.TestServiceContributor
1+
com.mongodb.hibernate.TestServiceContributor
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
hibernate.dialect=com.mongodb.hibernate.dialect.MongoDialect
22
hibernate.connection.provider_class=com.mongodb.hibernate.jdbc.MongoConnectionProvider
33
jakarta.persistence.jdbc.url=mongodb://localhost/mongo-hibernate-test?directConnection=false
4-
hibernate.query.plan_cache_enabled=false #make tests more isolated from each other
4+
hibernate.query.plan_cache_enabled=false #make tests more isolated from each other
Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,32 @@
1+
<?xml version="1.0" encoding="UTF-8" ?>
2+
<!--
3+
Copyright 2025-present MongoDB, Inc.
4+
5+
Licensed under the Apache License, Version 2.0 (the "License");
6+
you may not use this file except in compliance with the License.
7+
You may obtain a copy of the License at
8+
9+
http://www.apache.org/licenses/LICENSE-2.0
10+
11+
Unless required by applicable law or agreed to in writing, software
12+
distributed under the License is distributed on an "AS IS" BASIS,
13+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
See the License for the specific language governing permissions and
15+
limitations under the License.
16+
-->
17+
18+
<!DOCTYPE configuration>
119
<configuration>
2-
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
3-
<encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder">
4-
<Pattern>
5-
%d{HH:mm:ss} [%thread] %-5level %logger{36} - %msg%n
6-
</Pattern>
20+
<import class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"/>
21+
<import class="ch.qos.logback.core.ConsoleAppender"/>
22+
<appender name="STDOUT" class="ConsoleAppender">
23+
<encoder class="PatternLayoutEncoder">
24+
<pattern>%date{STRICT} [%thread] %level %logger{36} - %message%n</pattern>
725
</encoder>
826
</appender>
27+
<root level="info">
28+
<appender-ref ref="STDOUT"/>
29+
</root>
930
<logger name="org.hibernate" level="warn" additivity="true"/>
1031
<logger name="org.hibernate.SQL" level="debug" additivity="true"/>
1132
<logger name="org.hibernate.orm.jdbc.bind" level="trace" additivity="true"/>
@@ -14,7 +35,4 @@
1435
<logger name="org.hibernate.orm.sql.ast.tree" level="debug" additivity="true"/>
1536
<logger name="org.mongodb.driver" level="warn" additivity="true"/>
1637
<logger name="com.mongodb.hibernate" level="debug" additivity="true"/>
17-
<root level="info">
18-
<appender-ref ref="STDOUT"/>
19-
</root>
20-
</configuration>
38+
</configuration>

src/main/java/com/mongodb/hibernate/cfg/MongoConfigurator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818

1919
import com.mongodb.ConnectionString;
2020
import com.mongodb.MongoClientSettings;
21-
import com.mongodb.hibernate.internal.Sealed;
21+
import com.mongodb.hibernate.internal.cfg.MongoConfigurationBuilder;
2222
import com.mongodb.hibernate.service.spi.MongoConfigurationContributor;
2323
import java.util.Map;
2424
import java.util.function.Consumer;
@@ -74,8 +74,7 @@
7474
*
7575
* @see MongoConfigurationContributor
7676
*/
77-
@Sealed
78-
public interface MongoConfigurator {
77+
public sealed interface MongoConfigurator permits MongoConfigurationBuilder {
7978
/**
8079
* Configures {@link MongoClientSettings}.
8180
*

0 commit comments

Comments
 (0)