-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.gradle
394 lines (324 loc) · 12.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
392
393
394
// Gradle's plugins allow it to automatically generate build scripts
// for different types of code. Here we apply the Java plugin, which provides
// all the tools needed to build player code!
apply plugin: 'java'
// The Scala plugin expands upon the Java plugin, allowing us to compile Scala source files.
apply plugin: 'scala'
apply plugin: 'idea'
apply plugin: 'eclipse'
ext.versions = [
battlecode: new File(projectDir, "version.txt").text.trim()
//scala: '2.11.7'
]
// Battlecode updates a lot.
// We should make sure to check for new dependencies frequently.
configurations.all {
resolutionStrategy.cacheDynamicVersionsFor 60, 'seconds'
}
// Tell gradle that we want Java 8.
sourceCompatibility = 1.8
targetCompatibility = 1.8
// We override Gradle's defaults for project directory layout.
sourceSets {
main {
java.srcDirs = [ project.property('source') ]
scala.srcDirs = [ project.property('source') ]
java.outputDir = file("$buildDir/classes")
scala.outputDir = file("$buildDir/classes")
}
test {
java.srcDirs = ["test"]
scala.srcDirs = ["test"]
java.outputDir = file("$buildDir/tests")
scala.outputDir = file("$buildDir/tests")
}
}
//Setting default output directories for compiled classes and generated replay files
//For other default properties, see gradle.properties
if (!project.hasProperty("classLocation")) {
ext.classLocation = sourceSets.main.output.classesDirs.getAsPath()
}
if (!project.hasProperty("replay")) {
ext.replay = 'matches/' + project.property('teamA') + '-vs-' + project.property('teamB') + '-on-' + project.property('maps') + '.bc21'
}
// Mark the client as a special dependency, so that we can handle it separately.
configurations {
client
client32
}
// Download a different version of the client depending on the local OS.
def os = System.getProperty("os.name").toLowerCase()
def clientName = os.startsWith('windows') ? 'battlecode21-client-win' :
os.startsWith('mac') ? 'battlecode21-client-mac' :
'battlecode21-client-linux'
// The dependencies of this project.
dependencies {
// The Battlecode engine.
implementation group: 'org.battlecode', name: 'battlecode21', version: versions.battlecode
// The Battlecode client.
client group: 'org.battlecode', name: clientName, version: versions.battlecode
// Scala!
implementation 'org.scala-lang:scala-library:2.11.7'
testImplementation 'org.scalatest:scalatest_2.11:3.0.0'
testImplementation 'junit:junit:4.12'
}
// Eclipse specific setup to enable docs and sources, and configure layout.
eclipse {
classpath {
downloadJavadoc = true
downloadSources = true
defaultOutputDir = new File(project.buildDir, 'classes-eclipse')
}
}
// IntelliJ settings.
idea {
module {
jdkName = 1.8
downloadSources = true
downloadJavadoc = true
}
}
// Here we register battlecode's maven repository, so the gradle knows where to download the engine and client from
repositories {
mavenCentral()
maven {
url "https://maven.pkg.github.com/battlecode/battlecode21"
credentials {
username = project.findProperty("gpr.user")
password = getAccess()
}
}
// Use the JCenter repo to resolve Scala dependencies.
jcenter()
}
static String getVersionFromWeb() {
String[] urls = ["https://2021.battlecode.org/version.txt", "https://battlecode.org/2021version.txt"]
String version = null
for (String url in urls) {
try {
version = new URL(url).text.trim()
break
} catch (Exception ex) {}
}
if (version == null) {
throw new Exception("Couldn't find new version number. Connect to the internet or update your scaffold")
}
return version
}
static String getAccessFromWeb() {
String[] urls = ["https://2021.battlecode.org/access.txt", "https://battlecode.org/2021access.txt"]
String access = null
for (String url in urls) {
try {
access = new URL(url).text.trim()
break
} catch (Exception ex) {}
}
if (access == null) {
throw new Exception("Couldn't find new access key. Connect to the internet or update your scaffold")
}
return access
}
static String getAccess() {
String access = null
try {
access = getAccessFromWeb()
new File("access.txt").text = access
} catch (Exception ex) {
println("Couldn't get access key online, looking for stored copy...")
access = new File("access.txt").text.trim()
}
try {
assert (access.length() > 2)
} catch (Exception ex) {
throw Exception("Could not find access key online or locally. Connect to the internet or update your scaffold")
}
return access
}
task version {
group 'battlecode'
doLast{
println("\nVersion: " + versions.battlecode + "\n")
}
}
task checkForUpdate() {
group 'battlecode'
doLast {
version = getVersionFromWeb()
if (versions.battlecode != version) print("\n\n\n\n\n\n\tNEW VERSION" + version + " AVAILABLE\n\trun ./gradlew update to download \n\n\n\n")
}
}
// This task pulls the newest version number from the website
// The gradle will then download that version of the engine and client
task update {
group 'battlecode'
doLast {
//overwrites stored version number
version = getVersionFromWeb()
new File(projectDir, "version.txt").text = version
//overwrites cached version number
versions.battlecode = version
println("Updated to " + version)
}
}
// Here we define a task. Tasks like this one, 'unpackClient', can be
// executed in the terminal with `gradlew unpackClient`
task unpackClient(type: Copy, dependsOn: configurations.client) {
description 'Downloads the client.'
group 'battlecode'
dependsOn configurations.client
dependsOn checkForUpdate
from {
configurations.client.collect {
zipTree(it)
}
}
into 'client/'
}
build.group = 'battlecode'
build.dependsOn('unpackClient')
// Another task. This one accepts optional parameters, or "properties",
// corresponding to the bots used by the two teams, the map(s) used in this
// game, the location of the classes for the two teams, and the destination of the replay file.
// These properties can be set in the command line with:
// On Windows cmd:
// `gradlew -PteamA=<team A bot> -PteamB=<team B bot> -Pmaps=<comma
// separated list of maps> -Preplay=<destination> -PclassLocation=<where the packages are stored>`
// On Powershell, OS X, and Linux:
// `./gradlew -PteamA=<team A bot> -PteamB=<team B bot> -Pmaps=<comma
// separated list of maps>`
task run(type: JavaExec, dependsOn: 'build') {
description 'Runs a match without starting the client.'
group 'battlecode'
main = 'battlecode.server.Main'
classpath = sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.debug=true',
'-Dbc.engine.debug-methods=true',
'-Dbc.engine.enable-profiler='+project.property('profilerEnabled'),
'-Dbc.game.team-a='+project.property('teamA'),
'-Dbc.game.team-b='+project.property('teamB'),
'-Dbc.game.team-a.url='+project.property('classLocation'),
'-Dbc.game.team-b.url='+project.property('classLocation'),
'-Dbc.game.maps='+project.property('maps'),
'-Dbc.server.save-file=' +project.property('replay')
]
}
task runFromClient(type: JavaExec, dependsOn: 'build') {
main = 'battlecode.server.Main'
classpath = project.sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'-Dbc.server.wait-for-client=true',
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.debug=false',
'-Dbc.server.robot-player-to-system-out=false',
'-Dbc.engine.debug-methods=true',
'-Dbc.engine.enable-profiler='+project.property('profilerEnabled'),
'-Dbc.game.team-a='+project.property('teamA'),
'-Dbc.game.team-b='+project.property('teamB'),
'-Dbc.game.team-a.url='+project.property('classLocation'),
'-Dbc.game.team-b.url='+project.property('classLocation'),
'-Dbc.game.maps='+project.property('maps'),
'-Dbc.server.save-file=' + project.property('replay')
]
}
task runDebug(type: JavaExec, dependsOn: 'build') {
group 'battlecode'
main = 'battlecode.server.Main'
classpath = project.sourceSets.main.runtimeClasspath
args = ['-c=-']
jvmArgs = [
'-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=5005',
'-Dbc.server.mode=headless',
'-Dbc.server.map-path=maps',
'-Dbc.server.debug=false',
'-Dbc.server.robot-player-to-system-out=true',
'-Dbc.engine.debug-methods=true',
'-Dbc.engine.enable-profiler='+project.property('profilerEnabled'),
'-Dbc.game.team-a='+project.property('teamA'),
'-Dbc.game.team-b='+project.property('teamB'),
'-Dbc.game.team-a.url='+project.property('classLocation'),
'-Dbc.game.team-b.url='+project.property('classLocation'),
'-Dbc.game.maps='+project.property('maps'),
'-Dbc.server.save-file=' + project.property('replay')
]
}
// This task prints out all available players, in the format that the `run`
// task expects them to be given as.
task listPlayers {
description 'Lists all available players.'
group 'battlecode'
doLast {
sourceSets.main.allSource.each {
println it.name
if (it.getName().equals('RobotPlayer.java')
|| it.getName().equals('RobotPlayer.scala')
) {
URI base = new File(project.projectDir, 'src').toURI()
URI full = it.toURI()
String path = base.relativize(full).toString()
println 'PLAYER: '+path.substring(0, path.lastIndexOf('/')).replaceAll('/', '.')
}
}
}
}
// This task prints out all available maps, in the format that the `run` task
// expects them to be given as.
task listMaps {
description 'Lists all available maps.'
group 'battlecode'
doLast {
sourceSets.main.compileClasspath.each {
if (it.toString().contains('battlecode21-2021')) {
FileCollection fc = zipTree(it)
fc += fileTree(new File(project.projectDir, 'maps'))
fc.each {
String fn = it.getName()
if (fn.endsWith('.map21')) {
println 'MAP: '+fn.substring(0, fn.indexOf('.map21'))
}
}
}
}
}
}
// Some client commands for 32 bit architectures
def arch64 = false
def arch32 = false
if (System.getProperty("os.arch").matches("^(x8664|amd64|ia32e|em64t|x64)\$")) arch64 = true
if (System.getProperty("os.arch").matches("^(x8632|x86|i[3-6]86|ia32|x32)\$")) arch32 = true
if (arch32) {
def client32Name = os.startsWith('windows') ? 'battlecode21-client-win-32' :
os.startsWith('mac') ? 'UNSUPPORTED' :
'battlecode21-client-linux-32'
if (clientName.equals('UNSUPPORTED')) {
println 'Sorry, the Battlecode client does not support 32-bit architectures for OS X.'
project.unpackClient32.onlyIf { false }
}
dependencies {
client32 group: 'org.battlecode', name: client32Name, version: versions.battlecode
}
}
task unpackClient32(type: Copy, dependsOn: configurations.client32) {
description 'Downloads the 32-bit client.'
group 'battlecode'
dependsOn configurations.client32
from {
configurations.client32.collect {
zipTree(it)
}
}
into 'client32/'
}
task buildMap(type: JavaExec, dependsOn: 'build') {
group 'battlecode'
main = 'maps.' + project.property('buildMap')
classpath = project.sourceSets.main.runtimeClasspath
}
unpackClient32.onlyIf { arch32 }
build.dependsOn('unpackClient32')