Skip to content

Commit

Permalink
Merge HibernateTypes utils class into ClassNames utils class
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 21, 2024
1 parent dbff4d1 commit 6f818f8
Show file tree
Hide file tree
Showing 7 changed files with 401 additions and 423 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ ReflectiveClassBuildItem registerGeneratorClassesForReflections() {
@BuildStep
ReflectiveClassBuildItem registerJdbcArrayTypesForReflection() {
return ReflectiveClassBuildItem
.builder(HibernateOrmTypes.JDBC_JAVA_TYPES.stream().map(d -> d.toString() + "[]").toArray(String[]::new))
.builder(ClassNames.JDBC_JAVA_TYPES.stream().map(d -> d.toString() + "[]").toArray(String[]::new))
.build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,10 @@ public void preGenAnnotationProxies(List<PersistenceUnitDescriptorBuildItem> per
// but there are plans to make deep changes to XML mapping in ORM (to rely on Jandex directly),
// so let's not waste our time on optimizations that won't be relevant in a few months.
List<String> annotationClassNames = new ArrayList<>();
for (DotName name : HibernateOrmTypes.JPA_MAPPING_ANNOTATIONS) {
for (DotName name : ClassNames.JPA_MAPPING_ANNOTATIONS) {
annotationClassNames.add(name.toString());
}
for (DotName name : HibernateOrmTypes.HIBERNATE_MAPPING_ANNOTATIONS) {
for (DotName name : ClassNames.HIBERNATE_MAPPING_ANNOTATIONS) {
annotationClassNames.add(name.toString());
}
reflective.produce(ReflectiveClassBuildItem.builder(annotationClassNames.toArray(new String[0]))
Expand Down Expand Up @@ -759,7 +759,7 @@ public void registerInjectServiceMethodsForReflection(CombinedIndexBuildItem ind
Set<String> classes = new HashSet<>();

// Built-in service classes; can't rely on Jandex as Hibernate ORM is not indexed by default.
HibernateOrmTypes.ANNOTATED_WITH_INJECT_SERVICE.stream()
ClassNames.ANNOTATED_WITH_INJECT_SERVICE.stream()
.map(DotName::toString)
.forEach(classes::add);

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ public final class JpaJandexScavenger {
public JpaModelBuildItem discoverModelAndRegisterForReflection() throws BuildException {
Collector collector = new Collector();

for (DotName packageAnnotation : HibernateOrmTypes.PACKAGE_ANNOTATIONS) {
for (DotName packageAnnotation : ClassNames.PACKAGE_ANNOTATIONS) {
enlistJPAModelAnnotatedPackages(collector, packageAnnotation);
}
enlistJPAModelClasses(collector, ClassNames.JPA_ENTITY);
Expand All @@ -96,7 +96,7 @@ public JpaModelBuildItem discoverModelAndRegisterForReflection() throws BuildExc
enlistEmbeddedsAndElementCollections(collector);

enlistPotentialCdiBeanClasses(collector, ClassNames.CONVERTER);
for (DotName annotation : HibernateOrmTypes.JPA_LISTENER_ANNOTATIONS) {
for (DotName annotation : ClassNames.JPA_LISTENER_ANNOTATIONS) {
enlistPotentialCdiBeanClasses(collector, annotation);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package io.quarkus.hibernate.orm;
package io.quarkus.hibernate.orm.deployment;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatCode;

import java.io.File;
import java.io.IOException;
Expand Down Expand Up @@ -29,18 +30,18 @@
import org.jboss.jandex.Type;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

import io.quarkus.deployment.index.IndexWrapper;
import io.quarkus.deployment.index.IndexingUtil;
import io.quarkus.deployment.index.PersistentClassIndex;
import io.quarkus.deployment.util.JandexUtil;
import io.quarkus.hibernate.orm.deployment.ClassNames;
import io.quarkus.hibernate.orm.deployment.HibernateOrmTypes;

/**
* Test that hardcoded lists of Hibernate ORM types stay up-to-date.
* Test that class name constants point to actual classes and stay up-to-date.
*/
public class HibernateOrmTypesTest {
public class ClassNamesTest {

private static final DotName RETENTION = DotName.createSimple(Retention.class.getName());
private static final DotName TARGET = DotName.createSimple(Target.class.getName());
Expand All @@ -54,12 +55,23 @@ public static void index() throws IOException {
hibernateIndex = IndexingUtil.indexJar(determineHibernateJarLocation());
}

@ParameterizedTest
@MethodSource("provideConstantsToTest")
void testClassNameRefersToExistingClass(DotName constant) {
assertThatCode(() -> getClass().getClassLoader().loadClass(constant.toString()))
.doesNotThrowAnyException();
}

private static Set<DotName> provideConstantsToTest() {
return ClassNames.CREATED_CONSTANTS;
}

@Test
public void testNoMissingJpaAnnotation() {
Set<DotName> jpaMappingAnnotations = findRuntimeAnnotations(jpaIndex);
jpaMappingAnnotations.removeIf(name -> name.toString().startsWith("jakarta.persistence.metamodel."));

assertThat(HibernateOrmTypes.JPA_MAPPING_ANNOTATIONS)
assertThat(ClassNames.JPA_MAPPING_ANNOTATIONS)
.containsExactlyInAnyOrderElementsOf(jpaMappingAnnotations);
}

Expand All @@ -71,7 +83,7 @@ public void testNoMissingJpaListenerAnnotation() {
.filter(name -> listenerAnnotationNamePattern.matcher(name.toString()).matches())
.collect(Collectors.toSet());

assertThat(HibernateOrmTypes.JPA_LISTENER_ANNOTATIONS)
assertThat(ClassNames.JPA_LISTENER_ANNOTATIONS)
.containsExactlyInAnyOrderElementsOf(jpaMappingAnnotations);
}

Expand All @@ -82,7 +94,7 @@ public void testNoMissingHibernateAnnotation() {
hibernateMappingAnnotations.removeIf(name -> name.toString().contains(".spi."));
ignoreInternalAnnotations(hibernateMappingAnnotations);

assertThat(HibernateOrmTypes.HIBERNATE_MAPPING_ANNOTATIONS)
assertThat(ClassNames.HIBERNATE_MAPPING_ANNOTATIONS)
.containsExactlyInAnyOrderElementsOf(hibernateMappingAnnotations);
}

Expand All @@ -100,7 +112,7 @@ public void testNoMissingPackageLevelAnnotation() {
packageLevelHibernateAnnotations.removeIf(name -> name.toString().contains(".internal."));
ignoreInternalAnnotations(packageLevelHibernateAnnotations);

assertThat(HibernateOrmTypes.PACKAGE_ANNOTATIONS)
assertThat(ClassNames.PACKAGE_ANNOTATIONS)
.containsExactlyInAnyOrderElementsOf(packageLevelHibernateAnnotations);
}

Expand All @@ -109,7 +121,7 @@ public void testNoMissingInjectServiceAnnotatedClass() {
Set<DotName> injectServiceAnnotatedClasses = findClassesWithMethodsAnnotatedWith(hibernateIndex,
ClassNames.INJECT_SERVICE);

assertThat(HibernateOrmTypes.ANNOTATED_WITH_INJECT_SERVICE)
assertThat(ClassNames.ANNOTATED_WITH_INJECT_SERVICE)
.containsExactlyInAnyOrderElementsOf(injectServiceAnnotatedClasses);
}

Expand All @@ -132,7 +144,7 @@ public void testNoMissingJdbcJavaTypeClass() {
}
}

assertThat(HibernateOrmTypes.JDBC_JAVA_TYPES)
assertThat(ClassNames.JDBC_JAVA_TYPES)
.containsExactlyInAnyOrderElementsOf(jdbcJavaTypeNames);
}

Expand Down

This file was deleted.

0 comments on commit 6f818f8

Please sign in to comment.