HHH-18633 Split Jandex-based scanning into new module/artifact

This commit is contained in:
Andrea Boriero 2024-09-24 12:00:11 +02:00 committed by Steve Ebersole
parent 5280e15ba0
commit de6aa69fb0
26 changed files with 138 additions and 43 deletions

View File

@ -28,8 +28,6 @@ dependencies {
api jakartaLibs.jta
implementation libs.hibernateModels
implementation libs.hibernateModelsJandex
implementation libs.jandex
implementation libs.classmate
implementation libs.byteBuddy
@ -50,8 +48,12 @@ dependencies {
// annotationProcessor project( ":annotation-descriptor-generator" )
compileOnly project( ":annotation-descriptor-generator" )
runtimeOnly project(':hibernate-scan-jandex')
testImplementation project(':hibernate-testing')
testImplementation project(':hibernate-ant')
testImplementation project(':hibernate-scan-jandex')
testImplementation testLibs.shrinkwrapApi
testImplementation testLibs.shrinkwrap
testImplementation testLibs.shrinkwrapDescriptors
@ -71,6 +73,7 @@ dependencies {
testRuntimeOnly libs.byteBuddy
testRuntimeOnly testLibs.weld
testRuntimeOnly testLibs.wildFlyTxnClient
testImplementation libs.jandex
testImplementation jakartaLibs.jsonb
testImplementation libs.jackson
testRuntimeOnly libs.jacksonXml

View File

@ -5,7 +5,11 @@
package org.hibernate.boot.archive.scan.internal;
import java.util.Collections;
import java.util.Set;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
@ -19,11 +23,22 @@ import org.hibernate.boot.archive.scan.spi.Scanner;
* @author Petteri Pitkanen
*/
public class DisabledScanner implements Scanner {
private static final ScanResult emptyScanResult = new ScanResultImpl(
Collections.emptySet(),
Collections.emptySet(),
Collections.emptySet()
);
private static final ScanResult emptyScanResult = new ScanResult() {
@Override
public Set<PackageDescriptor> getLocatedPackages() {
return Collections.emptySet();
}
@Override
public Set<ClassDescriptor> getLocatedClasses() {
return Collections.emptySet();
}
@Override
public Set<MappingFileDescriptor> getLocatedMappingFiles() {
return Collections.emptySet();
}
};
@Override
public ScanResult scan(final ScanEnvironment environment, final ScanOptions options, final ScanParameters parameters) {

View File

@ -4,6 +4,8 @@
*/
package org.hibernate.boot.archive.scan.spi;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
/**
* Defines the contract for Hibernate to be able to scan for classes, packages and resources inside a
* persistence unit.
@ -29,4 +31,8 @@ public interface Scanner {
* @param params The parameters for scanning
*/
ScanResult scan(ScanEnvironment environment, ScanOptions options, ScanParameters params);
default void setArchiveDescriptorFactory(ArchiveDescriptorFactory archiveDescriptorFactory){
throw new UnsupportedOperationException();
}
}

View File

@ -0,0 +1,12 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.service.Service;
public interface ScannerFactory extends Service {
Scanner getScanner(ArchiveDescriptorFactory archiveDescriptorFactory);
}

View File

@ -8,20 +8,22 @@ import java.lang.reflect.Constructor;
import java.net.URL;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;
import org.hibernate.boot.MappingException;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.internal.UrlInputStreamAccess;
import org.hibernate.boot.archive.scan.internal.DisabledScanner;
import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.archive.scan.spi.ScannerFactory;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
import org.hibernate.boot.internal.ClassLoaderAccessImpl;
import org.hibernate.boot.jaxb.Origin;
@ -86,11 +88,18 @@ public class ScanningCoordinator {
if ( scannerSetting == null ) {
// No custom Scanner specified, use the StandardScanner
if ( archiveDescriptorFactory == null ) {
return new StandardScanner();
final Iterator<ScannerFactory> iterator = bootstrapContext.getServiceRegistry()
.requireService( ClassLoaderService.class )
.loadJavaServices( ScannerFactory.class )
.iterator();
if ( iterator.hasNext() ) {
// todo: check for multiple scanner and in case raise a warning?
final ScannerFactory factory = iterator.next();
return factory.getScanner( archiveDescriptorFactory );
}
else {
return new StandardScanner( archiveDescriptorFactory );
// todo: add a debug message that there is no Scanner?
return new DisabledScanner();
}
}
else {

View File

@ -4,7 +4,7 @@
*/
package org.hibernate.orm.test.bootstrap.scanning;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;

View File

@ -16,17 +16,17 @@ import java.net.URLStreamHandlerFactory;
import java.util.Collections;
import java.util.List;
import org.hibernate.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.archive.scan.internal.ScanResultCollector;
import org.hibernate.archive.scan.internal.StandardScanner;
import org.hibernate.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.boot.archive.internal.ArchiveHelper;
import org.hibernate.boot.archive.internal.ExplodedArchiveDescriptor;
import org.hibernate.boot.archive.internal.JarFileBasedArchiveDescriptor;
import org.hibernate.boot.archive.internal.JarProtocolArchiveDescriptor;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultCollector;
import org.hibernate.boot.archive.scan.internal.StandardScanOptions;
import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;

View File

@ -14,9 +14,9 @@ import java.util.Map;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import org.hibernate.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.internal.StandardScanOptions;
import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;

View File

@ -9,13 +9,13 @@ import java.net.URL;
import java.util.Arrays;
import java.util.Collections;
import org.hibernate.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.DisabledScanner;
import org.hibernate.archive.scan.internal.MappingFileDescriptorImpl;
import org.hibernate.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.MetadataSources;
import org.hibernate.boot.archive.internal.ByteArrayInputStreamAccess;
import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.DisabledScanner;
import org.hibernate.boot.archive.scan.internal.MappingFileDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultImpl;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.MappingFileDescriptor;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;

View File

@ -17,6 +17,7 @@ java.modularity.inferModulePath = true
dependencies {
api project( ':hibernate-core' )
api project( ':hibernate-envers' )
implementation project( ':hibernate-scan-jandex' )
//Provide the jakarta.cdi module, as it's required by module jakarta.transaction
//but not provided as transitive dependency of Narayana.
testRuntimeOnly( jakartaLibs.cdi )

View File

@ -10,7 +10,7 @@ import java.util.Set;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.scan.internal.StandardScanOptions;
import org.hibernate.boot.archive.scan.internal.StandardScanParameters;
import org.hibernate.boot.archive.scan.internal.StandardScanner;
import org.hibernate.archive.scan.internal.StandardScanner;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.orm.integrationtest.java.module.test.entity.Author;

View File

@ -0,0 +1,18 @@
description = 'Integrate support for Jandex into Hibernate O/RM'
apply from: rootProject.file( 'gradle/published-java-module.gradle' )
dependencies {
api project( ':hibernate-core' )
api jakartaLibs.jpa
implementation libs.jandex
testImplementation project( ':hibernate-testing' )
}
sourceSets.test.resources {
setSrcDirs( ['src/test/resources'] )
}

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import java.io.Serializable;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import java.io.Serializable;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveEntry;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import java.io.Serializable;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import java.util.Collections;
import java.util.HashSet;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import java.io.Serializable;
import java.util.Set;

View File

@ -2,10 +2,10 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.internal;
package org.hibernate.archive.scan.internal;
import org.hibernate.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.boot.archive.internal.StandardArchiveDescriptorFactory;
import org.hibernate.boot.archive.scan.spi.AbstractScannerImpl;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
/**

View File

@ -0,0 +1,19 @@
/*
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.archive.scan.internal;
import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.archive.scan.spi.ScannerFactory;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;
public class StandardScannerFactory implements ScannerFactory {
@Override
public Scanner getScanner(ArchiveDescriptorFactory archiveDescriptorFactory) {
if ( archiveDescriptorFactory == null ) {
return new StandardScanner();
}
return new StandardScanner( archiveDescriptorFactory );
}
}

View File

@ -2,14 +2,19 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;
package org.hibernate.archive.scan.spi;
import java.net.URL;
import java.util.HashMap;
import java.util.Map;
import org.hibernate.boot.archive.scan.internal.NoopEntryHandler;
import org.hibernate.boot.archive.scan.internal.ScanResultCollector;
import org.hibernate.archive.scan.internal.NoopEntryHandler;
import org.hibernate.archive.scan.internal.ScanResultCollector;
import org.hibernate.boot.archive.scan.spi.ScanEnvironment;
import org.hibernate.boot.archive.scan.spi.ScanOptions;
import org.hibernate.boot.archive.scan.spi.ScanParameters;
import org.hibernate.boot.archive.scan.spi.ScanResult;
import org.hibernate.boot.archive.scan.spi.Scanner;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveDescriptor;
import org.hibernate.boot.archive.spi.ArchiveDescriptorFactory;

View File

@ -2,7 +2,7 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;
package org.hibernate.archive.scan.spi;
import java.io.IOException;
import java.io.InputStream;
@ -11,8 +11,9 @@ import jakarta.persistence.Embeddable;
import jakarta.persistence.Entity;
import jakarta.persistence.MappedSuperclass;
import org.hibernate.boot.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultCollector;
import org.hibernate.archive.scan.internal.ClassDescriptorImpl;
import org.hibernate.archive.scan.internal.ScanResultCollector;
import org.hibernate.boot.archive.scan.spi.ClassDescriptor;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveEntry;
import org.hibernate.boot.archive.spi.ArchiveEntryHandler;

View File

@ -2,10 +2,10 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;
package org.hibernate.archive.scan.spi;
import org.hibernate.boot.archive.scan.internal.MappingFileDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultCollector;
import org.hibernate.archive.scan.internal.MappingFileDescriptorImpl;
import org.hibernate.archive.scan.internal.ScanResultCollector;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveEntry;
import org.hibernate.boot.archive.spi.ArchiveEntryHandler;

View File

@ -2,10 +2,11 @@
* SPDX-License-Identifier: LGPL-2.1-or-later
* Copyright Red Hat Inc. and Hibernate Authors
*/
package org.hibernate.boot.archive.scan.spi;
package org.hibernate.archive.scan.spi;
import org.hibernate.boot.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.boot.archive.scan.internal.ScanResultCollector;
import org.hibernate.archive.scan.internal.PackageDescriptorImpl;
import org.hibernate.archive.scan.internal.ScanResultCollector;
import org.hibernate.boot.archive.scan.spi.PackageDescriptor;
import org.hibernate.boot.archive.spi.ArchiveContext;
import org.hibernate.boot.archive.spi.ArchiveEntry;
import org.hibernate.boot.archive.spi.ArchiveEntryHandler;

View File

@ -0,0 +1 @@
org.hibernate.archive.scan.internal.StandardScannerFactory

View File

@ -347,6 +347,8 @@ if ( "OpenJDK Runtime Environment".equals( System.getProperty( "java.runtime.nam
include 'hibernate-jfr'
}
include 'hibernate-scan-jandex'
include 'metamodel-generator'
project(':metamodel-generator').projectDir = new File(rootProject.projectDir, "tooling/metamodel-generator")
project(':metamodel-generator').name = 'hibernate-processor'
@ -367,3 +369,5 @@ rootProject.children.each { project ->
assert project.buildFile.isFile()
}
include 'hibernate-platform'