-
Notifications
You must be signed in to change notification settings - Fork 104
/
build.xml
251 lines (217 loc) · 10 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
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
<!--
Apache Ant build script for Java Marine API
Copyright (C) 2010-2012 Kimmo Tuukkanen
This file is part of Java Marine API.
<http://ktuukkan.github.io/marine-api/>
Java Marine API is free software: you can redistribute it and/or modify it
under the terms of the GNU Lesser General Public License as published by the
Free Software Foundation, either version 3 of the License, or (at your
option) any later version.
Java Marine API 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 Lesser General Public License
for more details.
You should have received a copy of the GNU Lesser General Public License
along with Java Marine API. If not, see <http://www.gnu.org/licenses/>.
$Revision$
-->
<project name="Java Marine API" default="build" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<target name="init">
<echo message="Java version: ${ant.java.version}" />
<tstamp>
<format property="build.id" pattern="yyyyMMddHHmmss" />
<format property="date" pattern="yyyy-MM-dd" />
<format property="year" pattern="yyyy" />
</tstamp>
<property file="build.properties" />
<property name="project.id" value="${app.id}" />
<property name="version" value="${app.version}" />
<property name="src.dir" value="src/main/java" />
<property name="tests.dir" value="src/test/java" />
<property name="resources.dir" value="src/main/resources" />
<property name="doc.dir" value="${resources.dir}/doc/" />
<property name="data.dir" value="src/test/resources/data/" />
<property name="build.dir" value="target/" />
<property name="build.dir.classes" value="${build.dir}/classes" />
<property name="build.dir.tests" value="${build.dir}/test-classes" />
<property name="build.dir.dist" value="${build.dir}/dist/" />
<property name="build.dir.javadoc" value="${build.dir}/javadoc/" />
<property name="build.dir.reports" value="${build.dir}/reports/" />
<property name="manifest.file" value="${build.dir}/MANIFEST.MF" />
<property name="jar.file" value="${build.dir}/${project.id}-${version}.jar" />
<property name="release.zip"
value="${build.dir}/${project.id}-${version}.zip" />
<property name="javadoc.title"
value="${app.name} v${version} (b${build.id})" />
<property name="javadoc.footer"
value="Copyright (C) 2010-${year} ${app.name} authors. All Rights Reserved." />
<!-- define Maven coordinates (version is defined earlier above) -->
<property name="groupId" value="net.sf.marineapi" />
<property name="artifactId" value="${project.id}" />
<!-- artifact names, following the Maven conventions -->
<property name="maven-jar" value="${jar.file}" />
<property name="maven-javadoc-jar" value="${build.dir}/${artifactId}-${version}-javadoc.jar" />
<property name="maven-sources-jar" value="${build.dir}/${artifactId}-${version}-sources.jar" />
<!-- maven snapshot and staging repository id and url -->
<property name="maven-snapshots-repository-id" value="sonatype-nexus-snapshots" />
<property name="maven-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots/" />
<property name="maven-staging-repository-id" value="sonatype-nexus-staging" />
<property name="maven-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2/" />
</target>
<!-- compile project -->
<target name="compile-src" depends="init">
<mkdir dir="${build.dir.classes}" />
<javac destdir="${build.dir.classes}" srcdir="${src.dir}" debug="true"
includes="**/*.java" excludes="**/example/**" includeantruntime="true"
source="1.8" target="1.8" />
</target>
<!-- compile tests -->
<target name="compile-tests" depends="compile-src">
<mkdir dir="${build.dir.tests}" />
<javac destdir="${build.dir.tests}" debug="true" srcdir="${tests.dir}"
includeantruntime="true" excludes="**/example/*">
<classpath>
<pathelement path="${build.dir.classes}" />
</classpath>
</javac>
</target>
<!-- clean up -->
<target name="clean" depends="init" description="Cleans up the project">
<delete dir="${build.dir}" />
<delete dir="${builld.dir.release}" />
</target>
<!-- build project -->
<target name="build" depends="compile-src, jar"
description="Compiles the project and builds JAR archive" />
<!-- create jar package -->
<target name="jar" depends="compile-src">
<manifest file="${manifest.file}">
<attribute name="Specification-Title" value="${ant.project.name}" />
<attribute name="Specification-Version" value="${version}" />
<attribute name="Implementation-Title" value="net.sf.marineapi" />
<attribute name="Implementation-Version" value="b${build.id}" />
</manifest>
<jar destfile="${jar.file}" manifest="${manifest.file}">
<fileset dir="${build.dir.classes}" includes="**/*.class" excludes="**/example/*" />
</jar>
</target>
<!-- run all unit tests -->
<target name="test" depends="compile-src, compile-tests"
description="Run all unit tests">
<mkdir dir="${build.dir.reports}" />
<copy todir="${build.dir.tests}/data">
<fileset dir="${data.dir}" />
</copy>
<junit fork="yes" maxmemory="512m" printsummary="true"
haltonfailure="false">
<formatter type="xml" />
<classpath>
<pathelement location="${build.dir.tests}" />
<pathelement location="${build.dir.classes}" />
</classpath>
<batchtest fork="no" todir="${build.dir.reports}"
errorProperty="tests.failed" failureProperty="tests.failed">
<fileset dir="${tests.dir}">
<include name="**/*Test.java" />
</fileset>
</batchtest>
</junit>
<junitreport todir="${build.dir.reports}">
<fileset dir="${build.dir.reports}">
<include name="TEST-*.xml" />
</fileset>
<report format="noframes" todir="${build.dir.reports}" />
</junitreport>
<fail if="tests.failed" message="One or more unit tests failed" />
</target>
<!-- generate javadocs -->
<target name="javadoc" depends="init"
description="Generates the Javadoc documentation">
<mkdir dir="${build.dir.javadoc}" />
<javadoc sourcepath="${src.dir}" destdir="${build.dir.javadoc}"
private="false" windowtitle="${javadoc.title}"
bottom="${javadoc.footer}" breakiterator="true"
excludepackagenames="net.sf.marineapi.example">
<link href="http://docs.oracle.com/javase/7/docs/api/" />
</javadoc>
</target>
<!-- build and package release artifacts -->
<target name="dist" depends="clean, build, javadoc" description="Builds a distribution package">
<mkdir dir="${build.dir.dist}" />
<mkdir dir="${build.dir.dist}/examples" />
<copy todir="${build.dir.dist}" file="${jar.file}" />
<copy todir="${build.dir.dist}/doc/" file="changelog.txt" />
<copy todir="${build.dir.dist}/doc/">
<fileset dir="${doc.dir}" excludes="**/html/**" />
</copy>
<copy todir="${build.dir.dist}/doc/javadoc">
<fileset dir="${build.dir.javadoc}" />
</copy>
<copy todir="${build.dir.dist}/examples/src">
<fileset dir="${src.dir}" includes="**/example/*.java" />
<fileset dir="${build.dir}" includes="**/example/*.class" />
</copy>
<copy todir="${build.dir.dist}/examples/data">
<fileset dir="${data.dir}" includes="*.txt, *.log" />
</copy>
<replace token="@VERSION@" value="${version}"
file="${build.dir.dist}/doc/readme.txt" />
<replace token="@BUILD_ID@" value="${build.id}"
file="${build.dir.dist}/doc/readme.txt" />
<replace token="@YEAR@" value="${year}"
file="${build.dir.dist}/doc/readme.txt" />
<replace token="-SNAPSHOT" value=" (${date})"
file="${build.dir.dist}/doc/changelog.txt" />
<jar destfile="${maven-sources-jar}">
<fileset dir="${src.dir}" includes="**/*.java" excludes="**/example/*" />
</jar>
<jar destfile="${maven-javadoc-jar}">
<fileset dir="${build.dir.javadoc}" />
</jar>
<zip destfile="${release.zip}">
<zipfileset dir="${build.dir.dist}" prefix="${project.id}-${version}/" />
</zip>
</target>
<!-- before this, make sure project version is SNAPSHOT, e.g. 1.2.3-SNAPSHOT -->
<target name="snapshot" depends="dist" description="deploy snapshot version to Maven snapshot repository">
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
<arg value="-Durl=${maven-snapshots-repository-url}" />
<arg value="-DrepositoryId=${maven-snapshots-repository-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${jar.file}" />
</artifact:mvn>
</target>
<!-- before this, update project version number to release version, e.g. 1.2.3 -->
<target name="release" depends="dist" description="deploy release version to Maven staging repository">
<!-- sign and deploy the main artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${maven-staging-repository-url}" />
<arg value="-DrepositoryId=${maven-staging-repository-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${jar.file}" />
<arg value="-Pgpg" />
</artifact:mvn>
<!-- sign and deploy the sources artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${maven-staging-repository-url}" />
<arg value="-DrepositoryId=${maven-staging-repository-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${maven-sources-jar}" />
<arg value="-Dclassifier=sources" />
<arg value="-Pgpg" />
</artifact:mvn>
<!-- sign and deploy the javadoc artifact -->
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${maven-staging-repository-url}" />
<arg value="-DrepositoryId=${maven-staging-repository-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${maven-javadoc-jar}" />
<arg value="-Dclassifier=javadoc" />
<arg value="-Pgpg" />
</artifact:mvn>
</target>
</project>