Skip to content

Commit 7822d0f

Browse files
committed
U new config property generateInstaller
1 parent 7e15716 commit 7822d0f

File tree

3 files changed

+64
-35
lines changed

3 files changed

+64
-35
lines changed

README.md

Lines changed: 31 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Add the following `plugin` tag to your `pom.xml`.
2626
<plugin>
2727
<groupId>fvarrui.maven</groupId>
2828
<artifactId>javapackager</artifactId>
29-
<version>0.7.0</version>
29+
<version>0.8.0</version>
3030
<executions>
3131
<execution>
3232
<phase>package</phase>
@@ -42,6 +42,8 @@ Add the following `plugin` tag to your `pom.xml`.
4242
<param>folder path</param>
4343
<param>...</param>
4444
</additionalResources>
45+
<generateInstaller>true|false</generateInstaller>
46+
[...]
4547
</configuration>
4648
</execution>
4749
</executions>
@@ -50,15 +52,23 @@ Add the following `plugin` tag to your `pom.xml`.
5052

5153
Where:
5254

53-
| Property | Mandatory | Default value | Description |
54-
| ----------------------- | --------- | ------------- | ----------------------------------------------------------- |
55-
| `mainClass` | Yes | `null` | Full path to your app main class. |
56-
| `bundleJre` | No | `false` | Embed a customized JRE with the app. |
57-
| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. |
58-
| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. |
59-
| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. |
60-
61-
Some assets, like app icons, must be located in:
55+
| Property | Mandatory | Default value | Description |
56+
| ----------------------- | --------- | ------------------------------ | ----------------------------------------------------------- |
57+
| `mainClass` | Yes | `null` | Full path to your app main class. |
58+
| `bundleJre` | No | `false` | Embed a customized JRE with the app. |
59+
| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. |
60+
| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. |
61+
| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. |
62+
| `generateInstaller` | No | `true` | Generate an installer for the app. |
63+
| `displayName` | No | `${project.name}` | App name to show. |
64+
| `iconFile` | No | `null` | Path to the app icon file (PNG, ICO or ICNS). |
65+
| `licenseFile` | No | `${project.licenses[0].url}` | Path to project license file. |
66+
| `url` | No | `null` | App website URL. |
67+
| `organizationName` | No | `${project.organization.name}` | Organization name. |
68+
| `organizationUrl` | No | `${project.organization.url}` | Organization website URL. |
69+
| `organizationEmail` | No | `null` | Organization email. |
70+
71+
Some assets, such as application icons, could be located in `assets` folder organized by platform, and so it would not be necessary to specify the `iconFile` property:
6272

6373
```
6474
<project>
@@ -68,12 +78,14 @@ Some assets, like app icons, must be located in:
6878
├── macosx
6979
│   └── projectname.icns # on Mac OS X it has to be a icns file
7080
└── windows
71-
└── projectname.ico # on Windows it has to be a ico file
81+
└── projectname.ico # on Windows it has to be an ico file
7282
```
7383

74-
> Where **projectname** corresponds to `name` property in `pom.xml`.
84+
Where **projectname** corresponds to `name` property in `pom.xml`.
7585

76-
> :warning: If icon is not specified, it will use a default icon for every platform.
86+
> :warning: If `iconFile` property is not specified and it can't find the correct icon in `assets` folder, it will use next icon by default for all platforms:
87+
>
88+
> ![Default icon](https://raw.githubusercontent.com/fvarrui/JavaPackager/master/src/main/resources/linux/default-icon.png)
7789
7890
Execute next command in project's root folder:
7991

@@ -83,11 +95,12 @@ mvn package
8395

8496
By default, it will generate next artifacts in `target ` folder:
8597

86-
- A native application in `app` directory with a bundled JRE.
87-
- A `projectname_projectversion.deb` package file on GNU/Linux.
88-
- A `projectname_projectversion.rpm` package file on GNU/Linux (requires alien && rpmbuild).
89-
- A `projectname_projectversion.exe` installer file on Windows.
90-
- A `projectname_projectversion.dmg` installer file on Mac OS X.
98+
- `app`: directory with the native application.
99+
- `projectname-projectversion-runnable.jar`: runnable JAR file.
100+
- `projectname_projectversion.deb`: DEB package file only on GNU/Linux.
101+
- `projectname_projectversion.rpm`: RPM package file only on GNU/Linux (requires alien && rpmbuild).
102+
- `projectname_projectversion.exe`: installer file only on Windows.
103+
- `projectname_projectversion.dmg`: disk image file only on Mac OS X.
91104

92105
## Contributors
93106

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>fvarrui.maven</groupId>
77
<artifactId>javapackager</artifactId>
8-
<version>0.7.0</version>
8+
<version>0.8.0</version>
99
<packaging>maven-plugin</packaging>
1010

1111
<name>JavaPackager Maven Plugin</name>

src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ public class PackageMojo extends AbstractMojo {
6363
private File appFolder;
6464
private File assetsFolder;
6565
private File jarFile;
66+
private File executable;
6667

6768
// plugin configuration properties
6869
@Parameter(defaultValue = "${project.build.directory}", property = "outputDir", required = true)
@@ -71,15 +72,15 @@ public class PackageMojo extends AbstractMojo {
7172
@Parameter(property = "licenseFile", required = false)
7273
private File licenseFile;
7374

74-
@Parameter(defaultValue = "${project.build.directory}/app/${project.name}", property = "executable", required = true)
75-
private File executable;
76-
7775
@Parameter(property = "iconFile")
7876
private File iconFile;
7977

8078
@Parameter(defaultValue = "${java.version}", property = "jreMinVersion", required = true)
8179
private String jreMinVersion;
8280

81+
@Parameter(defaultValue = "true", property = "generateInstaller", required = true)
82+
private Boolean generateInstaller;
83+
8384
@Parameter(property = "mainClass", required = true)
8485
private String mainClass;
8586

@@ -125,7 +126,7 @@ public PackageMojo() {
125126
}
126127

127128
public void execute() throws MojoExecutionException {
128-
129+
129130
appFolder = new File(outputDirectory, "app");
130131
if (!appFolder.exists()) {
131132
appFolder.mkdirs();
@@ -136,6 +137,8 @@ public void execute() throws MojoExecutionException {
136137
assetsFolder.mkdirs();
137138
}
138139

140+
executable = new File(appFolder, name);
141+
139142
// if default license file doesn't exist and there's a license specified in
140143
// pom.xml file, get this last one
141144
if (licenseFile != null && !licenseFile.exists()) {
@@ -163,7 +166,8 @@ public void execute() throws MojoExecutionException {
163166
FileUtils.copyResourceToFile("/mac/default-icon.icns", iconFile);
164167
}
165168

166-
createMacAppBundle();
169+
createMacApp();
170+
generateDmgImage();
167171

168172
} else if (SystemUtils.IS_OS_LINUX) {
169173

@@ -251,6 +255,8 @@ private Map<String, Object> getInfo() throws MojoExecutionException {
251255
}
252256

253257
private void generateRpmPackage() throws MojoExecutionException {
258+
if (!generateInstaller) return;
259+
254260
getLog().info("Generating RPM package...");
255261

256262
if (!debFile.exists()) {
@@ -284,7 +290,7 @@ private void generateRpmPackage() throws MojoExecutionException {
284290

285291
}
286292

287-
private void createMacAppBundle() throws MojoExecutionException {
293+
private void createMacApp() throws MojoExecutionException {
288294
getLog().info("Creating Mac OS X app bundle...");
289295

290296
// create and set up directories
@@ -342,16 +348,6 @@ private void createMacAppBundle() throws MojoExecutionException {
342348
// codesign app folder
343349
ProcessUtils.execute("codesign", "--force", "--deep", "--sign", "-", appFile);
344350

345-
// create a symlink to Applications folder
346-
File targetFolder = new File("/Applications");
347-
File linkFile = new File(appFolder, "Applications");
348-
FileUtils.createSymlink(linkFile, targetFolder);
349-
350-
// create the DMG file including app folder content
351-
getLog().info("Generating the Disk Image file");
352-
File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg");
353-
ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile);
354-
355351
getLog().info("App Bundle generation finished");
356352

357353
}
@@ -455,6 +451,8 @@ private void createWindowsExecutable() throws MojoExecutionException {
455451
}
456452

457453
private void generateWindowsInstaller() throws MojoExecutionException {
454+
if (!generateInstaller) return;
455+
458456
getLog().info("Generating Windows installer...");
459457

460458
// copy ico file to assets folder
@@ -469,6 +467,8 @@ private void generateWindowsInstaller() throws MojoExecutionException {
469467
}
470468

471469
private void generateDebPackage() throws MojoExecutionException {
470+
if (!generateInstaller) return;
471+
472472
getLog().info("Generating DEB package ...");
473473

474474
// generate desktop file from velocity template
@@ -547,6 +547,22 @@ private void generateDebPackage() throws MojoExecutionException {
547547
),
548548
env);
549549
}
550+
551+
private void generateDmgImage() throws MojoExecutionException {
552+
if (!generateInstaller) return;
553+
554+
getLog().info("Generating DMG disk image file");
555+
556+
// create a symlink to Applications folder
557+
File targetFolder = new File("/Applications");
558+
File linkFile = new File(appFolder, "Applications");
559+
FileUtils.createSymlink(linkFile, targetFolder);
560+
561+
// create the DMG file including app folder content
562+
getLog().info("Generating the Disk Image file");
563+
File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg");
564+
ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile);
565+
}
550566

551567
private void copyAllDependencies(File libsFolder) throws MojoExecutionException {
552568
getLog().info("Copying all dependencies to app folder ...");

0 commit comments

Comments
 (0)