|
| 1 | +plugins { |
| 2 | + id "hr-java-library" |
| 3 | + id "hr-test-containers" |
| 4 | + id "hr-print-resolved-version" |
| 5 | +} |
| 6 | + |
1 | 7 | ext { |
2 | | - mavenPomName = 'Hibernate Reactive Core' |
| 8 | + mavenPomName = 'Hibernate Reactive Core' |
3 | 9 | } |
4 | 10 |
|
5 | 11 | description = 'The core module of Hibernate Reactive' |
@@ -90,113 +96,3 @@ tasks.withType(AbstractArchiveTask).configureEach { |
90 | 96 | preserveFileTimestamps = false |
91 | 97 | reproducibleFileOrder = true |
92 | 98 | } |
93 | | - |
94 | | -// Print a summary of the results of the tests (number of failures, successes and skipped) |
95 | | -def loggingSummary(db, result, desc) { |
96 | | - if ( !desc.parent ) { // will match the outermost suite |
97 | | - def output = "${db} results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} passed, ${result.failedTestCount} failed, ${result.skippedTestCount} skipped)" |
98 | | - def repeatLength = output.length() + 1 |
99 | | - logger.lifecycle '\n' + ('-' * repeatLength) + '\n' + output + '\n' + ('-' * repeatLength) |
100 | | - } |
101 | | -} |
102 | | - |
103 | | -// Example: |
104 | | -// gradle test -Pdb=MySQL |
105 | | -test { |
106 | | - def selectedDb = project.hasProperty( 'db' ) |
107 | | - ? project.properties['db'] |
108 | | - : 'PostgreSQL' |
109 | | - doFirst { |
110 | | - systemProperty 'db', selectedDb |
111 | | - } |
112 | | - afterSuite { desc, result -> |
113 | | - loggingSummary( selectedDb, result, desc ) |
114 | | - } |
115 | | -} |
116 | | - |
117 | | -// Configuration for the tests |
118 | | -tasks.withType( Test ).configureEach { |
119 | | - defaultCharacterEncoding = "UTF-8" |
120 | | - useJUnitPlatform() |
121 | | - testLogging { |
122 | | - showStandardStreams = project.hasProperty('showStandardOutput') |
123 | | - showStackTraces = true |
124 | | - exceptionFormat = 'full' |
125 | | - displayGranularity = 1 |
126 | | - events = ['PASSED', 'FAILED', 'SKIPPED'] |
127 | | - } |
128 | | - systemProperty 'docker', project.hasProperty( 'docker' ) ? 'true' : 'false' |
129 | | - systemProperty 'org.hibernate.reactive.common.InternalStateAssertions.ENFORCE', 'true' |
130 | | - |
131 | | - if ( project.hasProperty( 'includeTests' ) ) { |
132 | | - // Example: ./gradlew testAll -PincludeTests=DefaultPortTest |
133 | | - filter { |
134 | | - includeTestsMatching project.properties['includeTests'] ?: '*' as String |
135 | | - } |
136 | | - } |
137 | | -} |
138 | | - |
139 | | -def createTestDbTask(dbName) { |
140 | | - tasks.register( "testDb${dbName}", Test ) { |
141 | | - description = "Run tests for ${dbName}" |
142 | | - |
143 | | - doFirst() { |
144 | | - systemProperty 'db', dbName |
145 | | - } |
146 | | - afterSuite { desc, result -> |
147 | | - loggingSummary( dbName, result, desc ) |
148 | | - } |
149 | | - } |
150 | | -} |
151 | | - |
152 | | -// Rule to recognize calls to testDb<dbName> |
153 | | -// and run the tests on the selected db |
154 | | -// Example: |
155 | | -// gradle testDbMySQL testDbDB2 |
156 | | -tasks.addRule( "Pattern testDb<id>" ) { String taskName -> |
157 | | - if ( taskName.startsWith( "testDb" ) ) { |
158 | | - def dbName = taskName.substring( "testDb".length() ) |
159 | | - createTestDbTask( dbName ) |
160 | | - } |
161 | | -} |
162 | | - |
163 | | -// The dbs we want to test when running testAll |
164 | | -def dbs = ['MariaDB', 'MySQL', 'PostgreSQL', 'DB2', 'CockroachDB', 'MSSQLServer', 'Oracle'] |
165 | | -dbs.forEach { createTestDbTask it } |
166 | | - |
167 | | -tasks.register( "testAll", Test ) { |
168 | | - description = "Run tests for ${dbs}" |
169 | | - dependsOn = dbs.collect( [] as HashSet ) { db -> "testDb${db}" } |
170 | | -} |
171 | | - |
172 | | -// Task to print the resolved versions of Hibernate ORM and Vert.x |
173 | | -tasks.register( "printResolvedVersions" ) { |
174 | | - description = "Print the resolved hibernate-orm-core and vert.x versions" |
175 | | - doLast { |
176 | | - def hibernateCoreVersion = "n/a" |
177 | | - def vertxVersion = "n/a" |
178 | | - |
179 | | - // Resolve Hibernate Core and Vert.x versions from compile classpath |
180 | | - configurations.compileClasspath.resolvedConfiguration.resolvedArtifacts.each { artifact -> |
181 | | - if (artifact.moduleVersion.id.name == 'hibernate-core') { |
182 | | - hibernateCoreVersion = artifact.moduleVersion.id.version |
183 | | - } |
184 | | - if (artifact.moduleVersion.id.group == 'io.vertx' && artifact.moduleVersion.id.name == 'vertx-sql-client') { |
185 | | - vertxVersion = artifact.moduleVersion.id.version |
186 | | - } |
187 | | - } |
188 | | - |
189 | | - // Print the resolved versions |
190 | | - println "Resolved Hibernate ORM Core Version: ${hibernateCoreVersion}" |
191 | | - println "Resolved Vert.x SQL client Version: ${vertxVersion}" |
192 | | - } |
193 | | -} |
194 | | - |
195 | | -// Make the version printing task run before tests and JavaExec tasks |
196 | | -tasks.withType( Test ).configureEach { |
197 | | - dependsOn printResolvedVersions |
198 | | -} |
199 | | - |
200 | | -tasks.withType( JavaExec ).configureEach { |
201 | | - dependsOn printResolvedVersions |
202 | | -} |
0 commit comments