2020import java .util .ArrayList ;
2121import java .util .Arrays ;
2222import java .util .List ;
23+ import java .util .stream .Collectors ;
2324
25+ import org .apache .tools .ant .types .FileSet ;
2426import org .gradle .api .internal .project .ProjectInternal ;
2527import org .gradle .util .ConfigureUtil ;
2628
@@ -42,51 +44,53 @@ public class Dmg extends AbstractUnixSetupTask {
4244
4345 private Object backgroundImage , setupDarkBackground , setupBackground , setupIcon ;
4446
45- private int windowWidth = 400 , windowHeight = 300 , iconSize = 128 , fontSize = 14 , windowWidthCorrection = 0 , windowHeightCorrection = 22 ;
47+ private int windowWidth = 400 , windowHeight = 300 , iconSize = 128 , fontSize = 14 , windowWidthCorrection = 0 , windowHeightCorrection = 22 ;
4648
4749 private Color backgroundColor ;
4850
4951 private String applicationIdentifier ;
5052
5153 private boolean aquaSystemAppearanceRequired = false ;
52-
54+
5355 private OSXCodeSign <Dmg , SetupBuilder > codeSign ;
5456
55- private List <LocalizedResource > welcomePages = new ArrayList <>();
57+ private List <LocalizedResource > welcomePages = new ArrayList <>();
5658
57- private List <LocalizedResource > conclusionPages = new ArrayList <>();
59+ private List <LocalizedResource > conclusionPages = new ArrayList <>();
5860
59- private List <PreferencesLink > preferencesLink = new ArrayList <>();
61+ private List <PreferencesLink > preferencesLink = new ArrayList <>();
6062
61- final List <OSXApplicationBuilder > appBuilders = new ArrayList <>();
63+ final List <OSXApplicationBuilder > appBuilders = new ArrayList <>();
6264
63- private List <String > jreIncludes = Arrays .asList ( new String [] {
64- "bin/java" ,
65- "lib/" ,
66- "COPYRIGHT" ,
67- "LICENSE" ,
68- "README" ,
69- "THIRDPARTYLICENSEREADME-JAVAFX.txt" ,
70- "THIRDPARTYLICENSEREADME.txt" ,
71- "Welcome.html"
72- });
65+ private List <String > jreIncludes = Arrays .asList ( new String [] {
66+ "bin/java" ,
67+ "lib/" ,
68+ "COPYRIGHT" ,
69+ "LICENSE" ,
70+ "README" ,
71+ "THIRDPARTYLICENSEREADME-JAVAFX.txt" ,
72+ "THIRDPARTYLICENSEREADME.txt" ,
73+ "Welcome.html"
74+ } );
7375
74- private List <String > jreExcludes = Arrays .asList ( new String [] {
75- "lib/deploy/" ,
76- "lib/deploy.jar" ,
77- "lib/javaws.jar" ,
78- "lib/libdeploy.dylib" ,
79- "lib/libnpjp2.dylib" ,
80- "lib/plugin.jar" ,
81- "lib/security/javaws.policy"
82- });
76+ private List <String > jreExcludes = Arrays .asList ( new String [] {
77+ "lib/deploy/" ,
78+ "lib/deploy.jar" ,
79+ "lib/javaws.jar" ,
80+ "lib/libdeploy.dylib" ,
81+ "lib/libnpjp2.dylib" ,
82+ "lib/plugin.jar" ,
83+ "lib/security/javaws.policy"
84+ } );
85+
86+ private List <Object > nativeLibraries = new ArrayList <>();
8387
8488 /**
8589 * Create the task.
8690 */
8791 public Dmg () {
8892 super ( "dmg" );
89- getProject ().afterEvaluate ( (project ) -> {
93+ getProject ().afterEvaluate ( ( project ) -> {
9094 // if the "dmg" task should be executed then create some possible extra tasks on the end of the configuration phase
9195 boolean isExecute = GradleUtils .isTaskExecute ( Dmg .this , project );
9296 if ( isExecute ) {
@@ -98,7 +102,7 @@ public Dmg() {
98102 appBuilders .add ( builder );
99103 }
100104 }
101- });
105+ } );
102106 }
103107
104108 /**
@@ -320,6 +324,7 @@ public File getSetupBackgroundImage() {
320324
321325 /**
322326 * Set the background image for the setup
327+ *
323328 * @param setupBackground to set
324329 */
325330 public void setSetupBackgroundImage ( Object setupBackground ) {
@@ -328,6 +333,7 @@ public void setSetupBackgroundImage( Object setupBackground ) {
328333
329334 /**
330335 * Returns a dark background image for the package installer
336+ *
331337 * @return a dark background image for the package installer
332338 */
333339 public File getSetupDarkBackgroundImage () {
@@ -336,9 +342,10 @@ public File getSetupDarkBackgroundImage() {
336342 }
337343 return null ;
338344 }
339-
345+
340346 /**
341- * Set the dark background image for the package installer
347+ * Set the dark background image for the package installer
348+ *
342349 * @param setupDarkBackground to set
343350 */
344351 public void setSetupDarkBackgroundImage ( Object setupDarkBackground ) {
@@ -347,6 +354,7 @@ public void setSetupDarkBackgroundImage( Object setupDarkBackground ) {
347354
348355 /**
349356 * Returns the setup icon
357+ *
350358 * @return the setupIcon
351359 */
352360 public Object getSetupIcon () {
@@ -358,6 +366,7 @@ public Object getSetupIcon() {
358366
359367 /**
360368 * Set up the setup icon
369+ *
361370 * @param setupIcon the setupIcon to set
362371 */
363372 public void setSetupIcon ( Object setupIcon ) {
@@ -366,6 +375,7 @@ public void setSetupIcon( Object setupIcon ) {
366375
367376 /**
368377 * Return the list of preferences links
378+ *
369379 * @return preferences links
370380 */
371381 public List <PreferencesLink > getPreferencesLinks () {
@@ -374,6 +384,7 @@ public List<PreferencesLink> getPreferencesLinks() {
374384
375385 /**
376386 * Set a preferences link
387+ *
377388 * @param link the link
378389 */
379390 public void preferencesLink ( Object link ) {
@@ -382,6 +393,7 @@ public void preferencesLink( Object link ) {
382393
383394 /**
384395 * Get a list of string - defining files - that should be included in the bundled JRE
396+ *
385397 * @return the jreIncludes
386398 */
387399 public List <String > getJreIncludes () {
@@ -390,6 +402,7 @@ public List<String> getJreIncludes() {
390402
391403 /**
392404 * Set a list of string - defining files - that should be included in the bundled JRE
405+ *
393406 * @param jreIncludes the jreIncludes to set
394407 */
395408 public void setJreIncludes ( List <String > jreIncludes ) {
@@ -398,6 +411,7 @@ public void setJreIncludes( List<String> jreIncludes ) {
398411
399412 /**
400413 * Get a list of string - defining files - that should be excluded from the bundled JRE
414+ *
401415 * @return the jreExclude
402416 */
403417 public List <String > getJreExcludes () {
@@ -406,6 +420,7 @@ public List<String> getJreExcludes() {
406420
407421 /**
408422 * Set a list of string - defining files - that should be excluded from the bundled JRE
423+ *
409424 * @param jreExclude the jreExclude to set
410425 */
411426 public void setJreExcludes ( List <String > jreExclude ) {
@@ -414,19 +429,18 @@ public void setJreExcludes( List<String> jreExclude ) {
414429
415430 /**
416431 * Returns the converted background color as apple script string
432+ *
417433 * @return the backgroundColor as apple script color string
418434 */
419435 public String getBackgroundColor () {
420- if ( backgroundColor == null ) {
436+ if ( backgroundColor == null ) {
421437 // Fallback
422- backgroundColor = new Color (255 , 255 , 255 );
438+ backgroundColor = new Color ( 255 , 255 , 255 );
423439 }
424440
425441 return "{" +
426- String .join ( ", " , Arrays .asList ( String .valueOf (backgroundColor .getRed ()*257 ),
427- String .valueOf (backgroundColor .getGreen ()*257 ),
428- String .valueOf (backgroundColor .getBlue ()*257 )) ) +
429- "}" ;
442+ String .join ( ", " , Arrays .asList ( String .valueOf ( backgroundColor .getRed () * 257 ), String .valueOf ( backgroundColor .getGreen () * 257 ), String .valueOf ( backgroundColor .getBlue () * 257 ) ) ) +
443+ "}" ;
430444 }
431445
432446 /**
@@ -439,12 +453,13 @@ public void setBackgroundColor( Color backgroundColor ) {
439453 /**
440454 * Returns an application identifier set for the DMG builder.
441455 * It is being used as ID in the Info.plist
456+ *
442457 * @param setup the SetupBuilder instance for a fallback
443458 * @return the application identifier for macOS
444459 */
445460 public String getApplicationIdentifier ( SetupBuilder setup ) {
446- if ( applicationIdentifier == null || applicationIdentifier .isEmpty () ) {
447- if ( setup .getMainClass () == null || setup .getMainClass ().isEmpty () ) {
461+ if ( applicationIdentifier == null || applicationIdentifier .isEmpty () ) {
462+ if ( setup .getMainClass () == null || setup .getMainClass ().isEmpty () ) {
448463 return setup .getAppIdentifier ();
449464 }
450465 return setup .getMainClass ();
@@ -455,6 +470,7 @@ public String getApplicationIdentifier( SetupBuilder setup ) {
455470 /**
456471 * Sets an application identifier for the DMG builder.
457472 * It is being used as ID in the Info.plist
473+ *
458474 * @param applicationIdentifier the application identifier for macOS
459475 */
460476 public void setApplicationIdentifier ( String applicationIdentifier ) {
@@ -463,6 +479,7 @@ public void setApplicationIdentifier( String applicationIdentifier ) {
463479
464480 /**
465481 * Returns true, if the application requires the aqua system appearance. False by default
482+ *
466483 * @return true, if the application requires the aqua system appearance.
467484 */
468485 public boolean isAquaSystemAppearanceRequired () {
@@ -471,9 +488,30 @@ public boolean isAquaSystemAppearanceRequired() {
471488
472489 /**
473490 * Define, that the application requires the system appearance. False by default
491+ *
474492 * @param aquaSystemAppearanceRequired true, if the system appearance is required.
475493 */
476494 public void setAquaSystemAppearanceRequired ( boolean aquaSystemAppearanceRequired ) {
477495 this .aquaSystemAppearanceRequired = aquaSystemAppearanceRequired ;
478496 }
497+
498+ /**
499+ * add a native library using any gradle compatible file syntax
500+ * @param library a native library to add
501+ */
502+ public void nativeLibraries ( Object library ) {
503+ nativeLibraries .add ( library );
504+ }
505+
506+ /**
507+ * Returns the list of native libraries set for the current project
508+ * @return the list of native libraries set for the current project
509+ */
510+ public List <FileSet > getNativeLibraries () {
511+ return nativeLibraries .stream ().map ( e -> {
512+ FileSet set = new FileSet ();
513+ set .setDir ( getProject ().file ( e ) );
514+ return set ;
515+ } ).collect ( Collectors .toList () );
516+ }
479517}
0 commit comments