66import org .hibernate .search .develocity .SimpleConfiguredPlugin ;
77import org .hibernate .search .develocity .util .JavaVersions ;
88
9+ import com .gradle .maven .extension .api .cache .MojoMetadataProvider ;
10+
911public 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}
0 commit comments