blob: 0fe65eb07d41820b4e73263292a310d9df1a1ee3 [file] [log] [blame]
<!--
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
-->
<project name="edgent.common"
xmlns:jacoco="antlib:org.jacoco.ant"
>
<description>
Common tasks.
</description>
<!-- Assumption is that build files are two levels deep -->
<property name="edgent.dir" location="${basedir}/../.."/>
<property name="edgent.tools" location="${edgent.dir}/tools"/>
<property name="target.dir" location="${edgent.dir}/target"/>
<property name="edgent.ext" location="${edgent.dir}/ext"/>
<!-- Project specific extension jars -->
<property name="project.ext" location="${basedir}/ext"/>
<property name="target.java8.dir" location="${target.dir}/java8"/>
<property name="target.java8.ext" location="${target.java8.dir}/ext"/>
<property name="edgent.lib" location="${target.java8.dir}/lib"/>
<!-- default to edgent lib -->
<condition property="lib"
value="${target.java8.dir}/${component.path}/lib"
else="${edgent.lib}">
<isset property="component.path"/>
</condition>
<condition property="component.ext"
value="${target.java8.dir}/${component.path}/ext">
<isset property="component.path"/>
</condition>
<property name="edgent.analytics" location="${target.java8.dir}/analytics"/>
<property name="edgent.apps" location="${target.java8.dir}/apps"/>
<property name="edgent.connectors" location="${target.java8.dir}/connectors"/>
<property name="edgent.console" location="${target.java8.dir}/console"/>
<property name="edgent.utils" location="${target.java8.dir}/utils"/>
<property name="edgent.samples" location="${target.java8.dir}/samples"/>
<property name="src" location="src/main/java"/>
<property name="src.excludes" value=""/>
<property name="resources" location="src/main/resources"/>
<property name="classes" location="classes"/>
<property name="jarname" value="${ant.project.name}.jar"/>
<property name="jar" location="${lib}/${jarname}"/>
<property name="test.src" location="src/test/java"/>
<property name="test.classes" location="test.classes"/>
<property name="test.dir" location="unittests"/>
<!-- compile.classpath ref is used by default for compilation
and manifest class path generation.
When the full compile needs external jars that should
not be in the manifest compile.classpath should just
include local jars and a new reference id should be used
that includes compile.classpath and the external jars.
The property full.compile.classpath.id is set
to the name of the reference (see android examples).
-->
<property name="full.compile.classpath.id" value="compile.classpath"/>
<!-- Core Edgent ext class path -->
<path id="edgent.ext.classpath">
<pathelement location="${target.java8.ext}/google-gson-2.2.4/gson-2.2.4.jar" />
<pathelement location="${target.java8.ext}/slf4j-1.7.12/slf4j-api-1.7.12.jar"/>
<pathelement location="${target.java8.ext}/metrics-3.1.2/metrics-core-3.1.2.jar"/>
</path>
<!-- Edgent samples common class path -->
<path id="edgent.samples.classpath">
<pathelement location="${edgent.lib}/edgent.providers.development.jar"/>
<pathelement location="${edgent.lib}/edgent.providers.direct.jar"/>
<pathelement location="${target.java8.ext}/slf4j-1.7.12/slf4j-jdk14-1.7.12.jar"/>
</path>
<!-- Edgent unit tests common class path -->
<path id="test.common.classpath">
<pathelement location="${target.java8.ext}/slf4j-1.7.12/slf4j-jdk14-1.7.12.jar"/>
</path>
<!-- expects a property of component.path e.g. connectors/iotp -->
<!-- only called by non-core components -->
<macrodef name="setup.component">
<sequential>
<property name="component.target" location="${target.java8.dir}/${component.path}"/>
<property name="component.lib" location="${component.target}/lib"/>
<!-- <property name="component.ext" location="${component.target}/ext"/> -->
<mkdir dir="${component.lib}"/>
<mkdir dir="${component.ext}"/>
<copy todir="${component.ext}" includeEmptyDirs="no" failonerror="false" quiet="true">
<fileset dir="${project.ext}"/>
</copy>
</sequential>
</macrodef>
<target name="project.component" if="component.path">
<setup.component/>
</target>
<macrodef name="edgent.compile">
<sequential>
<javac debug="true" includeantruntime="no"
srcdir="${src}"
excludes="${src.excludes}"
destdir="${classes}"
classpathref="${full.compile.classpath.id}"/>
</sequential>
</macrodef>
<target name="all" depends="jar,test.compile"/>
<target name="init">
<mkdir dir="${src}"/>
<mkdir dir="${test.src}"/>
<mkdir dir="${classes}"/>
<mkdir dir="${resources}"/>
<mkdir dir="${test.classes}"/>
<mkdir dir="${target.java8.dir}"/>
<mkdir dir="${target.java8.ext}"/>
<mkdir dir="${edgent.lib}"/>
<copy todir="${target.java8.ext}">
<fileset dir="${edgent.ext}"/>
</copy>
</target>
<target name="clean" >
<delete dir="${classes}"/>
<delete dir="${test.classes}"/>
<delete dir="${test.dir}"/>
<delete file="${jar}"/>
</target>
<target name="compile" depends="init,project.component">
<edgent.compile/>
</target>
<target name="jar" depends="compile">
<mkdir dir="${classes}/META-INF"/>
<copy file="${edgent.dir}/LICENSE" tofile="${classes}/META-INF/LICENSE"/>
<copy file="${edgent.dir}/NOTICE" tofile="${classes}/META-INF/NOTICE"/>
<manifestclasspath property="jar.classpath" jarfile="${jar}"
maxParentLevels="10">
<classpath refid="compile.classpath"/>
</manifestclasspath>
<jar destfile="${jar}">
<manifest>
<attribute name="Implementation-Title" value="${ant.project.name}"/>
<attribute name="Implementation-Version" value="${commithash}-${DSTAMP}-${TSTAMP}"/>
<attribute name="Implementation-Vendor" value="Apache Software Foundation"/>
<attribute name="Class-Path" value="${jar.classpath}"/>
</manifest>
<fileset dir="${classes}"/>
<fileset dir="${resources}"/>
</jar>
</target>
<target name="test.compile" depends="jar">
<javac debug="true" includeantruntime="yes"
srcdir="${test.src}"
destdir="${test.classes}"
classpathref="test.compile.classpath"/>
</target>
<!-- Allow the pattern of tests to run be set
ant -Dtest.base.pattern='**/*TestManual.java test'
-->
<property name="test.base.pattern" value="**/*Test.java"/>
<target name="test" depends="test.compile,test.run"/>
<target name="test.run">
<mkdir dir="${test.dir}"/>
<tempfile property="test.run.dir" prefix="testrun" destDir="${test.dir}"/>
<mkdir dir="${test.run.dir}"/>
<jacoco:coverage enabled="yes" destfile="${test.run.dir}/jacoco.exec">
<junit fork="yes" dir="${test.run.dir}" printsummary="yes" showoutput="no"
haltonfailure="yes">
<classpath>
<path refid="test.classpath"/>
</classpath>
<sysproperty key="edgent.build.ci" value="${edgent.build.ci}"/>
<!-- Allow tests to know the root directory -->
<sysproperty key="edgent.test.root.dir" value="${edgent.dir}"/>
<assertions><enable/></assertions>
<formatter type="xml"/>
<!-- Only use the brief formatter for a continuous integration build" -->
<formatter type="brief" usefile="no" if="edgent.build.ci"/>
<batchtest todir="${test.run.dir}">
<fileset dir="${test.src}">
<include name="${test.base.pattern}"/>
</fileset>
</batchtest>
</junit>
</jacoco:coverage>
</target>
</project>