view ssdt-common-build.xml @ 301:74d939ce70d5

more printlns
author Marc Davis <davis@ssdt-ohio.org>
date Wed, 01 Feb 2023 08:12:46 -0500
parents 426d160e1e4a
children 7a36ea2cb81a
line wrap: on
line source
<?xml version="1.0" encoding="UTF-8"?>
<project name="ssdt-common-build" default="all" basedir="." 
         xmlns:tomcat="http://ssdt-ohio.org/ant/tomcat"
         xmlns:ssdt="http://www.ssdt-ohio.org/ant/common">
    <!--
    ssdt common build functions.  Contains generalized tasks to perform
    common functions. Assumes some standard properties from a NetBeans
    project are provided.

    Properties used for webapps:

        build.web.dir   - docBase of build webapp.
        web.docbase.dir - source docBase of webapp
        web.context.path    - path to install webapp in Tomcat
        tomcat.username     - Tomcat manager username
        tomcat.password     - Tomcat manager password

-->
    <target    name="project.cvs.update"
               depends="project.init"
               unless="build.devel.bamboo">
        <!-- Get the latest from CVS -->
        <cvs command="up -d -P"/>
    </target>

    <target name="-project.init.groovy.task">
        <echo message="Note: -project.init.groovy.task is a noop. Please remove from dependency."/>
    </target>

    <if>
        <available classpath="${run.test.classpath}" classname="org.codehaus.groovy.ant.Groovy"/>
        <then>
            <taskdef 	name="groovy" classname="org.codehaus.groovy.ant.Groovy"  classpath="${run.test.classpath}"/>
        </then>
        <else>
            <property	name="ssdt.groovy.jar.src"                               value="http://ivy.ssdt.nwoca.org/repository/groovy/groovy-all.jar"/>
            <ssdt:fetch dest="${ssdt.devel.kit}/groovy-all.jar" 		 src="${ssdt.groovy.jar.src}"/>
            <taskdef 	name="groovy" classname="org.codehaus.groovy.ant.Groovy" classpath="${ssdt.devel.kit}/groovy-all.jar"/>
        </else>
    </if>

    <target name="project.init" depends="init">
        <property file="build-number.txt" description="Bamboo build number"/>
        <property name="build.number" value="-1" description="Unknown build number"/>
        <property name="project.version" value="${ivy.revision}"/>
        <property name="project.name" value="${ivy.module}"/>
        <property name="project.version.file" value="${build.classes.dir}/version.properties"/>
    </target>

    <target name="project.version" depends="project.init" >
        <mkdir dir="${build.classes.dir}"/>
        <propertyfile  file="${project.version.file}" comment="Version build information">
            <entry key="projectName" value="${project.name}"/>
            <entry key="projectVersion" value="${project.version}"/>
            <entry key="buildDate" type="date" value="now"/>
            <entry key="buildNumber" value="${build.number}"/>
            <entry key="built.by" value="${ant.version}"/>
            <entry key="build.java.version" value="${ant.java.version}"/>
            <entry key="built.on" value="${os.name} ${os.arch} ${os.version} (${user.name})"/>
        </propertyfile>
        <property file="${project.version.file}" prefix="version"/>        
        
     </target>

    <target name="-project.pre-init" depends="init">
        <condition property="tomcat.available">
            <and>
                <available file="${tomcat.home}" type="dir"/>
            </and>
        </condition>
    </target>

    <target name="-project.init-tomcat" depends="-project.pre-init" if="tomcat.available">
        <property name="tomcat.url" value="http://localhost:8084"/>
        <property name="tomcat.manager.url" value="${tomcat.url}/manager"/>

        <taskdef resource="org/apache/catalina/ant/antlib.xml" uri="http://ssdt-ohio.org/ant/tomcat">
            <classpath>
                <fileset dir="${tomcat.home}" includes="**/lib/catalina-ant.jar"/>
            </classpath>
        </taskdef>
    </target>

    <target name="project.web.context" depends="-project.init-tomcat,init">
        <dirname property="docBase.dir.name" file="${build.web.dir}/WEB-INF"/>

        <property name="project.context.file"  value="${web.docbase.dir}/META-INF/context.xml"/>

        <copy file="${project.context.file}"
              tofile="${build.web.dir}/META-INF/context-dev.xml"
              overwrite="true">
            <filterchain>
                <tokenfilter>
                    <filetokenizer/>
                    <replaceregex
                        pattern="&lt;Context.*&gt;"
                        replace="&lt;Context path=&quot;${web.context.path}&quot; docBase=&quot;@DOCBASE&quot; &gt;"
                        />
                </tokenfilter>
            </filterchain>
        </copy>
        <replace file="${build.web.dir}/META-INF/context-dev.xml"
                 token="@DOCBASE"
                 value="${docBase.dir.name}"/>
    </target>

    <target name="project.undeploy" depends="-project.init-tomcat">
        <dirname property="build.web.dir.path" file="${build.web.dir}/WEB-INF"/>
        <tomcat:undeploy  password="${tomcat.password}"
                          url="${tomcat.manager.url}" username="${tomcat.username}"
                          path="${web.context.path}"
                          failonerror="false"
                          />
    </target>

    <target name="project.deploy" depends="project.undeploy,project.web.context">
        <dirname property="build.web.dir.path" file="${build.web.dir}/WEB-INF"/>
        <tomcat:deploy  password="${tomcat.password}"
                        url="${tomcat.manager.url}" username="${tomcat.username}"
                        path="${web.context.path}"
                        config="${build.web.dir.path}/META-INF/context-dev.xml"
                        />
        <delete file="${build.web.dir.path}/META-INF/context-dev.xml" failonerror="false"/>
    </target>
    <macrodef name="junit-summary"
              description="creates a summary of junit results"
              uri="http://www.ssdt-ohio.org/ant/common">
        <attribute name="dir" description="JUNIT test results" default="${build.test.results.dir}"/>
        <attribute name="file" description="output file" default="${build.test.results.dir}/summary.txt"/>
        <sequential>
            <junitreport tofile="@{dir}/combined.xml">
                <fileset dir="@{dir}">
                    <include name="TEST-*.xml"/>
                </fileset>
            </junitreport>
            <xslt in="@{dir}/combined.xml" out="@{file}">
                <style>
                    <javaresource name="org/ssdt_ohio/tools/ant/junit-summary_1.xsl" classpath="${user.home}/.ant/lib/ssdt-ant.jar"/>
                </style>
            </xslt>
        </sequential>
    </macrodef>

</project>