Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HSEARCH-5155 Build with JDK 21 #4171

Merged
merged 6 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ jobs:
matrix:
os:
- {
name: "Linux JDK 17",
name: "Linux JDK 21",
runs-on: 'ubuntu-latest',
java: {
version: 17
version: 21
},
maven: {
# Since we only start an Elasticsearch container on Linux we add the profile to enable container reuse here:
Expand All @@ -77,10 +77,10 @@ jobs:
# so we can't run Elasticsearch tests.
# See https://github.com/actions/runner-images/issues/1143#issuecomment-972929995
- {
name: "Windows JDK 17",
name: "Windows JDK 21",
runs-on: 'windows-latest',
java: {
version: 17
version: 21
},
maven: {
args: '-Dtest.elasticsearch.skip=true'
Expand Down
7 changes: 3 additions & 4 deletions Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ import org.hibernate.jenkins.pipeline.helpers.alternative.AlternativeMultiMap
* settingsId: ...
*/

@Field final String DEFAULT_JDK_TOOL = 'OpenJDK 17 Latest'
@Field final String DEFAULT_JDK_TOOL = 'OpenJDK 21 Latest'
@Field final String MAVEN_TOOL = 'Apache Maven 3.9'

// Default node pattern, to be used for resource-intensive stages.
Expand Down Expand Up @@ -189,14 +189,13 @@ stage('Configure') {
new JdkBuildEnvironment(version: '11', testCompilerTool: 'OpenJDK 11 Latest',
condition: TestCondition.AFTER_MERGE),
new JdkBuildEnvironment(version: '17', testCompilerTool: 'OpenJDK 17 Latest',
condition: TestCondition.AFTER_MERGE),
new JdkBuildEnvironment(version: '21', testCompilerTool: 'OpenJDK 21 Latest',
condition: TestCondition.BEFORE_MERGE,
isDefault: true),
// We want to enable preview features when testing newer builds of OpenJDK:
// even if we don't use these features, just enabling them can cause side effects
// and it's useful to test that.
new JdkBuildEnvironment(version: '21', testCompilerTool: 'OpenJDK 21 Latest',
testLauncherArgs: '--enable-preview',
condition: TestCondition.AFTER_MERGE),
new JdkBuildEnvironment(version: '22', testCompilerTool: 'OpenJDK 22 Latest',
testLauncherArgs: '--enable-preview',
condition: TestCondition.AFTER_MERGE),
Expand Down
8 changes: 8 additions & 0 deletions build/parents/build/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1014,6 +1014,10 @@
<bundledSignature>jdk-deprecated-16</bundledSignature>
<bundledSignature>jdk-deprecated-17</bundledSignature>
<bundledSignature>jdk-deprecated-18</bundledSignature>
<bundledSignature>jdk-deprecated-19</bundledSignature>
<bundledSignature>jdk-deprecated-20</bundledSignature>
<bundledSignature>jdk-deprecated-21</bundledSignature>
<bundledSignature>jdk-deprecated-22</bundledSignature>

<bundledSignature>jdk-internal-1.8</bundledSignature>
<bundledSignature>jdk-internal-9</bundledSignature>
Expand All @@ -1026,6 +1030,10 @@
<bundledSignature>jdk-internal-16</bundledSignature>
<bundledSignature>jdk-internal-17</bundledSignature>
<bundledSignature>jdk-internal-18</bundledSignature>
<bundledSignature>jdk-internal-19</bundledSignature>
<bundledSignature>jdk-internal-20</bundledSignature>
<bundledSignature>jdk-internal-21</bundledSignature>
<bundledSignature>jdk-internal-22</bundledSignature>
</bundledSignatures>
<signaturesArtifacts>
<signaturesArtifact>
Expand Down
3 changes: 1 addition & 2 deletions ci/dependency-update/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Map settings() {
]
case 'lucene10':
return [
testCompilerTool: 'OpenJDK 21 Latest',
updateProperties: ['version.org.apache.lucene'],
onlyRunTestDependingOn: ['hibernate-search-backend-lucene'],
additionalMavenArgs: '-Dtest.elasticsearch.skip=true -pl :hibernate-search-engine,:hibernate-search-backend-lucene,:hibernate-search-util-internal-integrationtest-backend-lucene,:hibernate-search-v5migrationhelper-engine'
Expand Down Expand Up @@ -76,7 +75,7 @@ def pullContainerImages() {
}

def withMavenWorkspace(Closure body) {
def actualJdk = settings().testCompilerTool == null ? 'OpenJDK 17 Latest' : settings().testCompilerTool
def actualJdk = settings().testCompilerTool == null ? 'OpenJDK 21 Latest' : settings().testCompilerTool
withMaven(jdk: actualJdk, maven: 'Apache Maven 3.9',
mavenLocalRepo: env.WORKSPACE_TMP + '/.m2repository',
options: [
Expand Down
2 changes: 1 addition & 1 deletion ci/performance/elasticsearch/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import groovy.transform.Field
import org.hibernate.jenkins.pipeline.helpers.job.JobHelper

@Field final String MAVEN_TOOL = 'Apache Maven 3.9'
@Field final String JDK_TOOL = 'OpenJDK 11 Latest'
@Field final String JDK_TOOL = 'OpenJDK 21 Latest'

// Performance node pattern, to be used for stages involving performance tests.
@Field final String PERFORMANCE_NODE_PATTERN = 'Performance'
Expand Down
2 changes: 1 addition & 1 deletion ci/performance/lucene/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import groovy.transform.Field
import org.hibernate.jenkins.pipeline.helpers.job.JobHelper

@Field final String MAVEN_TOOL = 'Apache Maven 3.9'
@Field final String JDK_TOOL = 'OpenJDK 11 Latest'
@Field final String JDK_TOOL = 'OpenJDK 21 Latest'

// Performance node pattern, to be used for stages involving performance tests.
@Field final String PERFORMANCE_NODE_PATTERN = 'Performance'
Expand Down
2 changes: 1 addition & 1 deletion ci/release/Jenkinsfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ pipeline {
}
tools {
maven 'Apache Maven 3.9'
jdk 'OpenJDK 17 Latest'
jdk 'OpenJDK 21 Latest'
}
options {
buildDiscarder logRotator(daysToKeepStr: '30', numToKeepStr: '10')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import java.io.InputStream;
import java.net.URL;

import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;

/**
* Default implementation of {@code ClassResolver} relying on an {@link AggregatedClassLoader}.
*
Expand All @@ -25,6 +27,8 @@ private DefaultResourceResolver(AggregatedClassLoader aggregatedClassLoader) {
}

@Override
@SuppressForbiddenApis(reason = "URL constructors are deprecated in JDK 20+ in favor of using URI.toURL(),"
+ " but we want to preserve backward compatibility for now (see below).")
public InputStream locateResourceStream(String name) {
try {
final InputStream stream = aggregatedClassLoader.getResourceAsStream( name );
Expand All @@ -42,6 +46,8 @@ public InputStream locateResourceStream(String name) {
try {
@SuppressWarnings("deprecation")
// TODO: HSEARCH-4765 address the URL -> URI constructor change once the URLClassLoader stops using the URL constructor
// Main problem: would URI.create(stripped).toURL() fail, since `stripped` seems to be a relative URL?
// Do we even have test coverage for this line?
InputStream resourceStream = new URL( stripped ).openStream();
return resourceStream;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ protected List<Float> createSingle() {
22.0f,
55f,
2500.5100000045f,
1584514514.000000184f,
1584514414.000000184f,
Float.MAX_VALUE
);
}
Expand Down Expand Up @@ -69,7 +69,7 @@ protected List<Float> createUniquelyMatchableValues() {
0.0f,
-0.0f, // Negative 0 is a different float
42.42f,
1584514514.000000184f,
1584514414.000000184f,
-1.001f, 3.0f, 5.1f
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.DocumentId;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.GenericField;
import org.hibernate.search.mapper.pojo.mapping.definition.annotation.Indexed;
import org.hibernate.search.util.impl.test.annotation.SuppressForbiddenApis;

public class JavaNetURLPropertyTypeDescriptor extends PropertyTypeDescriptor<URL, String> {

Expand Down Expand Up @@ -154,11 +155,10 @@ private static URL url(String spec) {
}
}

// TODO: HSEARCH-4765 To be removed when URL constructor is removed (JDK 20+). We keep it for now as users might still be using
// this constructor and we want to test such scenario
@SuppressForbiddenApis(reason = "We want to test 'new URL(...)' even in JDK 20+ where it's deprecated")
private static URL urlAsNewUrl(String spec) {
try {
@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation") // We want to test 'new URL(...)' even in JDK 20+ where it's deprecated
URL url = new URL( spec );
return url;
}
Expand Down
8 changes: 0 additions & 8 deletions integrationtest/performance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@
<name>Hibernate Search ITs - Performance - Parent POM</name>
<description>Parent POM of Hibernate Search performance tests</description>

<properties>
<!-- JMH or the annotation processor plugin has some trouble with newer JDKs.
Let's not bother, and use the same JDK as Maven, unlike other integration tests. -->
<java-version.main.release>8</java-version.main.release>
<java-version.main.compiler.java_home>${java.home}</java-version.main.compiler.java_home>
<java-version.main.compiler>${java-version.main.compiler.java_home}/bin/javac</java-version.main.compiler>
</properties>

<modules>
<module>backend/base</module>
<module>backend/lucene</module>
Expand Down
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>

<!-- JDK version required for the build; we target 11 but require at least 17 for the build -->
<jdk.min.version>17</jdk.min.version>
<jdk.min.version>21</jdk.min.version>
<!-- The lowest supported version of Java for applications using Hibernate Search -->
<!-- Set statically, independently from the current JDK: we want our code to comply with this version -->
<java-version.main.release>11</java-version.main.release>
Expand Down Expand Up @@ -303,7 +303,7 @@
<version.com.puppycrawl.tools.checkstyle>10.17.0</version.com.puppycrawl.tools.checkstyle>
<version.versions.plugin>2.16.2</version.versions.plugin>
<version.maven-wrapper-plugin>3.3.2</version.maven-wrapper-plugin>
<version.impsort-maven-plugin>1.10.0</version.impsort-maven-plugin>
<version.impsort-maven-plugin>1.11.0</version.impsort-maven-plugin>
<version.formatter-maven-plugin>2.24.1</version.formatter-maven-plugin>
<version.org.eclipse.m2e.lifecycle-mapping>1.0.0</version.org.eclipse.m2e.lifecycle-mapping>
<version.sisu-maven-plugin>0.9.0.M3</version.sisu-maven-plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import java.util.Map;
import java.util.function.BiFunction;

import org.hibernate.search.util.common.annotation.impl.SuppressForbiddenApis;
import org.hibernate.search.util.common.impl.Closer;
import org.hibernate.search.util.common.impl.SuppressingCloser;
import org.hibernate.search.util.common.impl.Throwables;
Expand Down Expand Up @@ -75,6 +76,8 @@ class CodeSource implements Closeable {
this.codeSourceLocation = codeSourceLocation;
}

@SuppressForbiddenApis(reason = "URL constructors are deprecated in JDK 20+ in favor of using URI.toURL(),"
+ " but we need to start from URLs (not URIs) coming from java.security.CodeSource.")
public InputStream readOrNull(String resourcePathString) throws IOException {
Throwable exception = null;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.hibernate.search.util.impl.test;

import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
Expand Down Expand Up @@ -35,7 +36,7 @@ public static SystemPropertyRestorer setSystemProperty(String key, String value)

public static Process runCommandWithInheritedIO(String... command) throws IOException {
// We can't use `inheritIO()` in surefire as that would bypass surefire's
// output capturingand lead to warnings.
// output capturing and lead to warnings.
// So we use an old-fashioned solution...

Process process = new ProcessBuilder( command )
Expand All @@ -44,20 +45,24 @@ public static Process runCommandWithInheritedIO(String... command) throws IOExce

// Drain the output/errors streams
ExecutorService service = Executors.newFixedThreadPool( 2 );
service.submit( () -> drain( process.getInputStream(), System.out::println ) );
service.submit( () -> drain( process.getErrorStream(), System.err::println ) );
try ( InputStream is = process.getInputStream(); InputStream es = process.getErrorStream();
Closeable pool = service::shutdownNow ) {
service.submit( () -> drain( is, System.out::println ) );
service.submit( () -> drain( es, System.err::println ) );
service.shutdown();

Awaitility.await( process + " termination" )
.atMost( 1, TimeUnit.MINUTES )
.until( () -> !process.isAlive() );
Awaitility.await( process + " termination" )
.atMost( 1, TimeUnit.MINUTES )
.until( () -> !process.isAlive() );
}

return process;
}

private static void drain(InputStream stream, Consumer<String> consumer) {
try ( InputStreamReader in = new InputStreamReader( stream, Charsets.UTF_8 );
BufferedReader bufferedReader = new BufferedReader( in ); ) {
bufferedReader.lines().forEach( System.out::println );
bufferedReader.lines().forEach( consumer );
}
catch (IOException e) {
throw new RuntimeException( e );
Expand Down
Loading