Skip to content

Commit f68adae

Browse files
committed
Merge branch 'issue-297' into devel
2 parents 7e8a402 + 9c3de46 commit f68adae

File tree

7 files changed

+115
-22
lines changed

7 files changed

+115
-22
lines changed

src/main/java/io/github/fvarrui/javapackager/gradle/PackageTask.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import io.github.fvarrui.javapackager.model.Manifest;
2222
import io.github.fvarrui.javapackager.model.Platform;
2323
import io.github.fvarrui.javapackager.model.Scripts;
24+
import io.github.fvarrui.javapackager.model.Template;
2425
import io.github.fvarrui.javapackager.model.WindowsConfig;
2526
import io.github.fvarrui.javapackager.packagers.Context;
2627
import io.github.fvarrui.javapackager.packagers.Packager;
@@ -572,6 +573,18 @@ public Arch getArch() {
572573
public void setArch(Arch arch) {
573574
this.arch = arch;
574575
}
576+
577+
@Input
578+
@Optional
579+
private List<Template> templates;
580+
581+
public List<Template> getTemplates() {
582+
return templates;
583+
}
584+
585+
public void setTemplates(List<Template> templates) {
586+
this.templates = templates;
587+
}
575588

576589
// ===============
577590
// create packager
@@ -623,6 +636,7 @@ protected Packager createPackager() throws Exception {
623636
.packagingJdk(defaultIfNull(packagingJdk, extension.getPackagingJdk(), Context.getGradleContext().getDefaultToolchain()))
624637
.runnableJar(defaultIfNull(runnableJar, extension.getRunnableJar()))
625638
.scripts(defaultIfNull(scripts, extension.getScripts()))
639+
.templates(defaultIfNull(templates, extension.getTemplates()))
626640
.useResourcesAsWorkingDir(defaultIfNull(useResourcesAsWorkingDir, extension.isUseResourcesAsWorkingDir()))
627641
.url(defaultIfNull(url, extension.getUrl()))
628642
.version(defaultIfNull(version, extension.getVersion(), getProject().getVersion().toString()))

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -321,6 +321,12 @@ public class PackageMojo extends AbstractMojo {
321321
*/
322322
@Parameter(property = "arch", required = false)
323323
private Arch arch;
324+
325+
/**
326+
* Templates configuration
327+
*/
328+
@Parameter(property = "templates", required = false)
329+
private List<Template> templates;
324330

325331
public void execute() throws MojoExecutionException {
326332

@@ -376,6 +382,7 @@ public void execute() throws MojoExecutionException {
376382
.packagingJdk(packagingJdk)
377383
.runnableJar(runnableJar)
378384
.scripts(scripts)
385+
.templates(templates)
379386
.useResourcesAsWorkingDir(useResourcesAsWorkingDir)
380387
.url(url)
381388
.version(version)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package io.github.fvarrui.javapackager.model;
2+
3+
public class Template {
4+
5+
private String name;
6+
private boolean bom = false;
7+
8+
public Template() {}
9+
10+
public Template(String name, boolean bom) {
11+
this.name = name;
12+
this.bom = bom;
13+
}
14+
15+
public String getName() {
16+
return name;
17+
}
18+
19+
public void setName(String name) {
20+
this.name = name;
21+
}
22+
23+
public boolean isBom() {
24+
return bom;
25+
}
26+
27+
public void setBom(boolean bom) {
28+
this.bom = bom;
29+
}
30+
31+
@Override
32+
public String toString() {
33+
return "Template [name=" + name + ", bom=" + bom + "]";
34+
}
35+
36+
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected File doApply(WindowsPackager packager) throws Exception {
4747

4848
// generates iss file from velocity template
4949
File issFile = new File(assetsFolder, name + ".iss");
50-
VelocityUtils.render("windows/iss.vtl", issFile, packager, true);
50+
VelocityUtils.render("windows/iss.vtl", issFile, packager);
5151

5252
// generates windows installer with inno setup command line compiler
5353
CommandUtils.execute("iscc", "/O" + outputDirectory.getAbsolutePath(), "/F" + name + "_" + version, issFile);

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,8 @@ private void init() throws Exception {
101101
throw new Exception("'mainClass' cannot be null");
102102
}
103103

104-
// sets assetsDir for velocity to locate custom velocity templates
105-
VelocityUtils.setAssetsDir(assetsDir);
104+
// init velocity utils
105+
VelocityUtils.init(this);
106106

107107
// using name as displayName, if it's not specified
108108
displayName = defaultIfBlank(displayName, name);

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

Lines changed: 32 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import io.github.fvarrui.javapackager.model.Manifest;
1616
import io.github.fvarrui.javapackager.model.Platform;
1717
import io.github.fvarrui.javapackager.model.Scripts;
18+
import io.github.fvarrui.javapackager.model.Template;
1819
import io.github.fvarrui.javapackager.model.WindowsConfig;
1920

2021
/**
@@ -68,6 +69,7 @@ public class PackagerSettings {
6869
protected File packagingJdk;
6970
protected Scripts scripts;
7071
protected Arch arch;
72+
protected List<Template> templates;
7173

7274
/**
7375
* Get packaging JDK
@@ -412,6 +414,14 @@ public List<FileAssociation> getFileAssociations() {
412414
public Scripts getScripts() {
413415
return scripts;
414416
}
417+
418+
/**
419+
* Get templates
420+
* @return Templates config list
421+
*/
422+
public List<Template> getTemplates() {
423+
return templates;
424+
}
415425

416426
// fluent api
417427

@@ -862,6 +872,17 @@ public PackagerSettings scripts(Scripts scripts) {
862872
this.scripts = scripts;
863873
return this;
864874
}
875+
876+
/**
877+
* Set templates config
878+
* @param templates Templates list config
879+
* @return Packager settings
880+
*/
881+
public PackagerSettings templates(List<Template> templates) {
882+
this.templates = templates;
883+
return this;
884+
}
885+
865886

866887
// some helpful methods
867888

@@ -893,21 +914,23 @@ public PackagerSettings arch(Arch arch) {
893914

894915
@Override
895916
public String toString() {
896-
return "PackagerSettings [" + "outputDirectory=" + outputDirectory + ", " + "licenseFile=" + licenseFile + ", "
897-
+ "iconFile=" + iconFile + ", " + "generateInstaller=" + generateInstaller + ", " + "forceInstaller="
898-
+ forceInstaller + ", " + "mainClass=" + mainClass + ", name=" + name + ", displayName=" + displayName
899-
+ ", version=" + version + ", description=" + description + ", url=" + url + ", administratorRequired="
917+
return "PackagerSettings [outputDirectory=" + outputDirectory + ", licenseFile=" + licenseFile + ", iconFile="
918+
+ iconFile + ", generateInstaller=" + generateInstaller + ", forceInstaller=" + forceInstaller
919+
+ ", mainClass=" + mainClass + ", name=" + name + ", displayName=" + displayName + ", version="
920+
+ version + ", description=" + description + ", url=" + url + ", administratorRequired="
900921
+ administratorRequired + ", organizationName=" + organizationName + ", organizationUrl="
901922
+ organizationUrl + ", organizationEmail=" + organizationEmail + ", bundleJre=" + bundleJre
902923
+ ", customizedJre=" + customizedJre + ", jrePath=" + jrePath + ", jdkPath=" + jdkPath
903924
+ ", additionalResources=" + additionalResources + ", modules=" + modules + ", additionalModules="
904925
+ additionalModules + ", platform=" + platform + ", envPath=" + envPath + ", vmArgs=" + vmArgs
905926
+ ", runnableJar=" + runnableJar + ", copyDependencies=" + copyDependencies + ", jreDirectoryName="
906927
+ jreDirectoryName + ", winConfig=" + winConfig + ", linuxConfig=" + linuxConfig + ", macConfig="
907-
+ macConfig + ", createTarball=" + createTarball + ", createZipball=" + createZipball + ", extra="
908-
+ extra + ", useResourcesAsWorkingDir=" + useResourcesAsWorkingDir + ", assetsDir=" + assetsDir
909-
+ ", classpath=" + classpath + ", jreMinVersion=" + jreMinVersion + ", manifest=" + manifest
910-
+ ", additionalModulePaths=" + additionalModulePaths + ", fileAssociations=" + fileAssociations
911-
+ ", packagingJdk=" + packagingJdk + ", scripts=" + scripts + ", arch=" + arch + "]";
928+
+ macConfig + ", createTarball=" + createTarball + ", tarballName=" + tarballName + ", createZipball="
929+
+ createZipball + ", zipballName=" + zipballName + ", extra=" + extra + ", useResourcesAsWorkingDir="
930+
+ useResourcesAsWorkingDir + ", assetsDir=" + assetsDir + ", classpath=" + classpath
931+
+ ", jreMinVersion=" + jreMinVersion + ", manifest=" + manifest + ", additionalModulePaths="
932+
+ additionalModulePaths + ", fileAssociations=" + fileAssociations + ", packagingJdk=" + packagingJdk
933+
+ ", scripts=" + scripts + ", arch=" + arch + ", templates=" + templates + "]";
912934
}
935+
913936
}

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

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import java.io.File;
66
import java.util.ArrayList;
7+
import java.util.List;
8+
import java.util.Optional;
79
import java.util.UUID;
810

911
import org.apache.velocity.Template;
@@ -14,13 +16,27 @@
1416
import org.apache.velocity.runtime.resource.loader.FileResourceLoader;
1517
import org.apache.velocity.util.StringBuilderWriter;
1618

19+
import io.github.fvarrui.javapackager.packagers.Packager;
20+
1721
/**
1822
* Velocity utils
1923
*/
2024
public class VelocityUtils {
2125

2226
private static File assetsDir = new File("assets");
2327
private static VelocityEngine velocityEngine = null;
28+
private static List<io.github.fvarrui.javapackager.model.Template> templates;
29+
30+
private VelocityUtils() {}
31+
32+
public static void init(Packager packager) {
33+
assetsDir = packager.getAssetsDir();
34+
templates = packager.getTemplates() != null ? packager.getTemplates() : new ArrayList<>();
35+
// add default template configs
36+
if (templates.stream().noneMatch(t -> t.getName().equals("windows/iss.vtl"))) {
37+
templates.add(new io.github.fvarrui.javapackager.model.Template("windows/iss.vtl", true));
38+
}
39+
}
2440

2541
private static VelocityEngine getVelocityEngine() {
2642

@@ -56,16 +72,8 @@ private static String render(String templatePath, Object info) throws Exception
5672
template.merge(context, writer);
5773
return writer.toString();
5874
}
59-
60-
public static void setAssetsDir(File assetsDir) {
61-
VelocityUtils.assetsDir = assetsDir;
62-
}
63-
64-
public static void render(String templatePath, File output, Object info) throws Exception {
65-
render(templatePath, output, info, false);
66-
}
6775

68-
public static void render(String templatePath, File output, Object info, boolean includeBom) throws Exception {
76+
private static void render(String templatePath, File output, Object info, boolean includeBom) throws Exception {
6977
String data = render(templatePath, info);
7078
data = StringUtils.dosToUnix(data);
7179
if (!includeBom) {
@@ -74,5 +82,10 @@ public static void render(String templatePath, File output, Object info, boolean
7482
FileUtils.writeStringToFileWithBOM(output, data);
7583
}
7684
}
77-
85+
86+
public static void render(String templatePath, File output, Object info) throws Exception {
87+
Optional<io.github.fvarrui.javapackager.model.Template> template = templates.stream().filter(t -> t.getName().equals(templatePath)).findFirst();
88+
render(templatePath, output, info, template.isPresent() ? template.get().isBom() : false);
89+
}
90+
7891
}

0 commit comments

Comments
 (0)