-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.xml
198 lines (170 loc) · 7.84 KB
/
build.xml
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
<?xml version="1.0"?>
<!-- The build file we use to compile and run battlecode players.
Uses Apache Ant: http://ant.apache.org/ -->
<project name="Battlecode 2016 Scaffold" basedir="." default="run"
xmlns:ivy="antlib:org.apache.ivy.ant"
xmlns:if="ant:if"
xmlns:unless="ant:unless">
<description>
Build file for Battlecode 2016 players.
</description>
<!-- Ant properties are just variables. They can be injected into strings;
"${path.lib}" will translate to "lib", and so on. -->
<property name="path.lib" location="lib"/>
<property name="path.src" location="src"/>
<property name="path.test" location="test"/>
<property name="path.bin" location="bin"/>
<property name="path.bin.main" location="${path.bin}/main"/>
<property name="path.bin.test" location="${path.bin}/test"/>
<property name="path.matches" location="matches/"/>
<!-- Check if any players use scala, by counting the number of .scala files. -->
<condition property="bc.scala">
<resourcecount when="greater" count="0">
<fileset dir=".">
<include name="${path.src}/**/*.scala"/>
<include name="${path.test}/**/*.scala"/>
</fileset>
</resourcecount>
</condition>
<!-- Classpaths are lists of places to look for compiled class files. -->
<path id="classpath.run">
<fileset dir="${path.lib}" includes="*.jar"/>
<pathelement location="${path.bin.main}"/>
</path>
<path id="classpath.test">
<pathelement location="${path.bin.test}"/>
<path refid="classpath.run"/>
</path>
<!-- Now we have the "targets": tasks ant can fulfill. -->
<target name="init" description="Create temporary directories.">
<mkdir dir="${path.bin.main}"/>
<mkdir dir="${path.bin.test}"/>
<mkdir dir="${path.lib}"/>
</target>
<target name="clean" description="Clean up temporary directories.">
<delete dir="${path.bin}"/>
</target>
<target name="get" description="Download battlecode resources.">
<!-- We use a tool called Apache Ivy to download things.
This bit of ant magic imports everything Ivy needs. -->
<taskdef resource="org/apache/ivy/ant/antlib.xml" uri="antlib:org.apache.ivy.ant">
<classpath>
<fileset dir=".ivy" includes="*.jar"/>
</classpath>
</taskdef>
<!-- Now we tell ivy to download things! -->
<ivy:settings file=".ivy/ivysettings.xml"/>
<ivy:retrieve pattern="${path.lib}/[artifact](-[classifier]).[ext]"
conf="default"/>
</target>
<target name="update" depends="init" description="Update to the latest version of the battlecode software.">
<!-- These URLs will get less horrible when we release. -->
<!-- Read the latest battlecode version from the web site. -->
<get src="https://www.battlecode.org/contestants/latest/"
dest="${java.io.tmpdir}/battlecode-version"/>
<loadfile srcFile="${java.io.tmpdir}/battlecode-version" property="bc.version">
<filterchain>
<striplinebreaks/>
</filterchain>
</loadfile>
<!-- Manually update ivy.xml, setting the battlecode versions to ${bc.version}.
Yes, it's horrible.
This is necessary because of limitations in the battlecode package repository;
it will be cleaner next year. -->
<replaceregexp file="ivy.xml" flags="g">
<regexp pattern="name="battlecode(-javadoc|-mapeditor)?"(\s+)rev="[^"]+""/>
<substitution expression="name="battlecode\1"\2rev="${bc.version}""/>
</replaceregexp>
<!-- Re-download all of our dependencies. -->
<delete dir="${path.lib}"/>
<mkdir dir="${path.lib}"/>
<!-- Download our updated dependencies. -->
<antcall target="get" inheritRefs="true"/>
<antcall target="clean" inheritRefs="true"/>
</target>
<target name="build" depends="init" description="Build players.">
<!-- We need to import ant tasks like "scalac" to compile scala. -->
<taskdef resource="scala/tools/ant/antlib.xml" if:set="bc.scala">
<classpath>
<fileset dir="${path.lib}" includes="*.jar"/>
</classpath>
</taskdef>
<!-- Compile scala files. We also point scalac at java files, in case you're mixing-and-matching. -->
<scalac srcdir="${path.src}" destdir="${path.bin.main}" target="jvm-1.8"
classpathref="classpath.run" if:set="bc.scala">
<include name="**/*.scala"/>
<include name="**/*.java"/>
</scalac>
<!-- Compile java files, after we've compiled scala files. This should resolve circular dependencies reasonably well. Probably. -->
<javac srcdir="${path.src}" destdir="${path.bin.main}" source="1.8" target="1.8"
debug="true" includeantruntime="false" classpathref="classpath.run">
<compilerarg line="-Xlint"/>
<include name="**/*.java"/>
</javac>
</target>
<target name="build-tests" depends="build" description="Build tests.">
<scalac srcdir="${path.test}" destdir="${path.bin.test}" target="jvm-1.8"
classpathref="classpath.run" if:set="bc.scala">
<include name="**/*.scala"/>
<include name="**/*.java"/>
</scalac>
<javac srcdir="${path.test}" destdir="${path.bin.test}" source="1.8" target="1.8"
debug="true" includeantruntime="false" classpathref="classpath.test">
<compilerarg line="-Xlint"/>
<include name="**/*.java"/>
</javac>
</target>
<target name="run" depends="build" description="Run the battlecode client.">
<!-- Call into battlecode.client to run things. -->
<java classpathref="classpath.run" fork="yes" classname="battlecode.client.Main">
<jvmarg value="-Dapple.awt.graphics.UseQuartz=true"/>
<jvmarg value="-Dsun.java2d.opengl=true"/>
<arg line="-c bc.conf" unless:set="bc.conf"/>
<arg line="-c ${bc.conf}" if:set="bc.conf"/>
</java>
</target>
<target name="headless" depends="build" description="Run the battlecode server without starting the client. Pass -Dbc.conf=[FILE] to supply your own configuration file.">
<!-- Call into battlecode.server to run things. -->
<java classpathref="classpath.run" fork="yes" classname="battlecode.server.Main">
<jvmarg value="-Dbc.server.mode=headless"/>
<arg line="-c bc.conf" unless:set="bc.conf"/>
<arg line="-c ${bc.conf}" if:set="bc.conf"/>
</java>
</target>
<target name="test" depends="build-tests" description="Run tests.">
<!-- Run JUnit for tests. -->
<junit printsummary="withOutAndErr" fork="true" forkmode="once">
<classpath refid="classpath.test"/>
<assertions>
<enable/>
</assertions>
<!-- We only write test output to the terminal. -->
<formatter type="plain" usefile="false"/>
<!-- Test all compiled files. -->
<batchtest>
<fileset dir="${path.bin.test}">
<include name="**/*.class"/>
</fileset>
</batchtest>
</junit>
</target>
<target name="jar" depends="build" description="Package a player for uploading to scrimmages or tournaments.">
<fail unless:set="team">
Run as "ant -Dteam=name jar" where "name" is a folder in your teams folder.
</fail>
<available file="${path.src}/${team}" property="team.exists"/>
<fail unless="team.exists">
You can't jar a team that doesn't exist!
</fail>
<available file="${team}-submission.jar" property="team.jar.exists"/>
<echo message="${team}-submission.jar already exists, deleting" if:set="team.jar.exists"/>
<delete file="${team}-submission.jar" if:set="team.jar.exists"/>
<jar destfile="${team}-submission.jar" basedir="${path.src}" includes="${team}/**/*.java,${team}/**/*.scala"/>
</target>
<target name="mapeditor" description="Run the map editor.">
<java classpathref="classpath.run" fork="yes" classname="battlecode.mapeditor.st3"/>
</target>
<target name="print-version" description="Print the current battlecode version">
<java classpathref="classpath.run" fork="yes" classname="battlecode.server.Version"/>
</target>
</project>