Skip to content

Commit a175fe9

Browse files
committed
fixed bugs with product output naming, bumped version to 0.0.11
1 parent e095094 commit a175fe9

File tree

5 files changed

+81
-69
lines changed

5 files changed

+81
-69
lines changed

README.md

Lines changed: 29 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#gradle-onejar
22
[![Maintainer Status](http://stillmaintained.com/akhikhl/gradle-onejar.png)](http://stillmaintained.com/akhikhl/gradle-onejar)
33
[![Build Status](https://travis-ci.org/akhikhl/gradle-onejar.png?branch=master)](https://travis-ci.org/akhikhl/gradle-onejar)
4-
[![Latest Version](http://img.shields.io/badge/latest_version-0.0.10-blue.svg)](https://github.com/akhikhl/gradle-onejar/tree/v0.0.10)
4+
[![Latest Version](http://img.shields.io/badge/latest_version-0.0.11-blue.svg)](https://github.com/akhikhl/gradle-onejar/tree/v0.0.11)
55
[![License](http://img.shields.io/badge/license-MIT-ff69b4.svg)](#copyright-and-license)
66

77
Gradle plugin for generating single jar for JVM-based application.
@@ -47,7 +47,7 @@ with name:
4747
"build/output/${project.name}-${project.version}/${project.name}.jar".
4848

4949
Alternatively, you can download the script from https://raw.github.com/akhikhl/gradle-onejar/master/pluginScripts/gradle-onejar.plugin
50-
to the project folder and include it like this:
50+
to the project directory and include it like this:
5151

5252
```groovy
5353
apply from: 'gradle-onejar.plugin'
@@ -86,7 +86,7 @@ for more information.
8686

8787
###copyExplodedResources task
8888

89-
The task copyExplodedResources copies additional files to the folder "${project.projectDir}/build/output",
89+
The task copyExplodedResources copies additional files to the directory "${project.projectDir}/build/output",
9090
so that these files get packed by task productArchive.
9191

9292
###run task
@@ -119,7 +119,7 @@ onejar {
119119
manifest {
120120
attributes attrName1: attrValue1 [, ...]
121121
}
122-
product name: 'productName', platform: ..., arch: ..., language: ..., suffix: ..., launchers: [ ... ]
122+
product name: 'productName', suffix: ..., platform: ..., arch: ..., language: ..., fileSuffix: ..., launchers: [ ... ], configBaseName: ..., explodedResource: [...], explodedResources: [...]
123123
archiveProducts true|false
124124
additionalProductFiles ... [, ...]
125125
excludeProductFile ... [, ...]
@@ -146,24 +146,38 @@ When omitted, gradle-onejar does not alter onejar manifest.
146146

147147
**product** - optional, multiplicity 0..N, hashmap, accepting the following properties:
148148

149-
- **name** - required, string, denotes the name of the product.
149+
- **name** - optional, string, denotes the name of the product. When omitted, project name is used.
150+
151+
- **suffix** - optional, string, denotes the suffix to be added to the generated files/directorys.
150152

151153
- **platform** - optional, string, denotes the target platform. Possible values are "windows" and "linux".
152-
When omitted, the product is platform-neutral.
153-
When equals to "windows", default launcher is ".bat" and target archive format is ".zip".
154-
When equals to "linux", default launcher is ".sh" and target archive format is ".tag.gz".
154+
- When omitted, the product is platform-neutral.
155+
- When specified, the value is appended to the name of generated directory/file name.
156+
- When equals to "windows", default launcher is ".bat" and target archive format is ".zip".
157+
- When equals to "linux", default launcher is ".sh" and target archive format is ".tag.gz".
155158

156-
- **arch** - optional, string, denotes the target architecture. Does not affect product generation (yet).
159+
- **arch** - optional, string, denotes the target architecture.
160+
- When specified, the value is appended to the name of generated directory/file name.
157161

158-
- **language** - optional, string, denotes the target language. When specified, the value is added
159-
to JVM parameters in launcher scripts in the form -Duser.language=$language.
162+
- **language** - optional, string, denotes the target language.
163+
- When specified, the value is added to JVM parameters in launcher scripts in the form -Duser.language=$language.
164+
- When specified, the value is appended to the name of generated directory/file name.
160165

161-
- **suffix** - optional, string, denotes the suffix to be added to the generated files/folders.
166+
- **fileSuffix** - optional, string denotes the suffix to be appended to the name of generated directory/file name.
167+
When omitted, default fileSuffix is appended: "-${suffix}-${platform}-${arch}-${language}".
162168

163169
- **launchers** - optional, array, contains one or more strings "windows", "shell".
164-
When omitted, launchers are defined by the selected platform.
165-
When equals to "windows", the product is supplied with ".bat" launcher.
166-
When equals to "shell", the product is supplied with ".sh" launcher.
170+
- When omitted, launchers are defined by the selected platform.
171+
- When equals to "windows", the product is supplied with ".bat" launcher.
172+
- When equals to "shell", the product is supplied with ".sh" launcher.
173+
174+
- **configBaseName** - optional, string, denotes base for gradle configuration name.
175+
The effective configuration name is calculated as "product_${configBaseName}_${product.suffix}_${platform}_${arch}_${language}"
176+
- When omitted, product name is used as configBaseName instead.
177+
178+
- **explodedResource(s)** - optional string or array of strings. When specified, should denote relative file paths
179+
to the resources that are to be copied to product directory/archive without compression to jar.
180+
The paths are relative to the project directory.
167181

168182
**archiveProducts** - optional, boolean. When true, gradle-onejar packs the generated product to ".zip" or ".tar.gz" archive -
169183
depending on the specified platform. If platform is not specified, target format is ".tar.gz".

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ buildscript {
1111

1212
ext {
1313
group = 'org.akhikhl.gradle-onejar'
14-
version = '0.0.10'
14+
version = '0.0.11'
1515
groovy_version = '2.2.2'
1616
spock_version = '0.7-groovy-2.0'
1717
}

examples/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ apply plugin: 'base' // add "clean" task to the root project.
1414

1515
ext {
1616
group = 'org.akhikhl.gradle-onejar'
17-
version = '0.0.10'
17+
version = '0.0.11'
1818
groovy_version = '2.2.2'
1919
logback_version = '1.1.1'
2020
}

examples/onejarMultiConfig/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ ext {
2222

2323
onejar {
2424
manifest { attributes 'Built-By': 'Some user' }
25-
product 'v2_3'
26-
product name: 'v2_4', launchers: [ 'shell', 'windows' ]
25+
product suffix: 'v2_3'
26+
product suffix: 'v2_4', launchers: [ 'shell', 'windows' ]
2727
jvmMinMemory '512m'
2828
jvmMaxMemory '1024m'
2929
}

libs/gradle-onejar/src/main/groovy/org/akhikhl/gradle/onejar/ProductConfigurator.groovy

Lines changed: 48 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -10,22 +10,26 @@ package org.akhikhl.gradle.onejar
1010
import org.gradle.api.Project
1111
import org.gradle.api.artifacts.Configuration
1212
import org.gradle.api.tasks.bundling.*
13+
import org.slf4j.Logger
14+
import org.slf4j.LoggerFactory
1315

1416
class ProductConfigurator {
1517

18+
private static final Logger log = LoggerFactory.getLogger(ProductConfigurator)
19+
1620
private final Project project
1721
private final Map product
1822
private final String platform
1923
private final String arch
2024
private final String language
21-
private final String productName
22-
private final String productTaskSuffix
23-
private final Configuration productConfig
24-
private final Configuration providedConfig
25+
private final String productBaseFileName
26+
private final String productQualifiedFileName
2527
private final String outputBaseDir
2628
private final String outputDir
27-
private final String baseName
2829
private final String destFile
30+
private final String productTaskSuffix
31+
private final Configuration productConfig
32+
private final Configuration providedConfig
2933
private final File mainJar
3034
private final List launchers
3135
private final String versionFileName
@@ -37,39 +41,31 @@ class ProductConfigurator {
3741
platform = product.platform
3842
arch = product.arch
3943
language = product.language
40-
String productConfigName
41-
if(product.name) {
42-
productName = product.name
43-
productConfigName = 'product_' + product.name
44-
}
45-
else {
46-
String productName = project.name + '-' + project.version
47-
if(product.suffix)
48-
productName += '-' + product.suffix
49-
else {
50-
if(platform)
51-
productName += '-' + platform
52-
if(arch)
53-
productName += '-' + arch
54-
if(language)
55-
productName += '-' + language
56-
}
57-
this.productName = productName
58-
productConfigName = 'product'
59-
if(platform)
60-
productConfigName += '_' + platform
61-
if(arch)
62-
productConfigName += '_' + arch
63-
if(language)
64-
productConfigName += '_' + language
65-
}
44+
45+
productBaseFileName = product.name ?: project.name
46+
47+
String productFileSuffix
48+
if(product.fileSuffix)
49+
productFileSuffix = product.fileSuffix
50+
else
51+
productFileSuffix = [ product.suffix, platform, arch, language ].findResults { it ?: null }.join('-')
52+
53+
productQualifiedFileName = [productBaseFileName, project.version, productFileSuffix].findResults { it ?: null }.join('-')
54+
55+
outputBaseDir = "${project.buildDir}/output"
56+
outputDir = "${outputBaseDir}/${productQualifiedFileName}"
57+
log.debug 'outputDir={}', outputDir
58+
59+
destFile = "${outputDir}/${productBaseFileName}.jar"
60+
61+
productTaskSuffix = [ product.name, product.suffix, platform, arch, language ].findResults { it ?: null }.join('_')
62+
63+
String productConfigName = [ 'product', product.configBaseName ?: product.name ?: '', product.suffix, platform, arch, language ].findResults { it ?: null }.join('_')
64+
log.debug 'product config: {}', productConfigName
6665
productConfig = project.configurations.findByName(productConfigName)
66+
6767
providedConfig = project.configurations.findByName('provided')
68-
this.productTaskSuffix = productConfigName
69-
outputBaseDir = "${project.buildDir}/output"
70-
outputDir = "${outputBaseDir}/${productName}"
71-
baseName = "${project.name}"
72-
destFile = "${outputDir}/${baseName}.jar"
68+
7369
mainJar = ProjectUtils.getMainJar(project)
7470
if(product.launchers)
7571
launchers = product.launchers
@@ -124,15 +120,17 @@ class ProductConfigurator {
124120
def archiveType = launchers.contains('windows') ? Zip : Tar
125121

126122
project.task("archive_${productTaskSuffix}", type: archiveType) {
127-
from new File(outputDir)
128-
into productName
123+
124+
archiveName = productQualifiedFileName + (archiveType == Tar ? '.tar.gz' : '.zip')
129125
destinationDir = new File(outputBaseDir)
130-
if(archiveType == Tar) {
131-
extension = 'tar.gz'
126+
if(archiveType == Tar)
132127
compression = Compression.GZIP
133-
}
128+
129+
from new File(outputDir), { into productBaseFileName }
130+
134131
doLast {
135-
ant.checksum file: it.archivePath
132+
project.logger.warn 'Created archive: {}', archivePath
133+
ant.checksum file: archivePath
136134
}
137135
dependsOn "build_${productTaskSuffix}"
138136
project.tasks.build.dependsOn it
@@ -152,10 +150,10 @@ class ProductConfigurator {
152150
outputs.file destFile
153151

154152
if(launchers.contains('shell'))
155-
outputs.file(new File("${outputDir}/${baseName}.sh"))
153+
outputs.file(new File("${outputDir}/${productBaseFileName}.sh"))
156154

157155
if(launchers.contains('windows'))
158-
outputs.file(new File("${outputDir}/${baseName}.bat"))
156+
outputs.file(new File("${outputDir}/${productBaseFileName}.bat"))
159157

160158
outputs.file versionFileName
161159

@@ -205,7 +203,7 @@ class ProductConfigurator {
205203
obj(product, outputDir)
206204
}
207205

208-
project.logger.info 'Created one-jar: {}', destFile
206+
project.logger.warn 'Created one-jar: {}', destFile
209207
} // doLast
210208

211209
task.dependsOn project.tasks.assemble, project.tasks.check
@@ -263,12 +261,12 @@ class ProductConfigurator {
263261

264262
def params = []
265263
addCommonParams(params)
266-
params.add('-jar ${DIR}/' + baseName + '.jar')
264+
params.add('-jar ${DIR}/' + productBaseFileName + '.jar')
267265
params.addAll(project.onejar.launchParameters)
268266
params.add('"$@"')
269267
params = params.join(' ')
270268

271-
def launchScriptFile = new File("${outputDir}/${baseName}.sh")
269+
def launchScriptFile = new File("${outputDir}/${productBaseFileName}.sh")
272270
launchScriptFile.text = '''#!/bin/bash
273271
SOURCE="${BASH_SOURCE[0]}"
274272
while [ -h "$SOURCE" ]; do # resolve $SOURCE until the file is no longer a symlink
@@ -285,19 +283,19 @@ java ''' + params
285283

286284
def params = []
287285
addCommonParams(params)
288-
params.add('-jar %~dp0\\' + baseName + '.jar')
286+
params.add('-jar %~dp0\\' + productBaseFileName + '.jar')
289287
params.addAll(project.onejar.launchParameters)
290288
params.add('%*')
291289
params = params.join(' ')
292290

293-
def launchScriptFile = new File("${outputDir}/${baseName}.bat")
291+
def launchScriptFile = new File("${outputDir}/${productBaseFileName}.bat")
294292
launchScriptFile.text = '@java ' + params
295293
}
296294
}
297295

298296
private void generateVersionFile() {
299297
new File(versionFileName).text = """\
300-
product: ${productName}
298+
product: ${productBaseFileName}
301299
version: ${project.version}
302300
platform: ${platform ?: 'any'}
303301
architecture: ${arch ?: 'any'}

0 commit comments

Comments
 (0)