forked from DeskChan/DeskChan
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.gradle
executable file
·362 lines (313 loc) · 10.2 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
buildscript {
ext.kotlin_version = '1.2.30'
repositories {
jcenter()
mavenCentral()
maven {
url 'https://plugins.gradle.org/m2/'
}
}
dependencies {
classpath 'com.github.jengelman.gradle.plugins:shadow:1.2.4'
classpath group: 'edu.sc.seis.gradle', name: 'launch4j', version: '2.4.1+'
classpath group: 'gradle.plugin.de.fuerstenau', name: 'BuildConfigPlugin', version: '1.1.8'
classpath group: 'org.jetbrains.kotlin', name: 'kotlin-gradle-plugin', version: kotlin_version
}
}
repositories {
jcenter()
mavenCentral()
}
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'groovy'
apply plugin: 'application'
apply plugin: 'com.github.johnrengelman.shadow'
apply plugin: 'edu.sc.seis.launch4j'
apply plugin: 'de.fuerstenau.buildconfig'
sourceCompatibility = 1.8
targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'
applicationDefaultJvmArgs = ["-XX:MinHeapFreeRatio=10", "-XX:MaxHeapFreeRatio=25"]
sourceSets {
main {
java {
srcDir 'src/main/java'
}
}
test {
java {
srcDirs 'src/test/java'
}
resources {
srcDirs 'src/test/resources'
}
}
}
test {
testLogging {
events "PASSED", "FAILED", "SKIPPED"
afterSuite { desc, result ->
if (!desc.parent) { // will match the outermost suite
println "Results: ${result.resultType} (${result.testCount} tests, ${result.successfulTestCount} successes, ${result.failedTestCount} failures, ${result.skippedTestCount} skipped)"
}
}
}
}
dependencies {
compile group: 'org.json', name: 'json', version: '20160810+'
compile group: 'org.codehaus.groovy', name: 'groovy', version: '2.4.13'
compile group: 'org.apache.commons', name: 'commons-lang3', version: '3.5+'
compile group: 'org.apache.commons', name: 'commons-io', version: '1.3.2+'
compile group: 'org.apache.ivy', name: 'ivy', version: '2.4.0'
compile group: 'com.dorkbox', name: 'SystemTray', version: '3.10'
compile group: 'org.javassist', name: 'javassist', version: '3.22+'
compile group: 'org.controlsfx', name: 'controlsfx', version: '8.40.12+'
compile group: 'com.1stleg', name: 'jnativehook', version: '2.0.2'
compile group: 'org.jetbrains.kotlin', name: 'kotlin-stdlib-jre8', version: kotlin_version
compile group: 'net.objecthunter', name: 'exp4j', version:'0.4.8'
testCompile group: 'junit', name: 'junit', version: '4.12'
testCompile group: 'org.mockito', name: 'mockito-core', version: '3.3.3'
}
ext.appName = 'DeskChan'
project.version = '0.3.5'
//mainClassName = 'info.deskchan.core.MainKt'
mainClassName = 'info.deskchan.core.Main'
// A list of standard plugins that should be packed into jar files.
ext.standardJarPlugins = [
'speech_command_system',
'chat_window',
'weather',
'notification_manager'
]
def gitCommitCount = '[UNOFFICIAL]'
def gitCommitHash = 'Unknown'
def gitBranchName = 'Unknown'
// We're getting the version information about the project from our git repository.
try {
def gitQueries = [
['rev-list', '--count', 'HEAD'],
['rev-parse', 'HEAD'],
['rev-parse', '--abbrev-ref', 'HEAD']
]
def stdout = new ByteArrayOutputStream()
for (def query : gitQueries) {
exec {
workingDir = project.rootDir
executable = 'git'
args = query
standardOutput = stdout
}
}
def versionInfo = stdout.toString().split('\n')
gitCommitCount = versionInfo[0].trim()
gitCommitHash = versionInfo[1].trim()
gitBranchName = versionInfo[2].trim()
} catch (Exception e) {
System.err.println('Failed to get git metadata')
}
ext.appVersion = "$version-r$gitCommitCount"
ext.fullAppName = "$appName-$appVersion"
allprojects {
tasks.withType(JavaCompile) {
options.encoding = 'UTF-8'
}
tasks.withType(Test) {
systemProperty "file.encoding", "UTF-8"
}
}
// At first, the application is assembled to this directory. And only then it packs into a zip file.
ext.launch4jDir = "${buildDir}/launch4j"
// Provides an automatically generated static class consisting of the version information.
buildConfig {
packageName = 'info.deskchan.core'
clsName = 'BuildConfig'
buildConfig.appName = appName
version = appVersion
buildConfigField 'String', 'GIT_COMMIT_HASH', gitCommitHash
buildConfigField 'String', 'GIT_BRANCH_NAME', gitBranchName
buildConfigField 'String', 'BUILD_DATETIME', new Date().format('HH:mm dd/MM/yyyy')
buildConfigField 'String', 'PROJECT_SITE_URL', 'http://deskchan.info/'
buildConfigField 'String', 'AUTHOR', 'DeskChan Project <support@deskchan.info> (http://deskchan.info)'
}
defaultTasks 'printHelpMessage'
task printHelpMessage(group: 'desk-chan') {
doLast {
println 'The Desk-Chan Project greetings you!\n'
println 'Use the "run" task to (obviously) run the application.'
println 'Use the "createExeDistZip" task to assemble a distributive archive.\n'
println 'If you have any issues, feel free to contact us via Telegram: t.me/dc_flood'
}
}
task copyIconForExe(type: Copy, group: 'desk-chan') {
from "$projectDir/misc/appicon.ico"
into launch4jDir
}
task assembleCore(type: Jar, group: 'desk-chan') {
baseName = appName
from (sourceSets.main.output) {
include 'info/deskchan/core/*'
include 'info/deskchan/core_utils/**/*'
include 'info/deskchan/jar_loader/**/*'
include 'info/deskchan/gui_javafx/**/*'
include 'info/deskchan/groovy_support/**/*'
include 'info/deskchan/talking_system/**/*'
}
from (sourceSets.main.resources) {
include 'info/deskchan/*'
}
manifest {
attributes 'Main-Class': project.mainClassName, 'Implementation-Version': appVersion
}
version = null
classifier = null
}
task assembleProxyInterface(type: Jar, group: 'desk-chan') {
baseName = 'ProxyInterface'
from (sourceSets.main.output) {
include 'info/deskchan/core/ResponseListener.class'
include 'info/deskchan/core/ResponseInfo.class'
include 'info/deskchan/core/MessageListener.class'
include 'info/deskchan/core/PluginProxyInterface.class'
include 'info/deskchan/core/Plugin.class'
include 'info/deskchan/core/PluginProperties.class'
include 'info/deskchan/core/LoggerLevel.class'
include 'info/deskchan/core/MessageDataMap.class'
include 'info/deskchan/core/MessageDataDeserializationException.class'
include 'info/deskchan/MessageData/*'
}
manifest {
attributes 'Main-Class': "info.deskchan.${baseName}.Main", 'Implementation-Version': appVersion
}
version = null
}
// Similar tasks for assembling plugins are generated dynamically.
// For example, task GroovySupport produces groovy_support.jar file.
// Unfortunately, IntelliJ IDEA doesn't like such code at all.
standardJarPlugins.each { name ->
task "assemble$name"(type: Jar, group: 'desk-chan') {
baseName = name
from (sourceSets.main.output) {
include "info/deskchan/$baseName/**/*"
}
manifest {
def commonAttrs = [
'Main-Class': "info.deskchan.${baseName}.Main",
'Type': 'Jar',
'Version': appVersion,
'Author': 'DeskChan Project <support@deskchan.info> (http://deskchan.info)',
'Resources': "info/deskchan/${baseName}/strings"
]
attributes commonAttrs
}
version = null
}
}
jar {
baseName = project.name
manifest {
attributes 'Main-Class': mainClassName
}
}
shadowJar {
baseName = "${project.name}-full"
classifier = null
version = null
}
task copyProxyLib(type: Copy, dependsOn: assembleProxyInterface, group: 'desk-chan') {
description 'Copies the ProxyInterface.jar into the /libs/ directory.'
from (libsDir){
include 'ProxyInterface*'
}
from ('misc/proxies'){
include '*'
}
into "$launch4jDir/libs/"
}
task copyJarPlugins(type: Copy, group: 'desk-chan') {
standardJarPlugins.forEach {
dependsOn "assemble$it"
}
description 'Copies all *.jar files of built-in plugins into the /plugins/ directory.'
from (libsDir) {
exclude 'Proxy*', 'DeskChan*'
}
into "$launch4jDir/plugins/"
}
task checkPath {
if(buildDir.toString().matches(".*[^A-Za-z0-9,_:\\\\\\.\\-\\/]+.*"))
println("WARNING: Build path contains incorrect symbols. If building fails, incorrect symbols may be the cause.")
}
/*task copyDependencies(type: Copy, group: 'desk-chan') {
description 'Copies all runtime dependencies into the /libs/ directory.'
from configurations.runtime
into "$launch4jDir/libs/"
}*/
task copyJars(
dependsOn: [copyProxyLib, copyJarPlugins/*, copyDependencies*/],
description: 'Applies all of the previous copy tasks.',
group: 'desk-chan'
)
createExe {
dependsOn checkPath, assembleCore, copyJars, copyIconForExe
description 'Produces an executable file containing the core plugin.'
outfile = "bin/${appName}.exe"
mainClassName = project.mainClassName
copyConfigurable = files()
jar = "${buildDir}/libs/${project.tasks.shadowJar.archiveName}"
icon = 'appicon.ico'
copy {
from "${projectDir}/assets"
into "$launch4jDir/assets"
}
copy {
from "${projectDir}/plugins"
into "$launch4jDir/plugins"
}
doLast {
delete "$launch4jDir/appicon.ico"
}
}
task createStartScriptsForExe(type: CreateStartScripts, dependsOn: createExe, group: 'desk-chan') {
description 'Produces the right executable batch files for Unix and Windows systems.'
outputDir = file("$launch4jDir/bin")
mainClassName = project.mainClassName
applicationName = appName
classpath = files(createExe.outfile)// + fileTree("$launch4jDir/libs")
doLast {
def windowsScriptFile = file getWindowsScript()
def unixScriptFile = file getUnixScript()
windowsScriptFile.text = windowsScriptFile.text
.replace("lib\\${appName}.exe", "bin\\${appName}.exe")
.replace('\\lib\\', '\\libs\\') // TODO: fix the classpath without this kludge
unixScriptFile.text = unixScriptFile.text
.replace("lib/${appName}.exe", "bin/${appName}.exe")
.replaceAll('/lib/', '/libs/')
}
}
task createExeDistZip(type: Zip, dependsOn: createStartScriptsForExe, group: 'build desk-chan') {
description 'The main task. Produces a complete and ready-to-use distributive in a zip archive.'
from launch4jDir
include '*'
include '*/*'
include '*/*/*'
include '*/*/*/*'
include '*/*/*/*/*'
include '*/*/*/*/*/*'
include '*/*/*/*/*/*/*'
archiveName "${fullAppName}.zip"
destinationDir file(distsDir)
}
task copyJarPluginsForRun(type: Copy) {
dependsOn checkPath
standardJarPlugins.forEach {
dependsOn "assemble$it"
}
description 'Copies all *.jar files of built-in plugins into the /build/plugins/ directory.'
from (libsDir) {
exclude 'Proxy*', 'DeskChan*'
}
from "$projectDir/plugins"
into "$launch4jDir/plugins/"
}
run.dependsOn copyJarPluginsForRun