summaryrefslogtreecommitdiffstats
path: root/proxy/build.xml
blob: dc3c6ea8f555cd70de74c1981a0088d535a01153 (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
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
<?xml version="1.0"?>

<!--
  Spacewalk build file, please indent 2 spaces. NO TABS!
-->
<project name="candlepin" default="all">

  <!-- setup properties -->
  <property environment="env" />
  <property file="${user.home}/.${ant.project.name}.properties" />
  <property file="buildconf/build.properties" />

  <path id="bootjars">
    <fileset dir="${boot.lib.dir}" includes="*.jar" />
  </path>
  
  <path id="testjars">
    <fileset dir="${test.lib.dir}" includes="*.jar" />
  </path>
  
  <path id="runjars">
    <fileset dir="${run.lib.dir}" includes="**/*.jar" />
  </path>

  <path id="libjars">
    <fileset dir="lib/" includes="**/*.jar" />
  </path>
  
  <path id="buildjars">
    <path refid="testjars" />
    <fileset dir="${build.lib.dir}">
      <include name="*.jar" />
      <include name="log4j.properties" />
      <include name="${build.dir}/classes/" />
    </fileset>
  </path>

  <path id="alljars">
    <path refid="buildjars" />
    <path refid="runjars" />
  </path>

  <target name="init-ivy" depends="boot-deps" unless="installbuild">
    <taskdef name="ivy-retrieve"
             classname="fr.jayasoft.ivy.ant.IvyRetrieve"
             classpathref="bootjars"/>
    <taskdef name="ivy-configure"
             classname="fr.jayasoft.ivy.ant.IvyConfigure"
             classpathref="bootjars"/>
    <taskdef name="ivy-resolve"
             classname="fr.jayasoft.ivy.ant.IvyResolve"
             classpathref="bootjars"/>
    <taskdef name="ivy-publish"
             classname="fr.jayasoft.ivy.ant.IvyPublish"
             classpathref="bootjars"/>
  </target>

  <target name="init-taskdefs" depends="link-jars"
          unless="init-taskdefs.notrequired">
    <!-- pull in checkstyle's properties defining its tasks -->
    <taskdef resource="checkstyletask.properties"
             classpathref="alljars" />
    <!-- =================== Ant Contrib Tasks ======================= -->
    <taskdef resource="net/sf/antcontrib/antcontrib.properties"
             classpathref="buildjars"/>
    <property name="init-taskdefs.notrequired" value="true" />
    <!-- =================== Hibernate tools ======================= -->
    <taskdef name="hibernatetool" classname="org.hibernate.tool.ant.HibernateToolTask" classpathref="libjars"/>
  </target>

  <!--
    creates symlinks for jpackage jars
    requires: jpackage-utils
    other: requires rpms of the jars specified to be installed
  -->
  <macrodef name="jpackage-deps">
    <attribute name="jars" />
    <attribute name="dir" />

    <sequential>
      <exec executable="build-jar-repository" failonerror="true" >
        <arg value="--preserve-naming" />
        <arg value="-s @{dir}" />
        <arg line="@{jars}" />
      </exec>
    </sequential>
  </macrodef>

  <!--
    creates symlinks for jars downloaded from the ivy repository
    requires: ivy jpackage rpm
              ivy.xml
              build-jar-dir script
  -->
  <macrodef name="link-jars">
    <attribute name="ivyxml" />
    <attribute name="libdir" />
    <attribute name="jars" />
    <attribute name="dir" />

    <sequential>
      <exec executable="${candlepin.home}/buildconf/scripts/build-jar-dir" failonerror="true" >
        <arg value="-s" />
        <arg value="@{ivyxml}" />
        <arg value="@{libdir}" />
        <arg value="@{dir}" />
        <arg line="@{jars}" />
      </exec>
    </sequential>
  </macrodef>

  <!-- define tasks -->
  <target name="prepare" depends="init-taskdefs">
        <mkdir dir="${build.dir}/src"/>
  </target>

  <target name="boot-deps" unless="installbuild">
    <mkdir dir="${boot.lib.dir}" />
    <jpackage-deps jars="${boot.jar.dependencies}" dir="${boot.lib.dir}" />
  </target>

  <!-- only runs if we are missing a jpackage dir; speeds builds -->
  <target name="link-jars" depends="test-deps,resolve" if="missing-deps">
    <mkdir dir="${build.lib.dir}" />
    <mkdir dir="${run.lib.dir}" />
    <mkdir dir="${run-external.lib.dir}" />
    <mkdir dir="${test.lib.dir}" />

    <link-jars ivyxml="${candlepin.home}/ivy.xml" libdir="${lib.dir}"
               jars="${build.jar.dependencies}" dir="${build.lib.dir}" />
    <link-jars ivyxml="${candlepin.home}/ivy.xml" libdir="${lib.dir}"
               jars="${test.jar.dependencies}" dir="${test.lib.dir}"/>
    <link-jars ivyxml="${candlepin.home}/ivy.xml" libdir="${lib.dir}"
               jars="${run.jar.dependencies}" dir="${run-external.lib.dir}"/>
    <!--
         allows adding jar files for quick testing of tools
         that do not have RPMs yet.
     -->
    <copy toDir="${build.lib.dir}" overwrite="true" failonerror="false">
      <fileset dir="${candlepin.home}/buildconf/tempjars">
          <include name="**/*.jar" />
          <include name="**/*.properties" />
      </fileset>
    </copy>
    <copy toDir="${run-external.lib.dir}" overwrite="true" failonerror="false">
      <fileset dir="${candlepin.home}/buildconf/tempjars">
          <include name="**/*.jar" />
          <include name="**/*.properties" />
      </fileset>
    </copy>
  </target>

  <!-- see if any of the jpackage managed dirs are missing -->
  <target name="test-deps">
    <condition property="missing-deps">
      <not>
        <and>
          <available file="${build.lib.dir}" type="dir" />
          <available file="${run.lib.dir}" type="dir" />
          <available file="${test.lib.dir}" type="dir" />
        </and>
      </not>
    </condition>
  </target>

  <target name="init"
          depends="resolve,link-jars,init-taskdefs">
    <tstamp />
  </target>

  <target name="all" depends="init,compile,pack"
          description="Compile and pack - no code generation in this step" />


  <!-- TODO: Would very much like to simplify this and *all* the other test tasks. -->
  <macrodef name="run-junit">
    <attribute name="include" />
    <attribute name="exclude" default=""/>
    <attribute name="banner" />
    <attribute name="testbuilddir" />
    <attribute name="classpathid" />
    <attribute name="reportdir" />
    <attribute name="debug" default="" />

    <sequential>
      <echo level="info">
--------------------------------------------------------------------
Running @{banner} ...
--------------------------------------------------------------------
      </echo>

      <!-- forkmode requires using Ant 1.6.2.  If you don't have
           1.6.2, remove forkmode attribute -->
      <junit forkmode="once" fork="yes" printsummary="on" showoutput="no"
             haltonfailure="${halt-tests-on-failure}"
             failureproperty="junit_test_failure" >

        <sysproperty key="candlepin-home" value="${candlepin.home}" />
        <sysproperty key="java.awt.headless" value="true" />
        <sysproperty key="log4j.threshold" value="${log4j.threshold}" />

        <sysproperty key="persistenceUnit" value="test" />

        <jvmarg value="-ea" />
        <jvmarg line="@{debug}" />
        <classpath refid="@{classpathid}" />
        <formatter type="plain" />
        <batchtest todir="@{reportdir}">
          <fileset dir="@{testbuilddir}">
            <include name="@{include}" />
            <exclude name="@{exclude}"/>
          </fileset>
        </batchtest>
      </junit>
    </sequential>
  </macrodef>

  <target name="test"
          description="Run the tests (use -Dtestsubsystem=&lt;subsystem&gt; or -Dtestcase=&lt;testcase&gt;)"
          depends="compile-main,init-tests,invoke-tests-testcase,invoke-tests-subsystem,invoke-tests-all" >
    <property name="debug" value=""/>

    <fail if="junit_test_failure" message="One or more tests failed" />
  </target>

  <target name="test-report" depends="init-tests"
          description="Pretty-print the results of a previous test run.">
    <junitreport todir="${testresults.dir}">
      <fileset dir="${testresults.dir}">
        <include name="TEST-*.xml"/>
        <exclude name="${testresults.exclude}"/>
      </fileset>
      <report format="frames" todir="${report.dir}/test-report"/>
    </junitreport>
  </target>

  <target name="clean-all" description="Nukes EVERYTHING including jar cache"
          depends="clean,clean-cache" />

  <target name="clean-cache" description="Removes the Ivy jar cache">
     <delete dir="${lib.dir}" quiet="true" />
     <delete dir="${user.home}/.ivy/${ant.project.name}/cache/" quiet="true" />
  </target>

  <target name="clean" description="Remove all build artifacts">
    <delete dir="${build.dir}" quiet="true"/>
    <delete>
      <fileset dir="${candlepin.home}" includes="junit*.properties" />
    </delete>
    <delete>
      <fileset defaultexcludes="no" dir="${candlepin.home}">
        <include name="**/*~" />
        <include name="velocity.log*" />
      </fileset>
    </delete>
  </target>

  <target name="apidoc-singlepage" description="Generate the api for jsps" depends="init">
    <property name="doclet.class" value="SinglePageDoclet" />
    <property name="template.dir" value="singlepage" />
    <antcall target="apidoc" />
  </target>

  <target name="apidoc-jsp" description="Generate the api for jsps" depends="init">
    <property name="doclet.class" value="JSPDoclet" />
    <property name="template.dir" value="jsp" />
    <antcall target="apidoc" />
  </target>

  <target name="apidoc-list" description="Generate the api for jsps" depends="init">
    <property name="doclet.class" value="ListDoclet" />
    <property name="template.dir" value="list" />
    <antcall target="apidoc" />
  </target>

  <target name="apidoc-html" description="Generate the api for jsps" depends="init">
    <property name="doclet.class" value="HtmlDoclet" />
    <property name="template.dir" value="html" />
    <antcall target="apidoc" />
  </target>

  <target name="apidoc" description="Generate the api documentation" depends="init">
    <path id="javadocpath">
    <path refid="buildjars" />
      <pathelement location="build/classes" />
    </path>

    <mkdir dir="${report.dir}/apidocs" />
    <mkdir dir="${report.dir}/apidocs/${template.dir}/" />
    <mkdir dir="${report.dir}/apidocs/${template.dir}/handlers/" />
    <javadoc doclet="com.redhat.rhn.internal.doclet.${doclet.class}" docletpathref="javadocpath" classpathref="buildjars" sourcepath="code/src" additionalparam="-quiet">
      <fileset dir="code" >
        <include name="**/src/com/redhat/rhn/frontend/xmlrpc/**/*Handler.java" />
        <include name="**/src/com/redhat/rhn/frontend/xmlrpc/serializer/*Serializer.java" />
        <include name="**/src/com/redhat/rhn/domain/config/xmlrpc/serializer/*Serializer.java" />
      </fileset>
      <excludepackage name="**/*" />
    </javadoc>

  </target>

  <target name="javadoc" description="Generate the java-doc" depends="init">
    <javadoc destdir="${report.dir}/javadoc" author="true" version="true"
             use="true" failonerror="true" classpathref="buildjars"
             stylesheetfile="${src.dir}/webapp/css/rhnjavadoc.css"
             breakiterator="yes" useexternalfile="true" maxmemory="128m" >
      <tag name="todo" scope="all" description="To do:" />
      <tag name="xmlrpc.param" scope="methods" enabled="false"/>
      <tag name="xmlrpc.returntype" scope="methods" enabled="false"/>
      <tag name="xmlrpc.namespace" scope="types" enabled="false"/>
      <tag name="xmlrpc.doc" scope="all" enabled="false"/>
      <tag name="xmlrpc.serializer" scope="methods" enabled="false"/>
      <fileset dir="code" >
        <include name="**/src/**/*.java" />
        <exclude name="**/test/**" />
        <exclude name="**/testing/*TestUtils.java" />
        <exclude name="**/testing/*Test.java" />
        <exclude name="**/internal/**" />
      </fileset>
      <fileset dir="${build.dir}/src" >
        <include name="**/*.java" />
      </fileset>
    </javadoc>
    <echo message="javadoc finished."/>
    <copy file="${src.dir}/webapp/img/inherit.gif"
          tofile="${report.dir}/javadoc/resources/inherit.gif"
          overwrite="yes" />
  </target>

  <target name="javadoc-deploy" description="Locally deploy javadocs"
          depends="javadoc">
    <delete quiet="true">
      <fileset dir="${javadoc.deploydir}"
               includes="**/*.html"
               followsymlinks="false"/>
    </delete>
    <copy todir="${javadoc.deploydir}">
      <fileset dir="${report.dir}/javadoc"
               includes="**/*.html" />
    </copy>
  </target>

  <!-- We may want to break this down so that we can specify directories or
       classes to operate on.  But, hopefully our checkstyle report will
       generally be clean, so we may be able to always check all classes. -->
  <target name="checkstyle" depends="init">
    <mkdir dir="${report.dir}" />
    <checkstyle config="buildconf/checkstyle.xml" failOnViolation="true" >
      <property key="javadoc.method.scope" value="public" />
      <property key="javadoc.type.scope" value="package" />
      <property key="javadoc.var.scope" value="package" />
      <property key="javadoc.lazy" value="${javadoc.lazy}" />
      <property key="checkstyle.cache.file" value="${checkstyle.cache.src}" />
      <fileset dir="code" >
        <include name="**/src/**/*.java" />
        <exclude name="**/test/*.java" />
      </fileset>
      <classpath>
          <path refid="buildjars" />
          <pathelement path="${build.dir}/classes" />
      </classpath>
      <formatter type="plain" />
      <formatter type="xml" toFile="${report.dir}/checkstyle_report.xml" />
    </checkstyle>
    <checkstyle config="buildconf/checkstyle.xml" failOnViolation="true" >
      <property key="javadoc.method.scope" value="nothing" />
      <property key="javadoc.type.scope" value="nothing" />
      <property key="javadoc.var.scope" value="nothing" />
      <property key="javadoc.lazy" value="true" />
      <property key="checkstyle.cache.file" value="${checkstyle.cache.test}" />
      <fileset dir="code" >
        <include name="**/test/*.java" />
      </fileset>
      <formatter type="plain" />
      <formatter type="xml" toFile="${report.dir}/checkstyle_report_test.xml" />
    </checkstyle>
  </target>

  <target name="pack" depends="init,pack-megajar,pack-webapp"
          description="Create jars and copy descriptors" />


  <!-- Anything below this line should not generally be run from the command
       line.  These are the tasks that actually implement the public tasks -->

  <!-- ============== Compile tasks ================== -->
  <target name="compile" depends="init, compile-main"
          description="Compile source" />

  <target name="compile-main" depends="link-jars,prepare"
          description="Compile the main codebase" unless="installbuild">
    <mkdir dir="${build.dir}/classes" />
    <javac destdir="${build.dir}/classes"
           optimize="off"
           debug="on"
           source="1.5"
           target="1.5"
           deprecation="${deprecation}"
           nowarn="${nowarn}"
           encoding="utf-8"
           fork="yes"
           memoryMaximumSize="256m"
           classpathref="buildjars" >
      <src>
        <path location="${build.dir}/src" />
        <path location="code/src" />
      </src>
    </javac>

    <copy toDir="${build.dir}/classes">
      <fileset dir="${src.dir}/src">
        <exclude name="**/*.java" />
        <exclude name="**/package.html" />
      </fileset>
    </copy>
  </target>

  <target name="init-tests">
    <property name="test.bin.dir" value="${build.dir}/classes" />
    <property name="testresults.dir" value="${report.dir}/tests" />

    <path id="tests.buildpath" >
      <path location="${build.dir}/classes" />
      <path refid="alljars" />
    </path>

    <path id="tests.runpath" >
      <path location="${test.bin.dir}" />
      <path refid="testjars" />
      <path refid="alljars" />
      <path location="${src.dir}/webapp/" />
    </path>

    <mkdir dir="${testresults.dir}" />
  </target>

  <target name="check-testcase-name" if="testcase">
    <propertyregex property="valid.testcase"
                   input="${testcase}"
                   regexp="(.*)Test$"
                   select="\1"
                   casesensitive="true" />
  </target>

  <target name="check-testcase" depends="check-testcase-name" if="testcase"
      unless="valid.testcase">
    <fail message="Invalid testcase name: ${testcase}. Class name must look like .*Test"/>
  </target>

  <!-- ================= Invoke tests ==================== -->
  <target name="invoke-tests-testcase" depends="check-testcase" if="testcase">
    <property name="testcaseorsubsystem" value="true" />
    <run-junit include="**/test/${testcase}.class" banner="${testcase}"
        testbuilddir="${build.dir}/classes"
        classpathid="tests.runpath" reportdir="${testresults.dir}"
        debug="${debug}"/>
  </target>

  <target name="invoke-tests-subsystem" if="testsubsystem">
    <property name="testcaseorsubsystem" value="true" />
    <run-junit include="**/${testsubsystem}/**/test/*Test.class"
                banner="all tests in ${testsubsystem} subsystem"
                testbuilddir="${build.dir}/classes"
                classpathid="tests.runpath" reportdir="${testresults.dir}"
                debug="${debug}" />
  </target>

  <target name="invoke-tests-all" unless="testcaseorsubsystem">
    <!--
    <antcall target="checkstyle" />
    -->
    <run-junit include="**/test/*Test.class"
               banner="all tests"
               testbuilddir="${build.dir}/classes"
               exclude="**/AuthenticationServiceTest.class"
               classpathid="tests.runpath"
               reportdir="${testresults.dir}"/>
  </target>

  <target name="pack-megajar" depends="compile">
    <mkdir dir="${run.lib.dir}" />
    <delete file="${megajar.jar}" />
    <jar destfile="${megajar.jar}">
      <fileset dir="${build.dir}/classes">
        <exclude name="**/test/*" />
        <exclude name="**/log4j.properties" />
      </fileset>
    </jar>
  </target>

  <target name="pack-webapp" depends="compile,pack-megajar">
    <mkdir dir="${build.dir}/webapp" />
    <war destfile="${candlepin.war}" webxml="${src.dir}/webapp/WEB-INF/web.xml">
      <fileset dir="${src.dir}/webapp">
        <exclude name="WEB-INF/web.xml"/>
      </fileset>
      <classes dir="${build.dir}/classes">
        <include name="log4j.properties" />
      </classes>
      <classes dir="${build.dir}/classes">
        <include name="persistence.xml" />
      </classes>
      <classes dir="${build.dir}/classes">
        <include name="logging.properties" />
      </classes>
      <lib dir="${run.lib.dir}">
        <include name="${ant.project.name}.jar"/>
      </lib>
      <lib dir="${run-external.lib.dir}">
        <!-- Don't want the Oracle drivers which use JNI in the war. -->
        <exclude name="**/ojdbc*" />
        <exclude name="**/oracle-jdbc*" />
        <exclude name="**/servlet*" />
      </lib>
    </war>
  </target>

  <!-- TODO: what is the resolver? -->
  <!-- ================== resolver ===================== -->
  <target name="resolve" depends="resolve-ivy,resolve-local" />

  <target name="resolve-local" if="installbuild">
    <mkdir dir="${build.lib.dir}" />
    <mkdir dir="${test.lib.dir}" />
    <mkdir dir="${run-external.lib.dir}" />
    <jpackage-deps jars="${install.build.jar.dependencies}"
                   dir="${build.lib.dir}" />
    <jpackage-deps jars="${install.run.jar.dependencies}"
                   dir="${run-external.lib.dir}"/>
    <copy toDir="${build.lib.dir}" overwrite="true">
      <fileset dir="${candlepin.home}/buildconf/tempjars">
          <include name="**/*.jar" />
          <include name="**/*.properties" />
      </fileset>
    </copy>
  </target>

  <target name="resolve-ivy" description="retrieve dependencies with ivy"
          depends="boot-deps,init-ivy" unless="installbuild">

    <!-- properties set here to show we are overriding default ivy values -->

    <!-- local directory -->
    <property name="ivy.default.ivy.user.dir" value="${user.home}/.ivy/${ant.project.name}/"/>
    <property name="ivy.local.default.artifact.pattern"
              value="[artifact]-[revision].[ext]" />
    <!-- public directory -->
    <property name="ivy.ivyrep.default.ivy.root" value="${ivyserver}/ivy/${ant.project.name}/" />
    <property name="ivy.ivyrep.default.artifact.root"
              value="${ivyserver}/ivy/${ant.project.name}/" />
    <property name="ivy.ivyrep.default.artifact.pattern"
              value="[artifact]-[revision].[ext]" />

    <ivy-retrieve/>
  </target>

  <target name="gen-dot-classpath" depends="link-jars"
          description="Generates eclipse .classpath file.">
    <exec executable="${basedir}/buildconf/scripts/gen-eclipse-dot-classpath.py"
          output="${basedir}/.classpath" >
      <arg value="${eclipse.lib.dirs}:${candlepin.home}/buildconf/tempjars:${env.JAVA_HOME}/lib/tools.jar" />
      <arg value="${eclipse.libsrc.dirs}" />
    </exec>
  </target>

  <target name="gen-schema" depends="init-taskdefs,all" description="Generates database schema from Hibernate annotations.">
    <property name="dir.genhbm" value="build/schemagen/" />
    <delete dir="${dir.genhbm}" />
    <mkdir dir="${dir.genhbm}" />

    <hibernatetool destdir="${dir.genhbm}">

        <classpath>
            <path location="build/classes"/>
        </classpath>

        <jpaconfiguration persistenceunit="production"/>

        <hbm2ddl export="false"
                 update="false"
                 drop="false"
                 create="true"
                 outputfilename="candlepin-proxy.sql"
                 delimiter=";"
                 format="false"
                 haltonerror="true"/>

        </hibernatetool>
  </target>
    
</project>