Skip to content

Commit

Permalink
Move Hibernate Search Elasticsearch backend to a dedicated extension
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Mar 13, 2024
1 parent d8fa79e commit eab51da
Show file tree
Hide file tree
Showing 37 changed files with 1,555 additions and 1,627 deletions.
6 changes: 6 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ updates:
- dependency-name: net.revelc.code:impsort-maven-plugin
- dependency-name: org.apache.maven.plugins:maven-invoker-plugin
- dependency-name: org.codehaus.mojo:build-helper-maven-plugin
- dependency-name: org.codehaus.mojo:build-helper-maven-plugin
- dependency-name: org.bsc.maven:maven-processor-plugin
# Narayana
- dependency-name: org.jboss.narayana.jta:*
- dependency-name: org.jboss.narayana.jts:*
Expand Down Expand Up @@ -213,6 +215,10 @@ updates:
# Only use dependabot for micros (patch versions).
- dependency-name: org.hibernate.*:*
update-types: ["version-update:semver-major", "version-update:semver-minor"]
- dependency-name: "org.bsc.maven:maven-processor-plugin"
# We require JDK 11, so we don't want to upgrade the "-jdk8" versions.
# Apparently patterns using wildcards are not supported here. Hopefully this will last until they drop these silly -jdk8 versions.
versions: [ "5.0-jdk8", "5.1-jdk8", "5.2-jdk8", "5.3-jdk8", "5.4-jdk8", "5.5-jdk8", "5.6-jdk8", "5.7-jdk8", "5.8-jdk8", "5.9-jdk8" ]
rebase-strategy: disabled
- package-ecosystem: gradle
directory: "/devtools/gradle"
Expand Down
10 changes: 10 additions & 0 deletions bom/application/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1210,6 +1210,16 @@
<artifactId>quarkus-mongodb-panache-common-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-backend-elasticsearch</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-backend-elasticsearch-deployment</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-orm-elasticsearch</artifactId>
Expand Down
7 changes: 6 additions & 1 deletion build-parent/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
<version.surefire.plugin>3.2.5</version.surefire.plugin>
<version.exec.plugin>3.0.0</version.exec.plugin>
<failsafe-plugin.version>${version.surefire.plugin}</failsafe-plugin.version>
<processor-plugin.version>5.0</processor-plugin.version>

<!-- Jandex versions -->
<jandex.version>3.1.6</jandex.version>
Expand Down Expand Up @@ -686,7 +687,11 @@
</execution>
</executions>
</plugin>

<plugin>
<groupId>org.bsc.maven</groupId>
<artifactId>maven-processor-plugin</artifactId>
<version>${processor-plugin.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-hibernate-search-backend-elasticsearch-deployment</artifactId>
<name>Quarkus - Hibernate Search - Elasticsearch - Deployment</name>

<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-common-deployment</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-search-backend-elasticsearch</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.quarkus.hibernate.search.backend.elasticsearch.deployment;

import java.util.Map;

import io.quarkus.builder.item.MultiBuildItem;
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.HibernateSearchBackendElasticsearchBuildTimeConfig;
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.MapperContext;

public final class HibernateSearchBackendElasticsearchEnabledBuildItem extends MultiBuildItem {

private final MapperContext mapperContext;
private final Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> buildTimeConfig;

public HibernateSearchBackendElasticsearchEnabledBuildItem(MapperContext mapperContext,
Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> buildTimeConfig) {
this.mapperContext = mapperContext;
this.buildTimeConfig = buildTimeConfig;
}

public MapperContext getMapperContext() {
return mapperContext;
}

public Map<String, HibernateSearchBackendElasticsearchBuildTimeConfig> getBuildTimeConfig() {
return buildTimeConfig;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
package io.quarkus.hibernate.search.backend.elasticsearch.deployment;

import java.nio.file.Files;
import java.nio.file.Path;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map.Entry;
import java.util.Optional;
import java.util.Set;

import org.hibernate.search.backend.elasticsearch.analysis.ElasticsearchAnalysisConfigurer;
import org.hibernate.search.backend.elasticsearch.gson.spi.GsonClasses;
import org.hibernate.search.backend.elasticsearch.index.layout.IndexLayoutStrategy;

import io.quarkus.arc.deployment.UnremovableBeanBuildItem;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.BuildSteps;
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem;
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.HibernateSearchBackendElasticsearchBuildTimeConfig;
import io.quarkus.hibernate.search.backend.elasticsearch.runtime.MapperContext;
import io.quarkus.runtime.configuration.ConfigurationException;

@BuildSteps
class HibernateSearchBackendElasticsearchProcessor {

@BuildStep
void registerBeans(List<HibernateSearchBackendElasticsearchEnabledBuildItem> searchEnabledPUs,
BuildProducer<UnremovableBeanBuildItem> unremovableBean) {
if (searchEnabledPUs.isEmpty()) {
return;
}
// Some user-injectable beans are retrieved programmatically and shouldn't be removed
unremovableBean.produce(UnremovableBeanBuildItem.beanTypes(ElasticsearchAnalysisConfigurer.class,
IndexLayoutStrategy.class));
}

@BuildStep
void registerReflectionForGson(List<HibernateSearchBackendElasticsearchEnabledBuildItem> enabled,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
if (enabled.isEmpty()) {
return;
}
String[] reflectiveClasses = GsonClasses.typesRequiringReflection().toArray(String[]::new);
reflectiveClass.produce(ReflectiveClassBuildItem.builder(reflectiveClasses).methods().fields().build());
}

@BuildStep
void processBuildTimeConfig(List<HibernateSearchBackendElasticsearchEnabledBuildItem> enabled,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
if (enabled.isEmpty()) {
return;
}
for (HibernateSearchBackendElasticsearchEnabledBuildItem enabledItem : enabled) {
processBuildTimeConfig(enabledItem, applicationArchivesBuildItem, nativeImageResources,
hotDeploymentWatchedFiles);
}
}

private void processBuildTimeConfig(HibernateSearchBackendElasticsearchEnabledBuildItem enabledItem,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
Set<String> propertyKeysWithNoVersion = new LinkedHashSet<>();
var buildTimeConfig = enabledItem.getBuildTimeConfig();

var mapperContext = enabledItem.getMapperContext();
Set<String> allBackendNames = new LinkedHashSet<>(mapperContext.backendNamesForIndexedEntities());
allBackendNames.addAll(buildTimeConfig.keySet());
// For all backends referenced either through @Indexed(backend = ...) or configuration...
for (String backendName : allBackendNames) {
HibernateSearchBackendElasticsearchBuildTimeConfig backendConfig = buildTimeConfig.get(backendName);
// ... we validate that the backend is configured and the version is present
if (backendConfig == null || backendConfig.version().isEmpty()) {
propertyKeysWithNoVersion.add(mapperContext.backendPropertyKey(backendName, null, "version"));
}
if (backendConfig == null) {
continue;
}
// ... we register files referenced from backends configuration
registerClasspathFilesFromBackendConfig(mapperContext, backendName, backendConfig,
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles);
}
if (!propertyKeysWithNoVersion.isEmpty()) {
throw new ConfigurationException(
"The Elasticsearch version needs to be defined via properties: "
+ String.join(", ", propertyKeysWithNoVersion) + ".",
propertyKeysWithNoVersion);
}
}

private static void registerClasspathFilesFromBackendConfig(MapperContext mapperContext, String backendName,
HibernateSearchBackendElasticsearchBuildTimeConfig backendConfig,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
registerClasspathFilesFromIndexConfig(mapperContext, backendName, null, backendConfig.indexDefaults(),
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles);
for (Entry<String, HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig> entry : backendConfig.indexes()
.entrySet()) {
String indexName = entry.getKey();
HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig indexConfig = entry.getValue();
registerClasspathFilesFromIndexConfig(mapperContext, backendName, indexName, indexConfig,
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles);
}
}

private static void registerClasspathFilesFromIndexConfig(MapperContext mapperContext, String backendName, String indexName,
HibernateSearchBackendElasticsearchBuildTimeConfig.IndexConfig indexConfig,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
registerClasspathFileFromConfig(mapperContext, backendName, indexName, "schema-management.settings-file",
indexConfig.schemaManagement().settingsFile(),
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles);
registerClasspathFileFromConfig(mapperContext, backendName, indexName, "schema-management.mapping-file",
indexConfig.schemaManagement().mappingFile(),
applicationArchivesBuildItem, nativeImageResources, hotDeploymentWatchedFiles);
}

private static void registerClasspathFileFromConfig(MapperContext mapperContext, String backendName, String indexName,
String propertyKeyRadical,
Optional<String> classpathFileOptional,
ApplicationArchivesBuildItem applicationArchivesBuildItem,
BuildProducer<NativeImageResourceBuildItem> nativeImageResources,
BuildProducer<HotDeploymentWatchedFileBuildItem> hotDeploymentWatchedFiles) {
if (!classpathFileOptional.isPresent()) {
return;
}
String classpathFile = classpathFileOptional.get();

Path existingPath = applicationArchivesBuildItem.getRootArchive().getChildPath(classpathFile);

if (existingPath == null || Files.isDirectory(existingPath)) {
//raise exception if explicit file is not present (i.e. not the default)
throw new ConfigurationException(
"Unable to find file referenced in '"
+ mapperContext.backendPropertyKey(backendName, indexName, propertyKeyRadical) + "="
+ classpathFile
+ "'. Remove property or add file to your path.");
}
nativeImageResources.produce(new NativeImageResourceBuildItem(classpathFile));
hotDeploymentWatchedFiles.produce(new HotDeploymentWatchedFileBuildItem(classpathFile));
}

}
20 changes: 20 additions & 0 deletions extensions/hibernate-search-backend-elasticsearch/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-extensions-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId>
<name>Quarkus - Hibernate Search - Elasticsearch</name>
<packaging>pom</packaging>
<modules>
<module>deployment</module>
<module>runtime</module>
</modules>
</project>
55 changes: 55 additions & 0 deletions extensions/hibernate-search-backend-elasticsearch/runtime/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>quarkus-hibernate-search-backend-elasticsearch-parent</artifactId>
<groupId>io.quarkus</groupId>
<version>999-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>quarkus-hibernate-search-backend-elasticsearch</artifactId>
<name>Quarkus - Hibernate Search - Elasticsearch - Runtime</name>
<description>Elasticsearch/OpenSearch backend for use in other Hibernate Search extensions</description>
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-elasticsearch-rest-client-common</artifactId>
</dependency>
<dependency>
<groupId>org.hibernate.search</groupId>
<artifactId>hibernate-search-backend-elasticsearch</artifactId>
</dependency>
<dependency>
<groupId>org.graalvm.sdk</groupId>
<artifactId>graal-sdk</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-extension-processor</artifactId>
<version>${project.version}</version>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.hibernate.search.orm.elasticsearch.runtime;
package io.quarkus.hibernate.search.backend.elasticsearch.runtime;

import org.hibernate.search.backend.elasticsearch.ElasticsearchVersion;

Expand Down
Loading

0 comments on commit eab51da

Please sign in to comment.