Skip to content

Commit 14d264e

Browse files
committed
U bundle app in zipball and tarball
1 parent b40cbf2 commit 14d264e

File tree

3 files changed

+87
-11
lines changed

3 files changed

+87
-11
lines changed

README.md

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -59,14 +59,17 @@ mvn package
5959

6060
And by default it will generate next artifacts in `target ` folder:
6161

62-
| Artifact | Description |
63-
| --------------------------------- | ------------------------------------------------------------ |
64-
| `${name}` | Directory with the native application and other needed assets. |
65-
| `${name}-${version}-runnable.jar` | Runnable JAR file. |
66-
| `${name}_${version}.deb` | DEB package file if it's executed on GNU/Linux (requires **dpkg-deb**). |
67-
| `${name}_${version}.rpm` | RPM package file if it's executed on GNU/Linux (requires **alien** & **rpmbuild**). |
68-
| `${name}_${version}.exe` | Installer file if it's executed on Windows (requires [**Inno Setup**](http://www.jrsoftware.org/isinfo.php)). |
69-
| `${name}_${version}.dmg` | Disk image file if it's executed on Mac OS X (requires **hdiutil**). |
62+
| Artifact | Description |
63+
| ---------------------------------- | ------------------------------------------------------------ |
64+
| `${name}` | Directory with the native application and other needed assets. |
65+
| `${name}-${version}-runnable.jar` | Runnable JAR file. |
66+
| `${name}_${version}.deb` | DEB package file if it's executed on GNU/Linux (requires **dpkg-deb**). |
67+
| `${name}_${version}.rpm` | RPM package file if it's executed on GNU/Linux (requires **alien** & **rpmbuild**). |
68+
| `${name}_${version}.exe` | Installer file if it's executed on Windows (requires [**Inno Setup**](http://www.jrsoftware.org/isinfo.php)). |
69+
| `${name}_${version}.dmg` | Disk image file if it's executed on Mac OS X (requires **hdiutil**). |
70+
| `${name}-${version}-bundle.zip` | Zipball containing generated directory `${name}` if `createZipball` property is `true`. |
71+
| `${name}-${version}-bundle.tar` | Tarball containing generated directory `${name}` if `createTarball` property is `true`. |
72+
| `${name}-${version}-bundle.tar.gz` | Compressed tarball containing generated directory `${name}` if `createTarball` property is `true`. |
7073

7174
> :warning: DEB, RPM, EXE installer and DMG files will be ommited if `generateInstaller` plugin property is `false` or if target platform is different from execution platform.
7275
@@ -79,6 +82,8 @@ And by default it will generate next artifacts in `target ` folder:
7982
| `administratorRequired` | :x: | `false` | App will run as administrator (with elevated privileges). |
8083
| `bundleJre` | :x: | `false` | Embeds a customized JRE with the app. |
8184
| `copyDependencies` | :x: | `true` | Bundles all dependencies (JAR files) with the app. |
85+
| `createTarball` | :x: | `false` | Bundles app folder in tarball. |
86+
| `createZipball` | :x: | `false` | Bundles app folder in zipball. |
8287
| `customizedJre` | :x: | `true` | Generates a customized JRE, including only identified or specified modules. Otherwise, all modules will be included. |
8388
| `description` | :x: | `${project.description}` or `${displayName}` | Project description. |
8489
| `displayName` | :x: | `${project.name}` or `${name}` | App name to show. |
@@ -165,9 +170,10 @@ It is possible to use your own customized templates. You just have to put one of
165170
├── macosx/
166171
| ├── Info.plist.vtl # Info.plist template
167172
│   └── startup.vtl # Startup script template
168-
└── windows/
169-
├── exe.manifest.vtl # exe.manifest template
170-
└── iss.vtl # Inno Setup Script template
173+
├── windows/
174+
| ├── exe.manifest.vtl # exe.manifest template
175+
│   └── iss.vtl # Inno Setup Script template
176+
└── assembly.xml.vtl # assembly.xml template for maven-assembly-plugin
171177
```
172178
173179
> Use [default templates](https://github.com/fvarrui/JavaPackager/tree/master/src/main/resources) as examples.
@@ -191,6 +197,8 @@ A map called `info` is passed to all templates when they are rendered with next
191197
| `${info.license}` | String | Full path to license file. |
192198
| `${info.envPath}` | String | Same as `envPath` plugin property. |
193199
| `${info.vmArgs}` | String | Same as `vmArgs` plugin property. |
200+
| `${info.createTarball}` | Boolean | Same as `createTarball` plugin property. |
201+
| `${info.createZipball}` | Boolean | Same as `createZipball` plugin property. |
194202
195203
## How to build and install the plugin
196204

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

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -240,6 +240,18 @@ public class PackageMojo extends AbstractMojo {
240240
@Parameter(property = "versionInfo", required = false)
241241
private VersionInfo versionInfo;
242242

243+
/**
244+
* Bundles app in a tarball file
245+
*/
246+
@Parameter(defaultValue = "false", property = "createTarball", required = false)
247+
private Boolean createTarball;
248+
249+
/**
250+
* Bundles app in a zipball file
251+
*/
252+
@Parameter(defaultValue = "false", property = "createZipball", required = false)
253+
private Boolean createZipball;
254+
243255

244256
public PackageMojo() {
245257
super();
@@ -325,6 +337,9 @@ public void execute() throws MojoExecutionException {
325337
default:
326338
throw new MojoExecutionException("Unsupported operating system: " + SystemUtils.OS_NAME + " " + SystemUtils.OS_VERSION + " " + SystemUtils.OS_ARCH);
327339
}
340+
341+
// bundles app in tarball/zipball
342+
createBundle(appFolder);
328343

329344
}
330345

@@ -431,6 +446,8 @@ private Map<String, Object> getInfo() {
431446
info.put("envPath", envPath);
432447
info.put("vmArgs", StringUtils.join(vmArgs, " "));
433448
info.put("jreDirectoryName", jreDirectoryName);
449+
info.put("createTarball", createTarball);
450+
info.put("createZipball", createZipball);
434451
return info;
435452
}
436453

@@ -1008,5 +1025,33 @@ private Platform getCurrentPlatform() {
10081025
if (SystemUtils.IS_OS_MAC_OSX) return Platform.mac;
10091026
return null;
10101027
}
1028+
1029+
/**
1030+
* Bundling app folder in tarball and/or zipball
1031+
* @param appFolder Folder to be bundled
1032+
* @throws MojoExecutionException
1033+
*/
1034+
private void createBundle(File appFolder) throws MojoExecutionException {
1035+
if (!createTarball && !createZipball) return;
1036+
1037+
getLog().info("Bundling app in tarball/zipball ...");
1038+
1039+
// generate assembly.xml file
1040+
File assemblyFile = new File(assetsFolder, "assembly.xml");
1041+
VelocityUtils.render("assembly.xml.vtl", assemblyFile, info);
1042+
1043+
// invokes plugin to copy dependecies to app libs folder
1044+
executeMojo(
1045+
plugin(
1046+
groupId("org.apache.maven.plugins"),
1047+
artifactId("maven-assembly-plugin"),
1048+
version("3.1.1")
1049+
),
1050+
goal("single"),
1051+
configuration(
1052+
element("descriptors", element("descriptor", assemblyFile.getAbsolutePath()))
1053+
),
1054+
env);
1055+
}
10111056

10121057
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<assembly
3+
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.2 http://maven.apache.org/xsd/assembly-1.1.2.xsd">
6+
<id>bundle</id>
7+
<formats>
8+
#if($info.createZipball)
9+
<format>zip</format>
10+
#end
11+
#if($info.createTarball)
12+
<format>tar</format>
13+
<format>tar.gz</format>
14+
#end
15+
</formats>
16+
<includeBaseDirectory>false</includeBaseDirectory>
17+
<fileSets>
18+
<fileSet>
19+
<outputDirectory>${info.name}</outputDirectory>
20+
<directory>${project.build.directory}/${info.name}</directory>
21+
</fileSet>
22+
</fileSets>
23+
</assembly>

0 commit comments

Comments
 (0)