Skip to content

Commit f2601b0

Browse files
committed
HHH-18522 Drop hard requirements on Jandex
1 parent d81b284 commit f2601b0

File tree

17 files changed

+40
-155
lines changed

17 files changed

+40
-155
lines changed

hibernate-core/src/main/java/org/hibernate/boot/MetadataBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ public interface MetadataBuilder {
148148
*
149149
* @return {@code this}, for method chaining
150150
*/
151-
MetadataBuilder applyIndexView(IndexView jandexView);
151+
MetadataBuilder applyIndexView(Object jandexView);
152152

153153
/**
154154
* Specify the options to be used in performing scanning.

hibernate-core/src/main/java/org/hibernate/boot/internal/BootstrapContextImpl.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ public class BootstrapContextImpl implements BootstrapContext {
6666
private Object scannerSetting;
6767
private ArchiveDescriptorFactory archiveDescriptorFactory;
6868

69-
private IndexView jandexView;
69+
private Object jandexView;
7070

7171
private HashMap<String,SqmFunctionDescriptor> sqlFunctionMap;
7272
private ArrayList<AuxiliaryDatabaseObject> auxiliaryDatabaseObjectList;
@@ -182,7 +182,7 @@ public Object getScanner() {
182182
}
183183

184184
@Override
185-
public IndexView getJandexView() {
185+
public Object getJandexView() {
186186
return jandexView;
187187
}
188188

@@ -300,7 +300,7 @@ void injectArchiveDescriptorFactory(ArchiveDescriptorFactory factory) {
300300
this.archiveDescriptorFactory = factory;
301301
}
302302

303-
void injectJandexView(IndexView jandexView) {
303+
void injectJandexView(Object jandexView) {
304304
log.debugf( "Injecting Jandex IndexView [%s] into BootstrapContext; was [%s]", jandexView, this.jandexView );
305305
this.jandexView = jandexView;
306306
}

hibernate-core/src/main/java/org/hibernate/boot/internal/MetadataBuilderImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ public MetadataBuilder applyAccessType(AccessType implicitCacheAccessType) {
213213
}
214214

215215
@Override
216-
public MetadataBuilder applyIndexView(IndexView jandexView) {
216+
public MetadataBuilder applyIndexView(Object jandexView) {
217217
this.bootstrapContext.injectJandexView( jandexView );
218218
return this;
219219
}

hibernate-core/src/main/java/org/hibernate/boot/model/process/spi/MetadataBuildingProcess.java

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -398,10 +398,6 @@ public static DomainModelSource processManagedResources(
398398
} );
399399
managedResources.getAnnotatedClassReferences().forEach( (clazz) -> allKnownClassNames.add( clazz.getName() ) );
400400

401-
// At this point we know all managed class names across all sources.
402-
// Resolve the Jandex Index and build the SourceModelBuildingContext.
403-
final IndexView jandexIndex = resolveJandexIndex( allKnownClassNames, bootstrapContext.getJandexView(), sourceModelBuildingContext.getClassLoading() );
404-
405401
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
406402
// - process metadata-complete XML
407403
// - collect overlay XML
@@ -424,7 +420,6 @@ public static DomainModelSource processManagedResources(
424420
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
425421
areIdGeneratorsGlobal,
426422
metadataCollector.getGlobalRegistrations(),
427-
jandexIndex,
428423
sourceModelBuildingContext
429424
);
430425

@@ -458,7 +453,6 @@ public static DomainModelSource processManagedResources(
458453

459454
return new DomainModelSource(
460455
classDetailsRegistry,
461-
jandexIndex,
462456
allKnownClassNames,
463457
modelCategorizationCollector.getGlobalRegistrations(),
464458
rootMappingDefaults,
@@ -491,31 +485,6 @@ private static void applyKnownClass(
491485
}
492486
}
493487

494-
public static IndexView resolveJandexIndex(
495-
List<String> allKnownClassNames,
496-
IndexView suppliedJandexIndex,
497-
ClassLoading classLoading) {
498-
// todo : we could build a new Jandex (Composite)Index that includes the `managedResources#getAnnotatedClassNames`
499-
// and all classes from `managedResources#getXmlMappingBindings`. Only really worth it in the case
500-
// of runtime enhancement. This would definitely need to be toggle-able.
501-
// +
502-
// For now, let's not as it does not matter for this PoC
503-
if ( 1 == 1 ) {
504-
return suppliedJandexIndex;
505-
}
506-
507-
final Indexer jandexIndexer = new Indexer();
508-
for ( String knownClassName : allKnownClassNames ) {
509-
JandexIndexerHelper.apply( knownClassName, jandexIndexer, classLoading );
510-
}
511-
512-
if ( suppliedJandexIndex == null ) {
513-
return jandexIndexer.complete();
514-
}
515-
516-
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
517-
}
518-
519488
private static void processAdditionalMappingContributions(
520489
InFlightMetadataCollectorImpl metadataCollector,
521490
MetadataBuildingOptions options,

hibernate-core/src/main/java/org/hibernate/boot/model/source/internal/annotations/DomainModelSource.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,23 @@
1414
import org.hibernate.boot.models.xml.spi.PersistenceUnitMetadata;
1515
import org.hibernate.models.spi.ClassDetailsRegistry;
1616

17-
import org.jboss.jandex.IndexView;
18-
1917
/**
2018
* @author Steve Ebersole
2119
*/
2220
public class DomainModelSource {
2321
private final ClassDetailsRegistry classDetailsRegistry;
24-
private final IndexView jandexIndex;
2522
private final GlobalRegistrations globalRegistrations;
2623
private final RootMappingDefaults effectiveMappingDefaults;
2724
private final PersistenceUnitMetadata persistenceUnitMetadata;
2825
private final List<String> allKnownClassNames;
2926

3027
public DomainModelSource(
3128
ClassDetailsRegistry classDetailsRegistry,
32-
IndexView jandexIndex,
3329
List<String> allKnownClassNames,
3430
GlobalRegistrations globalRegistrations,
3531
RootMappingDefaults effectiveMappingDefaults,
3632
PersistenceUnitMetadata persistenceUnitMetadata) {
3733
this.classDetailsRegistry = classDetailsRegistry;
38-
this.jandexIndex = jandexIndex;
3934
this.allKnownClassNames = allKnownClassNames;
4035
this.globalRegistrations = globalRegistrations;
4136
this.effectiveMappingDefaults = effectiveMappingDefaults;
@@ -46,10 +41,6 @@ public ClassDetailsRegistry getClassDetailsRegistry() {
4641
return classDetailsRegistry;
4742
}
4843

49-
public IndexView getJandexIndex() {
50-
return jandexIndex;
51-
}
52-
5344
public GlobalRegistrations getGlobalRegistrations() {
5445
return globalRegistrations;
5546
}

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/internal/CategorizedDomainModelImpl.java

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.hibernate.models.spi.ClassDetails;
1616
import org.hibernate.models.spi.ClassDetailsRegistry;
1717

18-
import org.jboss.jandex.IndexView;
19-
2018
/**
2119
* @author Steve Ebersole
2220
*/
@@ -28,13 +26,11 @@ public class CategorizedDomainModelImpl implements CategorizedDomainModel {
2826

2927
private final ClassDetailsRegistry classDetailsRegistry;
3028
private final AnnotationDescriptorRegistry annotationDescriptorRegistry;
31-
private final IndexView jandexIndex;
3229
private final PersistenceUnitMetadata persistenceUnitMetadata;
3330

3431
public CategorizedDomainModelImpl(
3532
ClassDetailsRegistry classDetailsRegistry,
3633
AnnotationDescriptorRegistry annotationDescriptorRegistry,
37-
IndexView jandexIndex,
3834
PersistenceUnitMetadata persistenceUnitMetadata,
3935
Set<EntityHierarchy> entityHierarchies,
4036
Map<String, ClassDetails> mappedSuperclasses,
@@ -47,7 +43,6 @@ public CategorizedDomainModelImpl(
4743
this.mappedSuperclasses = mappedSuperclasses;
4844
this.embeddables = embeddables;
4945
this.globalRegistrations = globalRegistrations;
50-
this.jandexIndex = jandexIndex;
5146
}
5247

5348
@Override
@@ -60,11 +55,6 @@ public AnnotationDescriptorRegistry getAnnotationDescriptorRegistry() {
6055
return annotationDescriptorRegistry;
6156
}
6257

63-
@Override
64-
public IndexView getJandexIndex() {
65-
return jandexIndex;
66-
}
67-
6858
@Override
6959
public PersistenceUnitMetadata getPersistenceUnitMetadata() {
7060
return persistenceUnitMetadata;

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/CategorizedDomainModel.java

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
import org.hibernate.models.spi.ClassDetails;
1616
import org.hibernate.models.spi.ClassDetailsRegistry;
1717

18-
import org.jboss.jandex.IndexView;
19-
2018
/**
2119
* The application's domain model, understood at a very rudimentary level - we know
2220
* a class is an entity, a mapped-superclass, ... And we know about persistent attributes,
@@ -38,8 +36,6 @@ public interface CategorizedDomainModel {
3836
*/
3937
AnnotationDescriptorRegistry getAnnotationDescriptorRegistry();
4038

41-
IndexView getJandexIndex();
42-
4339
PersistenceUnitMetadata getPersistenceUnitMetadata();
4440

4541
/**

hibernate-core/src/main/java/org/hibernate/boot/models/categorize/spi/ManagedResourcesProcessor.java

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,9 @@
3030
import org.hibernate.boot.spi.BootstrapContext;
3131
import org.hibernate.boot.spi.MetadataBuildingOptions;
3232
import org.hibernate.models.internal.BasicModelBuildingContextImpl;
33-
import org.hibernate.models.jandex.internal.JandexIndexerHelper;
3433
import org.hibernate.models.spi.AnnotationDescriptorRegistry;
3534
import org.hibernate.models.spi.ClassDetails;
3635
import org.hibernate.models.spi.ClassDetailsRegistry;
37-
import org.hibernate.models.spi.ClassLoading;
38-
39-
import org.jboss.jandex.CompositeIndex;
40-
import org.jboss.jandex.IndexView;
41-
import org.jboss.jandex.Indexer;
4236

4337
import static org.hibernate.boot.models.categorize.internal.EntityHierarchyBuilder.createEntityHierarchies;
4438
import static org.hibernate.internal.util.collections.CollectionHelper.mutableJoin;
@@ -100,7 +94,6 @@ public static CategorizedDomainModel processManagedResources(
10094

10195
// At this point we know all managed class names across all sources.
10296
// Resolve the Jandex Index and build the SourceModelBuildingContext.
103-
final IndexView jandexIndex = resolveJandexIndex( allKnownClassNames, bootstrapContext.getJandexView(), classLoading );
10497
final BasicModelBuildingContextImpl sourceModelBuildingContext = new BasicModelBuildingContextImpl(
10598
classLoading,
10699
ModelsHelper::preFillRegistries
@@ -131,7 +124,6 @@ public static CategorizedDomainModel processManagedResources(
131124
final DomainModelCategorizationCollector modelCategorizationCollector = new DomainModelCategorizationCollector(
132125
areIdGeneratorsGlobal,
133126
globalRegistrations,
134-
jandexIndex,
135127
sourceModelBuildingContext
136128
);
137129

@@ -222,31 +214,6 @@ private static void warnAboutUnusedMappedSuperclasses(Map<String, ClassDetails>
222214
}
223215
}
224216

225-
public static IndexView resolveJandexIndex(
226-
List<String> allKnownClassNames,
227-
IndexView suppliedJandexIndex,
228-
ClassLoading classLoading) {
229-
// todo : we could build a new Jandex (Composite)Index that includes the `managedResources#getAnnotatedClassNames`
230-
// and all classes from `managedResources#getXmlMappingBindings`. Only really worth it in the case
231-
// of runtime enhancement. This would definitely need to be toggle-able.
232-
// +
233-
// For now, let's not as it does not matter for this PoC
234-
if ( 1 == 1 ) {
235-
return suppliedJandexIndex;
236-
}
237-
238-
final Indexer jandexIndexer = new Indexer();
239-
for ( String knownClassName : allKnownClassNames ) {
240-
JandexIndexerHelper.apply( knownClassName, jandexIndexer, classLoading );
241-
}
242-
243-
if ( suppliedJandexIndex == null ) {
244-
return jandexIndexer.complete();
245-
}
246-
247-
return CompositeIndex.create( suppliedJandexIndex, jandexIndexer.complete() );
248-
}
249-
250217
/**
251218
* For testing use only
252219
*/

hibernate-core/src/main/java/org/hibernate/boot/models/internal/DomainModelCategorizationCollector.java

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
import org.hibernate.models.spi.ClassDetailsRegistry;
2525
import org.hibernate.models.spi.SourceModelBuildingContext;
2626

27-
import org.jboss.jandex.IndexView;
28-
2927
import jakarta.persistence.AttributeConverter;
3028
import jakarta.persistence.Converter;
3129
import jakarta.persistence.Embeddable;
@@ -40,7 +38,6 @@
4038

4139
public class DomainModelCategorizationCollector {
4240
private final boolean areIdGeneratorsGlobal;
43-
private final IndexView jandexIndex;
4441

4542
private final GlobalRegistrationsImpl globalRegistrations;
4643
private final SourceModelBuildingContext modelsContext;
@@ -52,10 +49,8 @@ public class DomainModelCategorizationCollector {
5249
public DomainModelCategorizationCollector(
5350
boolean areIdGeneratorsGlobal,
5451
GlobalRegistrations globalRegistrations,
55-
IndexView jandexIndex,
5652
SourceModelBuildingContext modelsContext) {
5753
this.areIdGeneratorsGlobal = areIdGeneratorsGlobal;
58-
this.jandexIndex = jandexIndex;
5954
this.globalRegistrations = (GlobalRegistrationsImpl) globalRegistrations;
6055
this.modelsContext = modelsContext;
6156
}
@@ -176,7 +171,6 @@ public CategorizedDomainModel createResult(
176171
return new CategorizedDomainModelImpl(
177172
classDetailsRegistry,
178173
annotationDescriptorRegistry,
179-
jandexIndex,
180174
persistenceUnitMetadata,
181175
entityHierarchies,
182176
mappedSuperclasses,

hibernate-core/src/main/java/org/hibernate/boot/models/internal/ModelsHelper.java

Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -29,38 +29,38 @@ public static void preFillRegistries(RegistryPrimer.Contributions contributions,
2929

3030
buildingContext.getAnnotationDescriptorRegistry().getDescriptor( TenantId.class );
3131

32-
if ( buildingContext instanceof JandexModelBuildingContext ) {
33-
final IndexView jandexIndex = buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex();
34-
if ( jandexIndex == null ) {
35-
return;
36-
}
37-
38-
final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
39-
final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
40-
41-
for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
42-
final String className = knownClass.name().toString();
43-
44-
if ( knownClass.isAnnotation() ) {
45-
// it is always safe to load the annotation classes - we will never be enhancing them
46-
//noinspection rawtypes
47-
final Class annotationClass = buildingContext
48-
.getClassLoading()
49-
.classForName( className );
50-
//noinspection unchecked
51-
annotationDescriptorRegistry.resolveDescriptor(
52-
annotationClass,
53-
(t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
54-
);
55-
}
56-
57-
resolveClassDetails(
58-
className,
59-
classDetailsRegistry,
60-
() -> new JandexClassDetails( knownClass, buildingContext )
61-
);
62-
}
63-
}
32+
// if ( buildingContext instanceof JandexModelBuildingContext ) {
33+
// final IndexView jandexIndex = buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex();
34+
// if ( jandexIndex == null ) {
35+
// return;
36+
// }
37+
//
38+
// final ClassDetailsRegistry classDetailsRegistry = buildingContext.getClassDetailsRegistry();
39+
// final AnnotationDescriptorRegistry annotationDescriptorRegistry = buildingContext.getAnnotationDescriptorRegistry();
40+
//
41+
// for ( ClassInfo knownClass : jandexIndex.getKnownClasses() ) {
42+
// final String className = knownClass.name().toString();
43+
//
44+
// if ( knownClass.isAnnotation() ) {
45+
// // it is always safe to load the annotation classes - we will never be enhancing them
46+
// //noinspection rawtypes
47+
// final Class annotationClass = buildingContext
48+
// .getClassLoading()
49+
// .classForName( className );
50+
// //noinspection unchecked
51+
// annotationDescriptorRegistry.resolveDescriptor(
52+
// annotationClass,
53+
// (t) -> JdkBuilders.buildAnnotationDescriptor( annotationClass, buildingContext )
54+
// );
55+
// }
56+
//
57+
// resolveClassDetails(
58+
// className,
59+
// classDetailsRegistry,
60+
// () -> new JandexClassDetails( knownClass, buildingContext )
61+
// );
62+
// }
63+
// }
6464
}
6565

6666
public static ClassDetails resolveClassDetails(

0 commit comments

Comments
 (0)