Skip to content

Commit dc24667

Browse files
committed
HSEARCH-5160 Include Lucene next dependencies in the dist package
1 parent bec6d2c commit dc24667

File tree

3 files changed

+241
-1
lines changed

3 files changed

+241
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,129 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
* Copyright Red Hat Inc. and Hibernate Authors
4+
*/
5+
package org.hibernate.search.build.enforcer;
6+
7+
import java.util.ArrayList;
8+
import java.util.List;
9+
import java.util.Set;
10+
11+
import javax.inject.Inject;
12+
import javax.inject.Named;
13+
14+
import org.apache.maven.enforcer.rule.api.AbstractEnforcerRule;
15+
import org.apache.maven.enforcer.rule.api.EnforcerRuleException;
16+
import org.apache.maven.execution.MavenSession;
17+
import org.apache.maven.model.Dependency;
18+
import org.apache.maven.model.Plugin;
19+
import org.apache.maven.model.PluginExecution;
20+
import org.apache.maven.project.DefaultDependencyResolutionRequest;
21+
import org.apache.maven.project.DependencyResolutionException;
22+
import org.apache.maven.project.DependencyResolutionResult;
23+
import org.apache.maven.project.MavenProject;
24+
import org.apache.maven.project.ProjectDependenciesResolver;
25+
import org.codehaus.plexus.util.xml.Xpp3Dom;
26+
import org.eclipse.aether.util.filter.AndDependencyFilter;
27+
import org.eclipse.aether.util.filter.ExclusionsDependencyFilter;
28+
import org.eclipse.aether.util.filter.ScopeDependencyFilter;
29+
30+
@Named("allLuceneNextDependenciesCopiedRule") // rule name - must start with lowercase character
31+
public class AllLuceneNextDependenciesCopiedRule extends AbstractEnforcerRule {
32+
33+
private static final String DEPENDENCY_PLUGIN = "org.apache.maven.plugins:maven-dependency-plugin";
34+
private static final String EXECUTION_COPY = "copy-dependencies-lucene-next";
35+
private static final String LUCENE_NEXT_ARTIFACT_ID = "hibernate-search-backend-lucene-next";
36+
// Inject needed Maven components
37+
@Inject
38+
private MavenSession session;
39+
40+
@Inject
41+
private ProjectDependenciesResolver dependenciesResolver;
42+
43+
/**
44+
* Rule parameter as list of items.
45+
*/
46+
private Set<Dependency> dependenciesToSkip;
47+
48+
public void execute() throws EnforcerRuleException {
49+
Plugin plugin = session.getCurrentProject().getPlugin( DEPENDENCY_PLUGIN );
50+
if ( plugin == null ) {
51+
throw new EnforcerRuleException( "Project %s:%s does not configure the Dependency plugin (%s)!"
52+
.formatted( session.getCurrentProject().getGroupId(), session.getCurrentProject().getArtifactId(),
53+
DEPENDENCY_PLUGIN
54+
) );
55+
}
56+
57+
PluginExecution execution = plugin.getExecutionsAsMap().get( EXECUTION_COPY );
58+
if ( execution == null ) {
59+
throw new EnforcerRuleException( "Project %s:%s does not configure the Dependency plugin (%s) execution \"%s\"!"
60+
.formatted( session.getCurrentProject().getGroupId(), session.getCurrentProject().getArtifactId(),
61+
DEPENDENCY_PLUGIN, EXECUTION_COPY
62+
) );
63+
}
64+
65+
if ( execution.getConfiguration() instanceof Xpp3Dom configuration ) {
66+
Xpp3Dom artifactItems = configuration.getChild( "artifactItems" );
67+
if ( artifactItems == null ) {
68+
throw new EnforcerRuleException(
69+
"Project %s:%s does not specify the Javadoc plugin (%s) execution \"%s\" sourcepath configuration attribute!"
70+
.formatted( session.getCurrentProject().getGroupId(),
71+
session.getCurrentProject().getArtifactId(),
72+
DEPENDENCY_PLUGIN, EXECUTION_COPY
73+
) );
74+
}
75+
76+
MavenProject luceneNextProject = session.getAllProjects().stream()
77+
.filter( p -> "jar".equals( p.getPackaging() ) && LUCENE_NEXT_ARTIFACT_ID.equals( p.getArtifactId() ) )
78+
.findFirst()
79+
.orElseThrow(
80+
() -> new EnforcerRuleException( "%s is not available, cannot determine required dependencies."
81+
.formatted( LUCENE_NEXT_ARTIFACT_ID ) ) );
82+
83+
List<org.eclipse.aether.graph.Dependency> dependencies = resolveDependencies( luceneNextProject );
84+
List<Dependency> redundantDependencies = new ArrayList<>();
85+
86+
87+
for ( Xpp3Dom artifact : artifactItems.getChildren() ) {
88+
if ( !dependencies
89+
.removeIf( dep -> dep.getArtifact().getGroupId().equals( artifact.getChild( "groupId" ).getValue() )
90+
&& dep.getArtifact().getArtifactId().equals( artifact.getChild( "artifactId" ).getValue() )
91+
&& dep.getArtifact().getVersion().equals( artifact.getChild( "version" ).getValue() ) ) ) {
92+
Dependency dependency = new Dependency();
93+
dependency.setGroupId( artifact.getChild( "groupId" ).getValue() );
94+
dependency.setArtifactId( artifact.getChild( "artifactId" ).getValue() );
95+
dependency.setVersion( artifact.getChild( "version" ).getValue() );
96+
redundantDependencies.add( dependency );
97+
}
98+
}
99+
100+
if ( !dependencies.isEmpty() ) {
101+
throw new EnforcerRuleException(
102+
"Some Lucene next backend dependencies are missing: %s".formatted( dependencies ) );
103+
}
104+
if ( !redundantDependencies.isEmpty() ) {
105+
throw new EnforcerRuleException(
106+
"Some Lucene next backend dependencies are redundant: %s".formatted( redundantDependencies ) );
107+
}
108+
}
109+
}
110+
111+
private List<org.eclipse.aether.graph.Dependency> resolveDependencies(MavenProject luceneNextProject) {
112+
try {
113+
DependencyResolutionResult result = dependenciesResolver
114+
.resolve( new DefaultDependencyResolutionRequest( luceneNextProject, session.getRepositorySession() )
115+
.setResolutionFilter(
116+
new AndDependencyFilter(
117+
// we skip test dependencies
118+
new ScopeDependencyFilter( "test" ),
119+
// and the ones we explicitly asked to skip:
120+
new ExclusionsDependencyFilter( dependenciesToSkip.stream()
121+
.map( d -> d.getGroupId() + ":" + d.getArtifactId() ).toList() )
122+
) ) );
123+
return result.getDependencies();
124+
}
125+
catch (DependencyResolutionException e) {
126+
throw new RuntimeException( e );
127+
}
128+
}
129+
}

distribution/pom.xml

+104
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,83 @@
152152

153153
<build>
154154
<plugins>
155+
<plugin>
156+
<groupId>org.apache.maven.plugins</groupId>
157+
<artifactId>maven-dependency-plugin</artifactId>
158+
<executions>
159+
<!--
160+
The Maven assembly plugin will not "pull" the Lucene-next dependencies since
161+
per dependency management Lucene libs are resolved to `version.org.apache.lucene` (9.x).
162+
We copy the libs required by the Lucene next backend and include them "manually" instead.
163+
164+
The enforcer plugin checks that this list matches what we have in the backend itself.
165+
-->
166+
<execution>
167+
<id>copy-dependencies-lucene-next</id>
168+
<phase>generate-sources</phase>
169+
<goals>
170+
<goal>copy</goal>
171+
</goals>
172+
<configuration>
173+
<artifactItems>
174+
<artifactItem>
175+
<groupId>org.apache.lucene</groupId>
176+
<artifactId>lucene-core</artifactId>
177+
<version>${version.org.apache.lucene.next}</version>
178+
</artifactItem>
179+
<artifactItem>
180+
<groupId>org.apache.lucene</groupId>
181+
<artifactId>lucene-analysis-common</artifactId>
182+
<version>${version.org.apache.lucene.next}</version>
183+
</artifactItem>
184+
<artifactItem>
185+
<groupId>org.apache.lucene</groupId>
186+
<artifactId>lucene-queryparser</artifactId>
187+
<version>${version.org.apache.lucene.next}</version>
188+
</artifactItem>
189+
<artifactItem>
190+
<groupId>org.apache.lucene</groupId>
191+
<artifactId>lucene-queries</artifactId>
192+
<version>${version.org.apache.lucene.next}</version>
193+
</artifactItem>
194+
<artifactItem>
195+
<groupId>org.apache.lucene</groupId>
196+
<artifactId>lucene-sandbox</artifactId>
197+
<version>${version.org.apache.lucene.next}</version>
198+
</artifactItem>
199+
<artifactItem>
200+
<groupId>org.apache.lucene</groupId>
201+
<artifactId>lucene-join</artifactId>
202+
<version>${version.org.apache.lucene.next}</version>
203+
</artifactItem>
204+
<artifactItem>
205+
<groupId>org.apache.lucene</groupId>
206+
<artifactId>lucene-facet</artifactId>
207+
<version>${version.org.apache.lucene.next}</version>
208+
</artifactItem>
209+
<artifactItem>
210+
<groupId>org.apache.lucene</groupId>
211+
<artifactId>lucene-highlighter</artifactId>
212+
<version>${version.org.apache.lucene.next}</version>
213+
</artifactItem>
214+
<artifactItem>
215+
<groupId>org.apache.lucene</groupId>
216+
<artifactId>lucene-memory</artifactId>
217+
<version>${version.org.apache.lucene.next}</version>
218+
</artifactItem>
219+
<artifactItem>
220+
<groupId>com.carrotsearch</groupId>
221+
<artifactId>hppc</artifactId>
222+
<version>${version.com.carrotsearch.hppc}</version>
223+
</artifactItem>
224+
</artifactItems>
225+
<outputDirectory>${project.build.directory}/dependencies-lucene-next</outputDirectory>
226+
<overWriteReleases>false</overWriteReleases>
227+
<overWriteSnapshots>true</overWriteSnapshots>
228+
</configuration>
229+
</execution>
230+
</executions>
231+
</plugin>
155232
<plugin>
156233
<groupId>org.apache.maven.plugins</groupId>
157234
<artifactId>maven-javadoc-plugin</artifactId>
@@ -238,10 +315,37 @@
238315
<pathsToSkip>
239316
<path>v5migrationhelper/engine/src/main/java</path>
240317
<path>v5migrationhelper/orm/src/main/java</path>
318+
<path>lucene-next/backend/lucene/src/main/java</path>
241319
<path>v5migrationhelper/orm/target/generated-sources/annotations</path>
242320
<path>v5migrationhelper/engine/target/generated-sources/annotations</path>
321+
<path>lucene-next/backend/lucene/target/generated-sources/annotations</path>
243322
</pathsToSkip>
244323
</javadocSourcePathIncludesAllPublicArtifactsRule>
324+
<allLuceneNextDependenciesCopiedRule>
325+
<!-- We skip these dependencies as they are already added to the distribution through other entries: -->
326+
<dependenciesToSkip>
327+
<dependency>
328+
<groupId>org.jboss.logging</groupId>
329+
<artifactId>jboss-logging</artifactId>
330+
</dependency>
331+
<dependency>
332+
<groupId>org.jboss.logging</groupId>
333+
<artifactId>jboss-logging-annotations</artifactId>
334+
</dependency>
335+
<dependency>
336+
<groupId>org.hibernate.search</groupId>
337+
<artifactId>hibernate-search-engine</artifactId>
338+
</dependency>
339+
<dependency>
340+
<groupId>org.hibernate.search</groupId>
341+
<artifactId>hibernate-search-util-common</artifactId>
342+
</dependency>
343+
<dependency>
344+
<groupId>io.smallrye</groupId>
345+
<artifactId>jandex</artifactId>
346+
</dependency>
347+
</dependenciesToSkip>
348+
</allLuceneNextDependenciesCopiedRule>
245349
</rules>
246350
</configuration>
247351
</execution>

distribution/src/main/assembly/dist.xml

+8-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@
33
SPDX-License-Identifier: Apache-2.0
44
Copyright Red Hat Inc. and Hibernate Authors
55
-->
6-
<assembly>
6+
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.2.0"
7+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
8+
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.2.0 http://maven.apache.org/xsd/assembly-2.2.0.xsd">
79
<id>dist</id>
810
<formats>
911
<format>tar.gz</format>
@@ -180,6 +182,11 @@
180182
</files>
181183

182184
<fileSets>
185+
<fileSet>
186+
<!-- Lucene "next" dependencies -->
187+
<directory>target/dependencies-lucene-next</directory>
188+
<outputDirectory>dist/backend/lucene-next</outputDirectory>
189+
</fileSet>
183190
<!-- Include all sources -->
184191
<fileSet>
185192
<directory>..</directory>

0 commit comments

Comments
 (0)