Skip to content

Commit b911a68

Browse files
committed
v0.8.8
1 parent 5f7f642 commit b911a68

File tree

7 files changed

+98
-21
lines changed

7 files changed

+98
-21
lines changed

README.md

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -103,17 +103,29 @@ And by default it will generate next artifacts in `target ` folder:
103103
104104
### Plugin assets
105105

106-
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:
106+
Some assets, such as application icons and Velocity templates, could be located in `assets` folder organized by platform.
107107

108108
```
109-
<project>
110-
└── assets
111-
├── linux
109+
<project>/
110+
└── assets/
111+
├── linux/
112+
├── macosx/
113+
└── windows/
114+
```
115+
116+
#### Icons
117+
118+
If icons are located in `assets` folders, it would not be necessary to specify the `iconFile` property:
119+
120+
```
121+
<project>/
122+
└── assets/
123+
├── linux/
112124
│   └── projectname.png # on GNU/Linux it has to be a png image
113-
├── macosx
125+
├── macosx/
114126
│   └── projectname.icns # on Mac OS X it has to be a icns file
115-
└── windows
116-
└── projectname.ico # on Windows it has to be an ico file
127+
└── windows/
128+
└── projectname.ico # on Windows it has to be a ico file
117129
```
118130

119131
> **projectname** corresponds to `name` property in `pom.xml`.
@@ -122,6 +134,48 @@ Some assets, such as application icons, could be located in `assets` folder orga
122134
>
123135
> ![Default icon](https://raw.githubusercontent.com/fvarrui/JavaPackager/master/src/main/resources/linux/default-icon.png)
124136
137+
#### Velocity templates
138+
139+
Velocity templates (.vtl files) are used to generate some artifacts which have to be bundled with the app.
140+
141+
It is possible to use our own customized templates. We only have to put all or some of the next templates in the `assets` folder organized by platform, and the plugin will use these templates instead of default ones:
142+
143+
```
144+
<project>/
145+
└── assets/
146+
├── linux/
147+
| ├── control.vtl # DEB control template
148+
| ├── desktop.vtl # Desktop template
149+
│   └── startup.sh.vtl # Startup script template
150+
├── macosx/
151+
| ├── Info.plist.vtl # Info.plist template
152+
│   └── startup.vtl # Startup script template
153+
└── windows/
154+
├── exe.manifest.vtl # exe.manifest template
155+
└── iss.vtl # Inno Setup Script template
156+
```
157+
158+
You can use the [default templates](https://github.com/fvarrui/JavaPackager/tree/master/src/main/resources) as an example.
159+
160+
A map called `info` is given to all templates when they are rendered, which contains next properties:
161+
162+
| Property | Type | Description |
163+
| ------------------------------- | ------- | ------------------------------------------------ |
164+
| `${info.name}` | String | Same as `name` plugin property. |
165+
| `${displayName}` | String | Same as `displayName` plugin property. |
166+
| `${info.version}` | String | Same as `version` plugin property. |
167+
| `${info.description}` | String | Same as `description` plugin property. |
168+
| `${info.url}` | String | Same as `url` plugin property. |
169+
| `${info.organizationName}` | String | Same as `organizationName` plugin property. |
170+
| `${info.organizationUrl}` | String | Same as `organizationUrl` plugin property. |
171+
| `${info.organizationEmail}` | String | Same as `organizationEmail` plugin property. |
172+
| `${info.administratorRequired}` | Boolean | Same as `administratorRequired` plugin property. |
173+
| `${info.bundleJre}` | Boolean | Same as `bundleJre` plugin property. |
174+
| `${info.jarFile}` | String | Full path to runnable JAR file. |
175+
| `${info.license}` | String | Full path to license file. |
176+
| `${info.envPath}` | String | Same as `envPath` plugin property. |
177+
| `${info.vmArgs}` | String | Same as `vmArgs` plugin property. |
178+
125179
## How to build and install the plugin
126180

127181
Execute next commands in BASH (GNU/Linux or macOS) or CMD (Windows):
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#NOTE: This is a Maven Resolver internal implementation file, its format can be changed without prior notice.
2-
#Thu Jan 16 12:38:57 WET 2020
2+
#Thu Jan 16 14:22:12 WET 2020
33
javapackager-0.8.8.jar>=
44
javapackager-0.8.8.pom>=
Binary file not shown.

releases/fvarrui/maven/javapackager/maven-metadata-local.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,6 @@
1919
<version>0.8.7</version>
2020
<version>0.8.8</version>
2121
</versions>
22-
<lastUpdated>20200116123857</lastUpdated>
22+
<lastUpdated>20200116142212</lastUpdated>
2323
</versioning>
2424
</metadata>

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

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import org.twdata.maven.mojoexecutor.MojoExecutor.ExecutionEnvironment;
3636

3737
import fvarrui.maven.plugin.javapackager.utils.FileUtils;
38+
import fvarrui.maven.plugin.javapackager.utils.IconUtils;
3839
import fvarrui.maven.plugin.javapackager.utils.JavaUtils;
3940
import fvarrui.maven.plugin.javapackager.utils.Logger;
4041
import fvarrui.maven.plugin.javapackager.utils.CommandUtils;
@@ -207,6 +208,9 @@ public void execute() throws MojoExecutionException {
207208

208209
// locates license file
209210
resolveLicense();
211+
212+
// locates icon file
213+
resolveIcon();
210214

211215
// creates a runnable jar file
212216
if (runnableJar == null || runnableJar.isBlank()) {
@@ -260,12 +264,10 @@ private void resolveLicense() {
260264
* Locates assets or default icon file if the specified one doesn't exist or
261265
* isn't specified
262266
*
263-
* @param platform Target platform
264-
* @param iconExtension Icon file extension (.ico for Windows, .png for
265-
* GNU/Linux, .icns for MacOS)
266267
* @throws MojoExecutionException
267268
*/
268-
private void resolveIcon(Platform platform, String iconExtension) throws MojoExecutionException {
269+
private void resolveIcon() throws MojoExecutionException {
270+
String iconExtension = IconUtils.getIconFileExtensionByPlatform(platform);
269271
if (iconFile == null) {
270272
iconFile = new File("assets/" + platform + "/", mavenProject.getName() + iconExtension);
271273
}
@@ -424,7 +426,6 @@ private void createMacApp() throws MojoExecutionException {
424426

425427
// determines icon file location and copies it to resources folder
426428
getLog().info("Copying icon file to Resources folder");
427-
resolveIcon(Platform.mac, ".icns");
428429
FileUtils.copyFileToFolder(iconFile.getAbsoluteFile(), resourcesFolder);
429430

430431
// creates and write the Info.plist file
@@ -452,7 +453,6 @@ private void createLinuxApp() throws MojoExecutionException {
452453
getLog().info("Creating GNU/Linux app bundle...");
453454

454455
// determines icon file location and copies it to app folder
455-
resolveIcon(Platform.linux, ".png");
456456
FileUtils.copyFileToFolder(iconFile, appFolder);
457457

458458
// copies all dependencies
@@ -489,9 +489,6 @@ private void createLinuxApp() throws MojoExecutionException {
489489
private void createWindowsApp() throws MojoExecutionException {
490490
getLog().info("Creating Windows app bundle...");
491491

492-
// determines icon file location
493-
resolveIcon(Platform.windows, ".ico");
494-
495492
// generates manifest file to require administrator privileges from velocity template
496493
File manifestFile = new File(assetsFolder, name + ".exe.manifest");
497494
VelocityUtils.render("windows/exe.manifest.vtl", manifestFile, info);
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package fvarrui.maven.plugin.javapackager.utils;
2+
3+
import fvarrui.maven.plugin.javapackager.Platform;
4+
5+
public class IconUtils {
6+
7+
public static String getIconFileExtensionByPlatform(Platform platform) {
8+
switch (platform) {
9+
case linux: return ".png";
10+
case mac: return ".icns";
11+
case windows: return ".ico";
12+
default: return null;
13+
}
14+
}
15+
16+
}

src/main/java/fvarrui/maven/plugin/javapackager/utils/VelocityUtils.java

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,31 @@
1111
import org.apache.velocity.app.VelocityEngine;
1212
import org.apache.velocity.runtime.RuntimeConstants;
1313
import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
14+
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
1415

1516
public class VelocityUtils {
1617

1718
private static VelocityEngine velocityEngine;
1819

1920
static {
2021
velocityEngine = new VelocityEngine();
21-
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "classpath");
22-
velocityEngine.setProperty("classpath.resource.loader.class", ClasspathResourceLoader.class.getName());
22+
23+
// specify resource loaders to use
24+
velocityEngine.setProperty(RuntimeConstants.RESOURCE_LOADER, "file,class");
25+
26+
// for the loader 'file', set the FileResourceLoader as the class to use and use 'assets' directory for templates
27+
velocityEngine.setProperty("file.resource.loader.class", FileResourceLoader.class.getName());
28+
velocityEngine.setProperty("file.resource.loader.path", "assets");
29+
30+
// for the loader 'class', set the ClasspathResourceLoader as the class to use
31+
velocityEngine.setProperty("class.resource.loader.class", ClasspathResourceLoader.class.getName());
32+
2333
velocityEngine.init();
2434
}
2535

2636
public static void render(String templatePath, File output, Map<String, Object> info) throws MojoExecutionException {
2737
try {
28-
38+
2939
VelocityContext context = new VelocityContext();
3040
context.put("info", info);
3141

0 commit comments

Comments
 (0)