forked from TinaYTZ/URLshortener
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild.xml
287 lines (238 loc) · 9.48 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
277
278
279
280
281
282
283
284
285
286
287
<?xml version="1.0" ?>
<!--
HSQLDB database server
Install Ant
Place this build.xml in a directory by itself
(e.g. C:\hsqldb or $HOME/hsqldb)
Change to that directory and run
ant -projecthelp
to see the available targets
Note: you will need an Internet connection to download dependencies
the first time you run this script
-->
<project name="hsqldb" default="init"
xmlns:artifact="antlib:org.apache.maven.artifact.ant">
<property name="maven.version" value="2.1.3" />
<property name="maven.jar"
value="maven-ant-tasks-${maven.version}.jar" />
<property name="maven.url"
value="http://search.maven.org/remotecontent?filepath=org/apache/maven/maven-ant-tasks/${maven.version}/${maven.jar}" />
<property name="hsqldb.version" value="2.3.4" />
<property name="sqltool.jar" value="sqltool-${hsqldb.version}.jar" />
<property name="hsqldb.jar" value="hsqldb-${hsqldb.version}.jar" />
<property name="ojdbc14.jar" value="ojdbc14.jar" />
<target name="check-maven-available">
<available file="antlib/${maven.jar}" property="maven.available" />
</target>
<target name="bootstrap-maven"
depends="check-maven-available"
unless="maven.available">
<mkdir dir="antlib" />
<mkdir dir="lib" />
<get dest="antlib/${maven.jar}"
usetimestamp="true"
skipexisting="true"
src="${maven.url}" />
</target>
<target name="resolve-dependencies" depends="bootstrap-maven">
<typedef resource="org/apache/maven/artifact/ant/antlib.xml"
uri="antlib:org.apache.maven.artifact.ant"
classpath="antlib/${maven.jar}" />
<artifact:dependencies filesetId="dependency.fileset">
<dependency groupId="org.hsqldb"
artifactId="hsqldb"
version="${hsqldb.version}" />
<dependency groupId="org.hsqldb"
artifactId="sqltool"
version="${hsqldb.version}" />
</artifact:dependencies>
<copy todir="lib">
<fileset refid="dependency.fileset" />
<mapper type="flatten" />
</copy>
</target>
<target name="check-sqltool-rc-available">
<available file="etc/sqltool.rc"
property="sqltool.rc.available" />
</target>
<target name="bootstrap-sqltool-rc"
depends="check-sqltool-rc-available"
unless="sqltool.rc.available">
<echo file="etc/sqltool.rc">
urlid cpsc476
url jdbc:hsqldb:hsql://localhost/cpsc476;ifexists=true
username SA
password Passw0rd
urlid create
url jdbc:hsqldb:file:data/cpsc476;create=true
username SA
password Passw0rd
</echo>
</target>
<target name="check-db-exists">
<available file="data" type="dir" property="db.exists" />
</target>
<target name="init"
depends="resolve-dependencies, bootstrap-sqltool-rc, check-db-exists"
unless="db.exists"
description="Create HSQLDB database">
<mkdir dir="data" />
<java classname="org.hsqldb.cmdline.SqlTool"
classpath="lib/${sqltool.jar}"
failonerror="true">
<arg value="--rcFile" />
<arg value="etc/sqltool.rc" />
<arg value="--sql" />
<arg value="" />
<arg value="create" />
</java>
</target>
<target name="check-server-properties-available">
<available file="etc/server.properties"
property="server.properties.available" />
</target>
<target name="bootstrap-server-properties"
depends="check-server-properties-available"
unless="server.properties.available">
<echo file="etc/server.properties">
server.database.0=file:../data/cpsc476;ifexists=true
server.dbname.0=cpsc476
server.silent=false
</echo>
</target>
<target name="start"
depends="init, bootstrap-server-properties"
description="Start HSQLDB server">
<java classname="org.hsqldb.server.Server"
classpath="lib/${hsqldb.jar}"
dir="etc"
fork="true"
spawn="true"
/>
<echo message="HSQLDB started" />
</target>
<target name="createTables" depends="init, bootstrap-server-properties"
description="Start HSQLDB server">
<echo message="Initializing the Database.." />
<echo message="Following tables will be created:" />
<echo message="1. Users: Maintains List of Users and passwords" />
<echo message="2. GlobalUrlDB: Maintains List of all Short URLs, LongURLs and the Visit Status to the Short URL" />
<echo message="3. UserUrlList: Tracks the list of URLs shortened by Users" />
<echo message="Initialized Users table with a test user" />
<echo message="Username: testUser, Password: testPassword" />
<sql
classpath="lib/hsqldb-2.3.4.jar"
driver="org.hsqldb.jdbcDriver"
url="jdbc:hsqldb:hsql://localhost/cpsc476"
userid="SA"
password="Passw0rd"
expandProperties="true">
<transaction>
CREATE TABLE Users(userID INTEGER GENERATED BY DEFAULT AS IDENTITY (START WITH 1) NOT NULL PRIMARY KEY,username VARCHAR(50) UNIQUE,password VARCHAR(16));
</transaction>
<transaction>
CREATE TABLE GlobalUrlDB(urlid INTEGER NOT NULL PRIMARY KEY IDENTITY, shortUrl VARCHAR(50),longUrl VARCHAR(1000),visitCount INTEGER);
</transaction>
<transaction>
CREATE TABLE UserUrlList(userid INTEGER, shortUrl VARCHAR(50), longUrl VARCHAR(1000));
</transaction>
<transaction>
INSERT INTO Users (userid, userName,password )values('1', 'testUser', 'testPassword');
</transaction>
</sql>
</target>
<target name="check-stopped"
depends="check-stopped-ok, check-stopped-error" />
<target name="check-stop-conditions">
<condition property="result.ok">
<equals arg1="${stop.result}" arg2="0" />
</condition>
<condition property="result.already-stopped">
<equals arg1="${stop.result}" arg2="7" />
</condition>
<condition property="stopped.ok">
<or>
<isset property="result.ok" />
<isset property="result.already-stopped" />
</or>
</condition>
</target>
<target name="check-stopped-ok"
depends="check-stop-conditions"
if="stopped.ok">
<echo message="HSQLDB stopped" />
</target>
<target name="check-stopped-error"
depends="check-stop-conditions"
unless="stopped.ok">
<echo message="Error stopping HSQLDB" />
</target>
<target name="stop-server">
<java classname="org.hsqldb.cmdline.SqlTool"
classpath="lib/${sqltool.jar}"
outputproperty="stop.output"
resultproperty="stop.result">
<arg value="--rcFile" />
<arg value="etc/sqltool.rc" />
<arg value="--sql" />
<arg value="SHUTDOWN SCRIPT;" />
<arg value="cpsc476" />
</java>
</target>
<target name="stop"
depends="init, stop-server, check-stopped"
description="Stop HSQLDB server" />
<target name="test-connection">
<java classname="org.hsqldb.cmdline.SqlTool"
classpath="lib/${sqltool.jar}"
outputproperty="check.output"
resultproperty="check.result">
<arg value="--rcFile" />
<arg value="etc/sqltool.rc" />
<arg value="--sql" />
<arg value="SELECT implementation_info_name, character_value
FROM information_schema.sql_implementation_info
WHERE implementation_info_name
IN ('DBMS NAME', 'DBMS VERSION';" />
<arg value="cpsc476" />
</java>
</target>
<target name="check-connection"
depends="check-connection-ok, check-connection-error" />
<target name="check-connection-conditions">
<condition property="connection.ok">
<equals arg1="${check.result}" arg2="3" />
</condition>
</target>
<target name="check-connection-ok"
depends="check-connection-conditions"
if="connection.ok">
<echo message="HSQLDB is running" />
</target>
<target name="check-connection-error"
depends="check-connection-conditions"
unless="connection.ok">
<echo message="HSQLDB is not running" />
</target>
<target name="status"
depends="init, test-connection, check-connection"
description="Check if HSQLDB server is running" />
<target name="clean"
depends="stop"
description="Delete HSQLDB database">
<delete dir="data" />
</target>
<target name="manage"
depends="start"
description="Start HSQLDB Database Manager GUI">
<java classname="org.hsqldb.util.DatabaseManagerSwing"
classpath="lib/${hsqldb.jar}"
fork="true"
spawn="true">
<arg value="--rcFile" />
<arg value="etc/sqltool.rc" />
<arg value="--urlid" />
<arg value="cpsc476" />
</java>
</target>
</project>