build.xml 4.08 KB
<project default="run-all-tests">
    <taskdef resource="net/sf/antcontrib/antlib.xml"
             classpath="/opt/eclipse/plugins/org.apache.ant_1.8.2.v20120109-1030/lib/ant-contrib.jar"/>

    <target name="run-all-tests">
        <dirset id="testModels" dir="." includes="*"/>
        <property name="prop.testModels" refid="testModels"/>
        <for list="${prop.testModels}" delimiter=";" param="testModelDirectory" keepgoing="true">
            <sequential>
                <antcall target="run-test">
                    <param name="testModelDirectory" value="@{testModelDirectory}"/>
                </antcall>
            </sequential>
        </for>
    </target>

    <target name="load-properties">
        <loadproperties srcfile="atl.properties"/>
    </target>

    <target name="run-test" depends="load-properties">
        <echo>Run model comparison on directory ${testModelDirectory}</echo>

        <fileset id="sourceFS" dir="${testModelDirectory}">
            <include name="source.sysml"/>
        </fileset>
        <property name="inModel" refid="sourceFS"/>
        <echo>Source model is ${inModel}</echo>

        <fileset id="expectedFS" dir="${testModelDirectory}">
            <include name="expected.problem"/>
        </fileset>
        <property name="outExpectedModel" refid="expectedFS"/>
        <echo>Expected model is ${outExpectedModel}</echo>

        <condition property="isInModel">
            <equals arg1="${inModel}" arg2=""/>
        </condition>
        <fail if="isInModel" message="Source model find not found (source.*) in directory ${testModelDirectory}"/>

        <condition property="isOutExpectedModel">
            <equals arg1="${outExpectedModel}" arg2=""/>
        </condition>
        <fail if="isOutExpectedModel" message="Expected model find not found (expected.*) in directory ${testModelDirectory}"/>

        <!-- compute inModel and outExpectedModel from testModelDirectory -->
        <epsilon.eunit src="atl.eunit" todir="${testModelDirectory}">
            <modeltasks>
                <epsilon.emf.loadModel name="SourceModel" modelfile="${testModelDirectory}/${inModel}" metamodeluri="${metamodel.source.nsuri}"
                                       read="true" store="false"/>
                <epsilon.emf.loadModel name="ExpectedTargetModel" modelfile="${testModelDirectory}/${outExpectedModel}"
                                       metamodeluri="${metamodel.target.nsuri}" read="true" store="false"/>
            </modeltasks>
        </epsilon.eunit>
    </target>

	<target name="run-atl" depends="load-properties">
		<!-- Create temporary files for input and output models -->
		<tempfile property="atl.temp.srcfile" />
		<tempfile property="atl.temp.dstfile" />

		<!-- Save input model to a file -->
		<epsilon.storeModel model="SourceModel" target="${atl.temp.srcfile}" />

		<!-- Load the metamodels and the source model -->
		<atl.loadModel name="${metamodel.source.name}" metamodel="MOF" nsURI="${metamodel.source.nsuri}" />
		<atl.loadModel name="${metamodel.source.name2}" metamodel="MOF" nsURI="${metamodel.source.nsuri2}" />
		<atl.loadModel name="${metamodel.target.name}" metamodel="MOF" nsURI="${metamodel.target.nsuri}" />
		<atl.loadModel name="SourceModel" metamodel="${metamodel.source.name}" path="${atl.temp.srcfile}" />
		<atl.loadModel name="SourceModel2" metamodel="${metamodel.source.name2}" path="${atl.temp.srcfile}" />
		
		<!-- Run ATL and save the model -->
		<atl.launch path="${atl.transformationFile}">
			<inmodel name="${model.source.name}" model="SourceModel" />
			<inmodel name="${model.source.name2}" model="SourceModel2" />
			<outmodel name="${model.target.name}" model="TargetModel" metamodel="${metamodel.target.name}" />
		</atl.launch>
		<atl.saveModel model="TargetModel" path="${atl.temp.dstfile}" derived="false" />

		<!-- Load it back into the EUnit suite -->
		<epsilon.emf.loadModel name="TargetModel" modelfile="${atl.temp.dstfile}" metamodeluri="${metamodel.target.nsuri}" read="true" store="false" />

		<!-- Delete temporary files -->
		<delete file="${atl.temp.srcfile}" />
		<delete file="${atl.temp.dstfile}" />
	</target>
</project>