Skip to content

Commit 6a0956f

Browse files
committed
U added version information property for launch4j
1 parent 005f38a commit 6a0956f

File tree

5 files changed

+247
-35
lines changed

5 files changed

+247
-35
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ And by default it will generate next artifacts in `target ` folder:
8181
| `envPath` | :x: | `null` | Defines PATH environment variable in GNU/Linux and Mac OS X startup scripts. |
8282
| `generateInstaller` | :x: | `true` | Generates an installer for the app. |
8383
| `iconFile` | :x: | `null` | Path to the app icon file (PNG, ICO or ICNS). |
84+
| `jreDirectoryName` | :x: | `"jre"` | Bundled JRE directory name. |
8485
| `jrePath` | :x: | `""` | Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
8586
| `licenseFile` | :x: | `${project.licenses[0].url}` or `${project.basedir}/LICENSE` | Path to project license file. |
8687
| `mainClass` | :heavy_check_mark: | `${exec.mainClass}` | Full path to your app main class. |
@@ -93,10 +94,27 @@ And by default it will generate next artifacts in `target ` folder:
9394
| `runnableJar` | :x: | `null` | Defines your own JAR file to be bundled. If it's ommited, the plugin packages your code in a runnable JAR and bundle it with the app. |
9495
| `url` | :x: | `null` | App website URL. |
9596
| ` version` | :x: | `${project.version}` | Project version in X.X.X format (e.g. 1.2.3), without letters. |
97+
| `versionInfo` | :x: | `null` | Version information for native Windows `.exe` file.\* |
9698
| `vmArgs` | :x: | [] | Adds VM arguments. |
9799

98100
> See [**Older documentation**](#older-documentation) for previous versions properties.
99101
102+
> #### \* Version information property example, using default values:
103+
>
104+
> ```xml
105+
> <versionInfo>
106+
> <fileVersion>1.0.0.0</fileVersion>
107+
> <txtFileVersion>${version}</txtFileVersion>
108+
> <productVersion>1.0.0.0</productVersion>
109+
> <txtProductVersion>${version}</txtProductVersion>
110+
> <fileDescription>${description}</fileDescription>
111+
> <copyright>${organizationName}</copyright>
112+
> <productName>${name}</productName>
113+
> <internalName>${name}</internalName>
114+
> <originalFilename>${name}.exe</originalFilename>
115+
> </versionInfo>
116+
> ```
117+
100118
### Plugin assets
101119
102120
Some assets, such as application icons and Velocity templates, could be placed in `assets` folder organized by platform.
@@ -165,12 +183,15 @@ A map called `info` is passed to all templates when they are rendered with next
165183
| `${info.administratorRequired}` | Boolean | Same as `administratorRequired` plugin property. |
166184
| `${info.bundleJre}` | Boolean | Same as `bundleJre` plugin property. |
167185
| `${info.jarFile}` | String | Full path to runnable JAR file. |
186+
| `${info.jreDirectoryName}` | String | Same as `jreDirectoryName` plugin property. |
168187
| `${info.license}` | String | Full path to license file. |
169188
| `${info.envPath}` | String | Same as `envPath` plugin property. |
170189
| `${info.vmArgs}` | String | Same as `vmArgs` plugin property. |
171190
172191
## How to build and install the plugin
173192
193+
> Useful to try SNAPSHOT versions.
194+
174195
Execute next commands in BASH (GNU/Linux or macOS) or CMD (Windows):
175196
176197
1. Download source code and change to the project directory:
@@ -202,6 +223,7 @@ Check the [TO-DO list](https://github.com/fvarrui/JavaPackager/projects/1#column
202223

203224
## Older documentation
204225

226+
- [v0.9.3](https://github.com/fvarrui/JavaPackager/blob/v0.9.3/README.md)
205227
- [v0.9.1](https://github.com/fvarrui/JavaPackager/blob/v0.9.1/README.md)
206228
- [v0.9.0](https://github.com/fvarrui/JavaPackager/blob/v0.9.0/README.md)
207229
- [v0.8.9](https://github.com/fvarrui/JavaPackager/blob/v0.8.9/README.md)

src/main/java/io/github/fvarrui/javapackager/PackageMojo.java

Lines changed: 49 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
import io.github.fvarrui.javapackager.utils.Logger;
4242
import 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)
4547
public 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

Lines changed: 174 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,174 @@
1+
package io.github.fvarrui.javapackager;
2+
3+
import static org.apache.commons.lang3.StringUtils.defaultIfBlank;
4+
5+
import java.util.Map;
6+
7+
import org.apache.maven.plugins.annotations.Parameter;
8+
9+
public class VersionInfo {
10+
11+
@Parameter(defaultValue = "${organizationName}", required = false)
12+
private String companyName;
13+
14+
@Parameter(required = false)
15+
private String copyright;
16+
17+
@Parameter(defaultValue = "${description}", required = false)
18+
private String fileDescription;
19+
20+
@Parameter(required = false)
21+
private String fileVersion;
22+
23+
@Parameter(defaultValue = "${name}", required = false)
24+
private String internalName;
25+
26+
@Parameter(required = false)
27+
private String language;
28+
29+
@Parameter(defaultValue = "${name}.exe", required = false)
30+
private String originalFilename;
31+
32+
@Parameter(defaultValue = "${name}", required = false)
33+
private String productName;
34+
35+
@Parameter(required = false)
36+
private String productVersion;
37+
38+
@Parameter(required = false)
39+
private String trademarks;
40+
41+
@Parameter(defaultValue = "${version}", required = false)
42+
private String txtFileVersion;
43+
44+
@Parameter(defaultValue = "${version}", required = false)
45+
private String txtProductVersion;
46+
47+
public String getCompanyName() {
48+
return companyName;
49+
}
50+
51+
public void setCompanyName(String companyName) {
52+
this.companyName = companyName;
53+
}
54+
55+
public String getCopyright() {
56+
return copyright;
57+
}
58+
59+
public void setCopyright(String copyright) {
60+
this.copyright = copyright;
61+
}
62+
63+
public String getFileDescription() {
64+
return fileDescription;
65+
}
66+
67+
public void setFileDescription(String fileDescription) {
68+
this.fileDescription = fileDescription;
69+
}
70+
71+
public String getFileVersion() {
72+
return fileVersion;
73+
}
74+
75+
public void setFileVersion(String fileVersion) {
76+
this.fileVersion = fileVersion;
77+
}
78+
79+
public String getLanguage() {
80+
return language;
81+
}
82+
83+
public void setLanguage(String language) {
84+
this.language = language;
85+
}
86+
87+
public String getOriginalFilename() {
88+
return originalFilename;
89+
}
90+
91+
public void setOriginalFilename(String originalFilename) {
92+
this.originalFilename = originalFilename;
93+
}
94+
95+
public String getProductName() {
96+
return productName;
97+
}
98+
99+
public void setProductName(String productName) {
100+
this.productName = productName;
101+
}
102+
103+
public String getProductVersion() {
104+
return productVersion;
105+
}
106+
107+
public void setProductVersion(String productVersion) {
108+
this.productVersion = productVersion;
109+
}
110+
111+
public String getTrademarks() {
112+
return trademarks;
113+
}
114+
115+
public void setTrademarks(String trademarks) {
116+
this.trademarks = trademarks;
117+
}
118+
119+
public String getTxtFileVersion() {
120+
return txtFileVersion;
121+
}
122+
123+
public void setTxtFileVersion(String txtFileVersion) {
124+
this.txtFileVersion = txtFileVersion;
125+
}
126+
127+
public String getTxtProductVersion() {
128+
return txtProductVersion;
129+
}
130+
131+
public void setTxtProductVersion(String txtProductVersion) {
132+
this.txtProductVersion = txtProductVersion;
133+
}
134+
135+
public String getInternalName() {
136+
return internalName;
137+
}
138+
139+
public void setInternalName(String internalName) {
140+
this.internalName = internalName;
141+
}
142+
143+
@Override
144+
public String toString() {
145+
return "VersionInfo ["
146+
+ "companyName=" + companyName + ", "
147+
+ "copyright=" + copyright + ", "
148+
+ "fileDescription=" + fileDescription + ", "
149+
+ "fileVersion=" + fileVersion + ", "
150+
+ "internalName=" + internalName + ", "
151+
+ "language=" + language + ", "
152+
+ "originalFilename=" + originalFilename + ", "
153+
+ "productName=" + productName + ", "
154+
+ "productVersion=" + productVersion + ", "
155+
+ "trademarks=" + trademarks + ", "
156+
+ "txtFileVersion=" + txtFileVersion + ", "
157+
+ "txtProductVersion=" + txtProductVersion +
158+
"]";
159+
}
160+
161+
public void setDefaults(Map<String, Object> info) {
162+
fileVersion = defaultIfBlank(fileVersion, "1.0.0.0");
163+
txtFileVersion = defaultIfBlank(txtFileVersion, "" + info.get("version"));
164+
productVersion = defaultIfBlank(productVersion, "1.0.0.0");
165+
txtProductVersion = defaultIfBlank(txtProductVersion, "" + info.get("version"));
166+
companyName = defaultIfBlank(companyName, "" + info.get("organizationName"));
167+
copyright = defaultIfBlank(copyright, "" + info.get("organizationName"));
168+
fileDescription = defaultIfBlank(fileDescription, "" + info.get("description"));
169+
productName = defaultIfBlank(productName, "" + info.get("name"));
170+
internalName = defaultIfBlank(internalName, "" + info.get("name"));
171+
originalFilename = defaultIfBlank(originalFilename, info.get("name") + ".exe");
172+
}
173+
174+
}

src/main/resources/linux/startup.sh.vtl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# GNU/Linux startup script generated by JavaPackager Maven Plugin
33
SCRIPTPATH=$(dirname $(readlink -e "$0"))
44
#if($info.bundleJre)
5-
JAVA=$SCRIPTPATH/jre/bin/java
5+
JAVA=$SCRIPTPATH/${info.jreDirectoryName}/bin/java
66
#else
77
JAVA=java
88
#end

src/main/resources/mac/startup.vtl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# Mac OS X startup script generated by JavaPackager Maven Plugin
33
SCRIPTPATH=`cd "$(dirname "$0")" ; pwd`
44
#if($info.bundleJre)
5-
JAVA=$SCRIPTPATH/../PlugIns/jre/Contents/Home/bin/java
5+
JAVA=$SCRIPTPATH/../PlugIns/${info.jreDirectoryName}/Contents/Home/bin/java
66
#else
77
JAVA=`/usr/libexec/java_home`/bin/java
88
#end

0 commit comments

Comments
 (0)