-
Notifications
You must be signed in to change notification settings - Fork 63
/
build.gradle
391 lines (342 loc) · 14.1 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
// JSettlers build script for gradle 6 or 7
// See bottom of file for copyright and license information (GPLv3).
apply plugin: 'java'
apply plugin: 'application'
apply plugin: 'idea'
buildscript {
repositories {
mavenCentral()
}
}
version = '2.7.00' // same as in src/main/resources/resources/version.info
ext.i18neditor_version = '1.2.1' // for PTE editor; same as in src/main/resources/pteResources/pteversion.properties
ext.git_revision = '?' // placed in jar manifests as Build-Revision attrib; will be filled in by findGitRevision task
mainClassName = "soc.client.SOCPlayerClient"
compileJava {
sourceCompatibility = '1.8'
targetCompatibility = '1.8'
}
ext.python_command = findPythonOrPython3() // python3 or python expected to be in PATH
repositories {
mavenCentral()
}
dependencies {
testImplementation 'junit:junit:4.13.1'
implementation 'com.google.code.gson:gson:2.8.6' // optional at runtime, for savegame feature
// If version changes, update Readme.developer.md and jsserver.properties.sample
// Same version is used by v3 branch (dependency of protobuf-java-util)
}
sourceSets {
extraTest {
// also runs extraTest/python/*.py, see task extraTaskPython below
java {
compileClasspath += main.output + test.output
runtimeClasspath += test.output + test.runtimeClasspath
srcDirs = ['src/extraTest/java']
}
// if needed later: resources.srcDir file('src/extraTest/resources')
}
}
configurations {
extraTestImplementation.extendsFrom testImplementation
extraTestRuntimeOnly.extendsFrom testRuntimeOnly
}
tasks.withType(JavaCompile) {
options.warnings = true // don't hide xlint warnings
options.compilerArgs += '-Xlint:classfile,empty,fallthrough,finally,options,processing,unchecked,varargs'
options.encoding = 'UTF-8' // override the system's default encoding
// To test that this has an effect, use 'Cp1252' instead here and expect "unmappable character" errors in StringUtil.java
}
// unit tests
// run all python unit tests, using PyUnit (unittest module); returns 0 if no failures
task testPython(type: Exec) {
executable python_command
workingDir 'src/test/python'
args '-m', 'unittest', 'discover' // discover requires python 2.7 or higher
environment CLASSPATH: tasks.test.classpath.asPath
}
// Make sure sql scripts template token data is self-consistent:
// If test_token_consistency.py finds problems, it will print a detail message.
task testSrcDBTemplateTokens(type: Exec) {
executable python_command
workingDir 'src/main/bin/sql/template'
args 'test_token_consistency.py', new File(sourceSets.main.java.srcDirs[0], '/soc/server/database/SOCDBHelper.java').absolutePath
outputs.upToDateWhen { false } // never skip this test
}
// Make sure sql scripts are consistent with their template:
// If render.py finds problems, it will print a message showing which script(s) must be regenerated.
task testSrcDBTemplates(type: Exec) {
executable python_command
workingDir 'src/main/bin/sql/template'
args 'render.py', '-i', 'jsettlers-tables-tmpl.sql', '-d', 'mysql,sqlite,postgres', '-c', '../jsettlers-tables-%s.sql'
outputs.upToDateWhen { false } // never skip this test
}
tasks.withType(Test) { task ->
task.outputs.upToDateWhen { false } // never skip testing ("UP-TO-DATE") when it's asked for or is dependency
task.afterSuite { desc, result ->
if (! desc.parent) {
// print overall results only
// Testing results: :test SUCCESS (62 tests, 62 successes, 0 failures, 0 skipped)
logger.lifecycle("Testing results: {} {} ({} tests, {} successes, {} failures, {} skipped)", task.path,
result.resultType, result.testCount, result.successfulTestCount, result.failedTestCount, result.skippedTestCount)
}
}
}
test.dependsOn ([testSrcDBTemplateTokens, testSrcDBTemplates])
test.finalizedBy testPython // run java tests first; run python tests even if java fails
// jars
// note: this task runs during configuration
task findGitRevision {
def cmd = "git rev-parse --short HEAD"
try {
def proc = cmd.execute()
project.ext.git_revision = proc.text.trim()
} catch (Exception e) {
// fail gracefully: continue build with git_revision = '?'
project.logger.lifecycle("warning: findGitRevision can't execute git rev-parse; using '?'")
}
}
tasks.withType(Jar) {
includeEmptyDirs = false
dependsOn findGitRevision
}
// prevent default jsettlers.git-<version>.{jar,zip,.tar.gz} artifact creation;
// various tasks will build artifacts with more specific names and contents instead
jar.enabled = false // instead build serverJar, fullJar, i18neditorJar
distZip.enabled = false // dist builds distFullZip
distTar.enabled = false // dist builds distSrcTar, distFullTar
task serverJar(type: Jar) {
archiveBaseName = 'JSettlersServer'
archiveVersion = project.version
manifest {
attributes(
'Main-Class': 'soc.server.SOCServer',
'Implementation-Version': project.version,
'Build-Revision': project.git_revision,
'Class-Path': 'gson.jar',
)
}
from(sourceSets.main.output) {
include "net/nand/util/i18n/mgr/**"
include "soc/baseclient/**"
include "soc/debug/**"
include "soc/disableDebug/**"
include "soc/game/**"
include "soc/message/**"
include "soc/robot/**"
include "soc/server/**"
include "soc/util/**"
}
from(sourceSets.main.resources) {
include "resources/version.info"
include "resources/strings/server/**"
}
}
task fullJar(type: Jar) {
archiveBaseName = 'JSettlers'
archiveVersion = project.version
manifest {
attributes(
'Main-Class': 'soc.client.SOCPlayerClient',
'Implementation-Version': project.version,
'Build-Revision': project.git_revision,
'Class-Path': 'gson.jar', // in case client launches a server, or another project uses fullJar
)
}
from(sourceSets.main.output) {
include "net/nand/util/i18n/mgr/**"
include "soc/baseclient/**"
include "soc/client/**"
include "soc/debug/**"
include "soc/disableDebug/**"
include "soc/game/**"
include "soc/message/**"
include "soc/robot/**"
include "soc/server/**"
include "soc/util/**"
}
from(sourceSets.main.resources) {
include "resources/**"
}
}
// PropertiesTranslatorEditor utility; not built by default
task i18neditorJar(type: Jar) {
archiveBaseName = 'PTE'
archiveVersion = project.i18neditor_version
manifest {
attributes(
'Main-Class': 'net.nand.util.i18n.gui.PTEMain',
'Implementation-Version': project.i18neditor_version,
'Build-Revision': project.git_revision,
)
}
from(sourceSets.main.output) {
include "net/nand/util/i18n/**" // i18n string manager, parser/writer, editor gui
}
from(sourceSets.main.resources) {
include "pteResources/**" // for pteversion.properties, strings/**
}
from('src/main/java/net/nand/util/i18n/') {
include 'README.txt' // into root directory of jar
}
}
// distribution tgzs and zip
// these include **/.gitignore files (see settings.gradle)
task cleanRemovePyc(type: Delete) {
outputs.upToDateWhen { false } // never skip if asked for
delete fileTree('src') {
include '**/*.pyc'
}
}
// This copies everything in your "src" directory, so be sure to run on a clean repository only!
// Includes target/lib/ to prevent eclipse ant import error
FileTree srcTree = fileTree(dir: '.', includes: ['src/**', 'doc/**', 'build.*', 'Readme.*', '*.txt', '.gitignore', 'target/lib/.gitignore'])
// Naming reminder: [archiveBaseName]-[archiveAppendix]-[archiveVersion]-[archiveClassifier].[archiveExtension]
// jsettlers-2.x.xx-src.tar.gz
task distSrcTar(type: Tar) {
dependsOn cleanRemovePyc
archiveBaseName = 'jsettlers'
archiveClassifier = 'src'
compression = Compression.GZIP
archiveExtension = 'tar.gz'
from srcTree
into 'jsettlers-' + project.version + '-src/'
}
// jsettlers-2.x.xx-full.tar.gz
task distFullTar(type: Tar) {
dependsOn cleanRemovePyc
archiveBaseName = 'jsettlers'
archiveClassifier = 'full'
compression = Compression.GZIP
archiveExtension = 'tar.gz'
from srcTree, fullJar.outputs.files, serverJar.outputs.files
into 'jsettlers-' + project.version + '/'
}
// jsettlers-2.x.xx-full.zip
task distFullZip(type: Zip) {
dependsOn cleanRemovePyc
archiveBaseName = 'jsettlers'
archiveClassifier = 'full'
from srcTree, fullJar.outputs.files, serverJar.outputs.files
into 'jsettlers-' + project.version + '/'
}
tasks.withType(AbstractArchiveTask) {
reproducibleFileOrder = true
}
// For dist, ensure no git-untracked files or uncommited changes in repo
task distCheckSrcDirty {
dependsOn cleanRemovePyc // prevent "Untracked files in repo: src/main/bin/sql/template/render.pyc"
outputs.upToDateWhen { false } // prevent "Task has not declared any outputs despite executing actions"
// Git command adapted from mark-longair's 2011-02-28 answer at
// http://stackoverflow.com/questions/5139290/how-to-check-if-theres-nothing-to-be-committed-in-the-current-branch
// Gradle capture of stdout from benjamin-muschko's 2012-06-19 answer at
// https://stackoverflow.com/questions/11093223/how-to-use-exec-output-in-gradle
doLast {
new ByteArrayOutputStream().withStream { ostr ->
def ostream = exec {
executable = 'git'
args = ['ls-files', '--other', '--exclude-standard', '--directory', '--no-empty-directory']
// ignore empty-ish target/classes/
standardOutput = ostr
}
def stdout = ostr.toString().trim()
if (! stdout.isEmpty())
{
println "Untracked files in repo: Commit, move, or .gitignore these:" + System.properties['line.separator'] + stdout
throw new BuildCancelledException
("Untracked files in repo: Commit, move, or .gitignore")
}
}
}
}
task dist {
dependsOn distCheckSrcDirty, distSrcTar, distFullTar, distFullZip
doLast {
println "Built for distribution in ${project.buildDir.getName()}/${project.distsDirName}:"
[distSrcTar, distFullTar, distFullZip].each { dtask -> dtask.outputs.files.each { File file ->
println file.name
}}}
}
// misc
javadoc { // generates into build/docs/javadoc/
source = sourceSets.main.allJava
classpath = sourceSets.main.runtimeClasspath
title = 'JSettlers ' + project.version + ' API'
excludes ['**/fedorahosted/**']
options.memberLevel = JavadocMemberLevel.PACKAGE
options.encoding = 'UTF-8'
options.overview = 'src/main/java/main-overview.html' // becomes overview-summary.html
options.addBooleanOption('author', true)
options.addBooleanOption('breakiterator', true)
options.addBooleanOption('version', true)
options.addBooleanOption('splitindex', false)
if (JavaVersion.current().isJava8Compatible()) {
// avoid overly-strict JDK 8 doclint;
// jdk 7 javadoc doesn't recognize this flag
options.addBooleanOption('Xdoclint:none', true)
}
// Unlike v1.x.xx in Ant, don't generate the "-use" page; IDEs can provide up-to-date usage info
}
// extra functional testing
task extraTest(type: Test) {
testClassesDirs = sourceSets.extraTest.output.classesDirs
classpath = sourceSets.extraTest.runtimeClasspath
testLogging.showStandardStreams = true // make it easy to see System.out, System.err from sometimes-lengthy tests
reports.junitXml.destination = file("$buildDir/extraTest-results") // unit tests use buildDir/test-results
reports.html.destination = file("$buildDir/reports/extraTests") // unit tests use buildDir/reports/tests
outputs.upToDateWhen { false } // never skip running it
}
// run all python extra tests, using PyUnit (unittest module); returns 0 if no failures
task extraTestPython(type: Exec) {
executable python_command
workingDir 'src/extraTest/python'
args '-m', 'unittest', 'discover', '--verbose' // discover requires python 2.7 or higher
environment CLASSPATH: tasks.extraTest.classpath.asPath
}
extraTest.dependsOn test
extraTest.finalizedBy extraTestPython // run java tests first; run python tests even if java fails
// build setup: try to run python3 or python available in PATH
def static findPythonOrPython3() {
try {
def cmd = "python3 --version"
def proc = cmd.execute()
proc.waitFor()
if (proc.exitValue() == 0)
return 'python3'
} catch(Exception e) {}
def cmd = "python --version"
def proc = cmd.execute()
proc.waitFor()
if (proc.exitValue() == 0)
return 'python'
else
throw new GradleScriptException("build environment problem: couldn't run python3 nor python")
}
clean {
// also remove python bytecode files
delete fileTree("src/test/python").matching{ include "**/*.pyc" }
delete fileTree("src/extraTest/python").matching{ include "**/*.pyc" }
}
artifacts {
archives serverJar, fullJar
}
/*
* This file is part of the JSettlers project.
*
* This file Copyright (C) 2017 Ruud Poutsma <[email protected]>
* Portions of this file Copyright (C) 2017,2019-2024 Jeremy D Monin <[email protected]>
* Portions of this file Copyright (C) 2019 Colin Werner
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/ .
*/