I'm trying to build the symettrical difference of two ";" seperated lists in my ant file. But it doesn't work and I think it might be because the result of String.split(";") seems to be a string, not an Array. (As seen in the println(a1). The result is: [Ljava.lang.String;@6395e579).
See the code:
<scriptdef language="javascript" name="diffLists">
<attribute name="list1" />
<attribute name="list2" />
<attribute name="target" />
<![CDATA[
function symmetricDifference(str1, str2) {
var a1 = str1.split(";");
println(Array.isArray(a1));
println(a1);
var a2 = str2.split(";");
var result = [];
for (var i = 0; i < a1.length; i++) {
if (a2.indexOf(a1[i]) == -1) {
result.push(a1[i]);
}
}
for (i = 0; i < a2.length; i++) {
if (a1.indexOf(a2[i]) == -1) {
result.push(a2[i]);
}
}
return result;
}
project.setProperty(attributes.get("target"),symmetricDifference(attributes.get("list1"),attributes.get("list2")).join(";"));
]]>
</scriptdef>
<target name="init">
<taskdef resource="net/sf/antcontrib/antlib.xml">
<classpath>
<pathelement location="${basedir}/lib/ant-contrib-1.0b3.jar"/>
</classpath>
</taskdef>
</target>
<target name="checkDiff" depends="init">
<var name="fileOld.list" value="a.txt;b.txt" />
<var name="file.list" value="b.txt;c.txt" />
<diffLists list1="${fileOld.list}" list2="${file.list}" target="diffList" />
<echo message="DIFF: ${diffList}" />
</target>
It is supposed to return: a.txt;c.txt But it returns: a.txt;b.txt;b.txt;c.txt
I'm using Apache Ant(TM) version 1.9.2 compiled on July 8 2013 if that matters.
Thank you for your help!