11package org .hibernate .search .develocity .plugins ;
22
33import java .util .Map ;
4+ import java .util .regex .Pattern ;
45
56import org .hibernate .search .develocity .GoalMetadataProvider ;
67import org .hibernate .search .develocity .SimpleConfiguredPlugin ;
78import org .hibernate .search .develocity .util .JavaVersions ;
89
10+ import com .gradle .maven .extension .api .cache .MojoMetadataProvider ;
11+
912public class SurefireConfiguredPlugin extends SimpleConfiguredPlugin {
1013
14+ private static final String SUREFIRE_ENVIRONMENT_VARIABLES = "environmentVariables" ;
15+
16+ private static final Pattern TEST_INDEXES_PATTERN = Pattern .compile ( "(^|/)test-indexes($|/)" );
17+
1118 @ Override
1219 protected String getPluginName () {
1320 return "maven-surefire-plugin" ;
@@ -26,14 +33,56 @@ protected void configureTest(GoalMetadataProvider.Context context) {
2633 dependsOnConfigurableJavaExecutable ( inputs , context , "jvm" , isSkipped ( context ),
2734 JavaVersions ::forJavaExecutable );
2835 } );
36+
37+ configureEnvironmentVariables (context );
38+ }
39+
40+ // Develocity handles environment variables as a big blob by default,
41+ // which won't work if some variables point to absolute paths.
42+ private void configureEnvironmentVariables (GoalMetadataProvider .Context context ) {
43+ context .metadata ().inputs ( inputs -> {
44+ // First, override the property to disable handling of environment variables as a blob.
45+ // NOTE: ignoring with inputs.ignore( "environmentVariables" ) doesn't work for some reason:
46+ // we end up with the goal being marked as "not cacheable"
47+ // because "properties were declared both as input and ignored: [environmentVariables]"
48+ // NOTE: we get the same result with context.nested( "environmentVariables" ),
49+ // which is why we don't use that.
50+ inputs .property ( SUREFIRE_ENVIRONMENT_VARIABLES , "IGNORED" );
51+
52+ // Then, try to mimic system properties handling.
53+ for ( Map .Entry <String , String > envVariable : context .configuration ()
54+ .getStringMap ( SUREFIRE_ENVIRONMENT_VARIABLES ).entrySet () ) {
55+ var key = envVariable .getKey ();
56+ var keyForDevelocity = SUREFIRE_ENVIRONMENT_VARIABLES + "." + key ;
57+ var value = envVariable .getValue ();
58+ if ( value == null ) {
59+ value = "" ;
60+ }
61+ if ( value .startsWith ( context .metadata ().getSession ().getExecutionRootDirectory () ) ) {
62+ if ( TEST_INDEXES_PATTERN .matcher ( "test-indexes" ).find () ) {
63+ // Lucene indexes used in tests -- we don't care about these.
64+ inputs .ignore ( keyForDevelocity );
65+ }
66+ else {
67+ inputs .fileSet ( keyForDevelocity , value , fileSet -> {
68+ fileSet .normalizationStrategy (
69+ MojoMetadataProvider .Context .FileSet .NormalizationStrategy .RELATIVE_PATH );
70+ } );
71+ }
72+ }
73+ else {
74+ inputs .property ( keyForDevelocity , value );
75+ }
76+ }
77+ } );
2978 }
3079
3180 protected boolean isSkipped (GoalMetadataProvider .Context context ) {
3281 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" );
82+ || context .properties ().getBoolean ( "maven.test.skip" )
83+ || context .configuration ().getBoolean ( "skipTests" )
84+ || context .properties ().getBoolean ( "skipTests" )
85+ || context .configuration ().getBoolean ( "skipExec" )
86+ || context .properties ().getBoolean ( "maven.test.skip.exec" );
3887 }
3988}
0 commit comments