forked from 23rd/chatty
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
332 lines (281 loc) · 9.69 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
import java.util.regex.Matcher
plugins {
id 'com.github.johnrengelman.shadow' version '8.1.1'
id "org.gradle.crypto.checksum" version "1.4.0"
id "java"
}
// This seems to fix non-ASCII characters in the code not appearing correctly after compiling
compileJava.options.encoding = 'UTF-8'
compileTestJava.options.encoding = 'UTF-8'
sourceCompatibility = 1.8
// Tells Netbeans what the main class is
ext.mainClass = 'chatty.Chatty'
archivesBaseName = 'Chatty'
repositories {
mavenCentral()
}
sourceSets {
main {
java {
srcDirs = ['src']
}
resources {
srcDirs = ['src']
}
}
test {
java {
srcDirs = ['test']
}
resources {
srcDirs = ['test']
}
}
}
// Method that gets the version name from Chatty.java. It's defined after the sourceSets block because it uses its path
def extractVersion = { ->
File chattyClassFile = new File((File) sourceSets.main.java.srcDirs.first(), 'chatty/Chatty.java');
// Use this regex to extract the version from the file
Matcher matcher = chattyClassFile.text =~ /(?m)^\s*public static final String VERSION = "(.*?)";/
// From the first matching line, return the first capture (the version)
return matcher[0][1]
}
version = extractVersion()
dependencies {
implementation fileTree(dir: 'assets/lib', include: ['*.jar'])
implementation 'net.java.dev.jna:jna:5.12.1'
implementation 'net.java.dev.jna:jna-platform:5.12.1'
implementation 'com.formdev:flatlaf:2.6'
testImplementation 'junit:junit:4.12'
}
// The wrapper is a small batch/bash script that can be used to run Gradle on machines where it hasn't been directly
// installed. It allows you to specify the project's Gradle version for everyone that has checked out the project.
wrapper {
gradleVersion = '7.2'
}
jar {
manifest {
attributes(
'Main-Class': mainClass,
//'SplashScreen-Image': 'chatty/splash/splash.png'
)
}
}
// Builds a jar that includes not only the compiled files from this project, but also the .class files from the
// dependencies. This removes the need for a separate 'libs' directory when Chatty is installed.
shadowJar {
// A suffix for the release jar name. By default this is '-all', which gives a name like 'Chatty-v0.8.3b3-all.jar'
archiveClassifier = ''
archiveVersion = ''
manifest {
inheritFrom project.tasks.jar.manifest
}
}
// The following are a series of tasks for building the release artifacts. They are bundled into zip files and placed
// in the 'build/releases' directory.
def releasesDir = new File(buildDir, 'releases')
task allPlatformsZip(type: Zip, group: 'build') {
dependsOn shadowJar
from tasks.shadowJar.archivePath
from ('assets') {
exclude 'lib'
}
destinationDirectory = releasesDir
archiveFileName = "${archivesBaseName}_${project.version}.zip"
}
// Builds all the release zips
task releaseZips(group: 'build') {
dependsOn allPlatformsZip
}
// Builds the full project, runs the unit tests and packages the release zips.
task release(group: 'build') {
dependsOn releaseZips, build
}
//--------
// Windows
//--------
def windowsBundleTarget = new File(buildDir, 'javapackager')
def windowsBundleSource = new File(windowsBundleTarget, 'bundles/Chatty')
def standaloneSuffix = "_legacy";
def isJPackage = false;
if (project.hasProperty('jpackagePath')) {
windowsBundleTarget = new File(buildDir, 'jpackage')
windowsBundleSource = new File(windowsBundleTarget, 'Chatty')
standaloneSuffix = "";
isJPackage = true;
}
ext.standaloneSuffix = standaloneSuffix
ext.isJPackageString = isJPackage ? "1" : "0";
task javapackagerBuild(type: Exec, group: 'build') {
dependsOn shadowJar
doFirst {
if (!project.hasProperty('javapackagerPath') && !project.hasProperty('jpackagePath')) {
throw new GradleException('Path to javapackager.exe must be defined with -PjavapackagerPath=<path>')
}
}
if (project.hasProperty('jpackagePath')) {
doFirst {
println 'Using jpackagePath';
delete windowsBundleTarget
copy {
from tasks.shadowJar.archivePath
into new File(windowsBundleTarget, 'input')
}
}
def command = [jpackagePath,
'--type', 'app-image',
'-n', 'Chatty',
'-i', new File(windowsBundleTarget, 'input'),
'-d', windowsBundleTarget,
'--main-class', 'chatty.Chatty2',
'--main-jar', 'Chatty.jar',
'--description', 'Chatty - Twitch Chat Client',
'--java-options', '-Xmx600M',
'--java-options', '-Dsun.java2d.d3d=false',
'--icon', 'assets-bundle/Chatty.ico',
'--app-version', project.version.replace("-",".").replace("b","0."),
'--arguments', '-abc',
'--add-launcher', 'ChattyPortable=assets-bundle/LauncherPortable.properties']
commandLine command
}
else if (project.hasProperty('javapackagerPath')) {
doFirst {
println 'Using javapackagerPath';
delete windowsBundleTarget
}
def command = [javapackagerPath, '-deploy', '-native', 'image', '-srcfiles', tasks.shadowJar.archivePath, '-appclass', 'chatty.Chatty', '-outdir', windowsBundleTarget, '-outfile', 'Chatty']
command << "-Bicon=assets-bundle/Chatty.ico"
command << "-BappVersion=${project.version}"
command << "-BjvmProperties=sun.java2d.d3d=false"
command << "-BjvmOptions=-Xmx400M"
if (project.hasProperty('jrePath')) {
command << "-Bruntime=${jrePath}"
}
commandLine command
}
}
def addApplicationManifest(target) {
// Exe files output by packager appear to be readonly
ant.attrib(readonly: false) {
fileset(file: target)
}
exec {
def command = [mtPath, '-nologo', '-manifest', new File('assets-bundle/Chatty.exe.manifest'), '-outputresource:'+target]
commandLine command
}
}
task javapackagerManifest(group: 'build') {
dependsOn javapackagerBuild
doLast {
if (project.hasProperty('mtPath')) {
addApplicationManifest(new File(windowsBundleSource, "Chatty.exe"));
if (isJPackage) {
addApplicationManifest(new File(windowsBundleSource, "ChattyPortable.exe"));
}
}
else {
println("Path to mt.exe has to be specified to add an application manifest, skipping..");
}
}
}
task javapackager(group: 'build') {
dependsOn javapackagerBuild, javapackagerManifest
}
task windowsZip(type: Zip, group: 'build') {
dependsOn javapackager
from windowsBundleSource
from ('assets') {
exclude 'lib'
into 'app'
}
from ('assets-bundle/fallback-fonts') {
into 'runtime/lib/fonts/fallback'
}
from 'assets-bundle/readme-bundle.txt'
destinationDirectory = releasesDir
archiveFileName = "${archivesBaseName}_${project.version}_win_standalone${standaloneSuffix}.zip"
}
task releaseWindows(group: 'build') {
dependsOn release, windowsZip
}
//----------
// Innosetup
//----------
def innosetupDir = new File(buildDir, 'innosetup')
def innosetupDir2 = new File(buildDir, 'innosetup2')
def prepareSetupFile(file, to) {
copy {
from("setup/"+file) {
rename(file, "setup.iss")
expand([
applicationVersion: project.version,
code: new File('setup/_functions.iss-part').getText('UTF-8'),
setup: new File('setup/_common.iss-part').getText('UTF-8'),
isJPackage: project.ext.isJPackageString,
standaloneSuffix: project.ext.standaloneSuffix
])
}
into(to)
}
}
task innosetup(type: Exec, group: 'build') {
dependsOn shadowJar
doFirst {
if (!project.hasProperty('innosetupPath')) {
throw new GradleException('Path to iscc.exe must be defined with -PinnosetupPath=<path>')
}
delete innosetupDir
innosetupDir.mkdir();
prepareSetupFile("setup.iss-template", innosetupDir)
copy {
from(tasks.shadowJar.archivePath)
from ('assets') {
exclude 'lib'
}
from('assets-bundle/Chatty.ico')
into("${innosetupDir}/pack")
}
def command = [innosetupPath, "/Q", "${innosetupDir}\\setup.iss"]
commandLine command
}
}
task innosetupStandalone(type: Exec, group: 'build') {
dependsOn javapackager
doFirst {
if (!project.hasProperty('innosetupPath')) {
throw new GradleException('Path to iscc.exe must be defined with -PinnosetupPath=<path>')
}
delete innosetupDir2
innosetupDir2.mkdir();
prepareSetupFile("setup_standalone.iss-template", innosetupDir2)
copy {
from windowsBundleSource
from ('assets') {
exclude 'lib'
into 'app'
}
from ('assets-bundle/fallback-fonts') {
into 'runtime/lib/fonts/fallback'
}
from 'assets-bundle/readme-bundle.txt'
into("${innosetupDir2}/pack")
}
def command = [innosetupPath, "/Q", "${innosetupDir2}\\setup.iss"]
commandLine command
}
}
task releaseWinSetups(group: 'build') {
dependsOn releaseWindows, innosetup, innosetupStandalone, build
}
//---------
// Checksum
//---------
import org.gradle.crypto.checksum.Checksum
task createChecksums(type: Checksum) {
mustRunAfter(allPlatformsZip, windowsZip, releaseWindows, releaseWinSetups)
files = layout.files { releasesDir.listFiles() }.filter { File f ->
f.name.endsWith(".exe") || f.name.endsWith(".zip")
}
outputDir = new File(releasesDir, "v"+version)
algorithm = Checksum.Algorithm.SHA256
}