Skip to content

Commit 019de79

Browse files
committed
Merge branch 'devel'
2 parents 15330cc + 1a672bb commit 019de79

16 files changed

+187
-57
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JavaPackager
22

3-
[![Maven Central](http://img.shields.io/maven-central/v/io.github.fvarrui/javapackager)](https://central.sonatype.com/artifact/io.github.fvarrui/javapackager/1.7.3)
3+
[![Maven Central](http://img.shields.io/maven-central/v/io.github.fvarrui/javapackager)](https://central.sonatype.com/search?smo=true&q=a%3Ajavapackager+g%3Aio.github.fvarrui)
44
[![GPL-3.0](https://img.shields.io/badge/license-GPL--3.0-%250778B9.svg)](https://www.gnu.org/licenses/gpl-3.0.html)
55

66
JavaPackager is a hybrid plugin for **Maven** and **Gradle** which provides an easy way to package Java applications in native Windows, MacOS or GNU/Linux executables, and generate installers for them.

build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ dependencies {
4646
implementation 'org.apache.commons:commons-compress:1.21'
4747
implementation 'org.apache.velocity:velocity-engine-core:2.3'
4848
implementation 'org.vafer:jdeb:1.9'
49-
implementation 'net.jsign:jsign-core:3.1'
49+
implementation 'net.jsign:jsign-core:5.0'
5050
implementation 'org.redline-rpm:redline:1.2.10'
5151
implementation 'edu.sc.seis.launch4j:launch4j:2.5.2'
5252

@@ -64,7 +64,7 @@ dependencies {
6464
}
6565

6666
group = 'io.github.fvarrui'
67-
version = '1.7.3'
67+
version = '1.7.4'
6868
description = 'Hybrid Maven/Gradle plugin to package Java applications as native Windows, Mac OS X or GNU/Linux executables and create installers for them'
6969

7070
sourceCompatibility = JavaVersion.VERSION_1_8

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

+14
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/CreateRunnableJar.java

+16-5
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@ protected File doApply(Packager packager) {
4545
File outputDirectory = packager.getOutputDirectory();
4646
ExecutionEnvironment env = Context.getMavenContext().getEnv();
4747
Manifest manifest = packager.getManifest();
48-
String artifactId = env.getMavenProject().getArtifactId();
49-
File jarFile = new File(outputDirectory, artifactId + "-" + classifier + ".jar");
5048

5149
List<Element> archive = new ArrayList<>();
5250
archive.add(
@@ -99,9 +97,22 @@ protected File doApply(Packager packager) {
9997

10098
}
10199

102-
File finalJarFile = new File(outputDirectory, name + "-" + version + "-" + classifier + ".jar");
103-
FileUtils.rename(jarFile, finalJarFile.getName());
104-
return finalJarFile;
100+
// gets build.finalName value
101+
String finalName = Context.getMavenContext().getEnv().getMavenProject().getBuild().getFinalName();
102+
103+
// creates file pointing to generated jar file
104+
File finalJarFile = new File(outputDirectory, finalName + "-" + classifier + ".jar");
105+
106+
// creates desired output jar file
107+
File jarFile = new File(outputDirectory, name + "-" + version + "-" + classifier + ".jar");
108+
109+
// renames generated jar to desired one if they are different
110+
if (!finalJarFile.equals(jarFile)) {
111+
FileUtils.rename(finalJarFile, jarFile.getName());
112+
}
113+
114+
return jarFile;
115+
105116
}
106117

107118
}

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

+7
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)

src/main/java/io/github/fvarrui/javapackager/model/LinuxConfig.java

+14-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import java.util.Arrays;
66
import java.util.List;
77

8+
import org.apache.commons.lang3.ObjectUtils;
9+
810
import io.github.fvarrui.javapackager.packagers.Packager;
911

1012
/**
@@ -19,6 +21,7 @@ public class LinuxConfig implements Serializable {
1921
private boolean generateAppImage = true;
2022
private File pngFile;
2123
private boolean wrapJar = true;
24+
private File installationPath;
2225

2326
public void setCategories(List<String> categories) {
2427
this.categories = categories;
@@ -67,11 +70,20 @@ public boolean isWrapJar() {
6770
public void setWrapJar(boolean wrapJar) {
6871
this.wrapJar = wrapJar;
6972
}
73+
74+
public File getInstallationPath() {
75+
return installationPath;
76+
}
77+
78+
public void setInstallationPath(File installationPath) {
79+
this.installationPath = installationPath;
80+
}
7081

7182
@Override
7283
public String toString() {
7384
return "LinuxConfig [categories=" + categories + ", generateDeb=" + generateDeb + ", generateRpm=" + generateRpm
74-
+ ", generateAppImage=" + generateAppImage + ", pngFile=" + pngFile + ", wrapJar=" + wrapJar + "]";
85+
+ ", generateAppImage=" + generateAppImage + ", pngFile=" + pngFile + ", wrapJar=" + wrapJar
86+
+ ", installationPath=" + installationPath + "]";
7587
}
7688

7789
/**
@@ -81,6 +93,7 @@ public String toString() {
8193
*/
8294
public void setDefaults(Packager packager) {
8395
this.setCategories((categories == null || categories.isEmpty()) ? Arrays.asList("Utility") : categories);
96+
this.setInstallationPath(ObjectUtils.defaultIfNull(installationPath, new File("/opt")));
8497
}
8598

8699
}
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/GenerateDeb.java

+8-6
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ protected File doApply(LinuxPackager packager) throws Exception {
6464
File executable = packager.getExecutable();
6565
File javaFile = new File(appFolder, jreDirectoryName + "/bin/java");
6666
File mimeXmlFile = packager.getMimeXmlFile();
67+
File installationPath = packager.getLinuxConfig().getInstallationPath();
68+
File appPath = new File(installationPath, name);
6769

6870
// generates desktop file from velocity template
6971
File desktopFile = new File(assetsFolder, name + ".desktop");
@@ -87,7 +89,7 @@ protected File doApply(LinuxPackager packager) throws Exception {
8789

8890
Mapper appFolderMapper = new Mapper();
8991
appFolderMapper.setType("perm");
90-
appFolderMapper.setPrefix("/opt/" + name);
92+
appFolderMapper.setPrefix(appPath.getAbsolutePath());
9193
appFolderMapper.setFileMode("644");
9294

9395
Data appFolderData = new Data();
@@ -102,12 +104,12 @@ protected File doApply(LinuxPackager packager) throws Exception {
102104

103105
Mapper executableMapper = new Mapper();
104106
executableMapper.setType("perm");
105-
executableMapper.setPrefix("/opt/" + name);
107+
executableMapper.setPrefix(appPath.getAbsolutePath());
106108
executableMapper.setFileMode("755");
107109

108110
Data executableData = new Data();
109111
executableData.setType("file");
110-
executableData.setSrc(new File(appFolder.getAbsolutePath() + "/" + name));
112+
executableData.setSrc(executable);
111113
executableData.addMapper(executableMapper);
112114

113115
dataProducers.add(executableData);
@@ -150,7 +152,7 @@ protected File doApply(LinuxPackager packager) throws Exception {
150152
Mapper javaBinaryMapper = new Mapper();
151153
javaBinaryMapper.setType("perm");
152154
javaBinaryMapper.setFileMode("755");
153-
javaBinaryMapper.setPrefix("/opt/" + name + "/" + jreDirectoryName + "/bin");
155+
javaBinaryMapper.setPrefix(appPath + "/" + jreDirectoryName + "/bin");
154156

155157
Data javaBinaryData = new Data();
156158
javaBinaryData.setType("file");
@@ -168,7 +170,7 @@ protected File doApply(LinuxPackager packager) throws Exception {
168170
Mapper javaSpawnHelperMapper = new Mapper();
169171
javaSpawnHelperMapper.setType("perm");
170172
javaSpawnHelperMapper.setFileMode("755");
171-
javaSpawnHelperMapper.setPrefix("/opt/" + name + "/" + jreDirectoryName + "/lib");
173+
javaSpawnHelperMapper.setPrefix(appPath + "/" + jreDirectoryName + "/lib");
172174

173175
Data javaSpawnHelperData = new Data();
174176
javaSpawnHelperData.setType("file");
@@ -182,7 +184,7 @@ protected File doApply(LinuxPackager packager) throws Exception {
182184

183185
// symbolic link in /usr/local/bin to app binary data producer
184186

185-
DataProducer linkData = createLink("/usr/local/bin/" + name, "/opt/" + name + "/" + name);
187+
DataProducer linkData = createLink("/usr/local/bin/" + executable.getName(), appPath + "/" + executable.getName());
186188

187189
dataProducers.add(linkData);
188190

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

+9-4
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@ protected File doApply(LinuxPackager packager) throws Exception {
4444
String jreDirectoryName = packager.getJreDirectoryName();
4545
Architecture arch = Architecture.valueOf(packager.getArch().getRpm());
4646
File mimeXmlFile = packager.getMimeXmlFile();
47+
File installationPath = packager.getLinuxConfig().getInstallationPath();
48+
File appPath = new File(installationPath, name);
4749

4850
// generates desktop file from velocity template
4951
File desktopFile = new File(assetsFolder, name + ".desktop");
5052
VelocityUtils.render("linux/desktop.vtl", desktopFile, packager);
51-
Logger.info("Rendering desktop file to " + desktopFile.getAbsolutePath());
53+
Logger.info("Desktop file rendered in " + desktopFile.getAbsolutePath());
5254

5355
// copies desktop file to app
5456
FileUtils.copyFileToFolder(desktopFile, appFolder);
@@ -68,17 +70,20 @@ protected File doApply(LinuxPackager packager) throws Exception {
6870
executionPermissions.add(new File(appFolder, jreDirectoryName + "/bin/java"));
6971
executionPermissions.add(new File(appFolder, jreDirectoryName + "/lib/jspawnhelper"));
7072

73+
// add all app files
74+
addDirectory(builder, installationPath.getAbsolutePath(), appFolder, executionPermissions);
75+
7176
// link to desktop file
72-
addLink(builder, "/usr/share/applications/" + desktopFile.getName(), "/opt/" + name + "/" + desktopFile.getName());
77+
addLink(builder, "/usr/share/applications/" + desktopFile.getName(), appPath + "/" + desktopFile.getName());
7378

7479
// copy and link to mime.xml file
7580
if (mimeXmlFile != null) {
7681
FileUtils.copyFileToFolder(mimeXmlFile, appFolder);
77-
addLink(builder, "/usr/share/mime/packages/" + mimeXmlFile.getName(), "/opt/" + name + "/" + mimeXmlFile.getName());
82+
addLink(builder, "/usr/share/mime/packages/" + mimeXmlFile.getName(), appPath + "/" + mimeXmlFile.getName());
7883
}
7984

8085
// link to binary
81-
addLink(builder, "/usr/local/bin/" + executable.getName(), "/opt/" + name + "/" + executable.getName());
86+
addLink(builder, "/usr/local/bin/" + executable.getName(), appPath + "/" + executable.getName());
8287

8388
// add all app files
8489
addDirectory(builder, "/opt", appFolder, executionPermissions);

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

+1-1
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/MacPackager.java

+5
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ public class MacPackager extends Packager {
3434
private File javaFolder;
3535
private File macOSFolder;
3636
private File jreBundleFolder;
37+
38+
public MacPackager() {
39+
super();
40+
platform(Platform.mac);
41+
}
3742

3843
public File getAppFile() {
3944
return appFile;

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

+11-16
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);
@@ -205,26 +205,21 @@ public void resolveResources() throws Exception {
205205
* @param resources List of files and folders to be copied
206206
* @param destination Destination folder. All specified resources will be copied
207207
* here
208+
* @throws Exception
208209
*/
209-
protected void copyAdditionalResources(List<File> resources, File destination) {
210+
protected void copyAdditionalResources(List<File> resources, File destination) throws Exception {
210211

211212
Logger.infoIndent("Copying additional resources");
212213

213-
resources.stream().forEach(r -> {
214+
for (File r : resources) {
214215
if (!r.exists()) {
215-
Logger.warn("Additional resource " + r + " doesn't exist");
216-
return;
216+
throw new Exception("Additional resource " + r + " doesn't exist");
217+
} else if (r.isDirectory()) {
218+
FileUtils.copyFolderToFolder(r, destination);
219+
} else if (r.isFile()) {
220+
FileUtils.copyFileToFolder(r, destination);
217221
}
218-
try {
219-
if (r.isDirectory()) {
220-
FileUtils.copyFolderToFolder(r, destination);
221-
} else if (r.isFile()) {
222-
FileUtils.copyFileToFolder(r, destination);
223-
}
224-
} catch (Exception e) {
225-
Logger.error(e.getMessage(), e);
226-
}
227-
});
222+
}
228223

229224
// copy bootstrap script
230225
if (FileUtils.exists(getScripts().getBootstrap())) {

0 commit comments

Comments
 (0)