Skip to content

Commit 1115861

Browse files
committed
U added new additionalManifestEntries property
1 parent 0636f4b commit 1115861

File tree

6 files changed

+96
-45
lines changed

6 files changed

+96
-45
lines changed

README.md

Lines changed: 37 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -134,42 +134,43 @@ By default it will generate next artifacts in `${outputDirectory} ` folder:
134134
135135
### Plugin configutation properties
136136

137-
| Property | Mandatory | Default value | Description |
138-
| -------------------------- | ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
139-
| `additionalModules` | :x: | `[]` | Additional modules to the ones identified by `jdeps` or the specified with `modules` property. |
140-
| `additionalResources` | :x: | `[]` | Additional files and folders to include in the bundled app. |
141-
| `administratorRequired` | :x: | `false` | App will run as administrator (with elevated privileges). |
142-
| `assetsDir` | :x: | `${basedir}/assets` or `${projectdir}/assets` | Assets location (icons and custom Velocity templates). |
143-
| `bundleJre` | :x: | `false` | Embeds a customized JRE with the app. |
144-
| `classpath` | :x: | `null` | List of additional paths to JVM classpath, separated with `;` (recommended) or `:`. |
145-
| `copyDependencies` | :x: | `true` | Bundles all dependencies (JAR files) with the app. |
146-
| `createTarball` | :x: | `false` | Bundles app folder in tarball. |
147-
| `createZipball` | :x: | `false` | Bundles app folder in zipball. |
148-
| `customizedJre` | :x: | `true` | Generates a customized JRE, including only identified or specified modules. Otherwise, all modules will be included. |
149-
| `description` | :x: | `${project.description}` or `${displayName}` | Project description. |
150-
| `displayName` | :x: | `${project.name}` or `${name}` | App name to show. |
151-
| `envPath` | :x: | `null` | Defines PATH environment variable in GNU/Linux and Mac OS X startup scripts. |
152-
| `extra` | :x: | `null` | Map with extra properties to be used in customized Velocity templates, accesible through `$info.extra` variable. |
153-
| `generateInstaller` | :x: | `true` | Generates an installer for the app. |
154-
| `iconFile` | :x: | `null` | Path to the app icon file (PNG, XPM, ICO or ICNS). **:warning: Deprecated (see platform specific properties).** |
155-
| `jdkPath` | :x: | `${java.home}` | JDK used to generate a customized JRE. It allows to bundle customized JREs for different platforms. |
156-
| `jreDirectoryName` | :x: | `"jre"` | Bundled JRE directory name. |
157-
| `jreMinVersion` | :x: | `null` | JRE minimum version. If an appropriate version cannot be found display error message. Disabled if a JRE is bundled. |
158-
| `jrePath` | :x: | `""` | Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
159-
| `licenseFile` | :x: | `${project.licenses[0].url}` or `${basedir}/LICENSE` or `${projectdir}/LICENSE` | Path to project license file. |
160-
| `mainClass` | :heavy_check_mark: | `${exec.mainClass}` | Full path to your app main class. |
161-
| `modules` | :x: | `[]` | Defines modules to customize the bundled JRE. Don't use `jdeps` to get module dependencies. |
162-
| `name` | :x: | `${project.name}` or `${project.artifactId}` | App name. |
163-
| `organizationName` | :x: | `${project.organization.name}` or `"ACME"` | Organization name. |
164-
| `organizationUrl` | :x: | `${project.organization.url}` | Organization website URL. |
165-
| `organizationEmail` | :x: | `null` | Organization email. |
166-
| `outputDirectory` | :x: | `${project.build.directory}` or `${project.builddir}` | Output directory (where the artifacts will be generated). |
167-
| `platform` | :x: | `auto` | Defines the target platform, which could be different to the execution platform. Possible values: `auto`, `mac`, `linux`, `windows`. Use `auto` for using execution platform as target. |
168-
| `runnableJar` | :x: | `null` | Defines your own JAR file to be bundled. If it's ommited, the plugin packages your code in a runnable JAR and bundle it with the app. |
169-
| `url` | :x: | `null` | App website URL. |
170-
| `useResourcesAsWorkingDir` | :x: | `true` | Uses app resources folder as default working directory (always `true` on Mac OS). |
171-
| ` version` | :x: | `${project.version}` | Project version. |
172-
| `vmArgs` | :x: | `[]` | Adds VM arguments. |
137+
| Property | Mandatory | Default value | Description |
138+
| --------------------------- | ------------------ | ------------------------------------------------------------ | ------------------------------------------------------------ |
139+
| `additionalManifestEntries` | :x: | `null` | Map with additional entries to be used in the manifest file of the generated runnable JAR. |
140+
| `additionalModules` | :x: | `[]` | Additional modules to the ones identified by `jdeps` or the specified with `modules` property. |
141+
| `additionalResources` | :x: | `[]` | Additional files and folders to include in the bundled app. |
142+
| `administratorRequired` | :x: | `false` | App will run as administrator (with elevated privileges). |
143+
| `assetsDir` | :x: | `${basedir}/assets` or `${projectdir}/assets` | Assets location (icons and custom Velocity templates). |
144+
| `bundleJre` | :x: | `false` | Embeds a customized JRE with the app. |
145+
| `classpath` | :x: | `null` | List of additional paths to JVM classpath, separated with `;` (recommended) or `:`. |
146+
| `copyDependencies` | :x: | `true` | Bundles all dependencies (JAR files) with the app. |
147+
| `createTarball` | :x: | `false` | Bundles app folder in tarball. |
148+
| `createZipball` | :x: | `false` | Bundles app folder in zipball. |
149+
| `customizedJre` | :x: | `true` | Generates a customized JRE, including only identified or specified modules. Otherwise, all modules will be included. |
150+
| `description` | :x: | `${project.description}` or `${displayName}` | Project description. |
151+
| `displayName` | :x: | `${project.name}` or `${name}` | App name to show. |
152+
| `envPath` | :x: | `null` | Defines PATH environment variable in GNU/Linux and Mac OS X startup scripts. |
153+
| `extra` | :x: | `null` | Map with extra properties to be used in customized Velocity templates, accesible through `$info.extra` variable. |
154+
| `generateInstaller` | :x: | `true` | Generates an installer for the app. |
155+
| `iconFile` | :x: | `null` | Path to the app icon file (PNG, XPM, ICO or ICNS). **:warning: Deprecated (see platform specific properties).** |
156+
| `jdkPath` | :x: | `${java.home}` | JDK used to generate a customized JRE. It allows to bundle customized JREs for different platforms. |
157+
| `jreDirectoryName` | :x: | `"jre"` | Bundled JRE directory name. |
158+
| `jreMinVersion` | :x: | `null` | JRE minimum version. If an appropriate version cannot be found display error message. Disabled if a JRE is bundled. |
159+
| `jrePath` | :x: | `""` | Path to JRE folder. If specified, it will bundle this JRE with the app, and won't generate a customized JRE. For Java 8 version or least. |
160+
| `licenseFile` | :x: | `${project.licenses[0].url}` or `${basedir}/LICENSE` or `${projectdir}/LICENSE` | Path to project license file. |
161+
| `mainClass` | :heavy_check_mark: | `${exec.mainClass}` | Full path to your app main class. |
162+
| `modules` | :x: | `[]` | Defines modules to customize the bundled JRE. Don't use `jdeps` to get module dependencies. |
163+
| `name` | :x: | `${project.name}` or `${project.artifactId}` | App name. |
164+
| `organizationName` | :x: | `${project.organization.name}` or `"ACME"` | Organization name. |
165+
| `organizationUrl` | :x: | `${project.organization.url}` | Organization website URL. |
166+
| `organizationEmail` | :x: | `null` | Organization email. |
167+
| `outputDirectory` | :x: | `${project.build.directory}` or `${project.builddir}` | Output directory (where the artifacts will be generated). |
168+
| `platform` | :x: | `auto` | Defines the target platform, which could be different to the execution platform. Possible values: `auto`, `mac`, `linux`, `windows`. Use `auto` for using execution platform as target. |
169+
| `runnableJar` | :x: | `null` | Defines your own JAR file to be bundled. If it's ommited, the plugin packages your code in a runnable JAR and bundle it with the app. |
170+
| `url` | :x: | `null` | App website URL. |
171+
| `useResourcesAsWorkingDir` | :x: | `true` | Uses app resources folder as default working directory (always `true` on Mac OS). |
172+
| ` version` | :x: | `${project.version}` | Project version. |
173+
| `vmArgs` | :x: | `[]` | Adds VM arguments. |
173174

174175
> Some default values depends on the used building tool.
175176

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.util.ArrayList;
55
import java.util.Arrays;
66
import java.util.List;
7+
import java.util.Map;
78
import java.util.stream.Collectors;
89

910
import org.apache.commons.lang3.StringUtils;
@@ -33,6 +34,7 @@ public File apply(Packager packager) {
3334
File outputDirectory = packager.getOutputDirectory();
3435
Project project = Context.getGradleContext().getProject();
3536
File libsFolder = packager.getLibsFolder();
37+
Map<String, String> additionalManifestEntries = packager.getAdditionalManifestEntries();
3638

3739
List<String> dependencies = new ArrayList<>();
3840
if (libsFolder != null && libsFolder.exists()) {
@@ -46,6 +48,9 @@ public File apply(Packager packager) {
4648
jarTask.setProperty("destinationDirectory", outputDirectory);
4749
jarTask.getManifest().getAttributes().put("Main-Class", mainClass);
4850
jarTask.getManifest().getAttributes().put("Class-Path", StringUtils.join(dependencies, " "));
51+
for (String key : additionalManifestEntries.keySet()) {
52+
jarTask.getManifest().getAttributes().put(key, additionalManifestEntries.get(key));
53+
}
4954
jarTask.getActions().forEach(action -> action.execute(jarTask));
5055

5156
return jarTask.getArchiveFile().get().getAsFile();

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -485,6 +485,18 @@ public void setJreMinVersion(String jreMinVersion) {
485485
this.jreMinVersion = jreMinVersion;
486486
}
487487

488+
@Input
489+
@Optional
490+
private Map<String, String> additionalManifestEntries;
491+
492+
public Map<String, String> getAdditionalManifestEntries() {
493+
return additionalManifestEntries;
494+
}
495+
496+
public void setAdditionalManifestEntries(Map<String, String> additionalManifestEntries) {
497+
this.additionalManifestEntries = additionalManifestEntries;
498+
}
499+
488500
// ===============
489501
// create packager
490502
// ===============
@@ -498,6 +510,7 @@ protected Packager createPackager() throws Exception {
498510
return
499511
(Packager) PackagerFactory
500512
.createPackager(defaultIfNull(platform, extension.getPlatform()))
513+
.additionalManifestEntries(defaultIfNull(additionalManifestEntries, extension.getAdditionalManifestEntries()))
501514
.additionalModules(defaultIfNull(additionalModules, extension.getAdditionalModules()))
502515
.additionalResources(defaultIfNull(additionalResources, extension.getAdditionalResources()))
503516
.administratorRequired(defaultIfNull(administratorRequired, extension.getAdministratorRequired()))

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

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import static org.twdata.maven.mojoexecutor.MojoExecutor.version;
1111

1212
import java.io.File;
13+
import java.util.ArrayList;
14+
import java.util.List;
15+
import java.util.Map;
1316

1417
import org.apache.maven.plugin.MojoExecutionException;
18+
import org.twdata.maven.mojoexecutor.MojoExecutor.Element;
1519
import org.twdata.maven.mojoexecutor.MojoExecutor.ExecutionEnvironment;
1620

1721
import io.github.fvarrui.javapackager.packagers.Context;
@@ -37,8 +41,24 @@ public File apply(Packager packager) {
3741
String mainClass = packager.getMainClass();
3842
File outputDirectory = packager.getOutputDirectory();
3943
ExecutionEnvironment env = Context.getMavenContext().getEnv();
44+
Map<String, String> additionalManifestEntries = packager.getAdditionalManifestEntries();
4045

4146
File jarFile = new File(outputDirectory, name + "-" + version + "-" + classifier + ".jar");
47+
48+
List<Element> archive = new ArrayList<>();
49+
archive.add(
50+
element("manifest",
51+
element("addClasspath", "true"),
52+
element("classpathPrefix", "libs/"),
53+
element("mainClass", mainClass)
54+
));
55+
if (additionalManifestEntries != null && !additionalManifestEntries.isEmpty()) {
56+
List<Element> manifestEntries = new ArrayList<>();
57+
for (String key : additionalManifestEntries.keySet()) {
58+
manifestEntries.add(element(key, additionalManifestEntries.get(key)));
59+
}
60+
archive.add(element("manifestEntries", manifestEntries.toArray(new Element[manifestEntries.size()])));
61+
}
4262

4363
try {
4464

@@ -51,13 +71,7 @@ public File apply(Packager packager) {
5171
goal("jar"),
5272
configuration(
5373
element("classifier", classifier),
54-
element("archive",
55-
element("manifest",
56-
element("addClasspath", "true"),
57-
element("classpathPrefix", "libs/"),
58-
element("mainClass", mainClass)
59-
)
60-
),
74+
element("archive", archive.toArray(new Element[archive.size()])),
6175
element("outputDirectory", jarFile.getParentFile().getAbsolutePath()),
6276
element("finalName", name + "-" + version)
6377
),

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

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ public class PackageMojo extends AbstractMojo {
246246
/**
247247
* Extra properties for customized Velocity templates, accesible through '$this.extra' map.
248248
*/
249-
@Parameter(property = "extra", required = false)
249+
@Parameter(required = false)
250250
private Map<String, String> extra;
251251

252252
/**
@@ -272,6 +272,12 @@ public class PackageMojo extends AbstractMojo {
272272
*/
273273
@Parameter(property = "jreMinVersion", required = false)
274274
private String jreMinVersion;
275+
276+
/**
277+
* Additional JAR manifest entries
278+
*/
279+
@Parameter(required = false)
280+
private Map<String, String> additionalManifestEntries;
275281

276282
public void execute() throws MojoExecutionException {
277283

@@ -287,6 +293,7 @@ public void execute() throws MojoExecutionException {
287293
Packager packager =
288294
(Packager) PackagerFactory
289295
.createPackager(platform)
296+
.additionalManifestEntries(additionalManifestEntries)
290297
.additionalModules(additionalModules)
291298
.additionalResources(additionalResources)
292299
.administratorRequired(administratorRequired)

0 commit comments

Comments
 (0)