<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project name="test_child" default="test_dump">
<!--PROPERTIES-->
<!-- The following property values are replaced by the system_test ant file when this file is copied -->
<property name="p4d.port" value="@PORT@" />
<property name="svn.dump" value="@DUMP@" />
<property name="src.dir" value="@SOURCE@" />
<!-- Default conversion mode -->
<property name="cvt.mode" value="CONVERT" /> <!-- CONVERT or IMPORT -->
<property name="cvt.vcs" value="SVN" />
<property name="cvt.jvm.args" value="-Dlog4j.configuration=file:${src.dir}/debug.log4j.xml" />
<!-- Change the following properties to use binaries which are not on the PATH -->
<property name="p4.binary" value="p4" />
<property name="p4d.binary" value="p4d" />
<property name="svn.binary" value="svn" />
<property name="svnadmin.binary" value="svnadmin" />
<property name="svnlook.binary" value="svnlook" />
<property name="status.file" value="status.properties" />
<property name="logfile" value="test.log" />
<property name="cvt.jar" value="${src.dir}/dist/p4convert-svn.jar" />
<!-- <property name="cvt.jar" value="${src.dir}/dumps/2012.2.577926/p4convert-svn.jar" /> -->
<property name="cvt.audit" value="audit.log" />
<property name="log.level" value="DEBUG" />
<property name="util.zapkeywords" value="${src.dir}/validate/zapkeywords.sh" />
<property name="util.dos2unix" value="/opt/local/bin/dos2unix" />
<property name="util.md5sum" value="/sbin/md5 -r" />
<property name="svn.root" value="svn_server" />
<property name="p4d.root" value="p4_root" />
<property name="p4d.caseflag" value="" /> <!-- C0 for case sensitive FS -->
<property name="validate.root" value="validate" />
<property name="p4.workspace" value="p4_client" />
<property name="p4.config" value="config.p4" />
<property name="p4.user" value="svn-user" />
<property name="p4.clientname" value="svn-client" />
<property name="p4.depot" value="import" />
<property name="at.character" value="@" />
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${src.dir}/ext/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
<target name="test_dump">
<if>
<available file="${status.file}" />
<then>
<fail message="Test directory needs to be cleaned before re-running test_dump" />
</then>
</if>
<set_status status="started" />
<echo file="${logfile}" append="true" > svn dump file is ${svn.dump} ${line.separator}</echo>
<echo file="${logfile}" append="true" > src directory is ${src.dir} ${line.separator}</echo>
<echo file="${logfile}" append="true" > basedir is ${basedir} ${line.separator}</echo>
<echo file="${logfile}" append="true" > p4d.port is ${p4d.port} ${line.separator}</echo>
<echo file="${logfile}" append="true" > cvt.mode is ${cvt.mode} ${line.separator}</echo>
<echo file="${logfile}" append="true" > cvt.vcs is ${cvt.vcs} ${line.separator}</echo>
<if>
<equals arg1="IMPORT" arg2="${cvt.mode}" />
<then>
<antcall target="prep_p4d" />
<antcall target="start_p4d" />
</then>
</if>
<convert_dump dump="${svn.dump}" />
<if>
<equals arg1="CONVERT" arg2="${cvt.mode}" />
<then>
<antcall target="prep_p4d" />
<antcall target="load_p4d" />
<antcall target="start_p4d" />
</then>
</if>
<set_status status="pre_validate" />
<antcall target="create_svn" />
<antcall target="init_client" />
<antcall target="validate" />
<antcall target="stop_p4d" />
</target>
<macrodef name="set_status">
<attribute name="status" />
<sequential>
<propertyfile file="${status.file}" >
<entry key="status" value="@{status}" />
</propertyfile>
</sequential>
</macrodef>
<!-- For a specific dump file, create a p4convert-svn configuration file, then run the conversion -->
<macrodef name="convert_dump">
<attribute name="dump" />
<sequential>
<propertyfile file="${status.file}" >
<entry key="status" value="configuring" />
<entry key="conversion.dump" value="@{dump}" />
</propertyfile>
<echo message="converting @{dump}" />
<create_config dump="@{dump}" mode="${cvt.mode}" vcs="${cvt.vcs}" />
<antcall target="run" />
</sequential>
</macrodef>
<!-- create a line in the config file with param and value -->
<macrodef name="set_config">
<attribute name="file" default="default.cfg" />
<attribute name="param" />
<attribute name="value" />
<sequential>
<replaceregexp file="@{file}" byline="true">
<regexp pattern="@{param}=.*$" />
<substitution expression="@{param}=@{value}" />
</replaceregexp>
</sequential>
</macrodef>
<!-- create a config file for p4convert -->
<macrodef name="create_config">
<attribute name="dump" />
<attribute name="mode" />
<attribute name="vcs" />
<sequential>
<exec executable="java" >
<arg line="-jar ${cvt.jar} --config @{vcs}" />
</exec>
<set_config param="com.p4convert.svn.dumpFile" value="@{dump}" />
<set_config param="com.p4convert.p4.mode" value="@{mode}" />
<set_config param="com.p4convert.p4.root" value="${p4d.root}" />
<set_config param="com.p4convert.p4.port" value="${p4d.port}" />
</sequential>
</macrodef>
<!-- takes a value, increments it, and writes it out to a var -->
<scriptdef name="increment" language="javascript">
<attribute name="value" />
<attribute name="variable" />
<![CDATA[
var initVal = attributes.get("value");
var nextNum = parseInt(initVal,10) + 1;
varnew = project.createTask("var");
varnew.setName(attributes.get("variable"))
varnew.setValue(nextNum.toString());
varnew.perform();
]]>
</scriptdef>
<!-- Create a subversion repository at svn.root -->
<target name="create_svn">
<exec executable="${svnadmin.binary}" output="${logfile}" append="true" >
<arg line="create ${svn.root}" />
</exec>
<exec executable="${svnadmin.binary}" input="${svn.dump}" output="${logfile}" append="true" >
<arg line="load ${svn.root}" />
</exec>
</target>
<!-- Run p4convert-svn with default.cfg -->
<target name="run">
<set_status status="converting" />
<stopwatch name="conversion.elapsed" action="start" />
<exec executable="java" output="${logfile}" append="true" >
<arg value="${cvt.jvm.args}" />
<arg value="-jar" />
<arg value="${cvt.jar}" />
<arg value="default.cfg" />
</exec>
<stopwatch name="conversion.elapsed" action="total" />
<propertyfile file="${status.file}" >
<entry key="status" value="converted" />
<entry key="conversion.elapsed" value="${conversion.elapsed}" />
</propertyfile>
<parse_conversion_results file="converter.log" />
</target>
<!-- takes a line from the conversion summary and converts it into property format -->
<scriptdef name="propertyize" language="javascript">
<attribute name="line" />
<attribute name="variable" />
<![CDATA[
var line = "" + attributes.get("line");
var tokens = line.trim().split(/\s+/);
var ntokens = [];
var last_tok = "";
for (var i = 0; i < tokens.length; i++) {
if (tokens[i] == ":"){
last_tok = ":";
ntokens.push("=");
} else if (tokens[i] == "***WARNINGS***" || tokens[i] == "****" || tokens[i] == "WARNING"){
} else {
if (last_tok != "" && last_tok != ":"){
ntokens.push("_");
}
last_tok = tokens[i];
ntokens.push(tokens[i]);
}
}
varnew = project.createTask("var");
varnew.setName(attributes.get("variable"))
varnew.setValue(ntokens.join("").toLowerCase());
varnew.perform();
]]>
</scriptdef>
<macrodef name="parse_conversion_results" >
<attribute name="file" />
<sequential>
<exec executable="sh" >
<arg value="-c" />
<arg value="tail -20 @{file} | grep -e ' : ' > results" />
</exec>
<loadfile srcFile="results" property="foo" quiet="true" />
<if>
<or>
<not><available file="audit.log" /></not>
<equals arg1="" arg2="${foo}" />
</or>
<then>
<exec executable="sh" >
<arg value="-c" />
<arg value="echo 'conversion.FAILED' >> ${status.file}" />
</exec>
<fail message="Conversion must be run before validate" />
</then>
</if>
<for param="line" list="${foo}" delimiter="${line.separator}" >
<sequential>
<propertyize line="@{line}" variable="nline" />
<exec executable="sh" >
<arg value="-c" />
<arg value="echo 'conversion.${nline}' >> ${status.file}" />
</exec>
</sequential>
</for>
<delete file="results" quiet="true" />
</sequential>
</macrodef>
<!-- initialize Perforce server, load jnl.0, run -xu, -xx, and load jnl.fix -->
<!-- Also create start.sh and stop.sh -->
<target name="prep_p4d">
<mkdir dir="${p4d.root}" />
<echo message="${p4d.binary} ${p4d.caseflag} -p ${p4d.port} -r . -L log -d" file="${p4d.root}/start.sh" />
<chmod file="${p4d.root}/start.sh" perm="+x" />
<echo message="${p4.binary} -p ${p4d.port} admin stop" file="${p4d.root}/stop.sh" />
<chmod file="${p4d.root}/stop.sh" perm="+x" />
</target>
<target name="load_p4d">
<exec executable="${p4d.binary}" dir="${p4d.root}" output="${logfile}" append="true">
<arg line="${p4d.caseflag} -r . -L log -jr jnl.0" />
</exec>
<exec executable="${p4d.binary}" dir="${p4d.root}" output="${logfile}" append="true">
<arg line="${p4d.caseflag} -r . -L log -xu" />
</exec>
<exec executable="${p4d.binary}" dir="${p4d.root}" output="${logfile}" append="true">
<arg line="${p4d.caseflag} -r . -L log -xx" />
</exec>
<exec executable="${p4d.binary}" dir="${p4d.root}" output="${logfile}" append="true">
<arg line="${p4d.caseflag} -r . -L log -jr jnl.fix" />
</exec>
</target>
<!-- start the server in "p4d.root" using port "p4d.port" -->
<target name="start_p4d">
<exec executable="${p4d.binary}" dir="${p4d.root}" failonerror="true" output="${logfile}" append="true" >
<arg line="${p4d.caseflag} -r . -p ${p4d.port} -L log -d" />
</exec>
</target>
<!-- stop the server in "p4d.root" -->
<target name="stop_p4d">
<exec executable="${p4d.root}/stop.sh" output="${logfile}" append="true"/>
</target>
<!-- create a workspace in "p4.workspace" and a matching P4CONFIG entry -->
<target name="init_client">
<mkdir dir="${p4.workspace}" />
<property name="full.workspace" location="${p4.workspace}" />
<echo message="P4PORT=${p4d.port}${line.separator}" file="${p4.workspace}/${p4.config}" />
<echo message="P4USER=${p4.user}${line.separator}" file="${p4.workspace}/${p4.config}" append="true" />
<echo message="P4CLIENT=${p4.clientname}${line.separator}" file="${p4.workspace}/${p4.config}" append="true" />
<tempfile property="p4.client.tmp" suffix=".tmp" deleteonexit="true" />
<!-- Set the client Root: entry -->
<exec executable="${p4.binary}" output="${p4.client.tmp}" >
<arg line="-p ${p4d.port} client -o ${p4.clientname}" />
</exec>
<replaceregexp file="${p4.client.tmp}" byline="true">
<regexp pattern="Root:.*$" />
<substitution expression="Root: ${full.workspace}" />
</replaceregexp>
<exec executable="${p4.binary}" input="${p4.client.tmp}" >
<arg line="-p ${p4d.port} client -i" />
</exec>
</target>
<target name="validate">
<if>
<not><available file="audit.log" /></not>
<then>
<fail message="Conversion must be run before validate" />
</then>
</if>
<set_status status="validating" />
<delete dir="${validate.root}" quiet="true" />
<var name="line.count" value="1" />
<var name="error.count" value="0" />
<mkdir dir="${validate.root}" />
<mkdir dir="${validate.root}/perforce" />
<mkdir dir="${validate.root}/subversion" />
<tstamp>
<format property="start" pattern="yyyy MMMM dd HH:mm:ss" locale="en"/>
</tstamp>
<echo message="# validation run ${start}${line.separator}" file="${validate.root}/fail.log" />
<echo message="# line failure : svn p4 hash path${line.separator}" file="${validate.root}/fail.log" append="true" />
<loadfile property="audit" srcfile="audit.log"/>
<for param="line" list="${audit}" delimiter="${line.separator}">
<sequential>
<propertyregex property="first"
input="@{line}"
regexp="(.).*$"
select="\1"
override="true"/>
<if>
<equals arg1="${first}" arg2="#" forcestring="true" />
<else>
<var name="x" value="1" />
<for param="element" list="@{line}" delimiter=", " >
<sequential>
<var name="arg${x}" value="@{element}"/>
<increment value="${x}" variable="x" />
</sequential>
</for>
<validate_file
svn.filename="${arg1}"
svn.revision="${arg2}"
p4.change="${arg3}"
svn.md5="${arg4}" />
</else>
</if>
<increment value="${line.count}" variable="line.count" />
</sequential>
</for>
<propertyfile file="${status.file}" >
<entry key="validate.lines" value="${line.count}" />
<entry key="validate.errors" value="${error.count}" />
</propertyfile>
<set_status status="validated" />
</target>
<macrodef name="validate_file">
<attribute name="svn.filename" />
<attribute name="svn.revision" />
<attribute name="p4.change" />
<attribute name="svn.md5" />
<sequential>
<local name="p4path" />
<local name="p4hash" />
<local name="svn.sum" />
<local name="p4.sum" />
<get_depot_path relpath="@{svn.filename}" change="@{p4.change}" prop="p4path" />
<get_p4_fstat depotpath="${p4path}" prop="p4hash" />
<if>
<equals arg1="${p4hash}" arg2="@{svn.md5}" forcestring="true" />
<else>
<echo file="${logfile}" append="true" > ...... md5 mismatch in @{svn.filename} - testing more...${line.separator} </echo>
<store_svn_file svn.filename="@{svn.filename}" svn.revision="@{svn.revision}" error.number="${error.count}" />
<store_p4_file depotpath="${p4path}" error.number="${error.count}" />
<compute_sum file="${validate.root}/subversion/file${error.count}" prop="svn.sum" />
<compute_sum file="${validate.root}/perforce/file${error.count}" prop="p4.sum" />
<echo file="${logfile}" append="true" > ...... new sums are: ${svn.sum} ${p4.sum} ${line.separator}</echo>
<if>
<equals arg1="${svn.sum}" arg2="${p4.sum}" forcestring="true" />
<else>
<!-- run dos2unix on svn file to see if we can make them match -->
<dos2unix file="${validate.root}/subversion/file${error.count}" />
<compute_sum file="${validate.root}/perforce/file${error.count}" prop="p4.sum" />
<if>
<equals arg1="${svn.sum}" arg2="${p4.sum}" forcestring="true" />
<then>
<echo file="${logfile}" append="true" > ...... File checks out after dos2unix! ${line.separator}</echo>
</then>
<else>
<increment value="${error.count}" variable="error.count" />
<echo file="${logfile}" append="true" >##ERROR## ${error.count} : ${p4path} ${line.separator}</echo>
<echo file="${logfile}" append="true" >##ERROR## line: ${line.count}, ${svn.sum} != ${p4.sum} ${line.separator}</echo>
<echo message="${line.count} ${error.count} : ${p4path} ${svn.sum} ${p4.sum}${line.separator}" file="${validate.root}/fail.log" append="true" />
</else>
</if>
</else>
</if>
</else>
</if>
</sequential>
</macrodef>
<macrodef name="store_svn_file">
<attribute name="svn.filename" />
<attribute name="svn.revision" />
<attribute name="error.number" />
<sequential>
<echo file="${logfile}" append="true" >cmd: ${svnlook.binary} cat -r @{svn.revision} ${svn.root} @{svn.filename} | ${util.zapkeywords} ${line.separator} </echo>
<exec executable="sh" output="${validate.root}/subversion/file@{error.number}" >
<arg value="-c" />
<arg value="${svnlook.binary} cat -r @{svn.revision} ${svn.root} @{svn.filename} | ${util.zapkeywords}" />
</exec>
</sequential>
</macrodef>
<macrodef name="store_p4_file">
<attribute name="depotpath" />
<attribute name="error.number" />
<sequential>
<echo file="${logfile}" append="true" >cmd: ${p4.binary} -p ${p4d.port} print -q -o - "@{depotpath}" | ${util.zapkeywords} ${line.separator}</echo>
<exec executable="sh" output="${validate.root}/perforce/file@{error.number}" >
<arg value="-c" />
<arg value="${p4.binary} -p ${p4d.port} print -q -o - "@{depotpath}" | ${util.zapkeywords}" />
</exec>
</sequential>
</macrodef>
<macrodef name="compute_sum">
<attribute name="file" />
<attribute name="prop" />
<sequential>
<exec executable="sh" >
<arg value="-c" />
<arg value="${util.md5sum} @{file} | awk '{ print $1; }' | tr "[:lower:]" "[:upper:]"" />
<redirector outputproperty="@{prop}" />
</exec>
</sequential>
</macrodef>
<macrodef name="dos2unix" >
<attribute name="file" />
<sequential>
<local name="temp.file" />
<tempfile property="temp.file" deleteonexit="true" />
<copy file="@{file}" tofile="${temp.file}" />
<exec executable="sh" output="@{file}" >
<arg value="-c" />
<arg value="cat ${temp.file} | ${util.dos2unix}" />
</exec>
</sequential>
</macrodef>
<macrodef name="get_depot_path">
<attribute name="relpath" />
<attribute name="change" />
<attribute name="prop" />
<sequential>
<local name="path" />
<property name="path" value="" />
<propertyregex property="path" input="@{relpath}" regexp="%" replace="%25" global="true" override="true" defaultValue="@{relpath}" />
<propertyregex property="path" input="${path}" regexp="@" replace="%40" global="true" override="true" defaultValue="${path}" />
<propertyregex property="path" input="${path}" regexp="#" replace="%23" global="true" override="true" defaultValue="${path}" />
<propertyregex property="path" input="${path}" regexp="[*]" replace="%2a" global="true" override="true" defaultValue="${path}" />
<property name="@{prop}" value="//${p4.depot}/${path}${at.character}@{change}" />
</sequential>
</macrodef>
<macrodef name="get_p4_fstat">
<attribute name="depotpath" />
<attribute name="prop" />
<sequential>
<local name="tmp.fstat" />
<echo file="${logfile}" append="true" > depot_path: @{depotpath} ${line.separator}</echo>
<exec executable="${p4.binary}" >
<arg value="-p" />
<arg value="${p4d.port}" />
<arg value="fstat" />
<arg value="-Ol" />
<arg value="-T" />
<arg value="digest" />
<arg value="@{depotpath}" />
<redirector outputproperty="tmp.fstat" />
</exec>
<!-- <echo file="${logfile}" append="true" > tmp.fstat: ${tmp.fstat} </echo> -->
<propertyregex property="@{prop}" input="${tmp.fstat}"
regexp=".* .* (.*)$"
select="\1" override="true"/>
<!-- sum: ${@{prop}} </echo> -->
</sequential>
</macrodef>
<target name="clean">
<delete file="converter.log" quiet="true" />
<delete file="default.cfg" quiet="true" />
<delete file="audit.log" quiet="true" />
<delete file="changeMap.txt" quiet="true" />
<delete file="test.log" quiet="true" />
<delete file="${status.file}" quiet="true" />
<delete dir="${p4d.root}" quiet="true" />
<delete dir="${p4.workspace}" quiet="true" />
<delete dir="${svn.root}" quiet="true" />
<delete dir="${validate.root}" quiet="true" />
</target>
</project>
# |
Change |
User |
Description |
Committed |
|
#1
|
10025 |
Norman Morse |
fixed system_test to work with both IMPORT and CONVERT mode |
|
|