4141import io .github .fvarrui .javapackager .utils .Logger ;
4242import io .github .fvarrui .javapackager .utils .VelocityUtils ;
4343
44+ import static org .apache .commons .lang3 .StringUtils .defaultIfBlank ;
45+
4446@ Mojo (name = "package" , defaultPhase = LifecyclePhase .PACKAGE , requiresDependencyResolution = ResolutionScope .RUNTIME )
4547public class PackageMojo extends AbstractMojo {
4648
@@ -225,6 +227,19 @@ public class PackageMojo extends AbstractMojo {
225227 */
226228 @ Parameter (defaultValue = "true" , property = "copyDependencies" , required = true )
227229 private Boolean copyDependencies ;
230+
231+ /**
232+ * Bundled JRE directory name
233+ */
234+ @ Parameter (defaultValue = "jre" , property = "jreDirectoryName" , required = false )
235+ private String jreDirectoryName ;
236+
237+ /**
238+ * Launch4j version info
239+ */
240+ @ Parameter (property = "versionInfo" , required = false )
241+ private VersionInfo versionInfo ;
242+
228243
229244 public PackageMojo () {
230245 super ();
@@ -237,28 +252,16 @@ public void execute() throws MojoExecutionException {
237252 this .env = executionEnvironment (mavenProject , mavenSession , pluginManager );
238253
239254 // using artifactId as name, if it's not specified
240- if (name == null || name .isEmpty ()) {
241- name = mavenProject .getArtifactId ();
242- getLog ().warn ("Using artifactId ('" + name + "') as name, because it has not been specified" );
243- }
244-
255+ name = defaultIfBlank (name , mavenProject .getArtifactId ());
256+
245257 // using name as displayName, if it's not specified
246- if (displayName == null || displayName .isEmpty ()) {
247- displayName = name ;
248- getLog ().warn ("Using name ('" + name + "') as displayName, because it has not been specified" );
249- }
250-
258+ displayName = defaultIfBlank (displayName , name );
259+
251260 // using displayName as description, if it's not specified
252- if (description == null || description .isEmpty ()) {
253- description = displayName ;
254- getLog ().warn ("Using displayName ('" + displayName + "') as description, because it has not been specified" );
255- }
256-
257- // using "Anonymous" as organizationName, if it's not specified
258- if (organizationName == null || organizationName .isEmpty ()) {
259- organizationName = "ACME" ;
260- getLog ().warn ("Using '" + organizationName + "' as organizationName, because it has not been specified" );
261- }
261+ description = defaultIfBlank (description , displayName );
262+
263+ // using "ACME" as organizationName, if it's not specified
264+ organizationName = defaultIfBlank (organizationName , "ACME" );
262265
263266 // determines current platform
264267 hostPlatform = getCurrentPlatform ();
@@ -427,6 +430,7 @@ private Map<String, Object> getInfo() {
427430 info .put ("license" , licenseFile != null ? licenseFile .getAbsolutePath () : "" );
428431 info .put ("envPath" , envPath );
429432 info .put ("vmArgs" , StringUtils .join (vmArgs , " " ));
433+ info .put ("jreDirectoryName" , jreDirectoryName );
430434 return info ;
431435 }
432436
@@ -498,7 +502,7 @@ private void createMacApp() throws MojoExecutionException {
498502
499503 // checks if JRE should be embedded
500504 if (bundleJre ) {
501- File jreFolder = new File (contentsFolder , "PlugIns/jre /Contents/Home" );
505+ File jreFolder = new File (contentsFolder , "PlugIns/" + jreDirectoryName + " /Contents/Home" );
502506 bundleJre (jreFolder , libsFolder );
503507 }
504508
@@ -549,7 +553,7 @@ private void createLinuxApp() throws MojoExecutionException {
549553
550554 // checks if JRE should be embedded
551555 if (bundleJre ) {
552- File jreFolder = new File (appFolder , "jre" );
556+ File jreFolder = new File (appFolder , jreDirectoryName );
553557 bundleJre (jreFolder , libsFolder );
554558 }
555559
@@ -587,10 +591,19 @@ private void createWindowsApp() throws MojoExecutionException {
587591
588592 // checks if JRE should be embedded
589593 if (bundleJre ) {
590- File jreFolder = new File (appFolder , "jre" );
594+ File jreFolder = new File (appFolder , jreDirectoryName );
591595 bundleJre (jreFolder , libsFolder );
592596 }
593597
598+ // test version info
599+
600+ if (versionInfo == null ) {
601+ getLog ().warn ("Version info not specified. Using defaults." );
602+ versionInfo = new VersionInfo ();
603+ }
604+ versionInfo .setDefaults (info );
605+ getLog ().info (versionInfo .toString ());
606+
594607 // prepares launch4j plugin configuration
595608
596609 List <Element > optsElements = vmArgs .stream ().map (arg -> element ("opt" , arg )).collect (Collectors .toList ());
@@ -603,20 +616,23 @@ private void createWindowsApp() throws MojoExecutionException {
603616 config .add (element ("manifest" , manifestFile .getAbsolutePath ()));
604617 config .add (element ("classPath" , element ("mainClass" , mainClass )));
605618 config .add (element ("jre" ,
606- element ("path" , bundleJre ? "jre" : "%JAVA_HOME%" ),
619+ element ("path" , bundleJre ? jreDirectoryName : "%JAVA_HOME%" ),
607620 element ("opts" , optsElements .toArray (new Element [optsElements .size ()]))
608621 )
609622 );
610623 config .add (element ("versionInfo" ,
611- element ("fileVersion" , "1.0.0.0" ),
612- element ("txtFileVersion" , "1.0.0.0" ),
613- element ("productVersion" , "1.0.0.0" ),
614- element ("txtProductVersion" , "1.0.0.0" ),
615- element ("copyright" , organizationName ),
616- element ("fileDescription" , description ),
617- element ("productName" , name ),
618- element ("internalName" , name ),
619- element ("originalFilename" , name + ".exe" )
624+ element ("fileVersion" , versionInfo .getFileVersion ()),
625+ element ("txtFileVersion" , versionInfo .getTxtFileVersion ()),
626+ element ("productVersion" , versionInfo .getProductVersion ()),
627+ element ("txtProductVersion" , versionInfo .getTxtProductVersion ()),
628+ element ("copyright" , versionInfo .getCopyright ()),
629+ element ("companyName" , versionInfo .getCompanyName ()),
630+ element ("fileDescription" , versionInfo .getFileDescription ()),
631+ element ("productName" , versionInfo .getProductName ()),
632+ element ("internalName" , versionInfo .getInternalName ()),
633+ element ("originalFilename" , versionInfo .getOriginalFilename ()),
634+ element ("trademarks" , versionInfo .getTrademarks ()),
635+ element ("language" , versionInfo .getLanguage ())
620636 )
621637 );
622638
0 commit comments