forked from hivemq/mqtt-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
522 lines (423 loc) · 15.9 KB
/
build.gradle
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
buildscript {
repositories {
mavenCentral()
mavenLocal()
}
dependencies {
classpath 'biz.aQute.bnd:biz.aQute.bnd.gradle:4.2.0'
}
}
plugins {
id 'java'
id 'idea'
id 'application'
id 'com.github.johnrengelman.shadow' version '4.0.4' apply false
id "com.github.hierynomus.license" version "0.15.0"
id 'org.gradle.crypto.checksum' version '1.1.0'
id "nebula.ospackage" version "7.1.0"
id 'edu.sc.seis.launch4j' version '2.4.6'
id 'com.palantir.graal' version '0.6.0'
id 'de.thetaphi.forbiddenapis' version '2.6' apply false
id "com.github.breadmoirai.github-release" version "2.2.9"
id 'org.ajoberstar.git-publish' version '2.1.1'
}
apply plugin: 'de.thetaphi.forbiddenapis'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'com.palantir.graal'
/****************
* Project Settings *
***************/
javadoc.options.encoding = 'UTF-8'
group = 'com.hivemq'
version = '1.2.0' + (Boolean.valueOf(System.getProperty("snapshot")) ? "-SNAPSHOT" : "")
description = 'MQTT CLI is a tool that provides a feature rich command line interface for connecting, ' +
'publishing, subscribing, unsubscribing and disconnecting ' +
'various MQTT clients simultaneously and supports MQTT 5.0 and MQTT 3.1.1 '
application {
mainClassName = 'com.hivemq.cli.MqttCLIMain'
}
idea {
module {
generatedSourceDirs += file('build/generated/sources/annotationProcessor/java/main')
}
}
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
repositories {
mavenCentral()
jcenter()
}
/****************
* Metadata *
***************/
ext {
moduleName = 'com.hivemq.cli'
readableName = 'mqtt-cli'
appName = 'MQTT CLI'
githubOrg = 'hivemq'
githubRepo = 'mqtt-cli'
githubUrl = 'https://github.com/' + githubOrg + '/' + githubRepo
scmConnection = 'scm:git:git://github.com/' + githubOrg + '/' + githubRepo + '.git'
scmDeveloperConnection = 'scm:git:ssh://[email protected]/' + githubOrg + '/' + githubRepo + '.git'
issuesUrl = githubUrl + '/issues'
docUrl = 'https://' + githubOrg + '.github.io/' + githubRepo + '/'
prevVersion = ''
appJarName = "${readableName}.jar"
appExe = "${readableName}.exe"
// Directories
iconsDir = "${projectDir}/icons"
resDir = "${projectDir}/res"
dmgDir = "${projectDir}/dmg"
pkgDir = "${projectDir}/packages"
brewDir = "${pkgDir}/homebrew"
debDir = "${pkgDir}/debian"
rpmDir = "${pkgDir}/rpm"
winDir = "${pkgDir}/windows"
buildLaunch4j = "$buildDir/launch4j"
buildPkgDir = "${buildDir}/packages"
buildBrewDir = "${buildPkgDir}/homebrew"
buildDebDir = "${buildPkgDir}/debian"
buildRpmDir = "${buildPkgDir}/rpm"
buildWinDir = "${buildPkgDir}/windows"
// Icons
hmqIco = "${iconsDir}/05-mqtt-cli-icon.ico"
hmqLogo = "${iconsDir}/05-mqtt-cli-icon.png"
// Vendor details
copyright = "Copyright 2019 HiveMQ and the HiveMQ Community"
vendor = "HiveMQ GmbH"
website = "https://www.hivemq.com/"
license = "${projectDir}/LICENSE"
// Dependency versions
picoclishell3Version = '4.0.4'
picocliVersion = '4.0.4'
jline3Version = '3.12.1'
jline3JansiVersion = '3.12.1'
daggerVersion = '2.21'
guavaVersion ='27.0.1-jre'
hivemqclientVersion = '1.1.3'
tinylogVersion = '2.0.1'
jcToolsVersion = '2.1.2'
jetbrainsAnnotationsVersion = '17.0.0'
bouncycastleVersion='1.62'
nettyVersion = '4.1.37.Final'
gsonVersion = '2.8.6'
substrateVmVersion = '19.2.0'
junitJupiterVersion = '5.5.1'
}
/****************
* Dependencies *
***************/
dependencies {
compile group: 'org.jline', name: 'jline', version: jline3Version
compile group: 'org.jline', name: 'jline-terminal-jansi', version: jline3JansiVersion
compile group: 'com.google.dagger', name: 'dagger', version: daggerVersion
compileOnly group: 'com.oracle.substratevm', name: "svm", version: substrateVmVersion
annotationProcessor group: 'com.google.dagger', name: 'dagger-compiler', version: daggerVersion
implementation group: 'info.picocli', name: 'picocli', version: picocliVersion
implementation group: 'info.picocli', name: 'picocli-shell-jline3', version: picoclishell3Version
implementation group: 'info.picocli', name: 'picocli-codegen', version: picocliVersion
implementation group: 'com.google.guava', name: 'guava', version: guavaVersion
implementation group: 'com.google.code.gson', name: 'gson', version: gsonVersion
implementation group: 'org.tinylog', name: 'tinylog-api', version: tinylogVersion
implementation group: 'org.tinylog', name: 'tinylog-impl', version: tinylogVersion
implementation group: 'org.jetbrains', name: 'annotations', version: jetbrainsAnnotationsVersion
implementation group: 'org.bouncycastle', name: 'bcprov-jdk15on', version: bouncycastleVersion
implementation group: 'org.bouncycastle', name: 'bcpkix-jdk15on', version: bouncycastleVersion
implementation group: 'com.hivemq', name: 'hivemq-mqtt-client', version: hivemqclientVersion
implementation group: 'io.netty', name: 'netty-handler', version: nettyVersion
implementation group: 'io.netty', name: 'netty-codec-http', version: nettyVersion
implementation group: 'io.netty', name: 'netty-transport-native-epoll', version: nettyVersion, classifier: 'linux-x86_64'
testImplementation group: 'org.mockito', name: 'mockito-core', version: '2.23.4'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-api', version: junitJupiterVersion
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-params', version: junitJupiterVersion
testRuntime group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version: junitJupiterVersion
}
/**************
* Compliance *
**************/
downloadLicenses {
ext.apacheTwo = license('Apache License, Version 2.0', 'http://opensource.org/licenses/Apache-2.0')
ext.cddlOnePointZero = license('CDDL, Version 1.0', 'http://glassfish.java.net/public/CDDLv1.0.html')
ext.cddlOnePointOne = license('CDDL, Version 1.1', 'http://glassfish.java.net/public/CDDL+GPL_1_1.html')
ext.lgplTwoPointOne = license('LGPL, Version 2.1', 'http://www.gnu.org/licenses/lgpl-2.1.html')
ext.eplOnePointZero = license('EPL, Version 1.0', 'http://www.eclipse.org/legal/epl-v10.html')
aliases = [
(apacheTwo) : ['Apache License 2', 'Apache Software License - Version 2.0', 'The Apache Software License, Version 2.0', 'Apache 2', 'Apache License Version 2.0', 'Apache License, Version 2.0', 'Apache License 2.0', 'Apache 2.0', 'The Apache License, Version 2.0', license('Apache License', 'http://www.apache.org/licenses/LICENSE-2.0')],
(cddlOnePointZero): ['Common Development and Distribution License (CDDL) v1.0', 'COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0'],
(cddlOnePointOne) : ['CDDL 1.1'],
(lgplTwoPointOne) : ['LGPL 2.1', 'GNU Lesser General Public License'],
(eplOnePointZero) : ['Eclipse Public License - Version 1.0', 'Eclipse Public License', 'Eclipse Public License - v 1.0']
]
}
license {
include "**/*.java"
header = file('HEADER')
}
task updateThirdPartyLicenses {
group 'license'
dependsOn ':downloadLicenses'
doLast {
javaexec {
main = '-jar'
args = ["${rootDir}/gradle/tools/license-third-party-tool-1.0.jar",
"${buildDir}/reports/license/dependency-license.xml",
"${projectDir}/src/packaging/third-party-licenses/licenses",
"${projectDir}/src/packaging/third-party-licenses/licenses.html"
]
}
}
}
forbiddenApisMain {
exclude '**/LoggingBootstrap.class'
}
forbiddenApis {
bundledSignatures = ['jdk-deprecated', 'jdk-non-portable', 'jdk-reflection' ]
ignoreFailures = false
}
//disable
forbiddenApisTest.enabled = false
/****************
* Jar *
***************/
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
options.encoding = 'UTF-8'
def jv = System.properties['java.version']
if ( jv.startsWith('6') || jv.startsWith('7') ) {
throw new RuntimeException('Incompatible JRE version: ' + System.properties['java.version'] + '. Use at least JRE 8 instead.')
}
}
jar {
manifest () {
attributes(
'Built-JDK': System.getProperty('java.version'),
'Implementation-Title': project.appName,
'Implementation-Version': project.version,
'Implementation-Vendor': project.vendor,
'Specification-Title': project.appName,
'Specification-Version': project.version,
'Specification-Vendor': project.vendor,
'Main-Class': application.mainClassName,
// 'Class-Path': configurations.compile.collect { 'lib/' + it.getName() }.join(' '),
'Built-Date': new Date().format("yyyy-MM-dd HH:mm:ss"),
// 'SplashScreen-Image': 'mqtt-logo.svg',
// 'Sealed': 'true'
)
}
from(configurations.runtime.resolve().collect { it.isDirectory() ? it : zipTree(it) }) {
exclude 'META-INF/MANIFEST.MF'
exclude 'META-INF/*.SF'
exclude 'META-INF/*.DSA'
exclude 'META-INF/*.RSA'
}
finalizedBy shadowJar
}
/****************
* Tests *
***************/
compileTestJava {
options.encoding = 'UTF-8'
}
test {
useJUnitPlatform()
}
/****************
* Graal *
***************/
graal {
graalVersion '19.2.0'
outputName "${rootProject.name}"
mainClass application.mainClassName
option '-H:+PrintClassInitialization'
option '-H:ReflectionConfigurationFiles=tools/reflection.json'
option '-H:-UseServiceLoaderFeature'
option '-H:IncludeResources="org/jline/utils/*.*'
option '-H:IncludeResources="org/jline/terminal/*.*'
option '--allow-incomplete-classpath'
option '--report-unsupported-elements-at-runtime'
option '--initialize-at-build-time'
option '--initialize-at-run-time=' +
'io.netty.channel.unix.Errors,' +
'io.netty.channel.unix.IovArray,' +
'io.netty.channel.unix.Limits,' +
'io.netty.channel.unix.Socket,' +
'io.netty.channel.epoll.EpollEventArray,' +
'io.netty.channel.epoll.EpollEventLoop,' +
'io.netty.channel.epoll.Native,' +
'io.netty.handler.ssl.ConscryptAlpnSslEngine,' +
'io.netty.handler.ssl.JdkNpnApplicationProtocolNegotiator,' +
'io.netty.handler.ssl.JettyNpnSslEngine,' +
'io.netty.handler.ssl.ReferenceCountedOpenSslEngine,' +
'io.netty.handler.ssl.ReferenceCountedOpenSslContext,' +
'io.netty.handler.codec.http.HttpObjectEncoder,' +
'io.netty.handler.codec.http.websocketx.WebSocket00FrameEncoder,' +
'com.hivemq.client.internal.mqtt.codec.encoder.MqttPingReqEncoder,' +
'com.hivemq.client.internal.mqtt.codec.encoder.mqtt3.Mqtt3DisconnectEncoder'
}
/****************
* Homebrew Package & Formula *
***************/
task buildPackageBrew(type: Zip) {
dependsOn shadowJar
archiveFileName = project.readableName + '-' + project.version + '-brew.zip'
destinationDirectory = file(project.buildBrewDir)
into('brew') {
from shadowJar.archiveFile
from "$brewDir/mqtt"
}
from(projectDir) {
include 'LICENSE'
into 'licenses'
}
}
task buildBrewFormula(type: Copy) {
dependsOn buildPackageBrew
from "$brewDir/mqtt-cli.rb"
into "$buildBrewDir"
doLast {
ant.replace(file: "$buildBrewDir/mqtt-cli.rb", token: "@@description@@", value: project.description)
ant.replace(file: "$buildBrewDir/mqtt-cli.rb", token: "@@version@@", value: project.version)
ant.replace(file: "$buildBrewDir/mqtt-cli.rb", token: "@@filename@@", value: buildPackageBrew.archiveFileName.get())
ant.replace(file: "$buildBrewDir/mqtt-cli.rb", token: "@@shasum@@", value: checkSum(buildPackageBrew.archiveFile.get().getAsFile()))
}
}
/****************
* Debian & RPM Packages *
***************/
ospackage {
packageName project.readableName
version project.version
url project.website
summary 'MQTT Command Line Interface for interacting with a MQTT broker'
packageDescription project.description
license 'apache2'
packager ''
vendor project.vendor
os LINUX
type BINARY
user 'root'
permissionGroup 'root'
into "/opt/$packageName"
from(shadowJar.outputs.files)
from(configurations.runtime) {
into 'lib'
}
from('lib') {
into 'lib'
}
from(projectDir) {
include 'LICENSE'
into 'licenses'
fileType LICENSE
}
from(debDir) {
include 'mqtt'
fileMode 0755
filter {
it.replaceAll("@@jarPath@@", "/opt/${packageName}/${shadowJar.archiveFileName.get()}")
}
}
link('/usr/bin/mqtt', "/opt/$packageName/mqtt", 0755)
}
buildDeb {
requires("default-jre").or("java8-runtime")
}
buildRpm {
arch NOARCH
release '1'
requires('jre', '1.8.0', GREATER | EQUAL)
}
task buildDebianPackage(type: Copy) {
from buildDeb
into project.buildDebDir
include "*.deb"
}
task buildRpmPackage(type: Copy) {
from buildRpm
into project.buildRpmDir
include "*.rpm"
}
/****************
* Windows Zipping *
***************/
launch4j {
outputDir = 'packages/windows'
headerType = "console"
mainClassName = application.mainClassName
icon = project.hmqIco
jar = "lib/${project.tasks.shadowJar.archiveFileName.get()}"
outfile = project.appExe
copyright = project.copyright
companyName = project.vendor
downloadUrl = "https://openjdk.java.net/install/"
jreMinVersion = "1.8"
windowTitle = project.appName
version = project.version
textVersion = project.version
}
task buildWindowsZip(type: Zip) {
dependsOn createExe
archiveFileName = "${project.readableName}-${project.version}-win.zip"
destinationDirectory = file(project.buildWinDir)
from ("${project.winDir}") {
include '*'
filter { line ->
line.replace('@@exeName@@', project.appExe)
}
}
from launch4j.dest
from project.license
}
/****************
* Package Task *
***************/
task buildPackageAll {
dependsOn buildBrewFormula, buildDebianPackage, buildRpmPackage, buildWindowsZip
}
/****************
* Publish Draft-Release with all packages to GitHub Releases*
***************/
githubRelease {
token "" + System.getenv("GITHUB_API_TOKEN")
owner = project.githubOrg
targetCommitish "develop"
body ""
draft true
prerelease false
releaseAssets jar.archiveFile,
file("${project.buildRpmDir}/${project.readableName}-${project.version}.noarch.rpm"),
file("${project.buildDebDir}/${project.readableName}_${project.version}_all.deb"),
file("${project.buildBrewDir}/${project.readableName}-${project.version}-brew.zip"),
buildWindowsZip
overwrite false
}
/****************
* Update the Homebrew-Formula with the newly built package *
***************/
gitPublish {
repoUri = "https://github.com/hivemq/homebrew-mqtt-cli.git"
branch = 'master'
contents {
from(project.buildBrewDir) {
include 'mqtt-cli.rb'
}
}
// message used when committing changes
commitMessage = "Release version v${project.version}"
}
tasks.githubRelease.dependsOn tasks.buildPackageAll
/****************
* Helpers *
***************/
import java.security.DigestInputStream
import java.security.MessageDigest
static def checkSum(File file) {
file.withInputStream {
new DigestInputStream(it, MessageDigest.getInstance('SHA-256')).withStream {
it.eachByte {}
it.messageDigest.digest().encodeHex() as String
}
}
}