Skip to content

Instantly share code, notes, and snippets.

@mhenke
Last active December 12, 2015 00:58
Show Gist options
  • Save mhenke/4687026 to your computer and use it in GitHub Desktop.
Save mhenke/4687026 to your computer and use it in GitHub Desktop.
cloudy with chance of tests and deploy
<?xml version="1.0" encoding="UTF-8"?>
<project name="CloudyBuild" default="all" basedir=".">
<description>Build file for compile and other easy to implement coldfusion checks</description>
<!--
=================================
Target: init
Initializes the general settings and properties used in the build
=================================
-->
<target name="init">
<tstamp />
<!--specific build location variables-->
<!-- let's load up a user's build file first, so they don't have to check in their
own properties into version control
It will look for something like /Users/username/<ant.projectname>.properties, for example:
/Users/markdrew/CloudyBuild.properties
-->
<property file="${user.home}/${ant.project.name}.properties" />
<property file="build.properties" />
<!-- some additional mxunit test properties -->
<!-- where do your tests live, relative to this build file? test.dir.location will be a full path to a directory -->
<property name="mxunit.dir.location" location="${mxunit.dir.name}" />
<!-- what is the cfc dot-notation path to that directory, as ColdFusion sees it? -->
<property name="mxunit.cfcpath" value="${mxunit.dir.name}" />
<!-- this is where the xml and html will live for the report generator and Jenkins -->
<property name="mxunit.output" location="${mxunit.dir.name}/testresults" />
<property name="mxunit.output.xml" location="${mxunit.output}/xml" />
<!--
make sure all the settings are defined *SOMEWHERE*, since comments and documentation are never read
If you add a new variable that has to be set, add it in the lines below
Read more about it here: http://www.javaranch.com/build_properties.jsp
-->
<property name="prop.message" value="must be defined, preferably in build.properties or ${user.home}/${ant.project.name}.properties (details at http://javaranch.com/props)" />
<fail message="cfmlengine.railo ${prop.message}" unless="cfmlengine.railo" />
<fail message="cfmlengine.openbd ${prop.message}" unless="cfmlengine.openbd" />
<fail message="cfmlengine.acf ${prop.message}" unless="cfmlengine.acf" />
<fail message="directoryName ${prop.message}" unless="directoryName" />
<fail message="pathToFilesToCheck ${prop.message}" unless="pathToFilesToCheck" />
<fail message="isolateInspection ${prop.message}" unless="isolateInspection" />
<fail message="compilePathJars ${prop.message}" unless="compilePathJars" />
<fail message="jrun.jar ${prop.message}" unless="jrun.jar" />
<fail message="webapp.server ${prop.message}" unless="webapp.server" />
<fail message="db.driver ${prop.message}" unless="db.driver" />
<fail message="db.classpath ${prop.message}" unless="db.classpath" />
<fail message="db.host ${prop.message}" unless="db.host" />
<fail message="db.port ${prop.message}" unless="db.port" />
<fail message="db.name ${prop.message}" unless="db.name" />
<fail message="db.user ${prop.message}" unless="db.user" />
<fail message="db.password ${prop.message}" unless="db.password" />
<fail message="db.url ${prop.message}" unless="db.url" />
<fail message="mxunit.server ${prop.message}" unless="mxunit.server" />
<fail message="mxunit.output.dir ${prop.message}" unless="mxunit.output.dir" />
<fail message="mxunit.haltonfailure ${prop.message}" unless="mxunit.haltonfailure" />
<fail message="mxunit.haltonerror ${prop.message}" unless="mxunit.haltonerror" />
<!-- mxunit default properties -->
<property name="testing.unit.haltonfailure" value="false" />
<property name="testing.unit.haltonerror" value="false" />
<property name="filePathToBuildFolder" value="${compilePathJars}/${isolateInspection}" />
<path id="project.classpath">
<fileset dir="lib-cloudy">
<include name="**/*.jar" />
</fileset>
</path>
<taskdef resource="net/sf/antcontrib/antcontrib.properties" classpathref="project.classpath" />
<taskdef name="mxunittask" classname="org.mxunit.ant.MXUnitAntTask" classpathref="project.classpath" />
<taskdef name="jslint" classname="com.googlecode.jslint4java.ant.JSLintTask" classpathref="project.classpath" />
<taskdef resource="org/eclipse/jgit/ant/ant-tasks.properties">
<classpath>
<pathelement location="${basedir}/lib/org.eclipse.jgit.ant-2.2.0.201212191850-r.jar" />
<pathelement location="${basedir}/lib/org.eclipse.jgit-2.2.0.201212191850-r.jar" />
<pathelement location="${basedir}/lib/jsch-0.1.49.jar" />
</classpath>
</taskdef>
<macrodef name="git">
<attribute name="command" />
<attribute name="dir" default="" />
<element name="args" optional="true" />
<sequential>
<echo message="git @{command}" />
<exec executable="git" dir="@{dir}" failonerror="true">
<arg value="@{command}" />
<args />
</exec>
</sequential>
</macrodef>
</target>
<!--
=================================
Target: all
=================================
-->
<target name="all" depends="init,compile.check,inspection.qpscanner,inspection.varscoper,inspection.csslint,inspection.jslint,package,deploy" description="--&gt; packages into a zip and uploads to google code" />
<!--
=================================
Target: package
=================================
-->
<target name="package" description="--&gt; packages the appropriate files into the deployment-ready zip file. use this for testing; otherwise, use publish">
<echo>packaging</echo>
</target>
<!--
=================================
Target: clean
Cleans up un-needed files in build folder
=================================
-->
<target name="clean">
<echo>Cleaning started...</echo>
<delete dir="${filePathToBuildFolder}" />
<echo>clean-up done</echo>
</target>
<!--
=================================
Target: copy
Copying files for compile test
=================================
-->
<target name="copy" depends="init,clean" unless="jenkins_workspace">
<echo>Copying from ${pathToFilesToCheck}/${directoryName}</echo>
<copy todir="${filePathToBuildFolder}">
<fileset dir="${pathToFilesToCheck}/${directoryName}">
<include name="**/*.cfm" />
<include name="**/*.cfml" />
<include name="**/*.cfc" />
<include name="**/*.js" />
<include name="**/*.xml" />
<include name="**/*.css" />
<exclude name="**/FusionCharts.cfm" />
<exclude name="**/mxunit/**" />
<exclude name="**/plugins/**" />
<exclude name="**/CFIDE/**" />
<exclude name="**/cfide/**" />
<exclude name="**/WEB-INF/**" />
<exclude name="**/META-INF/**" />
<exclude name="**/varscoper/**" />
<exclude name="**/ValidateThis/**" />
<exclude name="**/FusionCharts/**" />
<exclude name="**/fuseguard**" />
<exclude name="**/qpscanner/**" />
<exclude name="**/colddoc/**" />
<exclude name="**/lib-cloudy/**" />
<exclude name="**/wheels/**" />
<exclude name="**/tests/**" />
<exclude name="**/snapshots/**" />
</fileset>
</copy>
<echo>done copying files</echo>
</target>
<!--
=================================
Target: copy.jenkins
Copying files for compile test
=================================
-->
<target name="copy.jenkins" depends="init,clean" if="jenkins_workspace">
<echo>Copying from ${jenkins_workspace}</echo>
<copy todir="${filePathToBuildFolder}">
<fileset dir="${jenkins_workspace}">
<include name="**/*.cfm" />
<include name="**/*.cfml" />
<include name="**/*.cfc" />
<include name="**/*.xml" />
<include name="**/*.js" />
<include name="**/*.css" />
<exclude name="**/mxunit/**" />
<exclude name="**/plugins/**" />
<exclude name="**/CFIDE/**" />
<exclude name="**/cfide/**" />
<exclude name="**/WEB-INF/**" />
<exclude name="**/META-INF/**" />
<exclude name="**/varscoper/**" />
<exclude name="**/qpscanner/**" />
<exclude name="**/colddoc/**" />
<exclude name="**/lib-cloudy/**" />
<exclude name="**/tests/**" />
<exclude name="**/snapshots/**" />
</fileset>
</copy>
<echo>done copying files</echo>
</target>
<!--
=================================
Target: deploy
deploy
=================================
-->
<target name="deploy" depends="init, input-runbranch, update-development">
<echo>deploy</echo>
<!-- git-checkout src="/" branch="origin/stage" /> -->
<echo>checkout release</echo>
<git command="checkout">
<args>
<arg value="${branch}" />
</args>
</git>
<echo>make sure up to date</echo>
<git command="pull" />
<echo>checkout production</echo>
<git command="checkout">
<args>
<arg value="production-master" />
</args>
</git>
<echo>make sure up to date</echo>
<git command="pull" />
<echo>merge release into production</echo>
<git command="merge">
<args>
<arg value="${branch}" />
</args>
</git>
<echo>push changes to production</echo>
<git command="push">
<args>
<arg value="production" />
<arg value="production-master:master" />
</args>
</git>
</target>
<!--
=================================
Target: update-development
update-development
=================================
-->
<target name="update-development">
<echo>update-development</echo>
<echo>checkout production</echo>
<git command="checkout">
<args>
<arg value="production-master" />
</args>
</git>
<echo>make sure up to date</echo>
<git command="pull" />
<echo>checkout master</echo>
<git command="checkout">
<args>
<arg value="master" />
</args>
</git>
<echo>make sure up to date</echo>
<git command="pull" />
<echo>merge production into master</echo>
<git command="merge">
<args>
<arg value="${branch}" />
</args>
</git>
<echo>push changes to master</echo>
<git command="push" />
<echo>checkout stage</echo>
<git command="checkout">
<args>
<arg value="stage" />
</args>
</git>
<echo>make sure up to date</echo>
<git command="pull" />
<echo>merge master into stage</echo>
<git command="merge">
<args>
<arg value="stage" />
</args>
</git>
<echo>push changes to stage</echo>
<git command="push" />
</target>
<!--
=================================
Target: input-runargs
input-runargs
=================================
-->
<target name="input-runbranch" unless="branch" description="prompts for command line arguments if necessary">
<input addProperty="branch" message="Add the desired release branch: -Dbranch='xxxx'"/>
</target>
<!--
=================================
Target: documentation
Creates documentation
=================================
-->
<target name="documentation" depends="init" description="this will create documentation">
<echo>documentation</echo>
</target>
<!--
=================================
Target: database.create
Compile and Rebuild Database
=================================
-->
<target name="database.create">
<echo>Run the create scripts in the sql/create/ folder...</echo>
<sql driver="${db.driver}" classpath="${db.classpath}" url="${db.url}" userid="${db.user}" password="${db.password}">
<path>
<fileset dir="sql/create/">
<include name="*.sql" />
</fileset>
</path>
</sql>
</target>
<!--
=================================
Target: database.update
Update database
=================================
-->
<target name="database.update">
<echo>Run the update scripts in the sql/update/ folder...</echo>
<sql driver="${db.driver}" classpath="${db.classpath}" url="${db.url}" userid="${db.user}" password="${db.password}">
<path>
<fileset dir="sql/update/">
<include name="*.sql" />
</fileset>
</path>
</sql>
</target>
<!--
=================================
Target: testing.unit
Runs the unit tests
=================================
-->
<target name="testing.unit" depends="init" description="this will run unit tests">
<runTestDirectory testDirectoryName="unit" />
</target>
<!--
=================================
Target: testing.acceptance
Runs the acceptance tests
=================================
-->
<target name="testing.acceptance" depends="init" description="this will run acceptance tests">
<runTestDirectory testDirectoryName="ui" />
</target>
<!--
=================================
Target: inspection.qpscanner
Test for query params
=================================
-->
<target name="inspection.qpscanner" depends="init,copy" description="this will inspect code for sql injection issues">
<echo>Starting qpscanner...</echo>
<!-- Arguments for CFQueryParam checker -->
<property name="qpscanner.url" value="${webapp.server}/qpscanner/index.cfm?fuseaction=scanner.go" />
<property name="qpscanner.outputfile" location="${filePathToBuildFolder}/qpscanner.xml" />
<property name="qpscanner.failOnAlertsFound" value="false" />
<property name="qpscanner.config" value="default" />
<property name="qpscanner.profile" value="default" />
<property name="qpscanner.recurse" value="true" />
<property name="qpscanner.exclusions" value="(deprecated|scheduledTasks)" />
<property name="qpscanner.scanOrderBy" value="false" />
<property name="qpscanner.scanQoQ" value="false" />
<property name="qpscanner.scanBuiltinFunc" value="false" />
<property name="qpscanner.showScopeInfo" value="false" />
<property name="qpscanner.highlightClientScopes" value="false" />
<property name="qpscanner.clientScopes" value="form,url,client,cookie" />
<property name="qpscanner.results" value="${qpscanner.outputfile}" />
<echo>for ${inspection.absolutefilepath}</echo>
<post to="${qpscanner.url}" logfile="${qpscanner.results}" append="false" verbose="false">
<prop name="action" value="scan" />
<prop name="outputFormat" value="xml" />
<prop name="config" value="${qpscanner.config}" />
<prop name="profile" value="${qpscanner.profile}" />
<prop name="startingDir" value="${inspection.absolutefilepath}" />
<prop name="recurse" value="${qpscanner.recurse}" />
<prop name="exclusions" value="${qpscanner.exclusions}" />
<prop name="scanOrderBy" value="${qpscanner.scanOrderBy}" />
<prop name="scanQoQ" value="${qpscanner.scanQoQ}" />
<prop name="scanBuiltinFunc" value="${qpscanner.scanBuiltinFunc}" />
<prop name="showScopeInfo" value="${qpscanner.showScopeInfo}" />
<prop name="highlightClientScopes" value="${qpscanner.highlightClientScopes}" />
<prop name="clientScopes" value="${qpscanner.clientScopes}" />
</post>
<xmlproperty file="${qpscanner.results}" />
<echo message="Scanned ${qpscanner.info.count.files} files containing ${qpscanner.info.count.queries} queries." />
<echo message="Found ${qpscanner.info.count.alerts} alerts." />
<fail message="QueryParam Scanner alerts present.">
<condition>
<and>
<istrue value="${qpscanner.failOnAlertsFound}" />
<not>
<equals arg1="${qpscanner.info.count.alerts}" arg2="0" />
</not>
</and>
</condition>
</fail>
</target>
<!--
=================================
Target: inspection.varscoper
Test var scoped variables
=================================
-->
<target name="inspection.varscoper" depends="init,copy" description="this will inspect code for unscoped variables">
<property name="varscoper.baseurl" value="${webapp.server}/varscoper/" />
<property name="varscoper.results" value="varscoper.csv" />
<property name="varscoper.recursiveDirectory" value="true" />
<!-- note: this target should fail when running as default (test case has var scope violations-->
<echo>Starting VarScoper check...</echo>
<echo>for ${inspection.absolutefilepath}</echo>
<!-- save the results of the call to varscoper.cfm as a csv file that we will delete later -->
<get dest="${varscoper.results}" src="${varscoper.baseurl}?displayformat=csv&amp;filePath=${inspection.absolutefilepath}&amp;varscoper.recursiveDirectory=${varscoper.recursiveDirectory}" />
<loadfile srcfile="${varscoper.results}" property="varscoper.csv">
<filterchain>
<headfilter skip="1" />
<trim />
</filterchain>
</loadfile>
<property name="varscoper.csv" value="No VarScope Violations" />
<echo>${varscoper.csv}</echo>
<fail message="VarScope violations are found.">
<condition>
<not>
<equals arg1="${varscoper.csv}" arg2="No VarScope Violations" />
</not>
</condition>
</fail>
</target>
<!--
=================================
Target: inspection.cpd
Copy paste detector
http://www.joshuafrankamp.com/blog/keeping-dry/
=================================
-->
<target name="inspection.cpd" depends="init,copy" description="this will inspect code for duplication">
<echo>Starting Copy Paste detector...</echo>
<!-- copy paste detector!! -->
<echo>for ${filePathToBuildFolder}</echo>
<taskdef name="cpd" classname="net.sourceforge.pmd.cpd.CPDTask" classpathref="project.classpath" />
<cpd minimumTokenCount="200" outputFile="cpd.xml" format="xml" language="cfm" encoding="UTF-8">
<fileset dir="${filePathToBuildFolder}">
<include name="**/*.cfm" />
<include name="**/*.cfc" />
<include name="**/*.cfml" />
</fileset>
</cpd>
<!-- <native2ascii encoding="UTF-8" src="." dest="." includes="*.raw" ext=".xml"/> -->
</target>
<!--
=================================
Target: inspection.jslint
Checking if JavaScript source code complies with coding rules
=================================
-->
<target name="inspection.jslint" depends="init" description="this will inspect code for duplication">
<echo>Starting jslint...</echo>
<jslint haltOnFailure="false" options="sloppy">
<formatter type="xml" destfile="jslint.xml" />
<fileset dir="${filePathToBuildFolder}" includes="**/*.js" excludes="**/*.pack.js" />
</jslint>
</target>
<!--
=================================
Target: inspection.csslint
Checking if CSS source code complies with coding rules
=================================
-->
<target name="inspection.csslint" depends="init" description="this will inspect code for duplication">
<echo>Starting csslint...</echo>
<apply executable="java" failonerror="false" parallel="true" output="csslint.xml">
<fileset dir="${filePathToBuildFolder}" includes="**/*.css" />
<arg line="-jar" />
<arg path="lib-cloudy/js.jar" />
<arg path="lib-cloudy/csslint-rhino.js" />
<!-- your customized arguments go here -->
<arg line="--format=lint-xml --warnings=box-model,floats --errors=ids,important" />
<srcfile />
</apply>
</target>
<!--
=================================
Target: compile.openbd
Compiles the ColdFusion files for any OpenBD compile errors
=================================
-->
<target name="compile.openbd">
<echo>openbd compile check</echo>
</target>
<!--
=================================
Target: compile.railo
Compiles the ColdFusion files for any Railo compile errors
=================================
-->
<target name="compile.railo">
<echo>railo compile check</echo>
</target>
<!--
=================================
Target: compile.acf.standalone
Compiles the ColdFusion files for any ACF compile errors
=================================
-->
<target name="compile.acf.standalone" if="cfmlengine.acf.standalone">
<tstamp />
<!--ACF Compiler Arguments-->
<property name="coldfusion.bootstrap.jar" value="${compilePathJars}/WEB-INF/lib/cfmx_bootstrap.jar" />
<property name="coldfusion.cfx.jar" value="${compilePathJars}/WEB-INF/lib/cfx.jar" />
<property name="coldfusion.compiler.libpath" value="${compilePathJars}/WEB-INF/cfusion/lib/" />
<property name="coldfusion.compiler.classpath" value="${coldfusion.compiler.libpath}/updates,${coldfusion.compiler.libpath}" />
<property name="coldfusion.compiler.compileresults" value="compileresults.txt" />
<echo>Starting compile check for Adobe...</echo>
<echo>for ${filePathToBuildFolder}</echo>
<java classname="coldfusion.tools.CommandLineInvoker" fork="true" resultproperty="java.compilecheck" output="${coldfusion.compiler.compileresults}">
<classpath>
<pathelement location="${jrun.jar}" />
<pathelement location="${coldfusion.bootstrap.jar}" />
<pathelement location="${coldfusion.cfx.jar}" />
</classpath>
<sysproperty key=" coldfusion.classPath" value="${coldfusion.compiler.classpath}" />
<sysproperty key=" coldfusion.libPath" value="${coldfusion.compiler.libpath}" />
<arg line=" Compiler " />
<arg line=" -webroot ${compilePathJars} " />
<arg line=" ${filePathToBuildFolder}" />
</java>
<loadfile srcfile="${coldfusion.compiler.compileresults}" property="src.file.cferrors">
<filterchain>
<LineContainsRegExp>
<regexp pattern="^Error*" />
</LineContainsRegExp>
</filterchain>
</loadfile>
<property name="src.file.cferrors" value="No compile Errors" />
<echo>${src.file.cferrors}</echo>
<echo>compile check complete for Adobe</echo>
<fail>
<condition>
<equals arg1="${java.compilecheck}" arg2="1" />
</condition>
</fail>
</target>
<target name="compile.acf.multi" unless="cfmlengine.acf.standalone">
<tstamp />
<!--ACF Compiler Arguments-->
<property name="coldfusion.bootstrap.jar" value="${compilePathJars}/WEB-INF/lib/cfmx_bootstrap.jar" />
<property name="coldfusion.cfx.jar" value="${compilePathJars}/WEB-INF/lib/cfx.jar" />
<property name="coldfusion.compiler.libpath" value="${compilePathJars}/WEB-INF/cfusion/lib/" />
<property name="coldfusion.compiler.classpath" value="${coldfusion.compiler.libpath}/updates,${coldfusion.compiler.libpath}" />
<property name="coldfusion.compiler.compileresults" value="compileresults.txt" />
<echo>Starting compile check for Adobe...</echo>
<echo>for ${filePathToBuildFolder}</echo>
<java classname="coldfusion.tools.CommandLineInvoker" fork="true" resultproperty="java.compilecheck" output="${coldfusion.compiler.compileresults}">
<classpath>
<pathelement location="${jrun.jar}" />
<pathelement location="${coldfusion.bootstrap.jar}" />
<pathelement location="${coldfusion.cfx.jar}" />
</classpath>
<sysproperty key=" coldfusion.classPath" value="${coldfusion.compiler.classpath}" />
<sysproperty key=" coldfusion.libPath" value="${coldfusion.compiler.libpath}" />
<arg line=" Compiler " />
<arg line=" -webroot ${compilePathJars} " />
<arg line=" ${filePathToBuildFolder}" />
</java>
<loadfile srcfile="${coldfusion.compiler.compileresults}" property="src.file.cferrors">
<filterchain>
<LineContainsRegExp>
<regexp pattern="^Error*" />
</LineContainsRegExp>
</filterchain>
</loadfile>
<property name="src.file.cferrors" value="No compile Errors" />
<echo>${src.file.cferrors}</echo>
<echo>compile check complete for Adobe</echo>
<fail>
<condition>
<equals arg1="${java.compilecheck}" arg2="1" />
</condition>
</fail>
</target>
<!--
=================================
Target: compile.check
This is a check for any engine
=================================
-->
<target name="compile.check" depends="init,copy,copy.jenkins" description="this will inspect code for syntax issues">
<if>
<equals arg1="${cfmlengine.acf}" arg2="true" />
<then>
<antcall target="compile.acf.standalone" />
<antcall target="compile.acf.multi" />
</then>
</if>
<if>
<equals arg1="${cfmlengine.railo}" arg2="true" />
<then>
<antcall target="compile.railo" />
</then>
</if>
<if>
<equals arg1="${cfmlengine.openbd}" arg2="true" />
<then>
<antcall target="compile.openbd" />
</then>
</if>
</target>
<!--
=================================
Macrodef: runTestDirectory
This is used for unit and acceptance testing
=================================
-->
<macrodef name="runTestDirectory">
<attribute name="testDirectoryName" />
<attribute name="excludes" default="" />
<sequential>
<delete dir="${mxunit.output.xml}/@{testDirectoryName}" />
<mkdir dir="${mxunit.output.xml}/@{testDirectoryName}" />
<echo>for ${mxunit.dir.location}/@{testDirectoryName}</echo>
<mxunittask server="${mxunit.server}" port="${mxunit.serverport}" defaultrunner="${mxunit.runner}" outputdir="${mxunit.output.xml}/@{testDirectoryName}" verbose="true" failureproperty="tests.mxunit.bombed" errorproperty="tests.mxunit.bombed">
<directory path="${mxunit.dir.location}/@{testDirectoryName}" recurse="true" packageName="${mxunit.cfcpath}.@{testDirectoryName}" componentPath="${mxunit.cfcpath}.@{testDirectoryName}" excludes="@{excludes}" />
</mxunittask>
</sequential>
</macrodef>
</project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment