Skip to content

Commit

Permalink
U new config property generateInstaller
Browse files Browse the repository at this point in the history
  • Loading branch information
fvarrui committed May 19, 2019
1 parent 7e15716 commit 7822d0f
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 35 deletions.
49 changes: 31 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Add the following `plugin` tag to your `pom.xml`.
<plugin>
<groupId>fvarrui.maven</groupId>
<artifactId>javapackager</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
<executions>
<execution>
<phase>package</phase>
Expand All @@ -42,6 +42,8 @@ Add the following `plugin` tag to your `pom.xml`.
<param>folder path</param>
<param>...</param>
</additionalResources>
<generateInstaller>true|false</generateInstaller>
[...]
</configuration>
</execution>
</executions>
Expand All @@ -50,15 +52,23 @@ Add the following `plugin` tag to your `pom.xml`.

Where:

| Property | Mandatory | Default value | Description |
| ----------------------- | --------- | ------------- | ----------------------------------------------------------- |
| `mainClass` | Yes | `null` | Full path to your app main class. |
| `bundleJre` | No | `false` | Embed a customized JRE with the app. |
| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. |
| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. |
| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. |

Some assets, like app icons, must be located in:
| Property | Mandatory | Default value | Description |
| ----------------------- | --------- | ------------------------------ | ----------------------------------------------------------- |
| `mainClass` | Yes | `null` | Full path to your app main class. |
| `bundleJre` | No | `false` | Embed a customized JRE with the app. |
| `forceJreOptimization` | No | `false` | If JDK version < 13, it will try to reduce the bundled JRE. |
| `administratorRequired` | No | `false` | If true, app will run with administrator privileges. |
| `additionalResources` | No | [] | Additional files and folders to include in the bundled app. |
| `generateInstaller` | No | `true` | Generate an installer for the app. |
| `displayName` | No | `${project.name}` | App name to show. |
| `iconFile` | No | `null` | Path to the app icon file (PNG, ICO or ICNS). |
| `licenseFile` | No | `${project.licenses[0].url}` | Path to project license file. |
| `url` | No | `null` | App website URL. |
| `organizationName` | No | `${project.organization.name}` | Organization name. |
| `organizationUrl` | No | `${project.organization.url}` | Organization website URL. |
| `organizationEmail` | No | `null` | Organization email. |

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:

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

> Where **projectname** corresponds to `name` property in `pom.xml`.
Where **projectname** corresponds to `name` property in `pom.xml`.

> :warning: If icon is not specified, it will use a default icon for every platform.
> :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:
>
> ![Default icon](https://raw.githubusercontent.com/fvarrui/JavaPackager/master/src/main/resources/linux/default-icon.png)
Execute next command in project's root folder:

Expand All @@ -83,11 +95,12 @@ mvn package

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

- A native application in `app` directory with a bundled JRE.
- A `projectname_projectversion.deb` package file on GNU/Linux.
- A `projectname_projectversion.rpm` package file on GNU/Linux (requires alien && rpmbuild).
- A `projectname_projectversion.exe` installer file on Windows.
- A `projectname_projectversion.dmg` installer file on Mac OS X.
- `app`: directory with the native application.
- `projectname-projectversion-runnable.jar`: runnable JAR file.
- `projectname_projectversion.deb`: DEB package file only on GNU/Linux.
- `projectname_projectversion.rpm`: RPM package file only on GNU/Linux (requires alien && rpmbuild).
- `projectname_projectversion.exe`: installer file only on Windows.
- `projectname_projectversion.dmg`: disk image file only on Mac OS X.

## Contributors

Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

<groupId>fvarrui.maven</groupId>
<artifactId>javapackager</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
<packaging>maven-plugin</packaging>

<name>JavaPackager Maven Plugin</name>
Expand Down
48 changes: 32 additions & 16 deletions src/main/java/fvarrui/maven/plugin/javapackager/PackageMojo.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ public class PackageMojo extends AbstractMojo {
private File appFolder;
private File assetsFolder;
private File jarFile;
private File executable;

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

@Parameter(defaultValue = "${project.build.directory}/app/${project.name}", property = "executable", required = true)
private File executable;

@Parameter(property = "iconFile")
private File iconFile;

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

@Parameter(defaultValue = "true", property = "generateInstaller", required = true)
private Boolean generateInstaller;

@Parameter(property = "mainClass", required = true)
private String mainClass;

Expand Down Expand Up @@ -125,7 +126,7 @@ public PackageMojo() {
}

public void execute() throws MojoExecutionException {

appFolder = new File(outputDirectory, "app");
if (!appFolder.exists()) {
appFolder.mkdirs();
Expand All @@ -136,6 +137,8 @@ public void execute() throws MojoExecutionException {
assetsFolder.mkdirs();
}

executable = new File(appFolder, name);

// if default license file doesn't exist and there's a license specified in
// pom.xml file, get this last one
if (licenseFile != null && !licenseFile.exists()) {
Expand Down Expand Up @@ -163,7 +166,8 @@ public void execute() throws MojoExecutionException {
FileUtils.copyResourceToFile("/mac/default-icon.icns", iconFile);
}

createMacAppBundle();
createMacApp();
generateDmgImage();

} else if (SystemUtils.IS_OS_LINUX) {

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

private void generateRpmPackage() throws MojoExecutionException {
if (!generateInstaller) return;

getLog().info("Generating RPM package...");

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

}

private void createMacAppBundle() throws MojoExecutionException {
private void createMacApp() throws MojoExecutionException {
getLog().info("Creating Mac OS X app bundle...");

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

// create a symlink to Applications folder
File targetFolder = new File("/Applications");
File linkFile = new File(appFolder, "Applications");
FileUtils.createSymlink(linkFile, targetFolder);

// create the DMG file including app folder content
getLog().info("Generating the Disk Image file");
File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg");
ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile);

getLog().info("App Bundle generation finished");

}
Expand Down Expand Up @@ -455,6 +451,8 @@ private void createWindowsExecutable() throws MojoExecutionException {
}

private void generateWindowsInstaller() throws MojoExecutionException {
if (!generateInstaller) return;

getLog().info("Generating Windows installer...");

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

private void generateDebPackage() throws MojoExecutionException {
if (!generateInstaller) return;

getLog().info("Generating DEB package ...");

// generate desktop file from velocity template
Expand Down Expand Up @@ -547,6 +547,22 @@ private void generateDebPackage() throws MojoExecutionException {
),
env);
}

private void generateDmgImage() throws MojoExecutionException {
if (!generateInstaller) return;

getLog().info("Generating DMG disk image file");

// create a symlink to Applications folder
File targetFolder = new File("/Applications");
File linkFile = new File(appFolder, "Applications");
FileUtils.createSymlink(linkFile, targetFolder);

// create the DMG file including app folder content
getLog().info("Generating the Disk Image file");
File diskImageFile = new File(outputDirectory, name + "_" + version + ".dmg");
ProcessUtils.execute("hdiutil", "create", "-srcfolder", appFolder, "-volname", name, diskImageFile);
}

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

0 comments on commit 7822d0f

Please sign in to comment.