-
Notifications
You must be signed in to change notification settings - Fork 20
/
build.xml
232 lines (198 loc) · 8.92 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
<!--
// This file is part of TagSoup and is Copyright 2002-2008 by John Cowan.
//
// TagSoup is licensed under the Apache License,
// Version 2.0. You may obtain a copy of this license at
// http://www.apache.org/licenses/LICENSE-2.0 . You may also have
// additional legal rights not granted by this license.
//
// TagSoup is distributed in the hope that it will be useful, but
// unless required by applicable law or agreed to in writing, TagSoup
// is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
// OF ANY KIND, either express or implied; not even the implied warranty
// of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-->
<project name="tagsoup" default="dist" xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<!-- generic properties -->
<property file="etc/build/build.properties"/>
<!-- additional tasks -->
<taskdef file="etc/build/taskdefs.txt" classpath="bin"/>
<available property="transformer.factory"
classname="com.icl.saxon.TransformerFactoryImpl"
value="com.icl.saxon.TransformerFactoryImpl"/>
<available property="transformer.factory"
classname="net.sf.saxon.TransformerFactoryImpl"
value="net.sf.saxon.TransformerFactoryImpl"/>
<available property="transformer.factory"
classname="org.apache.xalan.processor.TransformerFactoryImpl"
value="org.apache.xalan.processor.TransformerFactoryImpl"/>
<available property="transformer.factory"
classname="com.sun.org.apache.xalan.processor.TransformerFactoryImpl"
value="com.sun.org.apache.xalan.processor.TransformerFactoryImpl"/>
<!-- some folder settings -->
<property name="bin" value="bin"/>
<property name="src" value="src"/>
<property name="build" value="build"/>
<property name="dist" value="dist"/>
<property name="docs" value="docs"/>
<property name="tmp" value="tmp"/>
<!-- define Maven coordinates -->
<property name="groupId" value="org.ccil.cowan.tagsoup" />
<property name="artifactId" value="tagsoup" />
<property name="version" value="${tagsoup.version}" />
<!-- define artifacts' name, which follows the convention of Maven -->
<property name="maven-jar" value="${dist}/lib/${artifactId}-${version}.jar" />
<property name="maven-javadoc-jar" value="${dist}/lib/${artifactId}-${version}-javadoc.jar" />
<property name="maven-sources-jar" value="${dist}/lib/${artifactId}-${version}-sources.jar" />
<!-- defined maven snapshots 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/" />
<!-- initialize project -->
<target name="init" description="Init project.">
<tstamp/>
</target>
<!-- ensure needed folders are available -->
<target name="prepare" description="Set up folders.">
<mkdir dir="${build}"/>
<mkdir dir="${tmp}"/>
</target>
<!-- Build a distribution jar file -->
<target name="dist" depends="init,compile,docs-api"
description="Build a binary distribution file.">
<antcall target="jar-release">
<param name="buildDir" value="build"/>
<param name="version" value="${tagsoup.version}"/>
</antcall>
<!-- build the javadoc artifact -->
<jar jarfile="${maven-javadoc-jar}">
<fileset dir="${docs}/api" />
</jar>
<!-- build the sources artifact -->
<jar jarfile="${maven-sources-jar}">
<fileset dir="${src}/java" />
<fileset dir="${tmp}/src" />
</jar>
</target>
<target name="jar-release" depends="init"
description="Build a release jar file.">
<mkdir dir="${dist}/lib" />
<jar jarfile="${dist}/lib/tagsoup-${tagsoup.version}.jar" basedir="${buildDir}">
<manifest>
<attribute name="Version" value="${tagsoup.version}"/>
<attribute name="Main-Class" value="org.ccil.cowan.tagsoup.CommandLine"/>
</manifest>
</jar>
</target>
<!-- compile java sources -->
<target name="compile" depends="init,prepare,build-parser"
description="Compile java classes.">
<javac source="1.4" target="1.4" srcdir="${src}/java" destdir="${build}" deprecation="on" verbose="off" debug="on">
<src path="${src}/java"/>
<src path="${tmp}/src"/>
</javac>
</target>
<!-- prepare generation of the parser classes based on the definition files -->
<target depends="init,prepare" description="Prepare generation of parser classes." name="prepare-parser">
<echo>
Using ${transformer.factory} as the TransformerFactory
</echo>
<xslt in="${src}/definitions/html.tssl" out="${tmp}/HTMLModels.i"
style="tssl/tssl-models.xslt">
<factory name="${transformer.factory}"/>
</xslt>
<xslt in="${src}/definitions/html.tssl" out="${tmp}/HTMLSchema.i"
style="tssl/tssl.xslt">
<factory name="${transformer.factory}"/>
</xslt>
<xslt in="${src}/definitions/html.stml" out="${tmp}/HTMLScanner.i"
style="stml/stml.xslt">
<factory name="${transformer.factory}"/>
</xslt>
</target>
<!-- patch the parser class files -->
<target name="build-parser" depends="prepare-parser"
description="Generate parser class files.">
<property name="parser.pkg-path" value="org/ccil/cowan/tagsoup"/>
<mkdir dir="${tmp}/src/${parser.pkg-path}"/>
<antcall target="patch-file">
<param name="file-pref" value="HTMLModels"/>
<param name="token" value="MODEL_DEFINITIONS"/>
</antcall>
<antcall target="patch-file">
<param name="file-pref" value="HTMLSchema"/>
<param name="token" value="SCHEMA_CALLS"/>
</antcall>
<antcall target="patch-file">
<param name="file-pref" value="HTMLScanner"/>
<param name="token" value="STATE_TABLE"/>
</antcall>
</target>
<!-- patch one parser class file -->
<target name="patch-file" depends="" description="Patch a parser class file.">
<copy file="${src}/templates/${parser.pkg-path}/${file-pref}.java" toDir="${tmp}/src/${parser.pkg-path}"/>
<loadfile property="patch" srcFile="${tmp}/${file-pref}.i"/>
<replace file="${tmp}/src/${parser.pkg-path}/${file-pref}.java" token="@@${token}@@" value="${patch}"/>
</target>
<!-- clean up the mess -->
<target name="clean" description="Clean up folders.">
<delete dir="${build}"/>
<delete dir="${tmp}"/>
<delete dir="${docs}"/>
<delete dir="${dist}"/>
</target>
<!-- generate javadoc for the java classes -->
<target name="docs-api" depends="init"
description="Generate javadoc documentation.">
<mkdir dir="${docs}/api"/>
<javadoc packagenames="org.*"
sourcepath="${src}/java" destdir="${docs}/api"
use="true"
windowtitle="TagSoup ${tagsoup.version} API">
<doctitle><![CDATA[<h1>TagSoup Package Documentation</h1>]]></doctitle>
<bottom><![CDATA[<em>License</em>: <strong>Apache 2.0</strong>]]></bottom>
</javadoc>
</target>
<target name="deploy" 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=${maven-jar}" />
</artifact:mvn>
</target>
<!-- before this, update project version (both build.xml and pom.xml) from SNAPSHOT to RELEASE -->
<target name="stage" 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=${maven-jar}" />
<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>