Skip to content

Commit 6302660

Browse files
committed
Handle Surefire/Failsafe environment variables similarly to system properties
1 parent 51bea15 commit 6302660

File tree

3 files changed

+67
-5
lines changed

3 files changed

+67
-5
lines changed

src/main/java/org/hibernate/search/develocity/GoalMetadataProvider.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
*/
99
package org.hibernate.search.develocity;
1010

11+
import java.util.function.Consumer;
12+
1113
import org.hibernate.search.develocity.util.MavenMojoExecutionConfig;
1214
import org.hibernate.search.develocity.util.MavenProperties;
1315

@@ -51,5 +53,10 @@ public MavenMojoExecutionConfig configuration() {
5153
public void buildScanDeduplicatedValue(String key, String value) {
5254
buildScanApi.executeOnce( key + value, ignored -> buildScanApi.value( key, value ) );
5355
}
56+
57+
public void nested(String propertyName, Consumer<? super Context> action) {
58+
metadataContext.nested( propertyName,
59+
nestedMetadataContext -> action.accept( new Context( buildScanApi, nestedMetadataContext ) ) );
60+
}
5461
}
5562
}

src/main/java/org/hibernate/search/develocity/plugins/SurefireConfiguredPlugin.java

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,12 @@
66
import org.hibernate.search.develocity.SimpleConfiguredPlugin;
77
import org.hibernate.search.develocity.util.JavaVersions;
88

9+
import com.gradle.maven.extension.api.cache.MojoMetadataProvider;
10+
911
public class SurefireConfiguredPlugin extends SimpleConfiguredPlugin {
1012

13+
private static final String SUREFIRE_ENVIRONMENT_VARIABLES = "environmentVariables";
14+
1115
@Override
1216
protected String getPluginName() {
1317
return "maven-surefire-plugin";
@@ -26,14 +30,50 @@ protected void configureTest(GoalMetadataProvider.Context context) {
2630
dependsOnConfigurableJavaExecutable( inputs, context, "jvm", isSkipped( context ),
2731
JavaVersions::forJavaExecutable );
2832
} );
33+
34+
configureEnvironmentVariables(context);
35+
}
36+
37+
// Develocity handles environment variables as a big blob by default,
38+
// which won't work if some variables point to absolute paths.
39+
private void configureEnvironmentVariables(GoalMetadataProvider.Context context) {
40+
context.metadata().inputs( inputs -> {
41+
// First, override the property to disable handling of environment variables as a blob.
42+
// NOTE: ignoring with inputs.ignore( "environmentVariables" ) doesn't work for some reason:
43+
// we end up with the goal being marked as "not cacheable"
44+
// because "properties were declared both as input and ignored: [environmentVariables]"
45+
// NOTE: we get the same result with context.nested( "environmentVariables" ),
46+
// which is why we don't use that.
47+
inputs.property( SUREFIRE_ENVIRONMENT_VARIABLES, "IGNORED" );
48+
49+
// Then, try to mimic system properties handling.
50+
for ( Map.Entry<String, String> envVariable : context.configuration()
51+
.getStringMap( SUREFIRE_ENVIRONMENT_VARIABLES ).entrySet() ) {
52+
var key = envVariable.getKey();
53+
var keyForDevelocity = SUREFIRE_ENVIRONMENT_VARIABLES + "." + key;
54+
var value = envVariable.getValue();
55+
if ( value == null ) {
56+
value = "";
57+
}
58+
if ( value.startsWith( context.metadata().getSession().getExecutionRootDirectory() ) ) {
59+
inputs.fileSet( keyForDevelocity, value, fileSet -> {
60+
fileSet.normalizationStrategy(
61+
MojoMetadataProvider.Context.FileSet.NormalizationStrategy.RELATIVE_PATH );
62+
} );
63+
}
64+
else {
65+
inputs.property( keyForDevelocity, value );
66+
}
67+
}
68+
} );
2969
}
3070

3171
protected boolean isSkipped(GoalMetadataProvider.Context context) {
3272
return context.configuration().getBoolean( "skip" )
33-
|| context.properties().getBoolean( "maven.test.skip" )
34-
|| context.configuration().getBoolean( "skipTests" )
35-
|| context.properties().getBoolean( "skipTests" )
36-
|| context.configuration().getBoolean( "skipExec" )
37-
|| context.properties().getBoolean( "maven.test.skip.exec" );
73+
|| context.properties().getBoolean( "maven.test.skip" )
74+
|| context.configuration().getBoolean( "skipTests" )
75+
|| context.properties().getBoolean( "skipTests" )
76+
|| context.configuration().getBoolean( "skipExec" )
77+
|| context.properties().getBoolean( "maven.test.skip.exec" );
3878
}
3979
}

src/main/java/org/hibernate/search/develocity/util/MavenMojoExecutionConfig.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
package org.hibernate.search.develocity.util;
1010

1111
import java.util.ArrayList;
12+
import java.util.LinkedHashMap;
1213
import java.util.List;
14+
import java.util.Map;
1315

1416
import org.hibernate.search.develocity.Log;
1517

@@ -58,6 +60,19 @@ public List<String> getStringList(String key) {
5860
return children;
5961
}
6062

63+
public Map<String, String> getStringMap(String key) {
64+
var configElement = mojoExecution.getConfiguration()
65+
.getChild( key );
66+
if ( configElement == null ) {
67+
return Map.of();
68+
}
69+
Map<String, String> result = new LinkedHashMap<>();
70+
for ( Xpp3Dom configElementChild : configElement.getChildren() ) {
71+
result.put( configElementChild.getName(), configElementChild.getValue() );
72+
}
73+
return result;
74+
}
75+
6176
public String getFailsafeSystemProperty(String key) {
6277
var systemPropertyVariables = mojoExecution.getConfiguration()
6378
.getChild( "systemPropertyVariables" );

0 commit comments

Comments
 (0)