35
35
import org .twdata .maven .mojoexecutor .MojoExecutor .Element ;
36
36
import org .twdata .maven .mojoexecutor .MojoExecutor .ExecutionEnvironment ;
37
37
38
+ import io .github .fvarrui .javapackager .model .MacConfig ;
39
+ import io .github .fvarrui .javapackager .model .Platform ;
40
+ import io .github .fvarrui .javapackager .model .WinConfig ;
38
41
import io .github .fvarrui .javapackager .utils .CommandUtils ;
39
42
import io .github .fvarrui .javapackager .utils .FileUtils ;
40
43
import io .github .fvarrui .javapackager .utils .IconUtils ;
43
46
import io .github .fvarrui .javapackager .utils .VelocityUtils ;
44
47
45
48
import static org .apache .commons .lang3 .StringUtils .defaultIfBlank ;
49
+ import static io .github .fvarrui .javapackager .utils .NumberUtils .defaultIfNull ;
46
50
47
51
@ Mojo (name = "package" , defaultPhase = LifecyclePhase .PACKAGE , requiresDependencyResolution = ResolutionScope .RUNTIME )
48
52
public class PackageMojo extends AbstractMojo {
@@ -238,10 +242,23 @@ public class PackageMojo extends AbstractMojo {
238
242
private String jreDirectoryName ;
239
243
240
244
/**
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
242
259
*/
243
260
@ Parameter (property = "versionInfo" , required = false )
244
- private VersionInfo versionInfo ;
261
+ private WinConfig versionInfo ;
245
262
246
263
/**
247
264
* Bundles app in a tarball file
@@ -674,12 +691,14 @@ private void createWindowsApp() throws MojoExecutionException {
674
691
675
692
// test version info
676
693
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 ;
680
699
}
681
- versionInfo .setDefaults (info );
682
- getLog ().info (versionInfo .toString ());
700
+ winConfig .setDefaults (info );
701
+ getLog ().info (winConfig .toString ());
683
702
684
703
// prepares launch4j plugin configuration
685
704
@@ -698,18 +717,18 @@ private void createWindowsApp() throws MojoExecutionException {
698
717
)
699
718
);
700
719
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 ())
713
732
)
714
733
);
715
734
@@ -848,20 +867,36 @@ private void generateDmgImage() throws MojoExecutionException {
848
867
if (!generateInstaller || hostPlatform != Platform .mac ) return ;
849
868
850
869
getLog ().info ("Generating DMG disk image file" );
870
+
871
+ // mac config
851
872
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
+
852
889
// final dmg file
853
890
File dmgFile = new File (outputDirectory , name + "_" + version + ".dmg" );
854
891
855
892
// temp dmg file
856
893
File tempDmgFile = new File (assetsFolder , name + "_" + version + ".dmg" );
857
894
858
- // volumen name
859
- String volumeName = name ;
860
-
861
895
// mount dir
862
896
File mountFolder = new File ("/Volumes/" + volumeName );
863
897
864
898
// creates a symlink to Applications folder
899
+ getLog ().info ("Creating Applications link" );
865
900
File targetFolder = new File ("/Applications" );
866
901
File linkFile = new File (appFolder , "Applications" );
867
902
FileUtils .createSymlink (linkFile , targetFolder );
@@ -870,11 +905,15 @@ private void generateDmgImage() throws MojoExecutionException {
870
905
getLog ().info ("Copying background image" );
871
906
File backgroundFolder = FileUtils .mkdir (appFolder , ".background" );
872
907
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
+
875
913
// copies volume icon
876
914
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" ));
878
917
879
918
// creates image
880
919
getLog ().info ("Creating image: " + tempDmgFile .getAbsolutePath ());
@@ -893,18 +932,18 @@ private void generateDmgImage() throws MojoExecutionException {
893
932
894
933
// rendering applescript
895
934
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 );
902
941
params .put ("background" , backgroundFile .getName ());
903
942
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 );
908
947
File applescript = new File (assetsFolder , "customize-dmg.applescript" );
909
948
getLog ().info ("Rendering applescript: " + applescript .getAbsolutePath ());
910
949
VelocityUtils .render ("/mac/customize-dmg.applescript.vtl" , applescript , params );
0 commit comments