-
Notifications
You must be signed in to change notification settings - Fork 13
/
JPackageTask.java
1100 lines (922 loc) · 34.4 KB
/
JPackageTask.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
Copyright © 2021-2023 Petr Panteleyev <[email protected]>
SPDX-License-Identifier: BSD-2-Clause
*/
package org.panteleyev.jpackage;
import org.gradle.api.DefaultTask;
import org.gradle.api.GradleException;
import org.gradle.api.plugins.JavaPluginExtension;
import org.gradle.api.provider.Provider;
import org.gradle.api.tasks.Input;
import org.gradle.api.tasks.TaskAction;
import org.gradle.jvm.toolchain.JavaLauncher;
import org.gradle.jvm.toolchain.JavaToolchainService;
import org.gradle.jvm.toolchain.JavaToolchainSpec;
import java.io.BufferedReader;
import java.io.File;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import static org.panteleyev.jpackage.CommandLineParameter.ABOUT_URL;
import static org.panteleyev.jpackage.CommandLineParameter.ADD_LAUNCHER;
import static org.panteleyev.jpackage.CommandLineParameter.ADD_MODULES;
import static org.panteleyev.jpackage.CommandLineParameter.APP_CONTENT;
import static org.panteleyev.jpackage.CommandLineParameter.APP_IMAGE;
import static org.panteleyev.jpackage.CommandLineParameter.APP_VERSION;
import static org.panteleyev.jpackage.CommandLineParameter.ARGUMENTS;
import static org.panteleyev.jpackage.CommandLineParameter.BIND_SERVICES;
import static org.panteleyev.jpackage.CommandLineParameter.COPYRIGHT;
import static org.panteleyev.jpackage.CommandLineParameter.DESCRIPTION;
import static org.panteleyev.jpackage.CommandLineParameter.DESTINATION;
import static org.panteleyev.jpackage.CommandLineParameter.FILE_ASSOCIATIONS;
import static org.panteleyev.jpackage.CommandLineParameter.ICON;
import static org.panteleyev.jpackage.CommandLineParameter.INPUT;
import static org.panteleyev.jpackage.CommandLineParameter.INSTALL_DIR;
import static org.panteleyev.jpackage.CommandLineParameter.JAVA_OPTIONS;
import static org.panteleyev.jpackage.CommandLineParameter.JLINK_OPTIONS;
import static org.panteleyev.jpackage.CommandLineParameter.LAUNCHER_AS_SERVICE;
import static org.panteleyev.jpackage.CommandLineParameter.LICENSE_FILE;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_APP_CATEGORY;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_APP_RELEASE;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_DEB_MAINTAINER;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_MENU_GROUP;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_PACKAGE_DEPS;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_PACKAGE_NAME;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_RPM_LICENSE_TYPE;
import static org.panteleyev.jpackage.CommandLineParameter.LINUX_SHORTCUT;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_APP_CATEGORY;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_APP_STORE;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_BUNDLE_SIGNING_PREFIX;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_DMG_CONTENT;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_ENTITLEMENTS;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_PACKAGE_IDENTIFIER;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_PACKAGE_NAME;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_PACKAGE_SIGNING_PREFIX;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_SIGN;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_SIGNING_KEYCHAIN;
import static org.panteleyev.jpackage.CommandLineParameter.MAC_SIGNING_KEY_USER_NAME;
import static org.panteleyev.jpackage.CommandLineParameter.MAIN_CLASS;
import static org.panteleyev.jpackage.CommandLineParameter.MAIN_JAR;
import static org.panteleyev.jpackage.CommandLineParameter.MODULE;
import static org.panteleyev.jpackage.CommandLineParameter.MODULE_PATH;
import static org.panteleyev.jpackage.CommandLineParameter.NAME;
import static org.panteleyev.jpackage.CommandLineParameter.RESOURCE_DIR;
import static org.panteleyev.jpackage.CommandLineParameter.RUNTIME_IMAGE;
import static org.panteleyev.jpackage.CommandLineParameter.TEMP;
import static org.panteleyev.jpackage.CommandLineParameter.TYPE;
import static org.panteleyev.jpackage.CommandLineParameter.VENDOR;
import static org.panteleyev.jpackage.CommandLineParameter.VERBOSE;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_CONSOLE;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_DIR_CHOOSER;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_HELP_URL;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_MENU;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_MENU_GROUP;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_PER_USER_INSTALL;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_SHORTCUT;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_SHORTCUT_PROMPT;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_UPDATE_URL;
import static org.panteleyev.jpackage.CommandLineParameter.WIN_UPGRADE_UUID;
import static org.panteleyev.jpackage.JDKVersionUtil.getJDKMajorVersion;
import static org.panteleyev.jpackage.OsUtil.isLinux;
import static org.panteleyev.jpackage.OsUtil.isMac;
import static org.panteleyev.jpackage.OsUtil.isWindows;
import static org.panteleyev.jpackage.StringUtil.escape;
@SuppressWarnings({"SameParameterValue", "unused"})
public class JPackageTask extends DefaultTask {
static final String EXECUTABLE = "jpackage";
private boolean verbose;
private ImageType type = ImageType.DEFAULT;
private String appName;
private String appImage;
private String appVersion = getProject().getVersion().toString();
private String vendor;
private String icon;
private String runtimeImage;
private String input;
private String installDir;
private String destination;
private String module;
private String mainClass;
private String mainJar;
private String copyright;
private String appDescription;
private List<String> modulePaths;
private String licenseFile;
private String resourceDir;
private String temp;
private List<String> javaOptions;
private List<String> arguments;
private List<String> fileAssociations;
private List<Launcher> launchers;
private List<String> addModules;
private boolean bindServices;
private List<String> jLinkOptions;
private String aboutUrl;
private boolean launcherAsService;
private List<String> appContent;
// Windows specific parameters
private boolean winMenu;
private boolean winDirChooser;
private String winUpgradeUuid;
private String winMenuGroup;
private boolean winShortcut;
private boolean winPerUserInstall;
private boolean winConsole;
private String winHelpUrl;
private boolean winShortcutPrompt;
private String winUpdateUrl;
// OS X specific parameters
private String macPackageIdentifier;
private String macPackageName;
private String macPackageSigningPrefix;
private String macBundleSigningPrefix;
private boolean macSign;
private String macSigningKeychain;
private String macSigningKeyUserName;
private boolean macAppStore;
private String macAppCategory;
private String macEntitlements;
private List<String> macDmgContent;
// Linux specific parameters
private String linuxPackageName;
private String linuxDebMaintainer;
private String linuxMenuGroup;
private String linuxRpmLicenseType;
private String linuxAppRelease;
private String linuxAppCategory;
private boolean linuxShortcut;
private boolean linuxPackageDeps;
// Additional parameters
private List<String> additionalParameters = new ArrayList<>();
// JPackage process environment variables
private Map<String, String> jpackageEnvironment;
// Plugin internal options
private final boolean dryRun;
public JPackageTask() {
dryRun = Boolean.getBoolean("jpackage.dryRun");
}
@Input
public boolean getVerbose() {
return verbose;
}
public void setVerbose(boolean verbose) {
this.verbose = verbose;
}
@Input
public ImageType getType() {
return type;
}
public void setType(ImageType type) {
this.type = type;
}
@Input
@org.gradle.api.tasks.Optional
public String getAppName() {
return appName;
}
public void setAppName(String appName) {
this.appName = appName;
}
@Input
@org.gradle.api.tasks.Optional
public String getAppImage() {
return appImage;
}
public void setAppImage(String appImage) {
this.appImage = appImage;
}
@Input
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
@Input
@org.gradle.api.tasks.Optional
public String getVendor() {
return vendor;
}
public void setVendor(String vendor) {
this.vendor = vendor;
}
@Input
@org.gradle.api.tasks.Optional
public String getIcon() {
return icon;
}
public void setIcon(String icon) {
this.icon = icon;
}
@Input
@org.gradle.api.tasks.Optional
public String getRuntimeImage() {
return runtimeImage;
}
public void setRuntimeImage(String runtimeImage) {
this.runtimeImage = runtimeImage;
}
@Input
@org.gradle.api.tasks.Optional
public String getInput() {
return input;
}
public void setInput(String input) {
this.input = input;
}
@Input
@org.gradle.api.tasks.Optional
public String getInstallDir() {
return installDir;
}
public void setInstallDir(String installDir) {
this.installDir = installDir;
}
@Input
@org.gradle.api.tasks.Optional
public String getDestination() {
return destination;
}
public void setDestination(String destination) {
this.destination = destination;
}
@Input
@org.gradle.api.tasks.Optional
public String getModule() {
return module;
}
public void setModule(String module) {
this.module = module;
}
@Input
@org.gradle.api.tasks.Optional
public String getMainClass() {
return mainClass;
}
public void setMainClass(String mainClass) {
this.mainClass = mainClass;
}
@Input
@org.gradle.api.tasks.Optional
public String getMainJar() {
return mainJar;
}
public void setMainJar(String mainJar) {
this.mainJar = mainJar;
}
@Input
@org.gradle.api.tasks.Optional
public String getCopyright() {
return copyright;
}
public void setCopyright(String copyright) {
this.copyright = copyright;
}
@Input
@org.gradle.api.tasks.Optional
public String getAppDescription() {
return appDescription;
}
public void setAppDescription(String appDescription) {
this.appDescription = appDescription;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getModulePaths() {
return modulePaths;
}
public void setModulePaths(List<String> modulePaths) {
this.modulePaths = modulePaths;
}
@Input
@org.gradle.api.tasks.Optional
public String getLicenseFile() {
return licenseFile;
}
public void setLicenseFile(String licenseFile) {
this.licenseFile = licenseFile;
}
@Input
@org.gradle.api.tasks.Optional
public String getResourceDir() {
return resourceDir;
}
public void setResourceDir(String resourceDir) {
this.resourceDir = resourceDir;
}
@Input
@org.gradle.api.tasks.Optional
public String getTemp() {
return temp;
}
public void setTemp(String temp) {
this.temp = temp;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getJavaOptions() {
return javaOptions;
}
public void setJavaOptions(List<String> javaOptions) {
this.javaOptions = javaOptions;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getArguments() {
return arguments;
}
public void setArguments(List<String> arguments) {
this.arguments = arguments;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getFileAssociations() {
return fileAssociations;
}
public void setFileAssociations(List<String> fileAssociations) {
this.fileAssociations = fileAssociations;
}
@Input
@org.gradle.api.tasks.Optional
public List<Launcher> getLaunchers() {
return launchers;
}
public void setLaunchers(List<Launcher> launchers) {
this.launchers = launchers;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getAddModules() {
return addModules;
}
public void setAddModules(List<String> addModules) {
this.addModules = addModules;
}
@Input
public boolean getBindServices() {
return bindServices;
}
public void setBindServices(boolean bindServices) {
this.bindServices = bindServices;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getJLinkOptions() {
return jLinkOptions;
}
public void setJLinkOptions(List<String> jLinkOptions) {
this.jLinkOptions = jLinkOptions;
}
@Input
@org.gradle.api.tasks.Optional
public String getAboutUrl() {
return aboutUrl;
}
public void setAboutUrl(String aboutUrl) {
this.aboutUrl = aboutUrl;
}
@Input
public boolean getLauncherAsService() {
return launcherAsService;
}
public void setLauncherAsService(boolean launcherAsService) {
this.launcherAsService = launcherAsService;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getAppContent() {
return appContent;
}
public void setAppContent(List<String> appContent) {
this.appContent = appContent;
}
@Input
public boolean getWinMenu() {
return winMenu;
}
public void setWinMenu(boolean winMenu) {
this.winMenu = winMenu;
}
@Input
public boolean getWinDirChooser() {
return winDirChooser;
}
public void setWinDirChooser(boolean winDirChooser) {
this.winDirChooser = winDirChooser;
}
@Input
@org.gradle.api.tasks.Optional
public String getWinUpgradeUuid() {
return winUpgradeUuid;
}
public void setWinUpgradeUuid(String winUpgradeUuid) {
this.winUpgradeUuid = winUpgradeUuid;
}
@Input
@org.gradle.api.tasks.Optional
public String getWinMenuGroup() {
return winMenuGroup;
}
public void setWinMenuGroup(String winMenuGroup) {
this.winMenuGroup = winMenuGroup;
}
@Input
public boolean getWinShortcut() {
return winShortcut;
}
public void setWinShortcut(boolean winShortcut) {
this.winShortcut = winShortcut;
}
@Input
public boolean getWinPerUserInstall() {
return winPerUserInstall;
}
public void setWinPerUserInstall(boolean winPerUserInstall) {
this.winPerUserInstall = winPerUserInstall;
}
@Input
public boolean getWinConsole() {
return winConsole;
}
public void setWinConsole(boolean winConsole) {
this.winConsole = winConsole;
}
@Input
@org.gradle.api.tasks.Optional
public String getWinHelpUrl() {
return winHelpUrl;
}
public void setWinHelpUrl(String winHelpUrl) {
this.winHelpUrl = winHelpUrl;
}
@Input
public boolean getWinShortcutPrompt() {
return winShortcutPrompt;
}
public void setWinShortcutPrompt(boolean winShortcutPrompt) {
this.winShortcutPrompt = winShortcutPrompt;
}
@Input
@org.gradle.api.tasks.Optional
public String getWinUpdateUrl() {
return winUpdateUrl;
}
public void setWinUpdateUrl(String winUpdateUrl) {
this.winUpdateUrl = winUpdateUrl;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacPackageIdentifier() {
return macPackageIdentifier;
}
public void setMacPackageIdentifier(String macPackageIdentifier) {
this.macPackageIdentifier = macPackageIdentifier;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacPackageName() {
return macPackageName;
}
public void setMacPackageName(String macPackageName) {
this.macPackageName = macPackageName;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacPackageSigningPrefix() {
return macPackageSigningPrefix;
}
public void setMacPackageSigningPrefix(String macPackageSigningPrefix) {
this.macPackageSigningPrefix = macPackageSigningPrefix;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacBundleSigningPrefix() {
return macBundleSigningPrefix;
}
public void setMacBundleSigningPrefix(String macBundleSigningPrefix) {
this.macBundleSigningPrefix = macBundleSigningPrefix;
}
@Input
public boolean getMacSign() {
return macSign;
}
public void setMacSign(boolean macSign) {
this.macSign = macSign;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacSigningKeychain() {
return macSigningKeychain;
}
public void setMacSigningKeychain(String macSigningKeychain) {
this.macSigningKeychain = macSigningKeychain;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacSigningKeyUserName() {
return macSigningKeyUserName;
}
public void setMacSigningKeyUserName(String macSigningKeyUserName) {
this.macSigningKeyUserName = macSigningKeyUserName;
}
@Input
public boolean getMacAppStore() {
return macAppStore;
}
public void setMacAppStore(boolean macAppStore) {
this.macAppStore = macAppStore;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacAppCategory() {
return macAppCategory;
}
public void setMacAppCategory(String macAppCategory) {
this.macAppCategory = macAppCategory;
}
@Input
@org.gradle.api.tasks.Optional
public String getMacEntitlements() {
return macEntitlements;
}
public void setMacEntitlements(String macEntitlements) {
this.macEntitlements = macEntitlements;
}
@Input
@org.gradle.api.tasks.Optional
public List<String> getMacDmgContent() {
return macDmgContent;
}
public void setMacDmgContent(List<String> macDmgContent) {
this.macDmgContent = macDmgContent;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxPackageName() {
return linuxPackageName;
}
public void setLinuxPackageName(String linuxPackageName) {
this.linuxPackageName = linuxPackageName;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxDebMaintainer() {
return linuxDebMaintainer;
}
public void setLinuxDebMaintainer(String linuxDebMaintainer) {
this.linuxDebMaintainer = linuxDebMaintainer;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxMenuGroup() {
return linuxMenuGroup;
}
public void setLinuxMenuGroup(String linuxMenuGroup) {
this.linuxMenuGroup = linuxMenuGroup;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxRpmLicenseType() {
return linuxRpmLicenseType;
}
public void setLinuxRpmLicenseType(String linuxRpmLicenseType) {
this.linuxRpmLicenseType = linuxRpmLicenseType;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxAppRelease() {
return linuxAppRelease;
}
public void setLinuxAppRelease(String linuxAppRelease) {
this.linuxAppRelease = linuxAppRelease;
}
@Input
@org.gradle.api.tasks.Optional
public String getLinuxAppCategory() {
return linuxAppCategory;
}
public void setLinuxAppCategory(String linuxAppCategory) {
this.linuxAppCategory = linuxAppCategory;
}
@Input
public boolean getLinuxShortcut() {
return linuxShortcut;
}
public void setLinuxShortcut(boolean linuxShortcut) {
this.linuxShortcut = linuxShortcut;
}
@Input
public boolean getLinuxPackageDeps() {
return linuxPackageDeps;
}
public void setLinuxPackageDeps(boolean linuxPackageDeps) {
this.linuxPackageDeps = linuxPackageDeps;
}
@Input
public List<String> getAdditionalParameters() {
return additionalParameters;
}
public void setAdditionalParameters(List<String> additionalParameters) {
this.additionalParameters = additionalParameters;
}
@Input
@org.gradle.api.tasks.Optional
public Map<String, String> getJpackageEnvironment() {
return jpackageEnvironment;
}
public void setJpackageEnvironment(Map<String, String> jpackageEnvironment) {
this.jpackageEnvironment = jpackageEnvironment;
}
@TaskAction
public void action() {
if (dryRun) {
getLogger().lifecycle("Executing jpackage plugin in dry run mode");
}
String jpackage = getJPackageFromToolchain()
.orElseGet(() -> getJPackageFromJavaHome()
.orElseThrow(() -> new GradleException("Could not detect " + EXECUTABLE)));
execute(jpackage);
}
private Optional<String> buildExecutablePath(String home) {
String executable = home + File.separator + "bin" + File.separator + EXECUTABLE + (isWindows() ? ".exe" : "");
if (new File(executable).exists()) {
return Optional.of(executable);
} else {
getLogger().warn("File {} does not exist", executable);
return Optional.empty();
}
}
private Optional<String> getJPackageFromToolchain() {
getLogger().info("Looking for {} in toolchain", EXECUTABLE);
try {
JavaToolchainSpec toolchain = getProject().getExtensions().getByType(JavaPluginExtension.class).getToolchain();
JavaToolchainService service = getProject().getExtensions().getByType(JavaToolchainService.class);
Provider<JavaLauncher> defaultLauncher = service.launcherFor(toolchain);
String home = defaultLauncher.get().getMetadata().getInstallationPath().getAsFile().getAbsolutePath();
getLogger().info("toolchain: " + home);
return buildExecutablePath(home);
} catch (Exception ex) {
getLogger().info("Toolchain is not configured");
return Optional.empty();
}
}
private Optional<String> getJPackageFromJavaHome() {
getLogger().info("Getting {} from java.home", EXECUTABLE);
String javaHome = System.getProperty("java.home");
if (javaHome == null) {
getLogger().error("java.home is not set");
return Optional.empty();
}
return buildExecutablePath(javaHome);
}
private void buildParameters(Collection<String> parameters, int version) {
addParameter(parameters, ABOUT_URL, aboutUrl, version);
if (launchers != null) {
for (Launcher launcher : launchers) {
File launcherFile = getProject().file(launcher.getFilePath());
if (!launcherFile.exists()) {
throw new GradleException("Launcher file " + launcherFile.getAbsolutePath() + " does not exist");
}
addParameter(parameters, ADD_LAUNCHER,
launcher.getName() + "=" + launcherFile.getAbsolutePath(), version);
}
}
if (addModules != null && !addModules.isEmpty()) {
addParameter(parameters, ADD_MODULES, String.join(",", addModules), version);
}
if (appContent != null) {
for (Object appContentElement : appContent) {
addFileParameter(parameters, APP_CONTENT, appContentElement.toString(), true, version);
}
}
addFileParameter(parameters, APP_IMAGE, appImage, version);
addParameter(parameters, APP_VERSION, appVersion, version);
if (arguments != null) {
for (Object arg : arguments) {
addParameter(parameters, ARGUMENTS, escape(arg.toString()), version);
}
}
addParameter(parameters, BIND_SERVICES, bindServices, version);
addParameter(parameters, COPYRIGHT, copyright, version);
addParameter(parameters, DESCRIPTION, appDescription, version);
addFileParameter(parameters, DESTINATION, destination, false, version);
if (fileAssociations != null) {
for (Object association : fileAssociations) {
addFileParameter(parameters, FILE_ASSOCIATIONS, association.toString(), true, version);
}
}
addFileParameter(parameters, ICON, icon, true, version);
addFileParameter(parameters, INPUT, input, true, version);
addParameter(parameters, INSTALL_DIR, installDir, version);
if (javaOptions != null) {
for (Object option : javaOptions) {
addParameter(parameters, JAVA_OPTIONS, escape(option.toString()), version);
}
}
if (jLinkOptions != null && !jLinkOptions.isEmpty()) {
addParameter(parameters, JLINK_OPTIONS, String.join(" ", jLinkOptions), version);
}
addParameter(parameters, LAUNCHER_AS_SERVICE, launcherAsService, version);
addFileParameter(parameters, LICENSE_FILE, licenseFile, true, version);
addParameter(parameters, MAIN_CLASS, mainClass, version);
addParameter(parameters, MAIN_JAR, mainJar, version);
addParameter(parameters, MODULE, module, version);
if (modulePaths != null) {
for (Object path : modulePaths) {
addFileParameter(parameters, MODULE_PATH, path.toString(), version);
}
}
addParameter(parameters, NAME, appName, version);
addFileParameter(parameters, RESOURCE_DIR, resourceDir, true, version);
addFileParameter(parameters, RUNTIME_IMAGE, runtimeImage, true, version);
addFileParameter(parameters, TEMP, temp, false, version);
if (type != ImageType.DEFAULT) {
addParameter(parameters, TYPE, type, version);
}
addParameter(parameters, VENDOR, vendor, version);
addParameter(parameters, VERBOSE, verbose, version);
if (isMac()) {
addParameter(parameters, MAC_APP_CATEGORY, macAppCategory, version);
addParameter(parameters, MAC_APP_STORE, macAppStore, version);
addParameter(parameters, MAC_BUNDLE_SIGNING_PREFIX, macBundleSigningPrefix, version);
if (macDmgContent != null) {
for (Object dmgContent : macDmgContent) {
addFileParameter(parameters, MAC_DMG_CONTENT, dmgContent.toString(), true, version);
}
}
addFileParameter(parameters, MAC_ENTITLEMENTS, macEntitlements, true, version);
addParameter(parameters, MAC_PACKAGE_IDENTIFIER, macPackageIdentifier, version);
addParameter(parameters, MAC_PACKAGE_NAME, macPackageName, version);
addParameter(parameters, MAC_PACKAGE_SIGNING_PREFIX, macPackageSigningPrefix, version);
addParameter(parameters, MAC_SIGN, macSign, version);
addParameter(parameters, MAC_SIGNING_KEY_USER_NAME, macSigningKeyUserName, version);
addFileParameter(parameters, MAC_SIGNING_KEYCHAIN, macSigningKeychain, true, version);
} else if (isWindows()) {
addParameter(parameters, WIN_CONSOLE, winConsole, version);
addParameter(parameters, WIN_DIR_CHOOSER, winDirChooser, version);
addParameter(parameters, WIN_HELP_URL, winHelpUrl, version);
addParameter(parameters, WIN_MENU, winMenu, version);
addParameter(parameters, WIN_MENU_GROUP, winMenuGroup, version);
addParameter(parameters, WIN_PER_USER_INSTALL, winPerUserInstall, version);
addParameter(parameters, WIN_SHORTCUT, winShortcut, version);
addParameter(parameters, WIN_SHORTCUT_PROMPT, winShortcutPrompt, version);
addParameter(parameters, WIN_UPDATE_URL, winUpdateUrl, version);
addParameter(parameters, WIN_UPGRADE_UUID, winUpgradeUuid, version);
} else if (isLinux()) {
addParameter(parameters, LINUX_APP_CATEGORY, linuxAppCategory, version);
addParameter(parameters, LINUX_APP_RELEASE, linuxAppRelease, version);
addParameter(parameters, LINUX_DEB_MAINTAINER, linuxDebMaintainer, version);
addParameter(parameters, LINUX_MENU_GROUP, linuxMenuGroup, version);
addParameter(parameters, LINUX_PACKAGE_DEPS, linuxPackageDeps, version);
addParameter(parameters, LINUX_PACKAGE_NAME, linuxPackageName, version);
addParameter(parameters, LINUX_RPM_LICENSE_TYPE, linuxRpmLicenseType, version);
addParameter(parameters, LINUX_SHORTCUT, linuxShortcut, version);
}
// Additional options
for (Object option : additionalParameters) {
addAdditionalParameter(parameters, option.toString());
}
}
private void execute(String cmd) {
int version = getJDKMajorVersion(cmd);
if (version == 0) {
getLogger().warn("Could not determine " + EXECUTABLE + " version, parameter check will be skipped");
getLogger().info("Using: {}", cmd);
} else {
getLogger().info("Using: {}, major version: {}", cmd, version);
}
List<String> parameters = new ArrayList<>();
parameters.add(cmd.contains(" ") ? "\"" + cmd + "\"" : cmd);
buildParameters(parameters, version);
if (dryRun) {
return;
}
try {
ProcessBuilder processBuilder = new ProcessBuilder();
if (jpackageEnvironment != null && !jpackageEnvironment.isEmpty()) {
getLogger().info(EXECUTABLE + " environment:");
Map<String, String> environment = processBuilder.environment();
for (Map.Entry<String, String> entry : jpackageEnvironment.entrySet()) {
String key = entry.getKey();
String value = entry.getValue();
if (key == null || key.trim().isEmpty() || value == null) {
// Silently skip null or empty keys or null values
continue;
}
environment.put(key, value);
getLogger().info(" " + key + " = " + value);
}
}
Process process = processBuilder
.redirectErrorStream(true)
.command(parameters)
.start();
getLogger().info(EXECUTABLE + " output:");
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()))) {
String line;
while ((line = reader.readLine()) != null) {
getLogger().info(line);
}
}
int status = process.waitFor();
if (status != 0) {
throw new GradleException("Error while executing " + EXECUTABLE);
}
} catch (Exception ex) {
throw new GradleException("Error while executing " + EXECUTABLE, ex);
}
}
/**
* Executes windows specific configuration block.
*
* @param block configuration block
*/
public void windows(Runnable block) {
if (isWindows()) {
block.run();
}
}
/**