Attachment 'build-cocoon-targets.xml'

Download

   1 <?xml version="1.0"?>
   2 <!--
   3 This Apache Ant build.xml snippet contains targets for helping out 
   4 managing the Cocoon dependencies of your project.
   5 It assumes that you have Ant version 1.6.x or later that supports the 
   6 <import> task.
   7 
   8 Usage: [full automatic, for fresh projects starts]
   9 1) Copy this file to the root of your project
  10    (e.g. to ./build-cocoon.targets.xml)
  11    and edit this file and replace "YourCocoonBasedProject" with your project name
  12 
  13 2) ant -buildfile build-cocoon-targets.xml -Dcocoon.distro.home=/...abs_path_to_cocoon_src_distro...
  14 
  15   this will generate a typical directory-structure containing:
  16   ./build.xml  (minimal version to be completed to project needs)
  17   ./user.properties (ready pointing to cocoon.distro.home)
  18   ./src/cocoon/local.build.properties
  19   ./src/cocoon/webapp
  20   ./src/cocoon/xconf
  21   .cvsignore (ignoring build and tools/cocoon/*)
  22   
  23   You manually start changing these as you go allong with your project.
  24 
  25   The script will not overwrite files that already exist.
  26 
  27 Usage: [manual, for existing build.xml files]
  28 1) Copy this file to the root of your project
  29    (e.g. to ./build-cocoon.targets.xml)
  30    and edit this file and replace "YourCocoonBasedProject" with your project name
  31 
  32 2) Add the following to the top-level of your project's Ant build.xml script (possibly adjusting the path):
  33    
  34    <property name="cocoon.targets" value="./build-cocoon.targets.xml">
  35    <import file="${cocoon.targets}">
  36 
  37 3) Add in various properties assumed to be available (change the paths to your own liking)
  38 
  39    <property file="user.properties">
  40    <property name="src" value="./src" />
  41    <property name="src.cocoon" value="${src}/cocoon" />
  42    <property name="cocoon.build.properties" value="${src.cocoon}/local.build.properties">
  43    <property name="cocoon.xconf.dir" value="${src.cocoon}/xconf">
  44    <property name="cocoon.tool.dir" value="tools/cocoon">
  45 
  46 
  47 How it works:
  48 
  49 All targets in this build file snippet depend upon 
  50 the following properties being set
  51   1. cocoon.distro.home
  52        location of src distribution of cocoon to use
  53   2. cocoon.build.properties
  54        property file with specific cocoon build settings
  55        (selecting which blocks, samples,...)
  56        typically src/cocoon/local.build.properties
  57   3. cocoon.xconf.dir
  58        location where the appropriate patch files can be found
  59        typically src/cocoon/xconf
  60   4. cocoon.tool.dir
  61        where cocoon is build inside your project
  62        typically this is tools/cocoon
  63 
  64 Updates and Background:
  65 http://wiki.cocoondev.org/Wiki.jsp?page=YourCocoonBasedProject
  66 -->
  67 <project name="YourCocoonBasedProject" default="seed" >
  68 
  69   <!-- if not set yet... -->
  70   <property file="user.properties" />
  71   <property name="src" value="./src" />
  72   <property name="src.cocoon" value="${src}/cocoon" />
  73   <property name="cocoon.build.properties" value="${src.cocoon}/local.build.properties" />
  74   <property name="cocoon.xconf.dir" value="${src.cocoon}/xconf" />
  75   <property name="cocoon.tool.dir" value="tools/cocoon" />
  76   <property name="cocoon.unpatched" value="${cocoon.tool.dir}/unpatched"/>
  77 
  78   <!--
  79     sets some essential properties for these targets
  80   --> 
  81   <target name="-cocoon:init">
  82     <mkdir dir="${cocoon.tool.dir}" />
  83     <property name="cocoon.webapp" value="${cocoon.tool.dir}/webapp" />
  84     <property name="cocoon.tasks" value="${cocoon.tool.dir}/taskdefs" />
  85     <property name="cocoon.lib" value="${cocoon.webapp}/WEB-INF/lib" />    
  86   </target>
  87 
  88   <!--
  89     checks what kind of OS this is running on
  90   -->
  91   <target name="-cocoon:oscheck" >
  92     <condition property="isWindows">
  93       <os family="windows" />
  94     </condition>
  95   </target>
  96     
  97   <!--
  98     creates Windows batch files for cocoon dependencies
  99   -->
 100   <target name="-cocoon:bat" if="isWindows"
 101           depends="-cocoon:init, -cocoon:oscheck" >
 102     <echo>Building batch files for support on windows OS</echo>
 103     <property name="shbat" value="bat" />
 104 
 105     <echo file="${cocoon.tool.dir}/getc2.${shbat}"><![CDATA[@echo off 
 106 if "%COCOON_HOME%"=="" then echo You haven't set the COCOON_HOME environment variable.
 107 echo GOING TO %COCOON_HOME%
 108 cd /d %COCOON_HOME%
 109 echo Running build.bat -propertyfile %PROJECT_PROPERTIES% clean webapp -Dbuild.webapp=%PROJECT_WEBAPP% -Dtools.tasks.dest=%PROJECT_TASKDEFS%
 110 build.bat -propertyfile %PROJECT_PROPERTIES% clean webapp -Dbuild.webapp=%PROJECT_WEBAPP% -Dtools.tasks.dest=%PROJECT_TASKDEFS% 
 111 ]]></echo>
 112 
 113     <echo file="${cocoon.tool.dir}/runc2.${shbat}"><![CDATA[@echo off
 114 set JETTY_WEBAPP=%PROJECT_WEBAPP%
 115 cd /d %COCOON_HOME%
 116 cocoon.bat servlet-debug
 117 ]]></echo>
 118   </target>
 119 
 120   <!--
 121     creates shell scripts for cocoon dependencies
 122   -->
 123   <target name="-cocoon:sh" unless="isWindows"
 124           depends="-cocoon:init, -cocoon:oscheck" >
 125 
 126     <echo>Building shell scripts for support on non-windows</echo>
 127     <property name="shbat" value="sh" />
 128 
 129     <echo file="${cocoon.tool.dir}/getc2.${shbat}"><![CDATA[#!/bin/sh
 130 cd $COCOON_HOME
 131 echo running /build.sh -propertyfile $PROJECT_PROPERTIES clean webapp -Dbuild.webapp=$PROJECT_WEBAPP -Dtools.tasks.dest=$PROJECT_TASKDEFS
 132 ./build.sh -propertyfile $PROJECT_PROPERTIES clean webapp -Dbuild.webapp=$PROJECT_WEBAPP -Dtools.tasks.dest=$PROJECT_TASKDEFS
 133 ]]></echo>
 134        <chmod file="${cocoon.tool.dir}/getc2.${shbat}" perm="u+x"/>
 135 
 136     <echo file="${cocoon.tool.dir}/runc2.${shbat}"><![CDATA[#!/bin/sh
 137 export COCOON_WEBAPP_HOME=$PROJECT_WEBAPP
 138 echo COCOON_WEBAPP_HOME=$COCOON_WEBAPP_HOME
 139 cd $COCOON_HOME
 140 ./cocoon.sh servlet-debug
 141 ]]></echo>
 142         <chmod file="${cocoon.tool.dir}/runc2.${shbat}" perm="u+x"/>
 143     </target>    
 144 
 145   <!--
 146     creates as needed batch files or shell scripts
 147   -->
 148   <target name="-cocoon:shbat" depends="-cocoon:bat, -cocoon:sh" />
 149 
 150   <!--
 151     checks if the cocoon dependency is holding what we expect 
 152     sets a variable if all is ok
 153   -->
 154   <target name="-cocoon:test" depends="-cocoon:init">
 155     <condition property="cocoon.ok" value="true">
 156       <and>
 157         <available type="dir" file="${cocoon.lib}" />
 158         <available classname="XConfToolTask" 
 159                    classpath="${cocoon.tasks}"/>
 160       </and>
 161     </condition>
 162   </target>
 163 
 164   <!--
 165     fails the build if the cocoon dependency is not met
 166   -->
 167   <target name="-cocoon:check" depends="-cocoon:test" unless="cocoon.ok">
 168     <fail>No cocoon available. Run 'ant cocoon.get' first.</fail>
 169   </target>
 170 
 171 
 172   <target name="-cocoon:patch">
 173     <echo>Patching ${cocoon.patch.target} with 
 174 ${cocoon.xconf.dir}/*.${cocoon.patch.src-extension} ...</echo>
 175     <xpatch 
 176       file="${cocoon.patch.target}"
 177       srcdir="${cocoon.xconf.dir}" 
 178       includes="**/*.${cocoon.patch.src-extension}"/>
 179     </target>
 180 
 181   <!-- 
 182       applies the patch files in the ${cocoon.xconf.dir} 
 183       on the various cocoon conf files
 184   -->
 185   <target name="cocoon:xconf" depends="-cocoon:check">
 186     <path id="cocoon.tasks.cp">
 187       <pathelement path="${cocoon.tasks}" />
 188       <path>
 189         <fileset dir="${cocoon.lib}">
 190           <include name="xalan*.jar" />
 191           <include name="xerces*.jar" />
 192           <include name="xml*.jar" />
 193         </fileset>
 194       </path>
 195     </path>
 196 
 197     <taskdef 
 198         name="xpatch" 
 199         classname="XConfToolTask" 
 200         classpathref="cocoon.tasks.cp"/>  
 201 
 202     <xpatch file="${cocoon.webapp}/WEB-INF/cocoon.xconf" srcdir="">
 203       <include name="${cocoon.xconf.dir}/*.xconf"/>
 204     </xpatch>
 205 
 206     <antcall target="-cocoon:patch" >
 207       <param name="cocoon.patch.target" 
 208            value="${cocoon.webapp}/WEB-INF/cocoon.xconf" />
 209       <param name="cocoon.patch.src-extension" 
 210            value="xconf" />
 211     </antcall>
 212 
 213     <antcall target="-cocoon:patch" >
 214       <param name="cocoon.patch.target" 
 215            value="${cocoon.webapp}/WEB-INF/logkit.xconf" />
 216       <param name="cocoon.patch.src-extension" 
 217            value="xlog" />
 218     </antcall>
 219 
 220     <antcall target="-cocoon:patch" >
 221       <param name="cocoon.patch.target" 
 222            value="${cocoon.webapp}/sitemap.xmap" />
 223       <param name="cocoon.patch.src-extension" 
 224            value="xmap" />
 225     </antcall>
 226 
 227     <antcall target="-cocoon:patch" >
 228       <param name="cocoon.patch.target" 
 229            value="${cocoon.webapp}/WEB-INF/web.xml" />
 230       <param name="cocoon.patch.src-extension" 
 231            value="xweb" />
 232     </antcall>
 233   </target>
 234 
 235   <target name="cocoon:unpatch">
 236     <copy todir="${cocoon.webapp}" overwrite="true" >
 237       <fileset dir="${cocoon.unpatched}">
 238         <include name="WEB-INF/web.xml" />
 239         <include name="WEB-INF/cocoon.xconf" />
 240         <include name="WEB-INF/logkit.xconf" />
 241         <include name="sitemap.xmap" />
 242       </fileset>
 243     </copy>
 244   </target>
 245 
 246   <target name="cocoon:get" depends="-cocoon:shbat" description="Get cocoon into this project">
 247       <mkdir dir="${cocoon.webapp}" />
 248       <exec executable="${cocoon.tool.dir}/getc2.${shbat}" >
 249         <env key="COCOON_HOME" file="${cocoon.distro.home}" />
 250         <env key="PROJECT_PROPERTIES" file="${cocoon.build.properties}" />
 251         <env key="PROJECT_WEBAPP" file="${cocoon.webapp}" />
 252         <env key="PROJECT_TASKDEFS" file="${cocoon.tasks}" />
 253       </exec>
 254       <mkdir dir="${cocoon.unpatched}" />
 255       <copy todir="${cocoon.unpatched}">
 256         <fileset dir="${cocoon.webapp}" >
 257           <include name="WEB-INF/web.xml" />
 258           <include name="WEB-INF/cocoon.xconf" />
 259           <include name="WEB-INF/logkit.xconf" />
 260           <include name="sitemap.xmap" />
 261         </fileset>
 262       </copy>
 263   </target>
 264 
 265   <target name="cocoon:run" depends="-cocoon:shbat, -cocoon:check" description="Run cocoon on the built-in jetty to test">
 266       <exec executable="${cocoon.tool.dir}/runc2.${shbat}" >
 267         <env key="COCOON_HOME" file="${cocoon.distro.home}" />
 268         <env key="PROJECT_WEBAPP" file="${cocoon.webapp}" />
 269       </exec>
 270   </target>
 271 
 272 
 273   <!-- 
 274   Below are some targets that build a default project-setting which allows you to 
 275   make use of the reusable targets declared in this build-script.
 276 
 277   You can launch the 'seed' target to start-off your project.
 278   -->
 279   <target name="seed-check">
 280     <available property="cocoonHomeOk" file="${cocoon.distro.home}" />
 281     <fail unless="cocoonHomeOk" >
 282     This script needs a property $${cocoon.distro.home} to be set and 
 283     pointing to an existing directory containing a cocoon 2.1.x distro.
 284     You can set it either by providing a -D flag to ant, or 
 285     by adding it to a local ./user.properties.
 286     </fail>
 287 
 288     <available property="existsBuild" file="build.xml" />
 289     <available property="existsLocalProps" file="${cocoon.build.properties}" />
 290     <available property="existsUserProps" file="user.properties" />
 291     <available property="existsCvsIgnore" file=".cvsignore" />
 292   </target>
 293 
 294   <target name="msg-seed-build" if="existsBuild">
 295     <echo>build.xml exists. This script cannot overwrite it.
 296     If you want to regenerate the build.xml then manually delete it prior to running the seed target again.</echo>
 297   </target>
 298 
 299   <target name="seed-build" depends="msg-seed-build" unless="existsBuild">
 300     <echo>Creating build.xml...</echo>
 301     <echo file="build.xml"><![CDATA[<?xml version="1.0"?>
 302 <!-- 
 303   File automatically generated by ant script for ${ant.project.name}.
 304   Manually extend it to your own needs.
 305   -->
 306 <project name="${ant.project.name}" default="init">
 307   <property file="user.properties" />
 308 
 309   <property name="src"              value="src" />
 310   <property name="src.java"         value="${src}/java" />
 311   <property name="src.cocoon"       value="${src}/cocoon" />
 312   <property name="src.webapp"       value="${src.cocoon}/webapp" />
 313   
 314   <property name="build"            value="build" />
 315   <property name="build.classes"    value="${build}/classes" />
 316   <property name="zipfile"          value="${build}/$${ant.project.name}.zip" />
 317   <property name="warfile"          value="${build}/$${ant.project.name}.war" />
 318 
 319   <property name="lib"            value="lib" />
 320 
 321   <property name="cocoon-build.properties" value="${src.cocoon}/local.build.properties" />
 322   <property name="cocoon-xconf.dir" value="${src.cocoon}/xconf" />
 323   <property name="cocoon-tool.dir"  value="tools/cocoon" />
 324   <property name="cocoon.webapp"    value="${cocoon-tool.dir}/webapp" />
 325   <property name="cocoon.lib"       value="${cocoon.webapp}/WEB-INF/lib" />
 326   <property name="cocoon.classes"   value="${cocoon.webapp}/WEB-INF/classes" />
 327 
 328   <property name="cocoon-targets" value="${ant.file}" />
 329   <!-- insert properties here to override defaults in the import cocoon-targets script -->
 330   <import file="$${cocoon-targets}" />
 331 
 332   <path id="all.cp">
 333     <pathelement location="${build.classes}" />
 334     <fileset dir="${cocoon.lib}">
 335       <include name="*.jar"/>
 336     </fileset>
 337     <fileset dir="${lib}">
 338       <include name="*.jar"/>
 339     </fileset>
 340   </path>
 341   
 342   <target name="init">
 343     <mkdir dir="${build.classes}" />
 344   </target>
 345   
 346   <target name="compile" depends="init,-cocoon:check" >
 347     <javac srcdir="${src.java}" destdir="${build.classes}" debug="true" >
 348       <classpath refid="all.cp"/>
 349       <include name="**/*.java"/>
 350     </javac>
 351   </target>
 352 
 353   <target name="webapp" depends="compile, cocoon:xconf"
 354           description="configure the webapp">
 355     <copy todir="${cocoon.lib}">
 356       <fileset dir="${lib}">
 357         <include name="*.jar"/>
 358       </fileset>
 359     </copy>
 360     <copy todir="${cocoon.classes}">
 361       <fileset dir="${build.classes}" />
 362     </copy>
 363     <copy todir="${cocoon.webapp}">
 364       <fileset dir="${src.webapp}" />
 365     </copy>          
 366   </target>  
 367 
 368   <target name="zip" depends="init">
 369     <zip zipfile="${zipfile}" basedir="." excludes="**/build/**, tools/**" />
 370   </target>
 371 
 372   <target name="war" depends="webapp" >
 373     <jar destfile="${warfile}" basedir="${cocoon.webapp}" />
 374   </target>
 375   
 376 </project>
 377     ]]></echo>
 378   </target>
 379   
 380   <target name="seed-dirs">
 381     <mkdir dir="${src.cocoon}" />
 382     <mkdir dir="${src.cocoon}/webapp" />
 383     <mkdir dir="${cocoon.xconf.dir}" />
 384     <mkdir dir="${cocoon.tool.dir}" />
 385     <mkdir dir="${cocoon.tool.dir}/webapp" />
 386     <mkdir dir="src/java" />
 387     <mkdir dir="lib" />
 388   </target>
 389   
 390   <target name="msg-seed-userprops" if="existsUserProps">
 391     <echo>user.properties already exists. This script cannot overwrite it.
 392     If you want to regenerate the user.properties then manually delete it prior to running the seed target again.</echo>
 393   </target>
 394 
 395   <target name="seed-userprops" depends="msg-seed-userprops" unless="existsUserProps">
 396     <echo file="user.properties">#
 397 # File automatically generated by ant script for ${ant.project.name}.
 398 # Manually extend it to your own needs.
 399 #
 400 cocoon.distro.home=${cocoon.distro.home}</echo>
 401   </target>
 402 
 403   <target name="msg-seed-cvsignore" if="existsCvsIgnore">
 404     <echo>.cvsignore already exists. This script cannot overwrite it.
 405     If you want to regenerate the .cvsignore then manually delete it prior to running the seed target again.</echo>
 406   </target>
 407 
 408   <target name="seed-cvsignore" depends="msg-seed-cvsignore" unless="existsCvsIgnore">
 409     <echo file=".cvsignore">build
 410 tools
 411 user.properties</echo>
 412   </target>
 413 
 414   <target name="msg-seed-localprops" if="existsLocalProps" >
 415     <echo>${cocoon.build.properties} already exists. This script cannot overwrite it.
 416     If you want to regenerate the ${cocoon.build.properties} then manually delete it prior to running the seed target again.</echo>
 417   </target>
 418 
 419   <target name="seed-localprops" 
 420           depends="msg-seed-localprops, seed-dirs" 
 421           unless="existsLocalProps" >
 422     <concat destfile="${cocoon.build.properties}" >
 423       <fileset dir="${cocoon.distro.home}">
 424         <include name="build.properties" />
 425         <include name="blocks.properties" />
 426       </fileset>
 427     </concat>
 428   </target>
 429 
 430   <target name="seed" depends="seed-check, seed-localprops, seed-cvsignore, seed-userprops, seed-build">
 431     <echo>Done.
 432        
 433     The directory src/cocoon/webapp is created to hold your cocoon 
 434     webapp resources.
 435     The directory src/cocoon/xconf is created to hold XConfPatch files 
 436     to (optionally) modify the cocoon.xconf log.xconf web.xml and 
 437     (root) sitemap.xmap
 438 
 439     From here:
 440     ---------
 441     You should now edit the file ${cocoon.build.properties} to select 
 442     only those optional components of Cocoon that your project needs.
 443     IMPORTANT: Remove the path-entries from that file!
 444     
 445     The build.xml can freely be extended for your project needs.
 446 
 447     To build a fresh Cocoon base for this project 
 448     (when you updated the distro pointed to by -Dcocoon.distro.home)
 449         > ant cocoon:get
 450 
 451     To blend in your own project resources and classes:
 452         > ant webapp
 453 
 454     To test-run using the Jetty container:
 455         > ant cocoon:run
 456     </echo>
 457   </target>
 458 </project>

Attached Files

To refer to attachments on a page, use attachment:filename, as shown below in the list of files. Do NOT use the URL of the [get] link, since this is subject to change and can break easily.
  • [get | view] (2005-03-22 06:03:42, 16.8 KB) [[attachment:build-cocoon-targets.xml]]
 All files | Selected Files: delete move to page

You are not allowed to attach a file to this page.