Skip to content

Commit f0beb01

Browse files
committed
[#2492] perf(test db task local): remove use of groovy closure and explicit get input of properties
Gradle need to know all input and prevent side effect with dynamic behaviors
1 parent bc61bd8 commit f0beb01

File tree

1 file changed

+34
-10
lines changed
  • local-build-plugins/src/main/java/org/hibernate/reactive/env

1 file changed

+34
-10
lines changed

local-build-plugins/src/main/java/org/hibernate/reactive/env/TestDbTask.java

Lines changed: 34 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
11
package org.hibernate.reactive.env;
22

3-
import org.gradle.api.tasks.CacheableTask;
3+
import java.util.HashMap;
4+
import java.util.Map;
5+
46
import org.gradle.api.tasks.Input;
57
import org.gradle.api.tasks.Optional;
68
import org.gradle.api.tasks.testing.Test;
79
import org.gradle.api.tasks.testing.TestDescriptor;
10+
import org.gradle.api.tasks.testing.TestListener;
811
import org.gradle.api.tasks.testing.TestResult;
912

10-
import groovy.lang.Closure;
1113
import org.jetbrains.annotations.NotNull;
1214
import org.jetbrains.annotations.Nullable;
1315

14-
@CacheableTask
1516
public abstract class TestDbTask extends Test {
1617

1718
@NotNull
@@ -61,6 +62,14 @@ public void setShowStandardStreams(boolean showStandardStreams) {
6162
this.showStandardStreams = showStandardStreams;
6263
}
6364

65+
@Input
66+
public Map<String, String> getCustomSystemProperties() {
67+
final Map<String, String> props = new HashMap<>();
68+
props.put("db", dbName);
69+
props.put("docker", dockerEnabled ? "true" : "false");
70+
return props;
71+
}
72+
6473
public TestDbTask() {
6574
// Default logging configuration
6675
setDefaultCharacterEncoding( "UTF-8" );
@@ -75,20 +84,35 @@ public TestDbTask() {
7584
// enforcing Hibernate internal state
7685
systemProperty( "org.hibernate.reactive.common.InternalStateAssertions.ENFORCE", "true" );
7786

78-
// Add afterSuite hook
79-
afterSuite( new Closure<Object>( this, this ) {
80-
public Object doCall(TestDescriptor desc, TestResult result) {
81-
logSummary( desc, result );
82-
return null;
87+
addTestListener( new TestListener() {
88+
89+
@Override
90+
public void beforeSuite(TestDescriptor suite) {
91+
/* Do nothing */
92+
}
93+
94+
// Add afterSuite hook
95+
@Override
96+
public void afterSuite(TestDescriptor suite, TestResult result) {
97+
logSummary( suite, result );
98+
}
99+
100+
@Override
101+
public void beforeTest(TestDescriptor testDescriptor) {
102+
/* Do nothing */
103+
}
104+
105+
@Override
106+
public void afterTest(TestDescriptor testDescriptor, TestResult result) {
107+
/* Do nothing */
83108
}
84109
} );
85110
}
86111

87112
@Override
88113
public void executeTests() {
89114
// Apply system properties before running
90-
systemProperty( "db", dbName );
91-
systemProperty( "docker", dockerEnabled ? "true" : "false" );
115+
getCustomSystemProperties().forEach(this::systemProperty);
92116
getTestLogging().setShowStandardStreams( showStandardStreams );
93117

94118
if ( includeTests != null && !includeTests.isEmpty() ) {

0 commit comments

Comments
 (0)