Skip to content

Commit 4072730

Browse files
committed
#91 - Consider multi-project / multi-jar set up for hibernate-models
#85 - Consider ways to make Jandex not required at runtime
1 parent 9947aa8 commit 4072730

File tree

283 files changed

+2083
-1786
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

283 files changed

+2083
-1786
lines changed

README.adoc

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,11 @@
11
:fn-managed: footnote:[The application's domain and related classes]
22
== Hibernate models
33

4-
Uses a mix of https://smallrye.io/jandex/[Jandex] and Java reflection to build the de-typed abstraction model of
5-
classes and annotations referenced by an application's managed resources{fn-managed}.
4+
Provides support for dealing with an application's managed resources{fn-managed} as a de-typed abstraction model
5+
backed by one or more sources. Consumers can then access details from that abstraction model in a unified way,
6+
regardless of the underlying source.
67

7-
Consumers can then access details from that abstraction model in a unified way, regardless of the underlying
8-
source. For classes which we are able to access from a Jandex index, this has the benefit that the classes are
9-
not loaded into the ClassLoader which is important because once a classes is loaded into a ClassLoader, its
10-
bytecode cannot be changed and run-time bytecode enhancement is not possible.
11-
12-
This work is intended to replace the https://github.com/hibernate/hibernate-commons-annotations[`hibernate-commons-annotation`] (HCANN)
13-
library, which suffered from a number of shortcomings.
8+
NOTE: This work replaces the https://github.com/hibernate/hibernate-commons-annotations[`hibernate-commons-annotation`] library, which suffered from a number of shortcomings.
149

1510

1611
=== Annotations
@@ -37,3 +32,12 @@ FieldDetails:: Think `java.lang.reflect.Field`
3732
MethodDetails:: Think `java.lang.reflect.Method`
3833
RecordComponentDetails:: Think `java.lang.reflect.RecordComponent`
3934
ClassDetailsRegistry:: registry of `ClassDetails` references
35+
36+
37+
=== Artifacts
38+
39+
hibernate-models:: The base support, using Java reflection as the backing source.
40+
hibernate-models-jandex:: Optional support for using https://smallrye.io/jandex/[Jandex] as the backing source. Using
41+
definitions from a Jandex index has the benefit that the classes are not loaded into the ClassLoader which can be important
42+
in a few scenarios (e.g. retain the ability to enhance a class's bytecode).
43+

build.gradle

Lines changed: 14 additions & 109 deletions
Original file line numberDiff line numberDiff line change
@@ -1,118 +1,23 @@
11
plugins {
2-
id "java-library"
3-
4-
id "base-information"
5-
6-
id "checkstyle"
7-
id "jacoco"
8-
9-
id "maven-publish"
10-
id "io.github.gradle-nexus.publish-plugin" version "2.0.0"
11-
id "publishing-config"
12-
id "signing-config"
13-
id "release-process"
2+
id "io.github.gradle-nexus.publish-plugin"
143
}
154

16-
dependencies {
17-
implementation libs.jandex
18-
implementation libs.logging
19-
20-
compileOnly libs.loggingAnnotations
21-
22-
annotationProcessor libs.loggingProcessor
23-
annotationProcessor libs.logging
24-
annotationProcessor libs.loggingAnnotations
25-
26-
testImplementation jakartaLibs.jpa
27-
testImplementation testLibs.junit5Api
28-
testImplementation testLibs.assertjCore
29-
30-
testRuntimeOnly testLibs.junit5Engine
31-
testRuntimeOnly testLibs.log4j
32-
}
33-
34-
355
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
36-
// Java handling
6+
// OSSRH publishing
377
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
388

39-
// To force the build produce the same byte-for-byte archives and hence make Hibernate Models build reproducible.
40-
// See also https://docs.gradle.org/current/userguide/working_with_files.html#sec:reproducible_archives
41-
tasks.withType(AbstractArchiveTask).configureEach {
42-
preserveFileTimestamps = false
43-
reproducibleFileOrder = true
44-
}
45-
46-
java {
47-
sourceCompatibility = jdks.versions.baseline.get() as int
48-
targetCompatibility = jdks.versions.baseline.get() as int
49-
50-
withJavadocJar()
51-
withSourcesJar()
52-
}
53-
54-
test {
55-
useJUnitPlatform()
56-
}
9+
String hibernatePublishUsername = project.hasProperty( 'hibernatePublishUsername' )
10+
? project.property( 'hibernatePublishUsername' )
11+
: null
12+
String hibernatePublishPassword = project.hasProperty( 'hibernatePublishPassword' )
13+
? project.property( 'hibernatePublishPassword' )
14+
: null
5715

58-
// create a single "compile" task
59-
tasks.register( "compile" ).configure {
60-
dependsOn tasks.withType( JavaCompile )
61-
}
62-
63-
tasks.withType( JavaCompile ).configureEach {javaCompile->
64-
options.encoding = "UTF-8"
65-
options.warnings false
66-
}
67-
68-
69-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
70-
// Javadoc
71-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
72-
73-
tasks.named( "javadoc", Javadoc ) {
74-
options {
75-
use = true
76-
encoding = "UTF-8"
77-
78-
addStringOption( "Xdoclint:none", "-quiet" )
79-
80-
tags(
81-
"todo:X",
82-
"apiNote:a:API Note:",
83-
"implSpec:a:Implementation Specification:",
84-
"implNote:a:Implementation Note:"
85-
)
16+
nexusPublishing {
17+
repositories {
18+
sonatype {
19+
username = hibernatePublishUsername
20+
password = hibernatePublishPassword
21+
}
8622
}
8723
}
88-
89-
90-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
91-
// Checkstyle
92-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
93-
94-
checkstyle {
95-
sourceSets = [ project.sourceSets.main ]
96-
showViolations = false
97-
}
98-
99-
100-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
101-
// JaCoCo
102-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
103-
104-
def jacocoReportTask = tasks.named( "jacocoTestReport" ) {
105-
dependsOn tasks.named( "test" )
106-
}
107-
108-
jacocoTestReport {
109-
reports {
110-
xml.required = false
111-
csv.required = false
112-
html.outputLocation = layout.buildDirectory.dir( "jacocoHtml" )
113-
}
114-
}
115-
116-
tasks.named( "check" ) {
117-
dependsOn jacocoReportTask
118-
}

buildSrc/src/main/groovy/base-information.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ group = "org.hibernate.models"
55
// Version handling
66
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
77

8-
def versionFile = project.file( "version.txt" )
8+
def versionFile = rootProject.file( "version.txt" )
99
def releaseVersion = determineVersion("releaseVersion", versionFile )
1010
def developmentVersion = determineVersion("developmentVersion", versionFile)
1111

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
plugins {
2+
id "base-information"
3+
id "java-library"
4+
5+
id "checkstyle"
6+
id "jacoco"
7+
}
8+
9+
dependencies {
10+
implementation libs.logging
11+
12+
compileOnly libs.loggingAnnotations
13+
14+
annotationProcessor libs.loggingProcessor
15+
annotationProcessor libs.logging
16+
annotationProcessor libs.loggingAnnotations
17+
18+
testImplementation jakartaLibs.jpa
19+
testImplementation testLibs.junit5Api
20+
testImplementation testLibs.assertjCore
21+
22+
testRuntimeOnly testLibs.junit5Engine
23+
testRuntimeOnly testLibs.log4j
24+
}
25+
26+
27+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
28+
// Java handling
29+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
30+
31+
java {
32+
sourceCompatibility = jdks.versions.baseline.get() as int
33+
targetCompatibility = jdks.versions.baseline.get() as int
34+
35+
withJavadocJar()
36+
withSourcesJar()
37+
}
38+
39+
test {
40+
useJUnitPlatform()
41+
}
42+
43+
// create a single "compile" task
44+
tasks.register( "compile" ).configure {
45+
dependsOn tasks.withType( JavaCompile )
46+
}
47+
48+
tasks.withType( JavaCompile ).configureEach {javaCompile->
49+
options.encoding = "UTF-8"
50+
options.warnings false
51+
}
52+
53+
54+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
55+
// Javadoc
56+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
57+
58+
tasks.named( "javadoc", Javadoc ) {
59+
options {
60+
use = true
61+
encoding = "UTF-8"
62+
63+
addStringOption( "Xdoclint:none", "-quiet" )
64+
65+
tags(
66+
"todo:X",
67+
"apiNote:a:API Note:",
68+
"implSpec:a:Implementation Specification:",
69+
"implNote:a:Implementation Note:"
70+
)
71+
}
72+
}
73+
74+
75+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
76+
// Checkstyle
77+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
78+
79+
checkstyle {
80+
sourceSets = [ project.sourceSets.main ]
81+
showViolations = false
82+
}
83+
84+
85+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
86+
// JaCoCo
87+
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
88+
89+
def jacocoReportTask = tasks.named( "jacocoTestReport" ) {
90+
dependsOn tasks.named( "test" )
91+
}
92+
93+
jacocoTestReport {
94+
reports {
95+
xml.required = false
96+
csv.required = false
97+
html.outputLocation = layout.buildDirectory.dir( "jacocoHtml" )
98+
}
99+
}
100+
101+
tasks.named( "check" ) {
102+
dependsOn jacocoReportTask
103+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
plugins {
2+
id "java-module"
3+
4+
id "maven-publish"
5+
id "publishing-config"
6+
id "signing-config"
7+
id "release-process"
8+
}

buildSrc/src/main/groovy/publishing-config.gradle

Lines changed: 2 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,8 @@
11
plugins {
2-
id "java-library"
3-
id "io.github.gradle-nexus.publish-plugin"
2+
id "java-module"
3+
id "maven-publish"
44
}
55

6-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
7-
// OSSRH publishing
8-
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
9-
10-
String hibernatePublishUsername = project.hasProperty( 'hibernatePublishUsername' )
11-
? project.property( 'hibernatePublishUsername' )
12-
: null
13-
String hibernatePublishPassword = project.hasProperty( 'hibernatePublishPassword' )
14-
? project.property( 'hibernatePublishPassword' )
15-
: null
166

177
publishing {
188
publications {
@@ -62,12 +52,3 @@ publishing {
6252
}
6353
}
6454

65-
nexusPublishing {
66-
repositories {
67-
sonatype {
68-
username = hibernatePublishUsername
69-
password = hibernatePublishPassword
70-
}
71-
}
72-
}
73-

hibernate-models-jandex/build.gradle

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
plugins {
2+
id "published-java-module"
3+
}
4+
5+
description = "Jandex support for hibernate-models (isolated dependency)"
6+
7+
dependencies {
8+
api project( ":hibernate-models" )
9+
10+
implementation libs.jandex
11+
12+
testImplementation project( ":hibernate-models-testing" )
13+
}

src/main/java/org/hibernate/models/internal/jandex/AbstractAnnotationTarget.java renamed to hibernate-models-jandex/src/main/java/org/hibernate/models/jandex/internal/AbstractAnnotationTarget.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
* SPDX-License-Identifier: Apache-2.0
55
* Copyright: Red Hat Inc. and Hibernate Authors
66
*/
7-
package org.hibernate.models.internal.jandex;
7+
package org.hibernate.models.jandex.internal;
88

99
import java.lang.annotation.Annotation;
1010
import java.util.Map;

src/main/java/org/hibernate/models/internal/jandex/AbstractValueExtractor.java renamed to hibernate-models-jandex/src/main/java/org/hibernate/models/jandex/internal/AbstractValueExtractor.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,11 @@
44
* SPDX-License-Identifier: Apache-2.0
55
* Copyright: Red Hat Inc. and Hibernate Authors
66
*/
7-
package org.hibernate.models.internal.jandex;
7+
package org.hibernate.models.jandex.internal;
88

9+
import org.hibernate.models.jandex.spi.JandexModelBuildingContext;
10+
import org.hibernate.models.jandex.spi.JandexValueExtractor;
911
import org.hibernate.models.spi.SourceModelBuildingContext;
10-
import org.hibernate.models.spi.JandexValueExtractor;
1112

1213
import org.jboss.jandex.AnnotationInstance;
1314
import org.jboss.jandex.AnnotationValue;
@@ -38,6 +39,6 @@ protected AnnotationValue resolveAnnotationValue(
3839
return explicitValue;
3940
}
4041

41-
return annotation.valueWithDefault( buildingContext.getJandexIndex(), attributeName );
42+
return annotation.valueWithDefault( buildingContext.as( JandexModelBuildingContext.class ).getJandexIndex(), attributeName );
4243
}
4344
}

0 commit comments

Comments
 (0)