Skip to content

Commit b0f8faa

Browse files
committed
A new assetsDir property
1 parent b0e25e7 commit b0f8faa

File tree

4 files changed

+57
-21
lines changed

4 files changed

+57
-21
lines changed

README.md

Lines changed: 8 additions & 6 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
| `additionalModules` | :x: | `[]` | Additional modules to the ones identified by `jdeps` or the specified with `modules` property. |
8282
| `additionalResources` | :x: | `[]` | Additional files and folders to include in the bundled app. |
8383
| `administratorRequired` | :x: | `false` | App will run as administrator (with elevated privileges). |
84+
| `assetsDir` | :x: | `${basedir}/assets` | Assets location. |
8485
| `bundleJre` | :x: | `false` | Embeds a customized JRE with the app. |
8586
| `copyDependencies` | :x: | `true` | Bundles all dependencies (JAR files) with the app. |
8687
| `createTarball` | :x: | `false` | Bundles app folder in tarball. |
@@ -122,23 +123,23 @@ And by default it will generate next artifacts in `target ` folder:
122123
123124
### Plugin assets
124125

125-
Some assets, such as application icons and Velocity templates, could be placed in `assets` folder organized by platform.
126+
Some assets, such as application icons and Velocity templates, could be placed in `${assetsDir}` folder organized by platform.
126127

127128
```
128129
<project>/
129-
└── assets/
130+
└── ${assetsDir}/
130131
├── linux/
131132
├── mac/
132133
└── windows/
133134
```
134135

135136
#### Icons
136137

137-
If icons are located in `assets` folders, it would not be necessary to specify the `iconFile` property:
138+
If icons are located in `${assetsDir}` folders, it would not be necessary to specify the `iconFile` property:
138139

139140
```
140141
<project>/
141-
└── assets/
142+
└── ${assetsDir}/
142143
├── linux/
143144
│   ├── ${name}.png # on GNU/Linux it has to be a PNG file for DEB package
144145
│   └── ${name}.xpm # and XPM file for RPM package
@@ -159,7 +160,7 @@ It is possible to use your own customized templates. You just have to put one of
159160

160161
```
161162
<project>/
162-
└── assets/
163+
└── ${assetsDir}/
163164
├── linux/
164165
| ├── control.vtl # DEB control template
165166
| ├── desktop.vtl # Desktop template
@@ -170,7 +171,8 @@ It is possible to use your own customized templates. You just have to put one of
170171
│   └── startup.vtl # Startup script template
171172
├── windows/
172173
| ├── exe.manifest.vtl # exe.manifest template
173-
│   └── iss.vtl # Inno Setup Script template
174+
| ├── iss.vtl # Inno Setup Script template
175+
│   └── wxs.vtl # WiX Toolset WXS template
174176
└── assembly.xml.vtl # template for maven-assembly-plugin
175177
```
176178

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,12 @@ public class PackageMojo extends ParentMojo {
226226
*/
227227
@Parameter(defaultValue = "true", property = "useResourcesAsWorkingDir", required = false)
228228
private boolean useResourcesAsWorkingDir;
229+
230+
/**
231+
* Assets directory
232+
*/
233+
@Parameter(defaultValue = "${project.basedir}/assets", property = "assetsDir", required = false)
234+
private File assetsDir;
229235

230236
public void execute() throws MojoExecutionException {
231237

@@ -236,6 +242,7 @@ public void execute() throws MojoExecutionException {
236242
.additionalResources(additionalResources)
237243
.administratorRequired(administratorRequired)
238244
.appVersion(version)
245+
.assetsDir(assetsDir)
239246
.bundleJre(bundleJre)
240247
.copyDependencies(copyDependencies)
241248
.createTarball(createTarball)

src/main/java/io/github/fvarrui/javapackager/packagers/Packager.java

Lines changed: 38 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ public abstract class Packager {
8888
protected Boolean createZipball;
8989
protected Map<String, String> extra;
9090
protected boolean useResourcesAsWorkingDir;
91+
protected File assetsDir;
9192

9293
public File getAppFolder() {
9394
return appFolder;
@@ -241,6 +242,10 @@ public boolean isUseResourcesAsWorkingDir() {
241242
return useResourcesAsWorkingDir;
242243
}
243244

245+
public File getAssetsDir() {
246+
return assetsDir;
247+
}
248+
244249
// fluent api
245250

246251
public Packager env(ExecutionEnvironment env) {
@@ -418,6 +423,11 @@ public Packager appFolder(File appFolder) {
418423
return this;
419424
}
420425

426+
public Packager assetsDir(File assetsDir) {
427+
this.assetsDir = assetsDir;
428+
return this;
429+
}
430+
421431
// ===============================================
422432

423433
public Packager() {
@@ -428,6 +438,9 @@ public Packager() {
428438
private void init() throws MojoExecutionException {
429439

430440
Logger.infoIndent("Initializing packager ...");
441+
442+
// sets assetsDir for velocity to locate custom velocity templates
443+
VelocityUtils.setFileResourceLoaderPath(assetsDir);
431444

432445
// using artifactId as name, if it's not specified
433446
name = defaultIfBlank(name, env.getMavenProject().getArtifactId());
@@ -451,6 +464,14 @@ private void init() throws MojoExecutionException {
451464

452465
doInit();
453466

467+
// removes not necessary platform specific configs
468+
switch (platform) {
469+
case linux: macConfig = null; winConfig = null; break;
470+
case mac: winConfig = null; linuxConfig = null; break;
471+
case windows: linuxConfig = null; macConfig = null; break;
472+
default:
473+
}
474+
454475
Logger.info("Effective packager configuration " + this);
455476

456477
Logger.infoUnindent("Packager initialized!");
@@ -785,7 +806,7 @@ protected File resolveLicense(File licenseFile, List<License> licenses) {
785806
}
786807
// if license is still null, looks for LICENSE file
787808
if (licenseFile == null || !licenseFile.exists()) {
788-
licenseFile = new File("LICENSE");
809+
licenseFile = new File(this.getEnv().getMavenProject().getBasedir(), "LICENSE");
789810
if (!licenseFile.exists()) licenseFile = null;
790811
}
791812

@@ -809,7 +830,7 @@ protected File resolveIcon(File iconFile, String name, File assetsFolder) throws
809830
String iconExtension = IconUtils.getIconFileExtensionByPlatform(platform);
810831

811832
if (iconFile == null) {
812-
iconFile = new File("assets/" + platform + "/", name + iconExtension);
833+
iconFile = new File(assetsDir, platform + "/" + name + iconExtension);
813834
}
814835

815836
if (!iconFile.exists()) {
@@ -950,19 +971,21 @@ public List<File> generateInstallers() throws MojoExecutionException {
950971
@Override
951972
public String toString() {
952973
return "[appFolder=" + appFolder + ", assetsFolder=" + assetsFolder + ", executable=" + executable
953-
+ ", jarFile=" + jarFile + ", outputDirectory=" + outputDirectory + ", licenseFile=" + licenseFile
954-
+ ", iconFile=" + iconFile + ", generateInstaller=" + generateInstaller + ", mainClass=" + mainClass
955-
+ ", name=" + name + ", displayName=" + displayName + ", version=" + version + ", description="
956-
+ description + ", url=" + url + ", administratorRequired=" + administratorRequired
957-
+ ", organizationName=" + organizationName + ", organizationUrl=" + organizationUrl
958-
+ ", organizationEmail=" + organizationEmail + ", bundleJre=" + bundleJre + ", customizedJre="
959-
+ customizedJre + ", jrePath=" + jrePath + ", additionalResources=" + additionalResources + ", modules="
960-
+ modules + ", additionalModules=" + additionalModules + ", platform=" + platform + ", envPath="
961-
+ envPath + ", vmArgs=" + vmArgs + ", runnableJar=" + runnableJar + ", copyDependencies="
962-
+ copyDependencies + ", jreDirectoryName=" + jreDirectoryName + ", winConfig=" + winConfig
963-
+ ", linuxConfig=" + linuxConfig + ", macConfig=" + macConfig + ", createTarball=" + createTarball
964-
+ ", createZipball=" + createZipball + ", extra=" + extra + ", useResourcesAsWorkingDir="
965-
+ useResourcesAsWorkingDir + "]";
974+
+ ", jarFile=" + jarFile + ", executableDestinationFolder=" + executableDestinationFolder
975+
+ ", jarFileDestinationFolder=" + jarFileDestinationFolder + ", jreDestinationFolder="
976+
+ jreDestinationFolder + ", resourcesDestinationFolder=" + resourcesDestinationFolder + ", env=" + env
977+
+ ", outputDirectory=" + outputDirectory + ", licenseFile=" + licenseFile + ", iconFile=" + iconFile
978+
+ ", generateInstaller=" + generateInstaller + ", mainClass=" + mainClass + ", name=" + name
979+
+ ", displayName=" + displayName + ", version=" + version + ", description=" + description + ", url="
980+
+ url + ", administratorRequired=" + administratorRequired + ", organizationName=" + organizationName
981+
+ ", organizationUrl=" + organizationUrl + ", organizationEmail=" + organizationEmail + ", bundleJre="
982+
+ bundleJre + ", customizedJre=" + customizedJre + ", jrePath=" + jrePath + ", additionalResources="
983+
+ additionalResources + ", modules=" + modules + ", additionalModules=" + additionalModules
984+
+ ", platform=" + platform + ", envPath=" + envPath + ", vmArgs=" + vmArgs + ", runnableJar="
985+
+ runnableJar + ", copyDependencies=" + copyDependencies + ", jreDirectoryName=" + jreDirectoryName
986+
+ ", winConfig=" + winConfig + ", linuxConfig=" + linuxConfig + ", macConfig=" + macConfig
987+
+ ", createTarball=" + createTarball + ", createZipball=" + createZipball + ", extra=" + extra
988+
+ ", useResourcesAsWorkingDir=" + useResourcesAsWorkingDir + ", assetsDir=" + assetsDir + "]";
966989
}
967990

968991
protected abstract void doCreateAppStructure() throws MojoExecutionException;

src/main/java/io/github/fvarrui/javapackager/utils/VelocityUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,8 @@ private static String render(String templatePath, Object info) throws MojoExecut
5959
return writer.toString();
6060
}
6161

62+
public static void setFileResourceLoaderPath(File assetsDir) {
63+
velocityEngine.setProperty("file.resource.loader.path", assetsDir.getAbsolutePath());
64+
}
65+
6266
}

0 commit comments

Comments
 (0)