<commit_before><?xml version="1.0"?>

<project name="yanel-main" default="deploy" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <description>Yanel Build</description>

<!--
  <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask"/>
  <svn failonerror="false">
    <status path="../../" lastChangedRevisionProperty="yanel.revision.svn"/>
  </svn>
  <condition property="yanel.revision" value="${yanel.revision.svn}">
   <not>
     <equals arg1="-1" arg2="${yanel.revision.svn}"/>
   </not>
  </condition>
-->
    
  <property file="local.build.properties"/>
  <property file="build.properties"/>
  
<!--
  <echo>Yanel Revision: ${yanel.revision}</echo>
-->
    
  <condition property="isWindows">
   <os family="windows"/>
  </condition>
  
  <condition property="isUnix">
   <os family="unix"/>
  </condition>

  <import file="dependencies.xml"/>
  <import file="continuous-integration.xml"/>
  <import file="targets/install-tomcat.xml"/>
  <import file="targets/add-third-party-realm.xml"/>
  <import file="targets/create-new-resource-type.xml"/>
  <import file="targets/build-binary-snapshot.xml"/>
  <import file="targets/build-update-war.xml"/>
  <import file="targets/execute-jmeter.xml"/>
  <import file="targets/check-conf-version.xml"/>
  
  <target name="ask-to-reconfigure-tomcat-cluster-node1" description="reconfigure Tomcat cluster node 1" if="isTomcat1PortsSet">
    <input message="Do you want to reconfigure tomcat cluster node 1 in order to support SSL? (YES/no):" defaultvalue="NO" addproperty="answerReconfigureTomcat1"/>
    <condition property="doNotReconfigureTomcat1">
      <equals arg1="no" arg2="${answerReconfigureTomcat1}"/>
    </condition>
    <antcall target="reconfigure-tomcat-cluster-node1"/>
    <antcall target="comment-local-tomcat1-ports"/>
  </target>
  
  <target name="comment-local-tomcat1-ports" if="doNotReconfigureTomcat1" description="Comment ports of Tomcat Cluster Node 1 within local.build.properties">
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="#tomcat1.ssl.port=${tomcat1.ssl.port}">
      <replacetoken>tomcat1.ssl.port=8443</replacetoken>
<!--
      <replacetoken>tomcat1.ssl.port=${tomcat1.ssl.port}</replacetoken>
-->
    </replace>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="#tomcat1.http.port=${tomcat1.http.port}">
      <replacetoken>tomcat1.http.port=8080</replacetoken>
<!--
      <replacetoken>tomcat1.http.port=${tomcat1.http.port}</replacetoken>
-->
    </replace>
  </target>

  <target name="reconfigure-tomcat-cluster-node1" unless="doNotReconfigureTomcat1" description="reconfigures tomcat regarding ssl">
    <!-- TODO: Ask the port numbers -->

<!--
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.http.port=8080">
      <replacetoken>#tomcat1.http.port=9190</replacetoken>
    </replace>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.ssl.port=8443">
      <replacetoken>#tomcat1.ssl.port=9143</replacetoken>
    </replace>
-->

    <antcall target="createCK"/>
    <copy file="${build.dir}/${certificate.keystore}" todir="${tomcat1.home.dir}"/>
    <xslt in="${tomcat1.home.dir}/conf/server.xml"
          out="${tomcat1.home.dir}/conf/server.xml.ssl"
          style="connector.xsl">
      <param name="ssl-port" expression="${tomcat1.ssl.port}"/>
      <param name="keystoreFile" expression="${certificate.keystore}"/>
      <param name="keystorePass" expression="${certificate.keypass}"/>
      <param name="http-port" expression="${tomcat1.http.port}"/>
    </xslt>
    <tstamp>
      <format property="timestamp" pattern="yyyyMMdd'T'HHmmss"/>
    </tstamp>
    <copy file="${tomcat1.home.dir}/conf/server.xml" tofile="${tomcat1.home.dir}/conf/server.xml.BAK_${timestamp}"/>
    <move file="${tomcat1.home.dir}/conf/server.xml.ssl" tofile="${tomcat1.home.dir}/conf/server.xml"/>
  </target>
  
  <target name="ask-to-reconfigure-tomcat-cluster-node2" description="reconfigure Tomcat cluster node 2" if="isTomcat2HomeSet">
    <input message="Do you want to reconfigure tomcat cluster node 2 in order to support SSL? (yes/NO):" defaultvalue="NO" addproperty="answerReconfigureTomcat2"/>
    <condition property="reconfigureTomcat2">
      <equals arg1="yes" arg2="${answerReconfigureTomcat2}"/>
    </condition>
    <antcall target="reconfigure-tomcat-cluster-node2"/>
  </target>
  
  <target name="reconfigure-tomcat-cluster-node2" if="reconfigureTomcat2" description="reconfigures tomcat regarding ssl">
    <antcall target="createCK"/>
    <copy file="${build.dir}/${certificate.keystore}" todir="${tomcat2.home.dir}"/>
    <xslt in="${tomcat2.home.dir}/conf/server.xml"
          out="${tomcat2.home.dir}/conf/server.xml.ssl"
          style="connector.xsl">
      <param name="ssl-port" expression="${tomcat2.ssl.port}"/>
      <param name="keystoreFile" expression="${certificate.keystore}"/>
      <param name="keystorePass" expression="${certificate.keypass}"/>
      <param name="http-port" expression="${tomcat2.http.port}"/>
    </xslt>
    <tstamp>
      <format property="timestamp" pattern="yyyyMMdd'T'HHmmss"/>
    </tstamp>
    <copy file="${tomcat2.home.dir}/conf/server.xml" tofile="${tomcat2.home.dir}/conf/server.xml.BAK_${timestamp}"/>
    <move file="${tomcat2.home.dir}/conf/server.xml.ssl" tofile="${tomcat2.home.dir}/conf/server.xml"/>
  </target>
  
  <target name="createCK" description="Add ssl configuration to your webserver"> 
    <!-- delete already created file -->
    <delete file="${build.dir}/${certificate.keystore}"/>
    <!-- create new keystore file -->
    <exec executable="keytool">
      <arg line="-genkey"/>
      <arg line="-alias"/>
      <arg value="${servlet.container}"/>
      <arg line="-keyalg"/>
      <arg value="RSA"/>
      <arg line="-storepass"/>
      <arg value="${certificate.keypass}"/>
      <arg line="-keypass"/>
      <arg value="${certificate.keypass}"/>
      <arg line="-keystore"/>
      <arg value="${build.dir}/${certificate.keystore}"/>
      <arg line="-dname"/>
      <arg value="CN=${certificate.common.name}, OU=${certificate.organisation.unit}, O=${certificate.organisation}, L=${certificate.locality.name}, S=${certificate.state.name}, C=${certificate.country.code}"/>
    </exec>
  </target>
  
  <target name="config" description="Initialize all local properties files" depends="init">
    <condition property="local.build.properties.does.not.exist.yet">
      <not>
        <available file="local.build.properties" type="file"/>
      </not>
    </condition>
    <antcall target="create-local-build-properties"/>

    <!-- Reload local.build.properties -->
    <property file="local.build.properties"/>

    <fail message="No such directory: ${tomcat1.home.dir}! You might have to delete src/build/local.build.properties and re-run configure.">
    <condition>
      <and>
        <isset property="tomcat1.home.dir"/>
        <not><available file="${tomcat1.home.dir}" type="dir"/></not>
      </and>
    </condition>
    </fail>

<!--
    <echo>Tomcat Ports: ${tomcat1.ssl.port}, ${tomcat1.http.port}</echo>
-->
  
    <condition property="isTomcat1PortsSet">
      <and>
        <isset property="tomcat1.ssl.port"/>
        <isset property="tomcat1.http.port"/>
      </and>
    </condition>
    <antcall target="ask-to-reconfigure-tomcat-cluster-node1"/>
    
    <condition property="isTomcat2HomeSet">
      <isset property="tomcat2.home.dir"/>
    </condition>
    <antcall target="ask-to-reconfigure-tomcat-cluster-node2"/>

    <antcall target="first-time-user-configuration-message"/>
    <input message="Do you want to continue the configuration nevertheless? (yes/NO)" addproperty="answer" defaultvalue="NO"/>

    <condition property="yes.continue">
      <equals arg1="yes" arg2="${answer}"/>
    </condition>
    <antcall target="configure-local"/>
  </target>

  <target name="first-time-user-configuration-message">
    <echo>#################################################################################</echo>
    <echo># As a first time user one does NOT have to configure anything any further, but #</echo>
    <echo># rather exit here and just run build.sh on UNIX resp. build.bat on Windows!    #</echo>
    <echo>#################################################################################</echo>
  </target>

  <target name="create-local-build-properties" if="local.build.properties.does.not.exist.yet" depends="init">
    <echo>Build configuration ${yanel.home.dir}/local.build.properties does not exist yet!</echo>

    <input message="Do you have an existing Tomcat instance which you want to use as servlet engine for Yanel?  If so, please enter the path of your Tomcat instance (e.g. /home/yanel/jakarta-tomcat-5.0.30). IMPORTANT NOTE (especially for Windows): Please use '/' instead of '\' in the Tomcat path.  Otherwise just hit return (recommended to first time users :-) and Tomcat ${tomcat.version} will be installed at ${default.tomcat.home.dir}.  (You will always be able to change this setting at some later time within src/build/local.build.properties): " defaultvalue="${default.tomcat.home.dir.forward.slashes}" addproperty="pathOfUserSpecificTomcat"/>

    <echo>User specific Tomcat: ${pathOfUserSpecificTomcat}</echo>

    <copy file="${yanel.home.dir}/src/build/build.properties" tofile="${yanel.home.dir}/src/build/local.build.properties" overwrite="false"/>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.home.dir=${pathOfUserSpecificTomcat}">
      <replacetoken>#tomcat1.home.dir=../tomcat-cluster/build/jakarta-tomcat-5.0.30-cnode1</replacetoken>
    </replace>

    <condition property="yes.install.default.tomcat">
      <equals arg1="${pathOfUserSpecificTomcat}" arg2="${default.tomcat.home.dir.forward.slashes}"/>
    </condition>

    <antcall target="install-default-tomcat"/>
  </target>

  <target name="configure-local" if="yes.continue">
    <echo>Will now create local properties files if these do not exist.</echo>

    <mkdir dir="${yanel.home.dir}/${local.config.dir}"/>

    <copy file="${yanel.home.dir}/conf/yanel.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.yanel.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/realms.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.realms.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/resource-types.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.resource-types.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/log4j.properties" tofile="${yanel.home.dir}/${local.config.dir}/local.log4j.properties" overwrite="false"/>

    <echo>Customize the ${local.config.dir}/local.* files and run build.sh OR run build.sh first and then customize the config files within build/webapps/yanel/WEB-INF/classes</echo>
  </target>
    
  <target name="init" description="Initialize all parameters and other settings" depends="dependencies">
    <echo>Building with ${ant.version} and Java version ${ant.java.version}</echo>

    <property name="yanel.home.dir" location="../../"/>
<!--
    <echo>Yanel Home Dir: ${yanel.home.dir}</echo>
-->
    <path id="yanel.home.dir.ref">
      <pathelement location="${yanel.home.dir}"/>
    </path>
    <pathconvert targetos="unix" property="yanel.home.dir.forward.slashes" refid="yanel.home.dir.ref">
    </pathconvert>

    <property name="build.dir" location="${yanel.home.dir}/build"/>
    <mkdir dir="${build.dir}"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="log4j.path" location="${build.dir}/logs"/>
    <mkdir dir="${log4j.path}"/>
    <property name="log4j.file" location="${log4j.path}/log4j-cmdl.log"/>
    <path id="log4j.file.ref">
      <pathelement location="${log4j.file}"/>
    </path>
    <pathconvert targetos="unix" property="log4j.file.forward.slashes" refid="log4j.file.ref">
    </pathconvert>
<!--
    <echo>Log4j file with forward slashes: ${log4j.file.forward.slashes}</echo>
-->

<!--
<property name="default.tomcat.home.dir" value="${yanel.home.dir}/local/apache-tomcat-${tomcat.version}"/>
-->
    <property name="default.tomcat.home.dir" location="${yanel.home.dir}/local/apache-tomcat-${tomcat.version}"/>
    <path id="default.tomcat.home.dir.ref">
      <pathelement location="${default.tomcat.home.dir}"/>
    </path>
    <pathconvert targetos="unix" property="default.tomcat.home.dir.forward.slashes" refid="default.tomcat.home.dir.ref"/>

    <path id="classpath">
      <!--
      <fileset dir="${yanel.home.dir}/lib">
        <include name="*.jar"/>
      </fileset>
      -->
      <pathelement path="${maven2.cp}"/>
    </path>


    <path id="classpath.yanel">
      <fileset dir="${yanel.home.dir}/build/lib">
        <include name="*.jar"/>
      </fileset>
      <pathelement path="${maven2.cp}"/>
    </path>


    <path id="classpath.cmdl">
      <pathelement path="${maven2.cp}"/>
    </path>
  </target>

  <target name="init-runtime" description="Initialize all parameters and other settings for runtime" depends="init">
<!--
  <target name="init-runtime" description="Initialize all parameters and other settings for runtime" depends="webapp">
-->

    <path id="classpath.run">
      <!-- Properties files -->
      <pathelement path="${yanel.home.dir}/build/webapps/${servlet.context.prefix}/WEB-INF/classes"/>

      <!-- All from source generated libs -->
      <fileset dir="${yanel.home.dir}/build/webapps/${servlet.context.prefix}/WEB-INF/lib">
        <include name="*.jar"/>
      </fileset>

      <!-- All external dependencies -->
      <!--
      <pathelement path="${maven2.cp}"/>
      -->
    </path>
    <property name="run.cp" refid="classpath.run"/>
<!--
    <echo>Classpath to run yanel: ${run.cp}</echo>
-->
  </target>

  <target name="compile-core" description="Compile Java classes of Yanel core" depends="init">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/core/java/org/wyona/yanel/core"
      destdir="${classes.dir}"
      source="${source.java.version}"
      target="${target.java.version}"
      debug="true">
      <classpath refid="classpath"/>
    </javac>
    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-core-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/core/**"/>

    <copy file="${yanel.home.dir}/src/build/pom-core.xml" todir="${yanel.home.dir}/build/lib"/>
    <replace file="${yanel.home.dir}/build/lib/pom-core.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="core.project" file="${yanel.home.dir}/build/lib/pom-core.xml"/>

    <artifact:install file="${yanel.home.dir}/build/lib/yanel-core-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="core.project"/>
    </artifact:install>


    <!-- Command Line library -->
    <jar destfile="${yanel.home.dir}/build/lib/yanel-cmdl-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/cmdl/**"/>
    <copy file="${yanel.home.dir}/src/build/pom-cmdl.xml" tofile="${yanel.home.dir}/build/lib/pom-cmdl.xml"/>
    <replace file="${yanel.home.dir}/build/lib/pom-cmdl.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="cmdl.project" file="${yanel.home.dir}/build/lib/pom-cmdl.xml"/>
    <artifact:install file="${yanel.home.dir}/build/lib/yanel-cmdl-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="cmdl.project"/>
    </artifact:install>
  </target>

  <target name="compile-impl" description="Compile Java classes of Yanel implementation" depends="init">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/impl/java/org/wyona/yanel/impl" destdir="${classes.dir}" debug="true">
      <classpath refid="classpath"/>
    </javac>

    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-impl-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/impl/**"/>
      
    <copy file="${yanel.home.dir}/src/build/pom-impl.xml" todir="${yanel.home.dir}/build/lib"/>
    <replace file="${yanel.home.dir}/build/lib/pom-impl.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="impl.project" file="${yanel.home.dir}/build/lib/pom-impl.xml"/>

    <artifact:install file="${yanel.home.dir}/build/lib/yanel-impl-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="impl.project"/>
    </artifact:install>      
  </target>

  <target name="compile-cmdl" description="Compile Java classes of Yanel command line" depends="init, compile-core">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/core/java/org/wyona/yanel/cmdl" destdir="${classes.dir}"
      debug="true"
      classpathref="classpath.cmdl"
    />
    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-cmdl-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/cmdl/**"/>
  </target>

  <target name="compile-webapp" description="Compile Java classes of Yanel webapp" depends="init, compile-core, compile-cmdl"><commit_msg>copying of cmdl lib into maven fixed<commit_after><?xml version="1.0"?>

<project name="yanel-main" default="deploy" xmlns:artifact="antlib:org.apache.maven.artifact.ant">

  <description>Yanel Build</description>

<!--
  <taskdef name="svn" classname="org.tigris.subversion.svnant.SvnTask"/>
  <svn failonerror="false">
    <status path="../../" lastChangedRevisionProperty="yanel.revision.svn"/>
  </svn>
  <condition property="yanel.revision" value="${yanel.revision.svn}">
   <not>
     <equals arg1="-1" arg2="${yanel.revision.svn}"/>
   </not>
  </condition>
-->
    
  <property file="local.build.properties"/>
  <property file="build.properties"/>
  
<!--
  <echo>Yanel Revision: ${yanel.revision}</echo>
-->
    
  <condition property="isWindows">
   <os family="windows"/>
  </condition>
  
  <condition property="isUnix">
   <os family="unix"/>
  </condition>

  <import file="dependencies.xml"/>
  <import file="continuous-integration.xml"/>
  <import file="targets/install-tomcat.xml"/>
  <import file="targets/add-third-party-realm.xml"/>
  <import file="targets/create-new-resource-type.xml"/>
  <import file="targets/build-binary-snapshot.xml"/>
  <import file="targets/build-update-war.xml"/>
  <import file="targets/execute-jmeter.xml"/>
  <import file="targets/check-conf-version.xml"/>
  
  <target name="ask-to-reconfigure-tomcat-cluster-node1" description="reconfigure Tomcat cluster node 1" if="isTomcat1PortsSet">
    <input message="Do you want to reconfigure tomcat cluster node 1 in order to support SSL? (YES/no):" defaultvalue="NO" addproperty="answerReconfigureTomcat1"/>
    <condition property="doNotReconfigureTomcat1">
      <equals arg1="no" arg2="${answerReconfigureTomcat1}"/>
    </condition>
    <antcall target="reconfigure-tomcat-cluster-node1"/>
    <antcall target="comment-local-tomcat1-ports"/>
  </target>
  
  <target name="comment-local-tomcat1-ports" if="doNotReconfigureTomcat1" description="Comment ports of Tomcat Cluster Node 1 within local.build.properties">
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="#tomcat1.ssl.port=${tomcat1.ssl.port}">
      <replacetoken>tomcat1.ssl.port=8443</replacetoken>
<!--
      <replacetoken>tomcat1.ssl.port=${tomcat1.ssl.port}</replacetoken>
-->
    </replace>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="#tomcat1.http.port=${tomcat1.http.port}">
      <replacetoken>tomcat1.http.port=8080</replacetoken>
<!--
      <replacetoken>tomcat1.http.port=${tomcat1.http.port}</replacetoken>
-->
    </replace>
  </target>

  <target name="reconfigure-tomcat-cluster-node1" unless="doNotReconfigureTomcat1" description="reconfigures tomcat regarding ssl">
    <!-- TODO: Ask the port numbers -->

<!--
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.http.port=8080">
      <replacetoken>#tomcat1.http.port=9190</replacetoken>
    </replace>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.ssl.port=8443">
      <replacetoken>#tomcat1.ssl.port=9143</replacetoken>
    </replace>
-->

    <antcall target="createCK"/>
    <copy file="${build.dir}/${certificate.keystore}" todir="${tomcat1.home.dir}"/>
    <xslt in="${tomcat1.home.dir}/conf/server.xml"
          out="${tomcat1.home.dir}/conf/server.xml.ssl"
          style="connector.xsl">
      <param name="ssl-port" expression="${tomcat1.ssl.port}"/>
      <param name="keystoreFile" expression="${certificate.keystore}"/>
      <param name="keystorePass" expression="${certificate.keypass}"/>
      <param name="http-port" expression="${tomcat1.http.port}"/>
    </xslt>
    <tstamp>
      <format property="timestamp" pattern="yyyyMMdd'T'HHmmss"/>
    </tstamp>
    <copy file="${tomcat1.home.dir}/conf/server.xml" tofile="${tomcat1.home.dir}/conf/server.xml.BAK_${timestamp}"/>
    <move file="${tomcat1.home.dir}/conf/server.xml.ssl" tofile="${tomcat1.home.dir}/conf/server.xml"/>
  </target>
  
  <target name="ask-to-reconfigure-tomcat-cluster-node2" description="reconfigure Tomcat cluster node 2" if="isTomcat2HomeSet">
    <input message="Do you want to reconfigure tomcat cluster node 2 in order to support SSL? (yes/NO):" defaultvalue="NO" addproperty="answerReconfigureTomcat2"/>
    <condition property="reconfigureTomcat2">
      <equals arg1="yes" arg2="${answerReconfigureTomcat2}"/>
    </condition>
    <antcall target="reconfigure-tomcat-cluster-node2"/>
  </target>
  
  <target name="reconfigure-tomcat-cluster-node2" if="reconfigureTomcat2" description="reconfigures tomcat regarding ssl">
    <antcall target="createCK"/>
    <copy file="${build.dir}/${certificate.keystore}" todir="${tomcat2.home.dir}"/>
    <xslt in="${tomcat2.home.dir}/conf/server.xml"
          out="${tomcat2.home.dir}/conf/server.xml.ssl"
          style="connector.xsl">
      <param name="ssl-port" expression="${tomcat2.ssl.port}"/>
      <param name="keystoreFile" expression="${certificate.keystore}"/>
      <param name="keystorePass" expression="${certificate.keypass}"/>
      <param name="http-port" expression="${tomcat2.http.port}"/>
    </xslt>
    <tstamp>
      <format property="timestamp" pattern="yyyyMMdd'T'HHmmss"/>
    </tstamp>
    <copy file="${tomcat2.home.dir}/conf/server.xml" tofile="${tomcat2.home.dir}/conf/server.xml.BAK_${timestamp}"/>
    <move file="${tomcat2.home.dir}/conf/server.xml.ssl" tofile="${tomcat2.home.dir}/conf/server.xml"/>
  </target>
  
  <target name="createCK" description="Add ssl configuration to your webserver"> 
    <!-- delete already created file -->
    <delete file="${build.dir}/${certificate.keystore}"/>
    <!-- create new keystore file -->
    <exec executable="keytool">
      <arg line="-genkey"/>
      <arg line="-alias"/>
      <arg value="${servlet.container}"/>
      <arg line="-keyalg"/>
      <arg value="RSA"/>
      <arg line="-storepass"/>
      <arg value="${certificate.keypass}"/>
      <arg line="-keypass"/>
      <arg value="${certificate.keypass}"/>
      <arg line="-keystore"/>
      <arg value="${build.dir}/${certificate.keystore}"/>
      <arg line="-dname"/>
      <arg value="CN=${certificate.common.name}, OU=${certificate.organisation.unit}, O=${certificate.organisation}, L=${certificate.locality.name}, S=${certificate.state.name}, C=${certificate.country.code}"/>
    </exec>
  </target>
  
  <target name="config" description="Initialize all local properties files" depends="init">
    <condition property="local.build.properties.does.not.exist.yet">
      <not>
        <available file="local.build.properties" type="file"/>
      </not>
    </condition>
    <antcall target="create-local-build-properties"/>

    <!-- Reload local.build.properties -->
    <property file="local.build.properties"/>

    <fail message="No such directory: ${tomcat1.home.dir}! You might have to delete src/build/local.build.properties and re-run configure.">
    <condition>
      <and>
        <isset property="tomcat1.home.dir"/>
        <not><available file="${tomcat1.home.dir}" type="dir"/></not>
      </and>
    </condition>
    </fail>

<!--
    <echo>Tomcat Ports: ${tomcat1.ssl.port}, ${tomcat1.http.port}</echo>
-->
  
    <condition property="isTomcat1PortsSet">
      <and>
        <isset property="tomcat1.ssl.port"/>
        <isset property="tomcat1.http.port"/>
      </and>
    </condition>
    <antcall target="ask-to-reconfigure-tomcat-cluster-node1"/>
    
    <condition property="isTomcat2HomeSet">
      <isset property="tomcat2.home.dir"/>
    </condition>
    <antcall target="ask-to-reconfigure-tomcat-cluster-node2"/>

    <antcall target="first-time-user-configuration-message"/>
    <input message="Do you want to continue the configuration nevertheless? (yes/NO)" addproperty="answer" defaultvalue="NO"/>

    <condition property="yes.continue">
      <equals arg1="yes" arg2="${answer}"/>
    </condition>
    <antcall target="configure-local"/>
  </target>

  <target name="first-time-user-configuration-message">
    <echo>#################################################################################</echo>
    <echo># As a first time user one does NOT have to configure anything any further, but #</echo>
    <echo># rather exit here and just run build.sh on UNIX resp. build.bat on Windows!    #</echo>
    <echo>#################################################################################</echo>
  </target>

  <target name="create-local-build-properties" if="local.build.properties.does.not.exist.yet" depends="init">
    <echo>Build configuration ${yanel.home.dir}/local.build.properties does not exist yet!</echo>

    <input message="Do you have an existing Tomcat instance which you want to use as servlet engine for Yanel?  If so, please enter the path of your Tomcat instance (e.g. /home/yanel/jakarta-tomcat-5.0.30). IMPORTANT NOTE (especially for Windows): Please use '/' instead of '\' in the Tomcat path.  Otherwise just hit return (recommended to first time users :-) and Tomcat ${tomcat.version} will be installed at ${default.tomcat.home.dir}.  (You will always be able to change this setting at some later time within src/build/local.build.properties): " defaultvalue="${default.tomcat.home.dir.forward.slashes}" addproperty="pathOfUserSpecificTomcat"/>

    <echo>User specific Tomcat: ${pathOfUserSpecificTomcat}</echo>

    <copy file="${yanel.home.dir}/src/build/build.properties" tofile="${yanel.home.dir}/src/build/local.build.properties" overwrite="false"/>
    <replace file="${yanel.home.dir}/src/build/local.build.properties" value="tomcat1.home.dir=${pathOfUserSpecificTomcat}">
      <replacetoken>#tomcat1.home.dir=../tomcat-cluster/build/jakarta-tomcat-5.0.30-cnode1</replacetoken>
    </replace>

    <condition property="yes.install.default.tomcat">
      <equals arg1="${pathOfUserSpecificTomcat}" arg2="${default.tomcat.home.dir.forward.slashes}"/>
    </condition>

    <antcall target="install-default-tomcat"/>
  </target>

  <target name="configure-local" if="yes.continue">
    <echo>Will now create local properties files if these do not exist.</echo>

    <mkdir dir="${yanel.home.dir}/${local.config.dir}"/>

    <copy file="${yanel.home.dir}/conf/yanel.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.yanel.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/realms.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.realms.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/resource-types.xml" tofile="${yanel.home.dir}/${local.config.dir}/local.resource-types.xml" overwrite="false"/>
    <copy file="${yanel.home.dir}/conf/log4j.properties" tofile="${yanel.home.dir}/${local.config.dir}/local.log4j.properties" overwrite="false"/>

    <echo>Customize the ${local.config.dir}/local.* files and run build.sh OR run build.sh first and then customize the config files within build/webapps/yanel/WEB-INF/classes</echo>
  </target>
    
  <target name="init" description="Initialize all parameters and other settings" depends="dependencies">
    <echo>Building with ${ant.version} and Java version ${ant.java.version}</echo>

    <property name="yanel.home.dir" location="../../"/>
<!--
    <echo>Yanel Home Dir: ${yanel.home.dir}</echo>
-->
    <path id="yanel.home.dir.ref">
      <pathelement location="${yanel.home.dir}"/>
    </path>
    <pathconvert targetos="unix" property="yanel.home.dir.forward.slashes" refid="yanel.home.dir.ref">
    </pathconvert>

    <property name="build.dir" location="${yanel.home.dir}/build"/>
    <mkdir dir="${build.dir}"/>
    <property name="classes.dir" location="${build.dir}/classes"/>
    <property name="log4j.path" location="${build.dir}/logs"/>
    <mkdir dir="${log4j.path}"/>
    <property name="log4j.file" location="${log4j.path}/log4j-cmdl.log"/>
    <path id="log4j.file.ref">
      <pathelement location="${log4j.file}"/>
    </path>
    <pathconvert targetos="unix" property="log4j.file.forward.slashes" refid="log4j.file.ref">
    </pathconvert>
<!--
    <echo>Log4j file with forward slashes: ${log4j.file.forward.slashes}</echo>
-->

<!--
<property name="default.tomcat.home.dir" value="${yanel.home.dir}/local/apache-tomcat-${tomcat.version}"/>
-->
    <property name="default.tomcat.home.dir" location="${yanel.home.dir}/local/apache-tomcat-${tomcat.version}"/>
    <path id="default.tomcat.home.dir.ref">
      <pathelement location="${default.tomcat.home.dir}"/>
    </path>
    <pathconvert targetos="unix" property="default.tomcat.home.dir.forward.slashes" refid="default.tomcat.home.dir.ref"/>

    <path id="classpath">
      <!--
      <fileset dir="${yanel.home.dir}/lib">
        <include name="*.jar"/>
      </fileset>
      -->
      <pathelement path="${maven2.cp}"/>
    </path>


    <path id="classpath.yanel">
      <fileset dir="${yanel.home.dir}/build/lib">
        <include name="*.jar"/>
      </fileset>
      <pathelement path="${maven2.cp}"/>
    </path>


    <path id="classpath.cmdl">
      <pathelement path="${maven2.cp}"/>
    </path>
  </target>

  <target name="init-runtime" description="Initialize all parameters and other settings for runtime" depends="init">
<!--
  <target name="init-runtime" description="Initialize all parameters and other settings for runtime" depends="webapp">
-->

    <path id="classpath.run">
      <!-- Properties files -->
      <pathelement path="${yanel.home.dir}/build/webapps/${servlet.context.prefix}/WEB-INF/classes"/>

      <!-- All from source generated libs -->
      <fileset dir="${yanel.home.dir}/build/webapps/${servlet.context.prefix}/WEB-INF/lib">
        <include name="*.jar"/>
      </fileset>

      <!-- All external dependencies -->
      <!--
      <pathelement path="${maven2.cp}"/>
      -->
    </path>
    <property name="run.cp" refid="classpath.run"/>
<!--
    <echo>Classpath to run yanel: ${run.cp}</echo>
-->
  </target>

  <target name="compile-core" description="Compile Java classes of Yanel core" depends="init">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/core/java/org/wyona/yanel/core"
      destdir="${classes.dir}"
      source="${source.java.version}"
      target="${target.java.version}"
      debug="true">
      <classpath refid="classpath"/>
    </javac>
    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-core-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/core/**"/>

    <copy file="${yanel.home.dir}/src/build/pom-core.xml" todir="${yanel.home.dir}/build/lib"/>
    <replace file="${yanel.home.dir}/build/lib/pom-core.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="core.project" file="${yanel.home.dir}/build/lib/pom-core.xml"/>

    <artifact:install file="${yanel.home.dir}/build/lib/yanel-core-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="core.project"/>
    </artifact:install>
  </target>

  <target name="compile-impl" description="Compile Java classes of Yanel implementation" depends="init">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/impl/java/org/wyona/yanel/impl" destdir="${classes.dir}" debug="true">
      <classpath refid="classpath"/>
    </javac>

    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-impl-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/impl/**"/>
      
    <copy file="${yanel.home.dir}/src/build/pom-impl.xml" todir="${yanel.home.dir}/build/lib"/>
    <replace file="${yanel.home.dir}/build/lib/pom-impl.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="impl.project" file="${yanel.home.dir}/build/lib/pom-impl.xml"/>

    <artifact:install file="${yanel.home.dir}/build/lib/yanel-impl-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="impl.project"/>
    </artifact:install>      
  </target>

  <target name="compile-cmdl" description="Compile Java classes of Yanel command line" depends="init, compile-core">
    <mkdir dir="${classes.dir}"/>
    <javac srcdir="${yanel.home.dir}/src/core/java/org/wyona/yanel/cmdl" destdir="${classes.dir}"
      debug="true"
      classpathref="classpath.cmdl"
    />
    <mkdir dir="${yanel.home.dir}/build/lib"/>
    <jar destfile="${yanel.home.dir}/build/lib/yanel-cmdl-${yanel.version}-r${yanel.revision}.jar"
      basedir="${classes.dir}"
      includes="org/wyona/yanel/cmdl/**"/>
    <copy file="${yanel.home.dir}/src/build/pom-cmdl.xml" tofile="${yanel.home.dir}/build/lib/pom-cmdl.xml"/>
    <replace file="${yanel.home.dir}/build/lib/pom-cmdl.xml" value="${yanel.version}-r${yanel.revision}">
      <replacetoken>@VERSION@</replacetoken>
    </replace>

    <artifact:pom id="cmdl.project" file="${yanel.home.dir}/build/lib/pom-cmdl.xml"/>
    <artifact:install file="${yanel.home.dir}/build/lib/yanel-cmdl-${yanel.version}-r${yanel.revision}.jar">
      <pom refid="cmdl.project"/>
    </artifact:install>
  </target>

  <target name="compile-webapp" description="Compile Java classes of Yanel webapp" depends="init, compile-core, compile-cmdl">
{'fraction_non_alphanumeric': 0.20220800184480572, 'fraction_numerical': 0.007667473769168685, 'mean_word_length': 3.921691020002837, 'pattern_counts': {'":': 0, '<': 647, '<?xml version=': 2, '>': 647, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 78}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2599179', 'n_tokens_mistral': 11559, 'n_tokens_neox': 11272, 'n_words': 1798}