48
48
import org .gradle .testing .base .TestSuite ;
49
49
import org .gradlex .javamodule .packaging .model .Target ;
50
50
import org .gradlex .javamodule .packaging .tasks .Jpackage ;
51
+ import org .gradlex .javamodule .packaging .tasks .ValidateHostSystemAction ;
51
52
52
53
import javax .inject .Inject ;
53
54
import java .util .Arrays ;
@@ -86,10 +87,19 @@ abstract public class JavaModulePackagingExtension {
86
87
abstract protected Project getProject ();
87
88
88
89
90
+ /**
91
+ * Retrieve the target with the given 'label'. If the target does not yet exist, it will be created.
92
+ */
93
+ @ SuppressWarnings ("unused" )
89
94
public Target target (String label ) {
90
95
return target (label , target -> {});
91
96
}
92
97
98
+ /**
99
+ * Register or update a target with the given 'label'. The 'label' uniquely identifies the target.
100
+ * It is used for task names and can be chosen freely.
101
+ * Details of the target are configured in the {@link Target} configuration action.
102
+ */
93
103
public Target target (String label , Action <? super Target > action ) {
94
104
Target target ;
95
105
if (targets .getNames ().contains (label )) {
@@ -102,6 +112,11 @@ public Target target(String label, Action<? super Target> action) {
102
112
return target ;
103
113
}
104
114
115
+ /**
116
+ * Set a 'primary target'. Standard Gradle tasks that are not bound to a specific target – like 'assemble' – use
117
+ * this 'primary target'.
118
+ */
119
+ @ SuppressWarnings ("unused" )
105
120
public Target primaryTarget (Target target ) {
106
121
SourceSetContainer sourceSets = getProject ().getExtensions ().getByType (SourceSetContainer .class );
107
122
ConfigurationContainer configurations = getProject ().getConfigurations ();
@@ -117,22 +132,25 @@ public Target primaryTarget(Target target) {
117
132
return target ;
118
133
}
119
134
135
+ /**
136
+ * Set a test suite to be 'multi-target'. This registers an additional 'test' task for each target.
137
+ */
120
138
public TestSuite multiTargetTestSuite (TestSuite testSuite ) {
121
139
if (!(testSuite instanceof JvmTestSuite )) {
122
140
return testSuite ;
123
141
}
124
142
125
143
JvmTestSuite suite = (JvmTestSuite ) testSuite ;
126
- targets .all (target -> {
127
- suite . getTargets ().register ( testSuite . getName () + capitalize ( target .getName ()), testTarget -> {
128
- testTarget . getTestTask ().configure ( task -> {
129
- ConfigurationContainer configurations = getProject (). getConfigurations ();
130
- task . setClasspath ( configurations . getByName ( target . getName () + capitalize ( suite . getSources (). getRuntimeClasspathConfigurationName ())). plus (
131
- getObjects (). fileCollection (). from ( getProject (). getTasks (). named (suite .getSources ().getJarTaskName ())))
132
- );
133
- } );
134
- } );
135
- });
144
+ targets .all (target -> suite . getTargets (). register ( testSuite . getName () + capitalize ( target . getName ()), testTarget -> testTarget . getTestTask (). configure ( task -> {
145
+ task . getInputs ().property ( "operatingSystem" , target .getOperatingSystem ());
146
+ task . getInputs ().property ( "architecture" , target . getArchitecture ());
147
+
148
+ ConfigurationContainer configurations = getProject (). getConfigurations ();
149
+ task . setClasspath ( configurations . getByName ( target . getName () + capitalize (suite .getSources ().getRuntimeClasspathConfigurationName ())). plus (
150
+ getObjects (). fileCollection (). from ( getProject (). getTasks (). named ( suite . getSources (). getJarTaskName ())))
151
+ );
152
+ task . doFirst ( new ValidateHostSystemAction () );
153
+ }))) ;
136
154
137
155
return testSuite ;
138
156
}
0 commit comments