2424package jdk .jpackage .internal ;
2525
2626import static java .util .stream .Collectors .toMap ;
27+ import static jdk .jpackage .internal .cli .StandardAppImageFileOption .DESCRIPTION ;
2728import static jdk .jpackage .internal .cli .StandardAppImageFileOption .LAUNCHER_AS_SERVICE ;
2829import static jdk .jpackage .internal .cli .StandardAppImageFileOption .LAUNCHER_NAME ;
2930import static jdk .jpackage .internal .cli .StandardAppImageFileOption .LINUX_LAUNCHER_SHORTCUT ;
@@ -258,6 +259,11 @@ LauncherBuilder service(boolean v) {
258259 return this ;
259260 }
260261
262+ LauncherBuilder description (String v ) {
263+ description = v ;
264+ return this ;
265+ }
266+
261267 LauncherBuilder addExtra (Map <String , String > v ) {
262268 extra .add (v );
263269 return this ;
@@ -281,7 +287,7 @@ private Launcher createLauncher() {
281287 Optional .empty (),
282288 List .of (),
283289 service ,
284- null ,
290+ description () ,
285291 Optional .empty (),
286292 null ,
287293 extra .asStringValues ());
@@ -295,6 +301,10 @@ private String name() {
295301 }
296302 }
297303
304+ private String description () {
305+ return Optional .ofNullable (description ).orElseGet (this ::name );
306+ }
307+
298308 private boolean isMainLauncher () {
299309 return name .isEmpty ();
300310 }
@@ -305,11 +315,13 @@ private LauncherInfo createLauncherInfo() {
305315 allProps .add (LAUNCHER_AS_SERVICE , Boolean .valueOf (service ));
306316 }
307317 allProps .add (LAUNCHER_NAME , name ());
318+ allProps .add (DESCRIPTION , description ());
308319 return LauncherInfo .create (allProps .asObjectValues ());
309320 }
310321
311322 private final Optional <String > name ;
312323 private boolean service ;
324+ private String description ;
313325 private final ExtraPropertyBuilder extra = new ExtraPropertyBuilder ();
314326 }
315327
@@ -435,9 +447,29 @@ private static List<List<String>> testInavlidXml() {
435447 createWithHeader (AppImageFile .getPlatform (os ), AppImageFile .getVersion (), () -> {
436448 // Missing 'app-version' element.
437449 return List .of (
438- "<main-launcher name='D'/>" ,
450+ "<main-launcher name='D'>" ,
451+ " <description>Foo</description>" ,
452+ "</main-launcher>" ,
439453 "<main-class>Hello</main-class>"
440454 );
455+ }),
456+ createWithHeader (AppImageFile .getPlatform (os ), AppImageFile .getVersion (), () -> {
457+ // Missing 'description' element in the main launcher.
458+ return List .of (
459+ "<app-version>321</app-version>" ,
460+ "<main-launcher name='B'/>"
461+ );
462+ }),
463+ createWithHeader (AppImageFile .getPlatform (os ), AppImageFile .getVersion (), () -> {
464+ // Missing 'description' element in the additional launcher.
465+ return List .of (
466+ "<app-version>123</app-version>" ,
467+ "<main-launcher name='B'>" ,
468+ " <description>Foo</description>" ,
469+ "</main-launcher>" ,
470+ "<main-class>Hello</main-class>" ,
471+ "<add-launcher name='C'/>"
472+ );
441473 })
442474 ));
443475
@@ -451,7 +483,9 @@ private static List<List<String>> testInavlidXml() {
451483 private static List <String > createValidBodyWithHeader (String platform , String version ) {
452484 return createWithHeader (platform , version , () -> {
453485 return List .of (
454- "<main-launcher name='D'/>" ,
486+ "<main-launcher name='D'>" ,
487+ " <description>Blah-Blah-Blah</description>" ,
488+ "</main-launcher>" ,
455489 "<app-version>100</app-version>" ,
456490 "<main-class>Hello</main-class>"
457491 );
@@ -483,16 +517,24 @@ private static Collection<ReadTestSpec> platformSpecificProperties() {
483517 "<signed>true</signed>" ,
484518 "<app-store>False</app-store>" ,
485519 "<add-launcher name='add-launcher'>" ,
520+ " <description>Quick brown fox</description>" ,
486521 " <service>true</service>" ,
487522 " <linux-shortcut>true</linux-shortcut>" ,
488523 " <win-shortcut>false</win-shortcut>" ,
489524 " <win-menu>app-dir</win-menu>" ,
490525 "</add-launcher>" ,
491- "<main-launcher name='Bar'/>"
526+ "<main-launcher name='Bar'>" ,
527+ " <description>Bar launcher description</description>" ,
528+ "</main-launcher>"
492529 );
493530
494531 Supplier <AppBuilder .LauncherBuilder > appBuilder = () -> {
495- return build ().mainClass ("Foo" ).version ("1.34" ).appName ("Bar" ).addlauncher ("add-launcher" ).service (true );
532+ return build ()
533+ .mainClass ("Foo" )
534+ .version ("1.34" )
535+ .appName ("Bar" )
536+ .mainlauncher ().description ("Bar launcher description" ).commit ()
537+ .addlauncher ("add-launcher" ).service (true ).description ("Quick brown fox" );
496538 };
497539
498540 List <ReadTestSpec > testCases = new ArrayList <>();
@@ -513,19 +555,24 @@ private static Collection<ReadTestSpec> platformSpecificProperties() {
513555 private static Stream <ReadTestSpec > testValidXml () {
514556 return Stream .concat (platformSpecificProperties ().stream (), Stream .of (
515557 ReadTestSpec .build ().expect (
516- build ().version ("72" ).appName ("Y" ).mainClass ("main.Class" )
558+ build ().version ("72" ).mainlauncher (). description ( "Blah-Blah-Blah" ). commit (). appName ("Y" ).mainClass ("main.Class" )
517559 ).xml (
518- "<main-launcher name='Y'/>" ,
560+ "<main-launcher name='Y'>" ,
561+ " <description>Blah-Blah-Blah</description>" ,
562+ "</main-launcher>" ,
519563 "<app-version>72</app-version>" ,
520564 "<main-class>main.Class</main-class>"
521565 ),
522566 ReadTestSpec .build ().os (OperatingSystem .LINUX ).expect (
523567 build ()
568+ .mainlauncher ().description ("Main launcher description" ).commit ()
524569 .addlauncher ("another-launcher" )
525570 .addExtra (LINUX_LAUNCHER_SHORTCUT , new LauncherShortcut (LauncherShortcutStartupDirectory .APP_DIR ))
571+ .description ("another-launcher description" )
526572 .commit ()
527573 .addlauncher ("service-launcher" )
528574 .service (true )
575+ .description ("service-launcher description" )
529576 .commit ()
530577 ).xml (
531578 "<app-version>1.2</app-version>" ,
@@ -536,13 +583,17 @@ private static Stream<ReadTestSpec> testValidXml() {
536583 "<signed>true</signed>" ,
537584 "<add-launcher name='service-launcher' service='true'>" ,
538585 " <linux-shortcut><nested>foo</nested></linux-shortcut>" ,
586+ " <description>service-launcher description</description>" ,
539587 "</add-launcher>" ,
540588 "<add-launcher name='another-launcher'>" ,
541589 " <linux-shortcut>true</linux-shortcut>" ,
542590 " <linux-shortcut>app-<!-- This is a comment -->dir</linux-shortcut>" ,
591+ " <description>another-launcher description</description>" ,
543592 "</add-launcher>" ,
544593 "<main-launcher name='Bar'/>" ,
545- "<main-launcher name='Foo'/>"
594+ "<main-launcher name='Foo'>" ,
595+ " <description>Main launcher description</description>" ,
596+ "</main-launcher>"
546597 )
547598 ).map (ReadTestSpec .Builder ::create ));
548599 }
0 commit comments