Skip to content

Commit 2e43b66

Browse files
committed
HSEARCH-5394 Change how the "default" versions of the backends are set in the processor
so that we wouldn't need to update the version on each elasticsearch/lucene update
1 parent d3d380e commit 2e43b66

File tree

3 files changed

+55
-3
lines changed

3 files changed

+55
-3
lines changed

metamodel/metamodel-processor/pom.xml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,10 +91,27 @@
9191
<artifactId>maven-surefire-plugin</artifactId>
9292
<configuration>
9393
<systemPropertyVariables>
94-
<org.hibernate.search.integrationtest.backend.elasticsearch.version>${version.org.elasticsearch.client}</org.hibernate.search.integrationtest.backend.elasticsearch.version>
94+
<org.hibernate.search.integrationtest.backend.elasticsearch.version>${version.org.elasticsearch.latest}</org.hibernate.search.integrationtest.backend.elasticsearch.version>
9595
</systemPropertyVariables>
9696
</configuration>
9797
</plugin>
98+
<plugin>
99+
<groupId>org.jboss.maven.plugins</groupId>
100+
<artifactId>maven-injection-plugin</artifactId>
101+
<configuration>
102+
<bytecodeInjections>
103+
<bytecodeInjection>
104+
<expression>${version.org.elasticsearch.latest}</expression>
105+
<targetMembers>
106+
<methodBodyReturn>
107+
<className>org.hibernate.search.processor.util.impl.DefaultBackendVersionUtils</className>
108+
<methodName>latestElasticsearchVersion</methodName>
109+
</methodBodyReturn>
110+
</targetMembers>
111+
</bytecodeInjection>
112+
</bytecodeInjections>
113+
</configuration>
114+
</plugin>
98115
</plugins>
99116
</build>
100117
<profiles>

metamodel/metamodel-processor/src/main/java/org/hibernate/search/processor/HibernateSearchProcessorSettings.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
package org.hibernate.search.processor;
66

77

8+
import static org.hibernate.search.processor.util.impl.DefaultBackendVersionUtils.latestElasticsearchVersion;
9+
import static org.hibernate.search.processor.util.impl.DefaultBackendVersionUtils.latestLuceneVersion;
10+
811
import java.io.Serializable;
912
import java.time.Clock;
1013
import java.time.LocalDateTime;
@@ -80,11 +83,11 @@ public String formattedGeneratedAnnotation() {
8083
}
8184

8285
public String elasticsearchVersion() {
83-
return version == null ? "9.0.1" : version;
86+
return version == null ? latestElasticsearchVersion() : version;
8487
}
8588

8689
public String luceneVersion() {
87-
return version == null ? "9.12.1" : version;
90+
return version == null ? latestLuceneVersion() : version;
8891
}
8992

9093
public String backendVersion() {
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.processor.util.impl;
6+
7+
import java.lang.reflect.Field;
8+
9+
public final class DefaultBackendVersionUtils {
10+
private DefaultBackendVersionUtils() {
11+
}
12+
13+
public static String latestElasticsearchVersion() {
14+
// This implementation is replaced during the build with another one that returns the correct value:
15+
return "UNKNOWN";
16+
}
17+
18+
public static String latestLuceneVersion() {
19+
// since this one depends on which backend we pass to the processor ...
20+
try {
21+
Class<?> luceneVersionClass = Class.forName( "org.apache.lucene.util.Version" );
22+
Field latestField = luceneVersionClass.getField( "LATEST" );
23+
24+
Object latestVersion = latestField.get( null );
25+
26+
return latestVersion.toString();
27+
}
28+
catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
29+
return null;
30+
}
31+
}
32+
}

0 commit comments

Comments
 (0)