summaryrefslogtreecommitdiff
path: root/src/interfaces/jdbc/build.xml
blob: 5b1b15f8cd65a732b1af78a5545d80dabd6ad502 (plain)
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
<?xml version="1.0"?>
<!--

  Build file to allow ant (http://jakarta.apache.org/ant/) to be used
  to build the PostgreSQL JDBC Driver.

  This file now requires Ant 1.4.1.  2002-04-18

  $Header: /cvsroot/pgsql/src/interfaces/jdbc/Attic/build.xml,v 1.35.2.1 2003/09/07 04:37:10 momjian Exp $

-->

<!DOCTYPE project [
  <!ENTITY jarfiles "postgresql.jar,postgresql-examples.jar">
]>

<project name="postgresqlJDBC" default="all" basedir=".">

  <!-- set global properties for this build -->
  <property name="srcdir"  value="." />
  <property name="jardir"  value="jars" />
  <property name="builddir" value="build" />
  <property name="package" value="org/postgresql" />
  <property name="debug" value="on" />

  <property file="build.properties"/>

  <!--
    This is a simpler method than utils.CheckVersion
    It defaults to jdbc1, but builds jdbc2 if the java.lang.Byte class is
    in the CLASSPATH (ie JDK1.2 or later), and then enterprise if the
    javax.sql.DataSource class is present.

    Important: This must have the following order: jdbc1, jdbc2, jdbc3
  -->
  <target name="check_versions">
    <condition property="jdbc1">
      <equals arg1="${ant.java.version}" arg2="1.1"/>
    </condition>
    <condition property="jdbc2">
      <or>
        <equals arg1="${ant.java.version}" arg2="1.2"/>
        <equals arg1="${ant.java.version}" arg2="1.3"/>
      </or>
    </condition>
    <condition property="jdbc3">
        <equals arg1="${ant.java.version}" arg2="1.4"/>
    </condition>
    <available property="datasource" classname="javax.sql.DataSource"/>
    <available property="ssl" classname="javax.net.ssl.SSLSocketFactory"/>
    <available property="junit" classname="junit.framework.Test"/>
    <available property="junit.task" classname="org.apache.tools.ant.taskdefs.optional.junit.JUnitTask"/>
    <condition property="jdbc2tests">
      <and>
        <or>
          <isset property="jdbc2"/>
          <isset property="jdbc3"/>
        </or>
        <isset property="junit"/>
      </and>
    </condition>
    <condition property="jdbc2optionaltests">
      <and>
        <or>
          <isset property="jdbc2"/>
          <isset property="jdbc3"/>
        </or>
        <isset property="datasource"/>
        <isset property="junit"/>
      </and>
    </condition>
    <condition property="jdbc3tests">
      <and>
        <isset property="jdbc3"/>
        <isset property="junit"/>
      </and>
    </condition>
  </target>


  <!-- default target -->
  <target name="all">
    <antcall target="jar" />
  </target>


  <!-- create the jar file -->
  <target name="jar" depends="compile,examples">
    <jar jarfile="${jardir}/postgresql.jar">
      <fileset dir="${builddir}">
        <include name="${package}/**/*.class" />
      </fileset>

      <fileset dir="${srcdir}">
        <include name="${package}/*.properties" />
      </fileset>
    </jar>

    <jar jarfile="${jardir}/postgresql-examples.jar">
      <fileset dir="${builddir}">
        <include name="example/**/*.class" />
      </fileset>

      <fileset dir="${srcdir}">
        <include name="example/*.properties" />
      </fileset>
    </jar>
  </target>


  <target name="compile" depends="prepare,check_versions,driver">

    <available classname="org.postgresql.Driver" property="old.driver.present" />
    <fail message="Old driver was detected on classpath or in jre/lib/ext, please remove and try again." if="old.driver.present" />

    <javac classpath="{$srcdir}" srcdir="${srcdir}" destdir="${builddir}" debug="${debug}">
      <!-- This is the core of the driver.  It is common for all three versions. -->
       <include name="${package}/*.java" />
       <include name="${package}/core/**" />
       <include name="${package}/fastpath/**" />
       <include name="${package}/geometric/**" />
       <include name="${package}/largeobject/**" />
       <include name="${package}/util/**" />

       <!--      
       Each jdbcN subpackage is used only if the driver supports *at least* that
       revision of JDBC. That is, a JDBC1 build uses only jdbc1, a JDBC2 build
       uses both jdbc1 and jdbc2, etc.
  
       Within those subpackages, classes beginning with "JdbcN" are assumed to be
       the concrete implementations for JDBC version N and are built only if the
       driver supports *exactly* that version. For example, jdbc1/Jdbc1Statement.java
       is built only if the driver build is a JDBC1 build.
       -->
 
       <!-- jdbc1 subpackage -->
       <include name="${package}/jdbc1/**"/>
       <exclude name="${package}/jdbc1/Jdbc1*.java" unless="jdbc1"/>
 
       <!-- jdbc2 subpackage -->
       <include name="${package}/jdbc2/**" if="jdbc2"/>
       <include name="${package}/jdbc2/**" if="jdbc3"/>
       <exclude name="${package}/jdbc2/Jdbc2*.java" unless="jdbc2"/>
       <exclude name="${package}/jdbc2/optional/**" unless="datasource"/>
 
       <!-- jdbc3 subpackage -->
       <include name="${package}/jdbc3/*.java" if="jdbc3"/>
       <exclude name="${package}/jdbc3/Jdbc3*.java" unless="jdbc3"/>

    </javac>
  </target>

  <target name="check_driver">
    <uptodate targetfile="${package}/Driver.java" property="driver.uptodate">
      <srcfiles dir=".">
      <include name="${package}/Driver.java.in"/>
      <include name="build.properties"/>
      </srcfiles>
    </uptodate>
  </target>

  <!--
    This generates Driver.java from Driver.java.in
    It's required for importing the driver version properties
  -->
  <target name="driver" depends="prepare,check_versions,check_driver"
          unless="driver.uptodate">
    <!-- determine the edition text -->
    <condition property="edition" value="JDBC1">
        <equals arg1="${jdbc1}" arg2="true"/>
    </condition>
    <condition property="edition" value="JDBC2">
        <equals arg1="${jdbc2}" arg2="true"/>
    </condition>
    <condition property="edition" value="JDBC3">
        <equals arg1="${jdbc3}" arg2="true"/>
    </condition>
    <condition property="edition" value="JDBC2 Enterprise">
      <and>
        <available classname="javax.sql.DataSource" />
        <equals arg1="${jdbc2}" arg2="true"/>
      </and>
    </condition>

    <!-- determine the connection class -->
    <condition property="connectclass" value="org.postgresql.jdbc1.Jdbc1Connection">
        <equals arg1="${jdbc1}" arg2="true"/>
    </condition>
    <condition property="connectclass" value="org.postgresql.jdbc2.Jdbc2Connection">
        <equals arg1="${jdbc2}" arg2="true"/>
    </condition>
    <condition property="connectclass" value="org.postgresql.jdbc3.Jdbc3Connection">
        <equals arg1="${jdbc3}" arg2="true"/>
    </condition>

    <!-- determine the ssl status -->
    <condition property="ssl_config" value="">
        <equals arg1="${ssl}" arg2="true"/>
    </condition>
    <condition property="ssl_config" value="//">
        <not>
            <equals arg1="${ssl}" arg2="true"/>
        </not>
    </condition>
    <condition property="ssl_edition" value="SSL">
        <equals arg1="${ssl}" arg2="true"/>
    </condition>
    <condition property="ssl_edition" value="NO SSL">
        <not>
            <equals arg1="${ssl}" arg2="true"/>
        </not>
    </condition>

    <!-- Some defaults -->
    <filter token="MAJORVERSION" value="${major}" />
    <filter token="MINORVERSION" value="${minor}" />
    <filter token="VERSION" value="PostgreSQL ${fullversion} ${edition} with ${ssl_edition}" />
    <filter token="JDBCCONNECTCLASS" value="${connectclass}" />
    <filter token="DEF_PGPORT" value="${def_pgport}" />
    <filter token="SSL" value="${ssl_config}" />

     <fail unless="major" message="'major' undefined. Please follow the directions in README."/>
     <fail unless="minor" message="'minor' undefined. Please follow the directions in README."/>
     <fail unless="fullversion" message="'fullversion' undefined. Please follow the directions in README."/>
     <fail unless="def_pgport" message="'def_pgport' undefined. Please follow the directions in README."/>
     <fail unless="enable_debug" message="'enable_debug' undefined. Please follow the directions in README."/>
 
    <!-- Put a check for the current version here -->

    <!-- now copy and filter the file -->
    <copy file="${package}/Driver.java.in"
          overwrite="true"
          tofile="${package}/Driver.java"
          filtering="yes" />

    <echo message="Configured build for the ${edition} edition driver with ${ssl_edition}" />
  </target>


  <!-- Prepares the build directory -->
  <target name="prepare">
    <!-- use the enable_debug option from configure -->
    <condition property="debug" value="on">
      <and>
        <equals arg1="${enable_debug}" arg2="yes" />
      </and>
    </condition>
    <mkdir dir="${builddir}" />
    <mkdir dir="${jardir}" />
  </target>


  <!-- This builds the examples -->
  <target name="examples" depends="compile">
    <javac srcdir="${srcdir}" destdir="${builddir}" debug="${debug}">
      <include name="example/**" />
      <exclude name="example/corba/**"/>
      <exclude name="example/blobtest.java" if="jdbc1"/>
    </javac>
  </target>


  <!-- Builds the corba example -->
  <target name="corba" if="jdbc2">
    <exec dir="${srcdir}/example/corba" executable="idl2java">
      <arg value="stock.idl" />
    </exec>

    <javac srcdir="${srcdir}" destdir="${builddir}" debug="${debug}">
      <include name="example/corba/**" />
    </javac>
  </target>



  <!-- Install the jar files -->
  <target name="install" depends="all" if="install.directory">
    <copy todir="${install.directory}" overwrite="true">
      <fileset dir="${jardir}" includes="&jarfiles;" />
    </copy>
  </target>


  <!-- Uninstall the jar file -->
  <target name="uninstall" if="install.directory">
    <delete>
      <fileset dir="${install.directory}" includes="&jarfiles;" />
    </delete>
  </target>



  <!-- This target removes any class files from the build directory -->
  <target name="clean">
    <delete quiet="true" dir="${builddir}" />
    <delete quiet="true" dir="${jardir}" />
    <delete quiet="true" file="${package}/Driver.java" />
  </target>

  <target name="clean_all" depends="clean">
    <delete quiet="true" file="build.properties" />
  </target>


  <!-- This compiles and executes the JUnit tests -->

  <!-- defaults for the tests - override these if required -->
  <property name="database" value="jdbc:postgresql:test" />
  <property name="username" value="test" />
  <!-- Password must be something.  Doesn't matter if trust is used! -->
  <property name="password" value="password" />

  <!-- The tests now build to a separate directory and jarfile from the
       driver build, to ensure we're really testing against the jar we just
       built, and not whatever happens to be in builddir. -->

  <!-- This compiles and builds the test jarfile. -->  
  <target name="testjar" depends="jar" if="junit">
    <mkdir dir="${builddir}/tests"/>
    <javac srcdir="${srcdir}" destdir="${builddir}/tests" debug="${debug}">
      <include name="${package}/test/**" />

      <exclude name="${package}/test/jdbc2/**" unless="jdbc2tests"/>
      <exclude name="${package}/test/jdbc2/optional/**" unless="jdbc2optionaltests" />
      <exclude name="${package}/test/jdbc3/**" unless="jdbc3tests" />
      <exclude name="${package}/test/util/**" unless="jdbc2optionaltests"/>

      <classpath>
        <pathelement location="${jardir}/postgresql.jar"/>
      </classpath>
    </javac>
    <jar jarfile="${jardir}/postgresql-tests.jar" basedir="${builddir}/tests"/>
  </target>
    
  <!-- This actually runs the tests -->
  <target name="runtest" depends="testjar" if="junit.task">
    <junit>
      <formatter type="brief" usefile="false"/>

      <sysproperty key="database" value="${database}" />
      <sysproperty key="username" value="${username}" />
      <sysproperty key="password" value="${password}" />

      <classpath>
        <pathelement location="${jardir}/postgresql.jar" />
        <pathelement location="${jardir}/postgresql-tests.jar" />
        <pathelement path="${java.class.path}" />
      </classpath>

      <test name="org.postgresql.test.jdbc2.Jdbc2TestSuite" if="jdbc2tests"/>
      <test name="org.postgresql.test.jdbc2.optional.OptionalTestSuite" if="jdbc2optionaltests"/>
      <test name="org.postgresql.test.jdbc3.Jdbc3TestSuite" if="jdbc3tests"/>
    </junit>
  </target>
  
  <!-- This is the target invoked by the Makefile -->
  <target name="test" depends="testjar,runtest"/>

</project>