Skip to content
Snippets Groups Projects
common-modules.xml 11.3 KiB
Newer Older
Michael Becker's avatar
Michael Becker committed
<?xml version="1.0" encoding="UTF-8"?>

<project name="common-modules" basedir="." xmlns:artifact="antlib:org.apache.maven.artifact.ant" xmlns:mcr="antlib:org.mycore.buildtools">

  <!-- =================================================================== -->
  <!-- Changeable properties                                               -->
  <!-- =================================================================== -->

  <property name="app.name" value="philae" />

  <property name="java.maxmemory" value="1024m" />

  <property name="dptbase-common.jar" value="dptbase-common-2023.06-SNAPSHOT.jar" />
  <property name="dptbase-agent.jar" value="dptbase-agent-2023.06-SNAPSHOT.jar" />
  <property name="mycore-base.jar" value="mycore-base-2023.02-SNAPSHOT.jar" />
  
  <property name="jetty.start.port" value="8961"/>
  <property name="jetty.stop.port" value="8962"/>
  <property name="jetty.debug.port" value="8964"/>

  <property environment="env" />

  <property name="stage-one" value="${env.PHILAE_HOME}" />

  <!-- =================================================================== -->
  <!-- check ant version                                                   -->
  <!-- =================================================================== -->

  <condition property="ant1.10">
    <available classname="org.apache.tools.ant.taskdefs.condition.AntVersion" />
  </condition>
  <fail unless="ant1.10">
  <![CDATA[
    Ant too old.
    Sorry your ant version is too old. You need at least "Ant 1.10.12".
    You have: ${ant.version}
    ]]>
  </fail>

  <!-- =================================================================== -->
  <!-- detecting OS                                                        -->
  <!-- =================================================================== -->

  <condition property="detected.os" value="unix">
    <os family="unix" />
  </condition>
  <condition property="os.is.unix">
    <os family="unix" />
  </condition>

  <!-- =================================================================== -->
  <!-- Global properties                                                   -->
  <!-- =================================================================== -->

  <property name="debug" value="on" />
  <property name="optimize" value="on" />
  <property name="deprecation" value="off" />
  <property name="javatarget" value="17" />
  <property name="sourcerelease" value="17" />
  <property name="sourceencoding" value="UTF-8" />

  <property name="stage-one.config" value="${stage-one}/config" />
  <property name="stage-one.modules" value="${stage-one}/modules" />

  <property name="build" value="${stage-one}/build" />

  <property name="build.cli" value="${build}/cli" />
  <property name="build.cli.bin" value="${build}/cli/bin" />
  <property name="build.cli.classes" value="${build}/cli/classes" />
  <property name="build.cli.config" value="${build}/cli/config" />
  <property name="build.cli.lib" value="${build}/cli/lib" />
  <property name="build.cli.schema" value="${build}/cli/schema" />
  <property name="build.cli.xsl" value="${build}/cli/xsl" />

  <property name="build.config" value="${build}/config" />
  <property name="build.content" value="${build}/content" />

  <property name="build.webapps" value="${build}/webapps" />

  <!-- =================================================================== -->
  <!-- Initalization for ANT                                               -->
  <!-- =================================================================== -->

  <target name="init">
    <path id="build.classpath">
      <pathelement location="${build.cli.classes}" />
      <pathelement location="${build.cli.config}" />
      <pathelement location="${build.cli.schema}" />
      <pathelement location="${build.cli.xsl}" />
      <fileset dir="${build.cli.lib}" includes="*.jar" />
    </path>
    <property file="${stage-one.config}/mycore.private.properties" />
    <taskdef resource="net/sf/antcontrib/antlib.xml">
         <classpath>
             <fileset dir="${build.cli.lib}"/>
         </classpath>
    </taskdef>
    <taskdef resource="org/mycore/buildtools/antlib.xml" uri="antlib:org.mycore.buildtools">
      <classpath>
          <fileset dir="${build.cli.lib}"/>
      </classpath>
    </taskdef>
    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpathref="build.classpath" />
    <pathconvert targetos="${detected.os}" property="build.classpath.translated" refid="build.classpath" />
  </target>

  <!-- =================================================================== -->
  <!-- hook definition for stage-one and stage-two                         -->
  <!-- =================================================================== -->

  <macrodef name="modulePreHook">
    <attribute name="target" />
    <sequential>
      <echo level="verbose">pre module Hook: @{target}</echo>
      <for list="${MCR.Modules.StageOne}" param="module" parallel="false">
        <sequential>
          <echo level="verbose">check module: @{module}</echo>
          <for param="build.file" parallel="false">
            <fileset dir="." includes="modules/@{module}/build.xml">
              <containsregexp expression="\u003ctarget.*name=\u0022pre.@{target}\u0022" />
            </fileset>
            <sequential>
              <echo level="verbose">running module: @{build.file}</echo>
              <java fork="true" classname="org.apache.tools.ant.Main" classpath="${java.class.path}" failonerror="true">
                <arg value="-Dant.home=${ant.home}" />
                <arg value="-Dant.library.dir=${ant.library.dir}" />
                <arg value="-f" />
                <arg value="@{build.file}" />
                <arg value="pre.@{target}" />
              </java>
            </sequential>
          </for>
        </sequential>
      </for>
    </sequential>
  </macrodef>
  <macrodef name="moduleHook">
    <attribute name="target" />
    <sequential>
      <echo level="verbose">module Hook: @{target}</echo>
      <for list="${MCR.Modules.StageOne}" param="module" parallel="false">
        <sequential>
          <echo level="verbose">check module: @{module}</echo>
          <for param="build.file" parallel="false">
            <fileset dir="." includes="modules/@{module}/build.xml">
              <containsregexp expression="\u003ctarget.*name=\u0022@{target}\u0022" />
            </fileset>
            <sequential>
              <echo level="verbose">running module: @{build.file}</echo>
              <java fork="true" classname="org.apache.tools.ant.Main" classpath="${java.class.path}" failonerror="true">
                <arg value="-Dant.home=${ant.home}" />
                <arg value="-Dant.library.dir=${ant.library.dir}" />
                <arg value="-f" />
                <arg value="@{build.file}" />
                <arg value="@{target}" />
              </java>
            </sequential>
          </for>
        </sequential>
      </for>
    </sequential>
  </macrodef>

  <!-- =================================================================== -->
  <!-- Initalization for ANT                                               -->
  <!-- =================================================================== -->

  <target name="initold">
    <path id="build.classpath">
      <pathelement location="${build.cli.classes}" />
      <pathelement location="${build.cli.config}" />
      <pathelement location="${build.cli.schema}" />
      <pathelement location="${build.cli.xsl}" />
      <fileset dir="${build.cli.lib}" includes="*.jar" />
    </path>
    <property resource="config/mycore.properties" classpathref="build.classpath" />
    <path id="script.classpath">
      <pathelement location="${build.cli.classes}" />
      <pathelement location="${build.cli.config}" />
      <pathelement location="${build.cli.lib}" />
    </path>
    <taskdef resource="net/sf/antcontrib/antlib.xml" onerror="ignore" classpathref="build.classpath" />
    <taskdef resource="org/mycore/buildtools/antlib.xml" uri="antlib:org.mycore.buildtools" classpathref="build.classpath"
      onerror="fail" />
    <taskdef name="xmltask" classname="com.oopsconsultancy.xmltask.ant.XmlTask" classpathref="build.classpath" />
    <pathconvert targetos="${detected.os}" property="build.classpath.translated" refid="build.classpath" />
    <pathconvert targetos="${detected.os}" property="script.classpath.translated" refid="script.classpath" />
  </target>

  <!-- System CLASSPATH is completely ignored! -->
  <property name="build.sysclasspath" value="ignore" />

  <!-- =================================================================== -->
  <!-- merge the web.xml from core with web.xml of the module              -->
  <!-- =================================================================== -->

  <target name="do.merge" if="web.xml.present">
    <xmltask source="${build.webapps}/WEB-INF/web.xml" dest="${build.webapps}/WEB-INF/web.xml">
      <insert path="/:web-app/:absolute-ordering" position="after" file="${web.xml.file}" />
    </xmltask>
    <replace file="${build.webapps}/WEB-INF/web.xml" token='xmlns=""' />
  </target>

  <!-- =================================================================== -->
  <!-- merge module_messages.properties with the message.properties file   -->
  <!-- 						in stage-one/config							   -->
  <!-- =================================================================== -->

  <target name="messages.merge">
    <echo level="info">parameter: ${locale_param} </echo>
    <echo level="info">Source path: ${module}</echo>
    <echo level="info">Dest path: ${build.webapps}/WEB-INF/classes/messages_${locale_param}.properties</echo>
    <echo file="${build.cli.config}/messages_${locale_param}.properties" append="true">
	<![CDATA[#Source: ${module}
]]>
    </echo>
    <concat destfile="${build.cli.config}/messages_${locale_param}.properties" append="true">
      <fileset file="${module}" />
    </concat>
  </target>

  <!-- =================================================================== -->
  <!-- build schema files from configuration							   -->
  <!-- =================================================================== -->

  <target name="datamodel2schema" depends="init">
    <basename file="${metadata.schema}" property="baseSchemaName" suffix=".xml" />
    <condition property="prefixName" value="datamodel-">
      <not>
        <contains string="${baseSchemaName}" substring="datamodel-" />
      </not>
    </condition>
    <condition property="prefixName" value="">
      <contains string="${baseSchemaName}" substring="datamodel-" />
    </condition>
    <echo level="info">Transforming ${metadata.schema}...</echo>
    <xslt basedir="${build.cli.config}" classpathref="build.classpath" in="${metadata.schema}" style="${build.cli.xsl}/datamodel2schema.xsl" out="${build.cli.schema}/${prefixName}${baseSchemaName}.xsd" />
  </target>

  <!-- =================================================================== -->
  <!-- Invokes the MyCoRe Command Line Interface with a given command      -->
  <!-- =================================================================== -->

  <target name="invoke.cli" depends="init">
    <java classname="org.mycore.frontend.cli.MCRCommandLineInterface" dir="${cli.directory}" fork="yes"
      maxmemory="${java.maxmemory}" classpathref="build.classpath" failonerror="true">
      <arg line="${cli.command}" />
      <env key="LIBPATH" value="${env.LIBPATH}" />
      <env key="LD_LIBRARY_PATH" value="${env.LD_LIBRARY_PATH}" />
    </java>
  </target>

</project>