18
18
19
19
import org .gradle .api .Action ;
20
20
import org .gradle .api .NamedDomainObjectContainer ;
21
+ import org .gradle .api .NamedDomainObjectSet ;
21
22
import org .gradle .api .Project ;
22
23
import org .gradle .api .Task ;
23
24
import org .gradle .api .artifacts .Configuration ;
35
36
import org .gradle .api .plugins .JavaApplication ;
36
37
import org .gradle .api .plugins .JavaPluginExtension ;
37
38
import org .gradle .api .plugins .jvm .JvmTestSuite ;
39
+ import org .gradle .api .provider .ListProperty ;
38
40
import org .gradle .api .provider .Property ;
39
41
import org .gradle .api .tasks .JavaExec ;
40
42
import org .gradle .api .tasks .SourceSet ;
45
47
import org .gradle .nativeplatform .MachineArchitecture ;
46
48
import org .gradle .nativeplatform .OperatingSystemFamily ;
47
49
import org .gradle .testing .base .TestSuite ;
50
+ import org .gradlex .javamodule .packaging .internal .HostIdentification ;
48
51
import org .gradlex .javamodule .packaging .model .Target ;
49
52
import org .gradlex .javamodule .packaging .tasks .Jpackage ;
50
53
import org .gradlex .javamodule .packaging .tasks .ValidateHostSystemAction ;
63
66
abstract public class JavaModulePackagingExtension {
64
67
private static final Attribute <Boolean > JAVA_MODULE_ATTRIBUTE = Attribute .of ("javaModule" , Boolean .class );
65
68
private static final String INTERNAL = "internal" ;
69
+ private static final String JPACKAGE = "jpackage" ;
66
70
67
71
abstract public Property <String > getApplicationName ();
68
72
abstract public Property <String > getApplicationVersion ();
69
73
abstract public Property <String > getApplicationDescription ();
70
74
abstract public Property <String > getVendor ();
71
75
abstract public Property <String > getCopyright ();
76
+ abstract public ListProperty <String > getJlinkOptions ();
77
+ abstract public ListProperty <String > getAddModules ();
72
78
abstract public DirectoryProperty getJpackageResources ();
73
79
abstract public ConfigurableFileCollection getResources ();
80
+ abstract public Property <Boolean > getVerbose ();
74
81
75
82
private final NamedDomainObjectContainer <Target > targets = getObjects ().domainObjectContainer (Target .class );
76
83
@@ -109,6 +116,16 @@ public Target target(String label, Action<? super Target> action) {
109
116
return target ;
110
117
}
111
118
119
+ /**
120
+ * Configure all targets for the given OS.
121
+ */
122
+ @ SuppressWarnings ("unused" )
123
+ public void targetsWithOs (String operatingSystem , Action <? super Target > action ) {
124
+ NamedDomainObjectSet <Target > matches = targets .matching (t ->
125
+ t .getOperatingSystem ().isPresent () && t .getOperatingSystem ().get ().equals (operatingSystem ));
126
+ matches .all (action );
127
+ }
128
+
112
129
/**
113
130
* Set a 'primary target'. Standard Gradle tasks that are not bound to a specific target – like 'assemble' – use
114
131
* this 'primary target'.
@@ -132,6 +149,7 @@ public Target primaryTarget(Target target) {
132
149
/**
133
150
* Set a test suite to be 'multi-target'. This registers an additional 'test' task for each target.
134
151
*/
152
+ @ SuppressWarnings ({"unused" , "UnstableApiUsage" })
135
153
public TestSuite multiTargetTestSuite (TestSuite testSuite ) {
136
154
if (!(testSuite instanceof JvmTestSuite )) {
137
155
return testSuite ;
@@ -220,7 +238,7 @@ private void registerTargetSpecificTasks(Target target, String applicationJarTas
220
238
JavaPluginExtension java = getProject ().getExtensions ().getByType (JavaPluginExtension .class );
221
239
JavaApplication application = getProject ().getExtensions ().getByType (JavaApplication .class );
222
240
223
- TaskProvider <Jpackage > jpackage = tasks .register ("jpackage" + capitalize (target .getName ()), Jpackage .class , t -> {
241
+ TaskProvider <Jpackage > jpackage = tasks .register (JPACKAGE + capitalize (target .getName ()), Jpackage .class , t -> {
224
242
t .getJavaInstallation ().convention (getJavaToolchains ().compilerFor (java .getToolchain ()).get ().getMetadata ());
225
243
t .getOperatingSystem ().convention (target .getOperatingSystem ());
226
244
t .getArchitecture ().convention (target .getArchitecture ());
@@ -230,14 +248,20 @@ private void registerTargetSpecificTasks(Target target, String applicationJarTas
230
248
t .getModulePath ().from (runtimeClasspath );
231
249
232
250
t .getApplicationName ().convention (getApplicationName ());
233
- t .getJpackageResources ().convention (getJpackageResources ().dir (target .getOperatingSystem ()));
251
+ t .getJpackageResources ().from (getJpackageResources ().dir (target .getOperatingSystem ()));
234
252
t .getApplicationDescription ().convention (getApplicationDescription ());
235
253
t .getVendor ().convention (getVendor ());
236
254
t .getCopyright ().convention (getCopyright ());
237
255
t .getJavaOptions ().convention (application .getApplicationDefaultJvmArgs ());
256
+ t .getJlinkOptions ().convention (getJlinkOptions ());
257
+ t .getAddModules ().convention (getAddModules ());
238
258
t .getOptions ().convention (target .getOptions ());
259
+ t .getAppImageOptions ().convention (target .getAppImageOptions ());
239
260
t .getPackageTypes ().convention (target .getPackageTypes ());
261
+ t .getSingleStepPackaging ().convention (target .getSingleStepPackaging ());
240
262
t .getResources ().from (getResources ());
263
+ t .getTargetResources ().from (target .getTargetResources ());
264
+ t .getVerbose ().convention (getVerbose ());
241
265
242
266
t .getDestination ().convention (getProject ().getLayout ().getBuildDirectory ().dir ("packages/" + target .getName ()));
243
267
t .getTempDirectory ().convention (getProject ().getLayout ().getBuildDirectory ().dir ("tmp/jpackage/" + target .getName ()));
@@ -252,15 +276,25 @@ private void registerTargetSpecificTasks(Target target, String applicationJarTas
252
276
t .setJvmArgs (application .getApplicationDefaultJvmArgs ());
253
277
t .classpath (tasks .named ("jar" ), runtimeClasspath );
254
278
});
279
+ maybeAddJpackageLifecycleTask (tasks , target , jpackage );
280
+ }
255
281
256
- String targetAssembleLifecycle = "assemble" + capitalize (target .getName ());
257
- if (!tasks .getNames ().contains (targetAssembleLifecycle )) {
258
- TaskProvider <Task > lifecycleTask = tasks .register (targetAssembleLifecycle , t -> {
282
+ private void maybeAddJpackageLifecycleTask (TaskContainer tasks , Target target , TaskProvider <Jpackage > targetJpackage ) {
283
+ // if a task already exists, do nothing to avoid conflciting with other plugins
284
+ TaskProvider <Task > jpackage ;
285
+ if (tasks .getNames ().contains (JPACKAGE )) {
286
+ jpackage = tasks .named (JPACKAGE );
287
+ } else {
288
+ jpackage = tasks .register (JPACKAGE , t -> {
259
289
t .setGroup (BUILD_GROUP );
260
- t .setDescription ("Builds this project for " + target . getName () );
290
+ t .setDescription ("Build the package for the current host system" );
261
291
});
262
292
}
263
- tasks .named (targetAssembleLifecycle , t -> t .dependsOn (jpackage ));
293
+ jpackage .configure (t -> {
294
+ if (HostIdentification .isHostTarget (target )) {
295
+ t .dependsOn (targetJpackage );
296
+ }
297
+ });
264
298
}
265
299
266
300
private Configuration maybeCreateInternalConfiguration () {
0 commit comments