forked from amplitude/Amplitude-Android
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.xml
276 lines (230 loc) · 12.4 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
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
<project name="Amplitude Android SDK" basedir="." default="dist" xmlns:artifact="urn:maven-artifact-ant">
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="urn:maven-artifact-ant"
classpath="lib/maven-ant-tasks-2.1.3.jar" />
<description />
<!-- set global properties for this build -->
<property name="src" location="src" />
<property name="build" location="build" />
<property name="dist" location="dist" />
<property name="test.src" location="test" />
<property name="test.reports" location="${dist}/reports"/>
<property environment="env" />
<property name="android-sdk-path" value="${env.ANDROID_SDK}" />
<property name="android-target" value="${env.ANDROID_TARGET}" />
<property name="groupId" value="com.amplitude" />
<property name="artifactId" value="amplitude-android" />
<property name="version" value="2.21.0" />
<property name="jar" value="${dist}/lib/${artifactId}-${version}.jar" />
<property name="uberjar" value="${dist}/lib/${artifactId}-${version}-with-dependencies.jar" />
<property name="unity-jar" value="amplitude-unity-${version}.jar" />
<property name="javadoc-jar" value="${dist}/lib/${artifactId}-${version}-javadoc.jar" />
<property name="sources-jar" value="${dist}/lib/${artifactId}-${version}-sources.jar" />
<tstamp>
<format property="long-date" pattern="MMMM dd, yyyy"/>
</tstamp>
<!-- Load dependencies from pom -->
<artifact:dependencies pathId="dependency.classpath" useScope="runtime">
<artifact:pom file="pom.xml" />
</artifact:dependencies>
<path id="project.classpath">
<path refid="dependency.classpath"/>
<pathelement path="${android-sdk-path}/platforms/android-${android-target}/android.jar" />
</path>
<!-- Prepare dependency path jar list for inclusion in uberjar -->
<pathconvert refid="dependency.classpath" property="dependency.list" pathsep="," dirsep="/">
<map from="/" to=""/>
</pathconvert>
<!-- Load test dependency classpath from pom-->
<artifact:dependencies pathId="dependency.testclasspath" useScope="test">
<artifact:pom file="pom.xml" />
</artifact:dependencies>
<path id="project.testclasspath">
<path refid="dependency.testclasspath"/>
<pathelement path="${android-sdk-path}/platforms/android-${android-target}/android.jar" />
</path>
<target name="init">
<mkdir dir="${build}" />
<mkdir dir="${dist}/lib" />
<mkdir dir="${test.reports}" />
</target>
<target name="clean" >
<delete dir="${build}" />
<delete dir="${dist}" />
</target>
<target name="build" depends="init" >
<echo message="Building for android target ${android-target}" />
<echo message="Java version: ${java.version}"/>
<echo message="Android SDK Path: ${toString:project.classpath}" />
<javac classpathref="project.classpath"
srcdir="${src}"
destdir="${build}"
includeantruntime="false"
debug="true"
target="1.7"
source="1.7">
<classpath refid="dependency.classpath" />
</javac>
</target>
<target name="docs" >
<javadoc classpathref="project.classpath" destdir="javadoc">
<fileset dir="${src}" defaultexcludes="yes">
<exclude name="com/amplitude/security/**"/>
<exclude name="com/amplitude/unity/**"/>
<exclude name="com/amplitude/api/AmplitudeLog.java"/>
<exclude name="com/amplitude/api/Constants.java"/>
<exclude name="com/amplitude/api/DeviceInfo.java"/>
<exclude name="**SSLContextBuilder**"/>
<exclude name="com/amplitude/api/Utils.java"/>
<exclude name="com/amplitude/api/WorkerThread.java"/>
<exclude name="com/amplitude/api/CursorWindowAllocationException.java"/>
</fileset>
</javadoc>
</target>
<target name="jar" depends="build">
<jar destfile="${jar}" basedir="${build}" includes="com/amplitude/api/*.class, com/amplitude/security/*.class" />
<jar destfile="${uberjar}">
<fileset dir="${build}" includes="com/amplitude/api/*.class, com/amplitude/security/*.class" />
<zipgroupfileset id="dependency.fileset" dir="/" includes="${dependency.list}"/>
</jar>
</target>
<target name="unity" depends="build" description="creates jar for unity plugin">
<jar destfile="${unity-jar}">
<fileset dir="${build}" includes="com/amplitude/api/*.class, com/amplitude/unity/plugins/*.class, com/amplitude/security/*.class" />
<fileset dir="${src}" includes="com/amplitude/api/*.java, com/amplitude/unity/plugins/*.java, com/amplitude/security/*.java" />
<zipgroupfileset id="dependency.fileset" dir="/" includes="${dependency.list}"/>
</jar>
</target>
<target name="dist" depends="jar" description="creates release jar with javadoc and sources">
<javadoc classpathref="project.classpath" sourcepath="${src}" destdir="${dist}/javadoc">
<fileset dir="${src}" includes="com/amplitude/api/*.java, com/amplitude/security/*.java" />
</javadoc>
<jar jarfile="${javadoc-jar}">
<fileset dir="${dist}/javadoc" />
</jar>
<jar jarfile="${sources-jar}">
<fileset dir="${src}" includes="com/amplitude/api/*.java, com/amplitude/security/*.java" />
</jar>
<copy file="${jar}" todir="."/>
<copy file="${uberjar}" todir="."/>
</target>
<target name="update-version">
<replaceregexp match="\d+\.\d+.\d+(-SNAPSHOT)?" replace="${version}" flags="g">
<fileset dir="." includes="README.md"/>
<fileset dir="${src}" includes="com/amplitude/api/Constants.java" />
</replaceregexp>
<replaceregexp match="<version>[\d.]*(-SNAPSHOT)?</version>" replace="<version>${version}</version>">
<fileset dir="." includes="pom.xml"/>
</replaceregexp>
<replaceregexp match="name=.version. value=.[\d.]*(-SNAPSHOT)?." replace="name="version" value="${version}"" >
<fileset dir="." includes="build.xml"/>
</replaceregexp>
</target>
<target name="tag" depends="update-version,dist,unity" description="commits new artifacts to git and tags the release">
<echo message="Tagging artifacts in git for version ${version}"/>
<exec dir="." executable="git"><arg line="checkout -b v${version}-snapshot"/></exec>
<exec dir="." executable="git"><arg line="rm amplitude-*jar"/></exec>
<replaceregexp match="## Unreleased" replace="## Unreleased ## ${version} (${long-date})" flags="g">
<fileset dir="." includes="CHANGELOG.md"/>
</replaceregexp>
<exec dir="." executable="git"><arg line="add amplitude-*jar README.md pom.xml build.xml" /></exec>
<exec dir="." executable="git"><arg line="add src/com/amplitude/api/Constants.java" /></exec>
<exec dir="." executable="git"><arg line="add CHANGELOG.md" /></exec>
<exec dir="." executable="git"><arg line="commit -m 'Version ${version}'" /></exec>
<exec dir="." executable="git"><arg line="tag v${version}" /></exec>
<exec dir="." executable="git"><arg line="push --tags origin v${version}-snapshot" /></exec>
<echo message="The release has been tagged in the v${version} branch. To publish the release to github:"/>
<echo message="git checkout master; git merge v${version}; git push origin master"/>
</target>
<target name="release" depends="clean,tag" description="prepares for a release">
<antcall target="test-snapshot" inheritAll="false">
<param name="version" value="${version}-SNAPSHOT"/>
</antcall>
<antcall target="maven-stage" >
<param name="version" value="${version}"/>
</antcall>
</target>
<property name="ossrh-snapshots-repository-url" value="https://oss.sonatype.org/content/repositories/snapshots" />
<property name="ossrh-staging-repository-url" value="https://oss.sonatype.org/service/local/staging/deploy/maven2" />
<property name="ossrh-server-id" value="ossrh" />
<!-- version in build.xml and pom.xml must be -SNAPSHOT -->
<target name="maven-snapshot" depends="update-version,dist" description="deploy snapshot version to Maven snapshot repository">
<echo message="Uploading artifacts to maven snapshot for version ${version}"/>
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-deploy-plugin:2.6:deploy-file" />
<arg value="-Durl=${ossrh-snapshots-repository-url}" />
<arg value="-DrepositoryId=${ossrh-server-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${jar}" />
</artifact:mvn>
</target>
<target name="test-snapshot" depends="maven-snapshot" description="test release packages">
<echo message="Testing release artifacts for ${version}"/>
<echo message="Cloning demo app..."/>
<exec dir="." executable="rm"><arg line="-rf test-release"/></exec>
<exec dir="." executable="git"><arg line="clone https://github.com/amplitude/AndroidDemo test-release"/></exec>
<exec dir="test-release" executable="./amplitude-test.sh"><arg line="${version}"/></exec>
<exec dir="." executable="rm"><arg line="-rf test-release"/></exec>
</target>
<target name="build-tests" depends="build" description="Compile test files">
<path id="test.classpath">
<fileset dir="lib" includes="**/*.jar" />
<path refid="project.testclasspath" />
</path>
<javac srcdir="${test.src}"
destdir="${build}"
classpathref="test.classpath"
includeantruntime="false"
debug="true"
target="1.7"
source="1.7">
<classpath refid="dependency.testclasspath" />
</javac>
</target>
<target name="test" depends="build-tests" description="Runs all Robolectric unit tests.">
<path id="junit.classpath">
<pathelement location="./"/>
<pathelement location="${build}" />
<fileset dir="lib" includes="**/*.jar" />
<path refid="project.testclasspath" />
</path>
<junit failureproperty="junit.failure" printsummary="yes" fork="on">
<classpath refid="junit.classpath" />
<formatter type="brief" />
<batchtest todir="${test.reports}">
<fileset dir="${test.src}" includes="**/*Test.java" excludes="**/BaseTest.java" />
</batchtest>
</junit>
<fail if="junit.failure" message="Unit test(s) failed. See reports!" />
</target>
<!-- version in build.xml and pom.xml must NOT be -SNAPSHOT -->
<target name="maven-stage" depends="update-version,dist" description="deploy release version to Maven staging repository">
<echo message="Uploading artifacts to maven for version ${version}"/>
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${ossrh-staging-repository-url}" />
<arg value="-DrepositoryId=${ossrh-server-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${jar}" />
<arg value="-Pgpg" />
</artifact:mvn>
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${ossrh-staging-repository-url}" />
<arg value="-DrepositoryId=${ossrh-server-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${sources-jar}" />
<arg value="-Dclassifier=sources" />
<arg value="-Pgpg" />
</artifact:mvn>
<artifact:mvn>
<arg value="org.apache.maven.plugins:maven-gpg-plugin:1.3:sign-and-deploy-file" />
<arg value="-Durl=${ossrh-staging-repository-url}" />
<arg value="-DrepositoryId=${ossrh-server-id}" />
<arg value="-DpomFile=pom.xml" />
<arg value="-Dfile=${javadoc-jar}" />
<arg value="-Dclassifier=javadoc" />
<arg value="-Pgpg" />
</artifact:mvn>
</target>
</project>