Source

hbbackend / build.xml

<project name="hbbackend" default="build"
	 xmlns:ivy="antlib:org.apache.ivy.ant">
    <property name="lib.dir" value="lib"/>
    <property name="lib2.dir" value="lib2"/>
    <property name="target.dir" value="target"/>
    <property name="target.classes.dir" value="${target.dir}/classes"/>
    <property name="target.modules.dir" value="${target.dir}/modules"/>
    <property name="target.work.dir" value="${target.dir}/work"/>
    <property name="src.dir" value="src/main/java"/>

    <property name="config.file" value="conf/default.conf"/>
    <property name="package.prefix" value="org.honeynet.hbbackend"/>


    <path id="lib.path.id">
      <fileset dir="${lib.dir}"/>
      <fileset dir="${lib2.dir}"/>
    </path>
    

    <target name="report" depends="retrieve" description="--> generates a report of dependencies">
        <ivy:report todir="${build.dir}"/>
    </target>


    <target name="retrieve" description="--> retreive dependencies with ivy">
        <ivy:retrieve conf="build" type="jar" pattern="${lib.dir}/[artifact]-[revision].[ext]"/>
        <ivy:retrieve conf="build" type="rar" pattern="${lib.dir}/[artifact]-[revision].[ext]"/>
        <ivy:retrieve conf="build" type="bundle" pattern="${lib.dir}/[artifact]-[revision].[ext]"/>
        <ivy:retrieve conf="build" type="sources" pattern="${lib.dir}/[type]/[artifact]-[revision]-[type].[ext]"/>
    </target>


    <!-- <target name="retrieve-buildlib"> -->
    <!--   <ivy:retrieve conf="buildlib" pattern="${buildlib.dir}/[artifact].[ext]" type="jar"/> -->
    <!-- </target> -->


    <target name="build"
	    depends="build-hpfeedsra,
		     build-hpfeeds,
		     build-virustotal,
		     build-shadowserver_asn,
		     build-shadowserver_geoip,
		     build-stats
		     "
	    description="--> build all modules"
    />


    <target name="compile" depends="" description="--> compile classes">
      <mkdir dir="${target.classes.dir}"/>
      <javac srcdir="${src.dir}"
	     destdir="${target.classes.dir}"
	     classpathref="lib.path.id"
	     source="1.6"
	     target="1.6"
	     debug="true"
	     includeAntRuntime="false"
	     />
    </target>


    <target name="clean" description="--> clean the project">
        <delete includeemptydirs="true" failonerror="false">
            <fileset dir="${target.dir}"/>
    	</delete>
    </target>

    <target name="clean-cache" description="--> clean the ivy cache">
      <ivy:cleancache />
    </target>




    <target name="build-hpfeedsra" depends="compile" description="resource adapter">
      <package-rar name="hpfeedsra"/>
    </target>

    <target name="build-hpfeeds" depends="compile" description="module">
      <package-ejb name="hpfeeds">
	<embed>
	  <!-- <embed-package package="common"/> -->
	</embed>
      </package-ejb>
    </target>

    <target name="build-virustotal" depends="compile" description="module">
      <package-ejb name="virustotal">
	<embed>
	  <!-- <embed-package package="common"/> -->
	</embed>
      </package-ejb>
    </target>

    <target name="build-shadowserver_asn" depends="compile" description="module">
      <package-ejb name="shadowserver_asn">
	<embed>
	  <!-- <embed-package package="common"/> -->
	</embed>
      </package-ejb>
    </target>

    <target name="build-shadowserver_geoip" depends="compile" description="module">
      <package-ejb name="shadowserver_geoip">
	<embed>
	  <!-- <embed-package package="common"/> -->
	</embed>
      </package-ejb>
    </target>

    <target name="build-stats" depends="compile" description="module">
      <package-ejb name="stats">
	<embed>
	  <!-- <embed-package package="common"/> -->
	</embed>
      </package-ejb>
    </target>



    <macrodef name="package-bundle">
      <attribute name="name"/>
      <!-- <element name="libraries" optional="true"/> -->

      <sequential>
        <package-module name="@{name}">
          <package>
            <mkdir dir="${target.modules.dir}"/>
            <!-- <mkdir dir="${target.work.dir}/${module.@{name}.package}/lib"/> -->
	    <!-- <copy todir="${target.work.dir}/${module.@{name}.package}/lib"> -->
	    <!--   <libraries/> -->
	    <!-- </copy> -->
            <jar basedir="${target.work.dir}/${module.@{name}.package}"
                 destfile="${target.modules.dir}/${module.@{name}.package}.jar"
                 compress="false"
		 filesetmanifest="merge"
                 />
          </package>
        </package-module>
      </sequential>
    </macrodef>


    <macrodef name="package-ejb">
      <attribute name="name"/>
      <element name="embed" optional="true"/>

      <sequential>
	<package-module name="@{name}">
	  <resources>
	    <fileset dir="${src.dir}/${module.@{name}.package.asdir}">
	      <include name="META-INF/**"/>
	    </fileset>
	  </resources>

	  <package-module-embed>
	    <embed/>
	  </package-module-embed>

	  <package>
	    <copy
		todir="${target.work.dir}/${module.@{name}.package}"
		verbose="true"
		>
	      <fileset dir="${target.work.dir}/${module.@{name}.package}">
		<include name="META-INF/*.template.*"/>
	      </fileset>

	      <mapper>
		<regexpmapper from="^(.*)\.template\.(.*)$$" to="\1.\2"/>
	      </mapper>

	      <filterset onmissingfiltersfile="fail">
		<filtersfile file="${config.file}"/>
	      </filterset>
	    </copy>
	    
	    <embed/>

	    <mkdir dir="${target.modules.dir}"/>
	    <jar basedir="${target.work.dir}/${module.@{name}.package}"
		 destfile="${target.modules.dir}/${module.@{name}.package}.jar"
		 compress="false"
		 filesetmanifest="merge"
		 mergeClassPathAttributes="true"
		 />
	  </package>
	</package-module>
      </sequential>
    </macrodef>


    <macrodef name="package-war">
      <attribute name="name"/>
      <element name="embed" optional="true"/>
      <sequential>
	<package-module name="@{name}">
	  <resources>
	    <fileset dir="${src.dir}/${module.@{name}.package.asdir}">
	      <include name="META-INF/**"/>
	      <include name="WEB-INF/**"/>
	    </fileset>
	  </resources>

	  <package-module-embed>
	    <embed/>
	  </package-module-embed>

          <package>
	    <copy
		todir="${target.work.dir}/${module.@{name}.package}"
		verbose="true"
		>
	      <fileset dir="${target.work.dir}/${module.@{name}.package}">
		<include name="META-INF/*.template.*"/>
		<include name="WEB-INF/*.template.*"/>
	      </fileset>

	      <mapper>
		<regexpmapper from="^(.*)\.template\.(.*)$$" to="\1.\2"/>
	      </mapper>

	      <filterset onmissingfiltersfile="fail">
		<filtersfile file="${config.file}"/>
	      </filterset>
	    </copy>

	    <embed/>

	    <move todir="${target.work.dir}/${module.@{name}.package}/WEB-INF/classes">
	      	<fileset dir="${target.work.dir}/${module.@{name}.package}">
		  <exclude name="META-INF/**"/>
		  <exclude name="WEB-INF/**"/>
		</fileset>
	    </move>

            <mkdir dir="${target.modules.dir}"/>
            <jar basedir="${target.work.dir}/${module.@{name}.package}"
		 destfile="${target.modules.dir}/${module.@{name}.package}.war"
                 compress="false"
		 filesetmanifest="merge"
		 mergeClassPathAttributes="true"
		 >
	    </jar>
          </package>
        </package-module>
      </sequential>
    </macrodef>


    <macrodef name="package-rar">
      <attribute name="name"/>
      <attribute name="prefix" default="${package.prefix}"/>

      <sequential>
        <package-module name="@{name}" prefix="@{prefix}">
	  <resources>
	    <fileset dir="${src.dir}/${module.@{name}.package.asdir}">
	      <include name="META-INF/**"/>
	    </fileset>
	  </resources>

          <package>
            <mkdir dir="${target.modules.dir}"/>
            <jar basedir="${target.work.dir}/${module.@{name}.package}"
                 destfile="${target.modules.dir}/${module.@{name}.package}.rar"
                 compress="false"
		 filesetmanifest="merge"
		 mergeClassPathAttributes="true"
                 />
          </package>
	</package-module>
      </sequential>
    </macrodef>


    <macrodef name="package-module">
      <attribute name="name"/>
      <attribute name="prefix" default="${package.prefix}"/>

      <element name="package"/>
      <element name="resources" optional="true"/>
      <element name="package-module-embed" optional="true"/>

      <sequential>
	<macrodef name="embed-package">

	  <attribute name="package"/>
	  <attribute name="parent" default="${package.prefix}"/>

	  <sequential>
	    <property name="module.@{name}.embed.@{package}.package" value="@{parent}.@{package}"/>

	    <echo message="embed-package: ${module.@{name}.embed.@{package}.package} (into ${module.@{name}.package})"/>
	    <pathconvert property="module.@{name}.embed.@{package}.package.asdir">
	      <string>${module.@{name}.embed.@{package}.package}</string>
	      <mapper>
		<unpackagemapper from="*" to="*"/>
	      </mapper>
	    </pathconvert>
	    <echo message="embed-package: package dir: ${module.@{name}.embed.@{package}.package.asdir}"/>

	    <copy todir="${target.work.dir}/${module.@{name}.package}/${module.@{name}.embed.@{package}.package.asdir}" verbose="true">
	      <tarfileset dir="${target.classes.dir}/${module.@{name}.embed.@{package}.package.asdir}"/>
	    </copy>

	  </sequential>
	</macrodef>

        <echo message="package-module: @{name}"/>

        <property name="module.@{name}.package" value="@{prefix}.@{name}"/>

        <pathconvert property="module.@{name}.package.asdir">
          <string>${module.@{name}.package}</string>
          <mapper>
            <unpackagemapper from="*" to="*"/>
          </mapper>
        </pathconvert>

        <echo message="package-module: module dir: ${module.@{name}.package.asdir}"/>

        <delete dir="${target.work.dir}/${module.@{name}.package}"/>
        <mkdir dir="${target.work.dir}/${module.@{name}.package}"/>
        <copy todir="${target.work.dir}/${module.@{name}.package}/${module.@{name}.package.asdir}" verbose="true">
          <fileset dir="${target.classes.dir}/${module.@{name}.package.asdir}"/>
	</copy>
        <copy todir="${target.work.dir}/${module.@{name}.package}" verbose="true">
          <resources/>
        </copy>

	<package-module-embed/>

        <package/>

      </sequential>
    </macrodef>


</project>