Skip to content

Commit a1b303b

Browse files
DavideDSanne
authored andcommitted
[#1686] Simplify examples
1 parent 192d705 commit a1b303b

File tree

2 files changed

+86
-117
lines changed

2 files changed

+86
-117
lines changed
Lines changed: 42 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
// Optional: We configure the repositories to ease development and CI builds
2+
buildscript {
3+
repositories {
4+
// Optional: Enables the maven local repository
5+
// Example: ./gradlew build -PenableMavenLocalRepo
6+
if ( project.hasProperty( 'enableMavenLocalRepo' ) ) {
7+
// Useful for local development, it should be disabled otherwise
8+
mavenLocal()
9+
}
10+
mavenCentral()
11+
}
12+
}
13+
14+
plugins {
15+
// Optional: Hibernate Gradle plugin to enable bytecode enhancements
16+
id "org.hibernate.orm" version "${hibernateOrmGradlePluginVersion}"
17+
}
18+
119
description = 'Hibernate Reactive native SQL Example'
220

321
dependencies {
4-
implementation project(':hibernate-reactive-core')
22+
implementation project( ':hibernate-reactive-core' )
523

624
// Hibernate Validator (optional)
725
implementation 'org.hibernate.validator:hibernate-validator:7.0.2.Final'
@@ -20,66 +38,35 @@ dependencies {
2038
runtimeOnly 'com.ongres.scram:client:2.1'
2139
}
2240

23-
// All of the remaining configuration is only necessary to enable
24-
// the Hibernate bytecode enhancer and field-level lazy fetching.
25-
// (This is very optional!)
41+
// Optional: enable the bytecode enhancements
42+
hibernate { enhancement }
2643

27-
buildscript {
28-
repositories {
29-
// Example: ./gradlew build -PenableMavenLocalRepo
30-
if ( project.hasProperty( 'enableMavenLocalRepo' ) ) {
31-
// Useful for local development, it should be disabled otherwise
32-
mavenLocal()
33-
}
34-
maven {
35-
url 'https://plugins.gradle.org/m2/'
36-
}
37-
mavenCentral()
38-
}
39-
dependencies {
40-
classpath "org.hibernate.orm:hibernate-gradle-plugin:${hibernateOrmGradlePluginVersion}"
41-
}
42-
}
43-
44-
// Hibernate Gradle plugin to enable bytecode enhancements
45-
apply plugin: 'org.hibernate.orm'
46-
47-
hibernate {
48-
enhancement {
49-
lazyInitialization(true)
50-
dirtyTracking(true)
51-
associationManagement(false)
52-
}
53-
}
54-
55-
// The following rules define a task to run
56-
// the different API available.
44+
// Create tasks to run the different API available.
5745
//
58-
// They require the selected db ready
59-
// to accept connections.
46+
// They require the selected db ready to accept connections.
6047
//
61-
// Examples:
62-
// gradle runExampleMySQLMain runExamplePostgreSQLMutinyMain
63-
def mainClasses = ['Main', 'MutinyMain']
48+
// Examples, in the native-sql-example folder:
49+
// gradle runExampleOnPostgreSQLMain runExampleOnPostgreSQLMutinyMain
50+
def mainJavaClasses = ['Main', 'MutinyMain']
6451
def dbs = ['PostgreSQL']
65-
66-
dbs.each { db ->
67-
tasks.addRule( "Pattern runExampleOn${db}<mainClass>" ) { String taskName ->
68-
if ( taskName.startsWith( "runExampleOn${db}" ) ) {
69-
task( type: JavaExec, taskName ) {
70-
def mainClass = taskName.substring( "runExampleOn${db}".length() )
71-
group = "Execution"
72-
description = "Run ${mainClass} on ${db}"
73-
classpath = sourceSets.main.runtimeClasspath
74-
main = "org.hibernate.reactive.example.nativesql.${mainClass}"
75-
// The persistence unit name defined in resources/META-INF/persistence.xml
76-
args db.toLowerCase() + '-example'
77-
}
52+
mainJavaClasses.each { String mainJavaClass ->
53+
dbs.each { String db ->
54+
tasks.register( "runExampleOn${db}${mainJavaClass}", JavaExec ) {
55+
description = "Run ${mainJavaClass} on ${db}"
56+
classpath = sourceSets.main.runtimeClasspath
57+
mainClass = "org.hibernate.reactive.example.nativesql.${mainJavaClass}"
58+
// The persistence unit name defined in resources/META-INF/persistence.xml
59+
args db.toLowerCase() + '-example'
7860
}
7961
}
8062
}
8163

82-
task runAllExamplesOnPostgreSQL(
83-
dependsOn: mainClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnPostgreSQL${mainClass}" } ) {
84-
description = "Run ${mainClasses} on PostgreSQL"
64+
tasks.register( "runAllExamplesOnPostgreSQL" ) {
65+
dependsOn = mainJavaClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnPostgreSQL${mainClass}" }
66+
description = "Run ${mainJavaClasses} on PostgreSQL"
67+
}
68+
69+
tasks.register( "runAllExamples" ) {
70+
dependsOn = ["runAllExamplesOnPostgreSQL"]
71+
description = "Run all examples on ${dbs}"
8572
}

examples/session-example/build.gradle

Lines changed: 44 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1-
description = 'Hibernate Reactive Session Example'
1+
// Optional: We configure the repositories to ease development and CI builds
2+
buildscript {
3+
repositories {
4+
// Optional: Enables the maven local repository
5+
// Example: ./gradlew build -PenableMavenLocalRepo
6+
if ( project.hasProperty( 'enableMavenLocalRepo' ) ) {
7+
// Useful for local development, it should be disabled otherwise
8+
mavenLocal()
9+
}
10+
mavenCentral()
11+
}
12+
}
13+
14+
plugins {
15+
// Optional: Hibernate Gradle plugin to enable bytecode enhancements
16+
id "org.hibernate.orm" version "${hibernateOrmGradlePluginVersion}"
17+
}
18+
19+
description = 'Hibernate Reactive Session Examples'
220

321
dependencies {
4-
implementation project(':hibernate-reactive-core')
22+
implementation project( ':hibernate-reactive-core' )
523

624
// Hibernate Validator (optional)
725
implementation 'org.hibernate.validator:hibernate-validator:7.0.2.Final'
@@ -21,76 +39,40 @@ dependencies {
2139
runtimeOnly 'com.ongres.scram:client:2.1'
2240
}
2341

24-
// All of the remaining configuration is only necessary to enable
25-
// the Hibernate bytecode enhancer and field-level lazy fetching.
26-
// (This is very optional!)
27-
28-
buildscript {
29-
repositories {
30-
// Example: ./gradlew build -PenableMavenLocalRepo
31-
if ( project.hasProperty( 'enableMavenLocalRepo' ) ) {
32-
// Useful for local development, it should be disabled otherwise
33-
mavenLocal()
34-
}
35-
maven {
36-
url 'https://plugins.gradle.org/m2/'
37-
}
38-
mavenCentral()
39-
}
40-
dependencies {
41-
classpath "org.hibernate.orm:hibernate-gradle-plugin:${hibernateOrmGradlePluginVersion}"
42-
}
43-
}
44-
45-
46-
// Hibernate Gradle plugin to enable bytecode enhancements
47-
apply plugin: 'org.hibernate.orm'
42+
// Optional: enable the bytecode enhancements
43+
hibernate { enhancement }
4844

49-
hibernate {
50-
enhancement {
51-
lazyInitialization(true)
52-
dirtyTracking(true)
53-
associationManagement(false)
54-
}
55-
}
56-
57-
// The following rules define a task to run
58-
// the different API available.
45+
// Create tasks to run the different API available.
5946
//
60-
// They require the selected db ready
61-
// to accept connections.
47+
// They require the selected db ready to accept connections.
6248
//
63-
// Examples:
64-
// gradle runExampleMySQLMain runExamplePostgreSQLMutinyMain
65-
def mainClasses = ['Main', 'MutinyMain']
49+
// Examples, in the session-example folder:
50+
// gradle runExampleOnMySQLMain runExampleOnPostgreSQLMutinyMain
51+
def mainJavaClasses = ['Main', 'MutinyMain']
6652
def dbs = ['PostgreSQL', 'MySQL']
67-
68-
dbs.each { db ->
69-
tasks.addRule( "Pattern runExampleOn${db}<mainClass>" ) { String taskName ->
70-
if ( taskName.startsWith( "runExampleOn${db}" ) ) {
71-
task( type: JavaExec, taskName ) {
72-
def mainClass = taskName.substring( "runExampleOn${db}".length() )
73-
group = "Execution"
74-
description = "Run ${mainClass} on ${db}"
75-
classpath = sourceSets.main.runtimeClasspath
76-
main = "org.hibernate.reactive.example.session.${mainClass}"
77-
// The persistence unit name defined in resources/META-INF/persistence.xml
78-
args db.toLowerCase() + '-example'
79-
}
53+
mainJavaClasses.each { String mainJavaClass ->
54+
dbs.each { String db ->
55+
tasks.register( "runExampleOn${db}${mainJavaClass}", JavaExec ) {
56+
description = "Run ${mainJavaClass} on ${db}"
57+
classpath = sourceSets.main.runtimeClasspath
58+
mainClass = "org.hibernate.reactive.example.session.${mainJavaClass}"
59+
// The persistence unit name defined in resources/META-INF/persistence.xml
60+
args db.toLowerCase() + '-example'
8061
}
8162
}
8263
}
8364

84-
task runAllExamplesOnPostgreSQL(
85-
dependsOn: mainClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnPostgreSQL${mainClass}" } ) {
86-
description = "Run ${mainClasses} on PostgreSQL"
65+
tasks.register( "runAllExamplesOnPostgreSQL" ) {
66+
dependsOn = mainJavaClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnPostgreSQL${mainClass}" }
67+
description = "Run ${mainJavaClasses} on PostgreSQL"
8768
}
8869

89-
task runAllExamplesOnMySQL(
90-
dependsOn: mainClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnMySQL${mainClass}" } ) {
91-
description = "Run ${mainClasses} on MySQL"
70+
tasks.register( "runAllExamplesOnMySQL" ) {
71+
dependsOn = mainJavaClasses.collect( [] as HashSet ) { mainClass -> "runExampleOnMySQL${mainClass}" }
72+
description = "Run ${mainJavaClasses} on MySQL"
9273
}
9374

94-
task runAllExamples( dependsOn: ["runAllExamplesOnPostgreSQL", "runAllExamplesOnMySQL"] ) {
95-
description = "Run examples on ${mainClasses}"
75+
tasks.register( "runAllExamples" ) {
76+
dependsOn = ["runAllExamplesOnPostgreSQL", "runAllExamplesOnMySQL"]
77+
description = "Run all examples on ${dbs}"
9678
}

0 commit comments

Comments
 (0)