3535import org .twdata .maven .mojoexecutor .MojoExecutor .Element ;
3636import org .twdata .maven .mojoexecutor .MojoExecutor .ExecutionEnvironment ;
3737
38+ import io .github .fvarrui .javapackager .model .MacConfig ;
39+ import io .github .fvarrui .javapackager .model .Platform ;
40+ import io .github .fvarrui .javapackager .model .WinConfig ;
3841import io .github .fvarrui .javapackager .utils .CommandUtils ;
3942import io .github .fvarrui .javapackager .utils .FileUtils ;
4043import io .github .fvarrui .javapackager .utils .IconUtils ;
4346import io .github .fvarrui .javapackager .utils .VelocityUtils ;
4447
4548import static org .apache .commons .lang3 .StringUtils .defaultIfBlank ;
49+ import static io .github .fvarrui .javapackager .utils .NumberUtils .defaultIfNull ;
4650
4751@ Mojo (name = "package" , defaultPhase = LifecyclePhase .PACKAGE , requiresDependencyResolution = ResolutionScope .RUNTIME )
4852public class PackageMojo extends AbstractMojo {
@@ -238,10 +242,23 @@ public class PackageMojo extends AbstractMojo {
238242 private String jreDirectoryName ;
239243
240244 /**
241- * Launch4j version info
245+ * Mac OS X specific config
246+ */
247+ @ Parameter (property = "macConfig" , required = false )
248+ private MacConfig macConfig ;
249+
250+ /**
251+ * Windows specific config
252+ */
253+ @ Parameter (property = "winConfig" , required = false )
254+ private WinConfig winConfig ;
255+
256+ /**
257+ * Old windows version information
258+ * @deprecated
242259 */
243260 @ Parameter (property = "versionInfo" , required = false )
244- private VersionInfo versionInfo ;
261+ private WinConfig versionInfo ;
245262
246263 /**
247264 * Bundles app in a tarball file
@@ -674,12 +691,14 @@ private void createWindowsApp() throws MojoExecutionException {
674691
675692 // test version info
676693
677- if (versionInfo == null ) {
678- getLog ().warn ("Version info not specified. Using defaults." );
679- versionInfo = new VersionInfo ();
694+ if (winConfig == null ) {
695+ if (versionInfo == null )
696+ winConfig = new WinConfig ();
697+ else
698+ winConfig = versionInfo ;
680699 }
681- versionInfo .setDefaults (info );
682- getLog ().info (versionInfo .toString ());
700+ winConfig .setDefaults (info );
701+ getLog ().info (winConfig .toString ());
683702
684703 // prepares launch4j plugin configuration
685704
@@ -698,18 +717,18 @@ private void createWindowsApp() throws MojoExecutionException {
698717 )
699718 );
700719 config .add (element ("versionInfo" ,
701- element ("fileVersion" , versionInfo .getFileVersion ()),
702- element ("txtFileVersion" , versionInfo .getTxtFileVersion ()),
703- element ("productVersion" , versionInfo .getProductVersion ()),
704- element ("txtProductVersion" , versionInfo .getTxtProductVersion ()),
705- element ("copyright" , versionInfo .getCopyright ()),
706- element ("companyName" , versionInfo .getCompanyName ()),
707- element ("fileDescription" , versionInfo .getFileDescription ()),
708- element ("productName" , versionInfo .getProductName ()),
709- element ("internalName" , versionInfo .getInternalName ()),
710- element ("originalFilename" , versionInfo .getOriginalFilename ()),
711- element ("trademarks" , versionInfo .getTrademarks ()),
712- element ("language" , versionInfo .getLanguage ())
720+ element ("fileVersion" , winConfig .getFileVersion ()),
721+ element ("txtFileVersion" , winConfig .getTxtFileVersion ()),
722+ element ("productVersion" , winConfig .getProductVersion ()),
723+ element ("txtProductVersion" , winConfig .getTxtProductVersion ()),
724+ element ("copyright" , winConfig .getCopyright ()),
725+ element ("companyName" , winConfig .getCompanyName ()),
726+ element ("fileDescription" , winConfig .getFileDescription ()),
727+ element ("productName" , winConfig .getProductName ()),
728+ element ("internalName" , winConfig .getInternalName ()),
729+ element ("originalFilename" , winConfig .getOriginalFilename ()),
730+ element ("trademarks" , winConfig .getTrademarks ()),
731+ element ("language" , winConfig .getLanguage ())
713732 )
714733 );
715734
@@ -848,20 +867,36 @@ private void generateDmgImage() throws MojoExecutionException {
848867 if (!generateInstaller || hostPlatform != Platform .mac ) return ;
849868
850869 getLog ().info ("Generating DMG disk image file" );
870+
871+ // mac config
851872
873+ if (macConfig == null ) {
874+ macConfig = new MacConfig ();
875+ }
876+
877+ int windowX = defaultIfNull (macConfig .getWindowX (), 10 );
878+ int windowY = defaultIfNull (macConfig .getWindowY (), 60 );
879+ int windowWidth = defaultIfNull (macConfig .getWindowWidth (), 540 );
880+ int windowHeight = defaultIfNull (macConfig .getWindowHeight (), 360 );
881+ int iconSize = defaultIfNull (macConfig .getIconSize (), 128 );
882+ int textSize = defaultIfNull (macConfig .getIconSize (), 16 );
883+ int fileX = defaultIfNull (macConfig .getIconX (), 52 );
884+ int fileY = defaultIfNull (macConfig .getIconY (), 116 );
885+ int appX = defaultIfNull (macConfig .getAppsLinkIconX (), 360 );
886+ int appY = defaultIfNull (macConfig .getAppsLinkIconY (), 116 );
887+ String volumeName = defaultIfBlank (macConfig .getVolumeName (), name );
888+
852889 // final dmg file
853890 File dmgFile = new File (outputDirectory , name + "_" + version + ".dmg" );
854891
855892 // temp dmg file
856893 File tempDmgFile = new File (assetsFolder , name + "_" + version + ".dmg" );
857894
858- // volumen name
859- String volumeName = name ;
860-
861895 // mount dir
862896 File mountFolder = new File ("/Volumes/" + volumeName );
863897
864898 // creates a symlink to Applications folder
899+ getLog ().info ("Creating Applications link" );
865900 File targetFolder = new File ("/Applications" );
866901 File linkFile = new File (appFolder , "Applications" );
867902 FileUtils .createSymlink (linkFile , targetFolder );
@@ -870,11 +905,15 @@ private void generateDmgImage() throws MojoExecutionException {
870905 getLog ().info ("Copying background image" );
871906 File backgroundFolder = FileUtils .mkdir (appFolder , ".background" );
872907 File backgroundFile = new File (backgroundFolder , "background.png" );
873- FileUtils .copyResourceToFile ("/mac/background.png" , backgroundFile );
874-
908+ if (macConfig .getBackgroundImage () != null )
909+ FileUtils .copyFileToFile (macConfig .getBackgroundImage (), backgroundFile );
910+ else
911+ FileUtils .copyResourceToFile ("/mac/background.png" , backgroundFile );
912+
875913 // copies volume icon
876914 getLog ().info ("Copying icon file: " + iconFile .getAbsolutePath ());
877- FileUtils .copyFileToFile (iconFile , new File (appFolder , ".VolumeIcon.icns" ));
915+ File volumeIcon = (macConfig .getVolumeIcon () != null ) ? macConfig .getVolumeIcon () : iconFile ;
916+ FileUtils .copyFileToFile (volumeIcon , new File (appFolder , ".VolumeIcon.icns" ));
878917
879918 // creates image
880919 getLog ().info ("Creating image: " + tempDmgFile .getAbsolutePath ());
@@ -893,18 +932,18 @@ private void generateDmgImage() throws MojoExecutionException {
893932
894933 // rendering applescript
895934 Map <String , Object > params = new HashMap <>();
896- params .put ("windowX" , 10 );
897- params .put ("windowY" , 60 );
898- params .put ("windowWidth" , 540 );
899- params .put ("windowHeight" , 360 );
900- params .put ("iconSize" , 128 );
901- params .put ("textSize" , 16 );
935+ params .put ("windowX" , windowX );
936+ params .put ("windowY" , windowY );
937+ params .put ("windowWidth" , windowWidth );
938+ params .put ("windowHeight" , windowHeight );
939+ params .put ("iconSize" , iconSize );
940+ params .put ("textSize" , textSize );
902941 params .put ("background" , backgroundFile .getName ());
903942 params .put ("file" , name + ".app" );
904- params .put ("fileX" , 52 );
905- params .put ("fileY" , 116 );
906- params .put ("appX" , 360 );
907- params .put ("appY" , 116 );
943+ params .put ("fileX" , fileX );
944+ params .put ("fileY" , fileY );
945+ params .put ("appX" , appX );
946+ params .put ("appY" , appY );
908947 File applescript = new File (assetsFolder , "customize-dmg.applescript" );
909948 getLog ().info ("Rendering applescript: " + applescript .getAbsolutePath ());
910949 VelocityUtils .render ("/mac/customize-dmg.applescript.vtl" , applescript , params );
0 commit comments