<commit_before><?xml version="1.0" encoding="UTF-8"?>
<project default="susi" basedir="${rootDir}" name="LuceeCore" ><!-- TODO maybe there is a better way for this -->
  <description>
        Build Lucee Core
  </description>
  


  <property name="build.compiler" value="extJavac"/>
  <property name="agent" value="lucee.runtime.instrumentation.ExternalAgent"/>
  <property name="bundleName" value="Lucee Core"/>
  <property name="bundleSymbolicName" value="lucee.core"/>
  
  <property name="testboxVersion" value="2.2.0"/>
  <property name="testboxURL" 
    value="http://downloads.ortussolutions.com/ortussolutions/testbox/${testboxVersion}/testbox-${testboxVersion}.zip"/>
  <property name="extURL" value="http://extension.lucee.org/rest/extension/provider/full/"/>
  
  <property name="extMongo"       value="E6634E1A-4CC5-4839-A83C67549ECA8D5B"/>
  <property name="extH2"          value="465E1E35-2425-4F4E-8B3FAB638BD7280A"/>


<!-- TODO get the version number from manifest.mf -->
  
  <!-- http://www.coldbox.org/download/testbox -->
  <tstamp>
      <format property="NOW" pattern="yyyy/MM/dd HH:mm:ss z" locale="en,GB"/>
  </tstamp>

  <scriptdef name="readManifestEntry" language="javascript" loaderRef="sharedbuild-loaderRef">
    <attribute name="file" />
    <attribute name="variable" />
    <attribute name="key" />
    <![CDATA[
        var filename = attributes.get("file");
        var variable = attributes.get("variable");
        var key = attributes.get("key");
        
        var manifest;
        if (filename != null) {
            manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
        } else {
            self.fail("missing file definition!");
        }

        var attrs=manifest.getMainAttributes();
        project.setProperty(variable, attrs.getValue(key));
    ]]>
</scriptdef>

  <scriptdef name="readRequiredExtensions" language="javascript" loaderRef="sharedbuild-loaderRef">
    <attribute name="file" />
    <![CDATA[
        var filename = attributes.get("file");
        var manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
        var attrs=manifest.getMainAttributes();
        var str=attrs.getValue("Require-Extension");
        var arr=str.split(",");
        var count=0;
        var ids="";
        var data="";
        var versions="";
        var labels="";
        for (var i=0;i<arr.length;i++) {
          var line=arr[i];
          var extArr=line.split(';');
          if(extArr.length<1) continue;
          count++;
          // the first is the id
          if(ids.length>0)ids+=",";
          ids+=extArr[0];
          if(data.length>0)data+=",";
          data+=extArr[0];
          var _id=extArr[0];
          project.setProperty("reqExt.ID"+(i+1), _id);

          // the rest has names
          var _version="";
          var _name="";
          for (var y=1;y<extArr.length;y++) {
            var ext=extArr[y];
            var index=ext.indexOf('=');
            if(index==-1) continue;
              var name=ext.substring(0,index).trim();
              var value=ext.substring(index+1).trim();
              if(name=="version") {
                if(versions.length>0)versions+=",";
                versions+=value;
                data+=";"+value;
                _version=value;
              }
              if(name=="label") {
                if(labels.length>0)labels+=",";
                labels+=value;
              }
              else if(name=="name") {
                _name=value;
              }
             project.setProperty("reqExt."+name+(i+1), value);
          }
          project.setProperty("reqExt."+_name, _version);
          project.setProperty("ext"+_name+"Version", _version);
          project.setProperty("ext"+_name, _id);

        }
        project.setProperty("reqExt.length", count+"");
        project.setProperty("reqExt.ids", ids);
        project.setProperty("reqExt.versions", versions);
        project.setProperty("reqExt.labels", labels);
        project.setProperty("reqExt.data", data);


        //
    ]]>
  </scriptdef>
  <scriptdef name="splitIdVersion" language="javascript">
     <attribute name="prefix" />
     <attribute name="value" />
     <![CDATA[
      var prefix = attributes.get("prefix");
      var value = attributes.get("value");
      
      var index=value.indexOf(";");
      var id;
      var version="";
      // no version
      if(index==-1) {
        id=value.trim();
      }
      else {
        id=value.substring(0,index);
        version=value.substring(index+1);
      }
      project.setProperty(prefix+"id", id);
      project.setProperty(prefix+"version", version);
     ]]>
  </scriptdef>



  <macrodef name="echots">
    <attribute name="message"/>
    <sequential>
      <local name="timestamp" />
      <tstamp>
        <format property="timestamp" pattern="yyyy-MM-dd HH:mm:ss" />
      </tstamp>
      <echo message="---------- ${timestamp} - @{message} ----------" />
    </sequential>
  </macrodef>

  <scriptdef name="unwrap" language="javascript">
     <attribute name="text" />
     <attribute name="property" />
     <![CDATA[
      var text = attributes.get("text");
      text=text.trim();
      if(text.startsWith('"') && text.endsWith('"')) {
        text=text.substring(1,text.length()-1);
      }
      project.setProperty(attributes.get("property"), text);
     ]]>
  </scriptdef>

  <scriptdef name="updatedate" language="javascript">
     <attribute name="text" />
     <attribute name="date" />
     <attribute name="property" />
     <![CDATA[
      var text = attributes.get("text");
      var date = attributes.get("date");
      
      var index=text.indexOf("lucee.core.release.date");
      if(index!=-1) {
        var start=text.indexOf('"',index);
        var end=text.indexOf('"',start+1);
        if(start!=-1 && end!=-1) {
          text=text.substring(0,start+1)+date+text.substring(end);
        }
      }

      project.setProperty(attributes.get("property"), text);
     ]]>
  </scriptdef>

  <scriptdef name="felix" language="javascript">
     <attribute name="property" />
     <attribute name="dependencies" />
     <attribute name="separator" />
     <![CDATA[
      var dep = attributes.get("dependencies");
      var sep = attributes.get("separator");
      var arr=dep.split(sep);
      
      var rtn="";
      for(var i=0;i<arr.length;i++){
        if(arr[i].indexOf("felix")!=-1) {
          rtn=arr[i];
          break;
        } 
      }

      var res=arr[0];
      project.setProperty(attributes.get("property"), rtn);
     ]]>
  </scriptdef>
  
  <scriptdef name="currentTime" language="javascript">
     <attribute name="property" />
     <![CDATA[
      project.setProperty(attributes.get("property"), new Date().getTime());
     ]]>
  </scriptdef>

  <scriptdef name="toFileName" language="javascript">
     <attribute name="name" />
     <attribute name="version" />
     <attribute name="property" />
     <![CDATA[
      var name = attributes.get("name").trim();
      var version = attributes.get("version").trim();
      
      var needle = ' ';
      //var regex = new RegExp(needle,'g');
      var repl = '-';
      
      // removes quotes
      if(name.startsWith('"') && name.endsWith('"')) {
        name=name.substring(1,name.length()-1).trim();
      }

      // remove brackets
      var start,end;
      while((start=name.indexOf('('))!=-1) {
        end=name.indexOf(')',start+1);
        if(end==-1) break;
        name=(name.substring(0,start) + name.substring(end+1)).trim();
      }

      // version
      if(version.startsWith('"') && version.endsWith('"')) {
        version=version.substring(1,version.length()-1).trim();
      }

      name=name.trim();
      name=name.replace(" ","-").toLowerCase();
      name=name.replace(" ","-"); // TODO make better but not with regex some ant version will fail
      name=name.replace(" ","-");
      name=name.replace(" ","-");
      name=name.replace(" ","-");
      name=name.replace(" ","-");

      project.setProperty(attributes.get("property"), name+"-"+version+".lex");
     ]]>
  </scriptdef>


<!-- TPDO make extension handling more dynamic
<target name="setVar">
    <splitIdVersion prefix="ext." value="${var}"/>
    
    <available file="${cache}/${ext.id}-${ext.version}.lex" property="ext.available"/>
    <echo>available: ${ext.id}:${ext.available}</echo>

</target>
-->


  <target name="init">
    

    <property name="srcLoader" location="${rootDir}/loader/src/main/java"/>
    <property name="srcCore" location="${rootDir}/core/src/main/java"/>
    <property name="coreManifest" location="${srcCore}/META-INF/MANIFEST.MF"/>
    <property name="cache" location="${rootDir}/cache"/>
    <property name="trgLoader" location="${rootDir}/loader/target"/>
    <property name="trgCore" location="${rootDir}/core/target"/>
    <property name="srcCFML" location="${rootDir}/core/src/main/cfml"/>
    <property name="srcInst" location="${rootDir}/instrumentation/src/main/java"/> 
    <property name="ant" location="${rootDir}/ant"/>
    <property name="test" location="${rootDir}/test"/>
    <property name="temp" location="${rootDir}/temp"/>
    <property name="loader" location="${temp}/loader"/>
    <property name="core" location="${temp}/core"/>
    <property file="${rootDir}/build.properties"/>


    <!-- get the extensions from manifest -->
    <!-- TODO extension handling must be more dynamic! -->
    <readRequiredExtensions file="${coreManifest}"/>
    <fail message="Missing data from [Require-Extension] inside ${coreManifest}">
    <condition>
        <or>
        <!-- Lucene -->
        <not><isset property="extLucene"/></not>
        <not><isset property="extLuceneVersion"/></not>
        <!-- Hibernate -->
        <not><isset property="extHibernate"/></not>
        <not><isset property="extHibernateVersion"/></not>
        <!-- PDF -->
        <not><isset property="extPDF"/></not>
        <not><isset property="extPDFVersion"/></not>
        <!-- S3 -->
        <not><isset property="extS3"/></not>
        <not><isset property="extS3Version"/></not>
        <!-- Chart -->
        <not><isset property="extChart"/></not>
        <not><isset property="extChartVersion"/></not>
        <!-- MySQL -->
        <not><isset property="extMySQL"/></not>
        <not><isset property="extMySQLVersion"/></not>
        <!-- MSSQL -->
        <not><isset property="extMSSQL"/></not>
        <not><isset property="extMSSQLVersion"/></not>
        <!-- PostgreSQL -->
        <not><isset property="extPostgreSQL"/></not>
        <not><isset property="extPostgreSQLVersion"/></not>
        <!-- JDTsSQL -->
        <not><isset property="extJDTsSQL"/></not>
        <not><isset property="extJDTsSQLVersion"/></not>
        <!-- Admin -->
        <not><isset property="extAdmin"/></not>
        <not><isset property="extAdminVersion"/></not>
        <!-- Doc -->
        <not><isset property="extDoc"/></not>
        <not><isset property="extDocVersion"/></not>
        </or>
    </condition>
    </fail>

<echo>                                                              
           `@@@@                                                               
           @@@@@@                                                              
          ``#@@@@#                                                             
          '@`@@@@@                                                             
          +@@+@@@@.                                                            
          ,@@.@@@@'                                                            
           @@ @@@@#                                                            
           ;@ @@@@#                                                            
            ; @@@@+                                                            
              @@@@'                                                            
             .@@@@,                                                            
             ;@@@@                                                             
             #@@@@                                                             
             @@@@@                                                             
             @@@@#                                                             
            ,@@@@`                                                             
            @@@@@                                                              
            @@@@#             `'@`     ,+@       :@@@#      ;@@@'       #@@@`  
           ;@@@@`            @@@@    .@@@@      @@:@@@@    @@.+@@#    +@#`@@@` 
           @@@@@            ,@@@#    @@@@,     @@   @@@  `@@   @@@   #@#  :@@# 
          ;@@@@,            @@@@`    @@@@     @@:   @@@  @@:   @@@  ;@@   ;@@' 
          @@@@@             @@@@    `@@@@    @@@    @:  @@@   .@@#  @@@   @@@  
         @@@@@..`          .@@@@    #@@@;    @@@       `@@@   @@@  #@@'  `@@#  
      +@.@@@@@:@@@@+       +@@@,    @@@@    #@@#       #@@@  @@@   @@@,  @@@   
    +@@ @@@@@ @@@@@@@`     @@@@     @@@@    @@@#       @@@@ @@@    @@@.,@@;    
    @@`@@@@@'@@@@@@@@,@'   @@@@    +@@@@   @@@@@       @@@@@@'    .@@@@@@     ;
  @; @@@@@@@'###@@@@@`@@@  @@@@    @@@@'  .@@@@@       @@@@#      ,@@@@`     '#
 ,@@@@@@@@@       .@@:@@@: @@@@   @'@@@#  @`@@@@@     `@@@@       ;@@@@     @@,
 :@@@@@@@@          +@@@@@ @@@@,:@;`@@@@@@@ @@@@@@,`+@@@@@@@.   '@@@@@@@,.#@@, 
  @@@@@@#            @@@@@ @@@@@@:  @@@@@@   @@@@@@@@@  @@@@@@@@@# `@@@@@@@@`  
   +@@#              #@@@:  @@@@    ;@@@;     @@@@@@`    @@@@@@#    `@@@@@#    
                      .+.    `                                                 
                                                                               


          In every job that must be done. There is an element of fun!                  
    </echo>

    <echo message="${version}"/>
    <echo message="${name}"/>
    <echo message="${name.explanation}"/>
    <echo message="Root: ${rootDir}"/>
    <echo message="Required-Extensions: ${reqExt.labels}"/>
                    
    
    <!-- Create the time stamp -->
    <tstamp/>
    
    <delete dir="${temp}"/>
    
    <!-- Create the  directory structure needed -->
    <mkdir dir="${core}"/>
    <mkdir dir="${loader}"/>
    <mkdir dir="${temp}/agent"/>
    <mkdir dir="${cache}"/>

  </target>




    <macrodef name="loadmf">
        <attribute name="jar"/>
        <attribute name="prefix" default=""/>
        <sequential>
            <loadproperties>
                <!-- Load the manifest entries -->
                <zipentry zipfile="@{jar}" name="META-INF/MANIFEST.MF"/>
                <!-- Add the prefix -->
                <filterchain>
                    <prefixlines prefix="@{prefix}"/>
                </filterchain>
            </loadproperties>
        </sequential>
    </macrodef>

  <target name="check-cache">

    <available file="${cache}/testbox-${testboxVersion}.zip" property="testbox.present"/>

    <available file="${cache}/${extMySQL}-${extMySQLVersion}.lex" property="mysql.present"/>
    <available file="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" property="mssql.present"/>
    <available file="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" property="postgre.present"/>
    <available file="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" property="jdts.present"/>

    <available file="${cache}/${extChart}-${extChartVersion}.lex" property="chart.present"/>
    <available file="${cache}/${extS3}-${extS3Version}.lex" property="s3.present"/>
    <available file="${cache}/${extAdmin}-${extAdminVersion}.lex" property="admin.present"/>
    <available file="${cache}/${extDoc}-${extDocVersion}.lex" property="doc.present"/>
    <available file="${cache}/${extHibernate}-${extHibernateVersion}.lex" property="hibernate.present"/>
    <available file="${cache}/${extLucene}-${extLuceneVersion}.lex" property="lucene.present"/>
    <available file="${cache}/${extPDF}-${extPDFVersion}.lex" property="pdf.present"/>


  </target>


  <target name="check-mysql" depends="check-cache" unless="mysql.present">
      <get src="${extURL}${extMySQL}?version=${extMySQLVersion}" dest="${cache}/${extMySQL}-${extMySQLVersion}.lex"/>
  </target> 
  <target name="check-mssql" depends="check-cache" unless="mssql.present">
      <get src="${extURL}${extMSSQL}?version=${extMSSQLVersion}" dest="${cache}/${extMSSQL}-${extMSSQLVersion}.lex"/>
  </target> 
  <target name="check-postgre" depends="check-cache" unless="postgre.present">
      <get src="${extURL}${extPostgreSQL}?version=${extPostgreSQLVersion}" dest="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex"/>
  </target> 
  <target name="check-jdts" depends="check-cache" unless="jdts.present">
      <get src="${extURL}${extJDTsSQL}?version=${extJDTsSQLVersion}" dest="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex"/>
  </target>
  <target name="check-chart" depends="check-cache" unless="chart.present">
      <get src="${extURL}${extChart}?version=${extChartVersion}" dest="${cache}/${extChart}-${extChartVersion}.lex"/>
  </target>
  <target name="check-s3" depends="check-cache" unless="s3.present">
      <get src="${extURL}${extS3}?version=${extS3Version}" dest="${cache}/${extS3}-${extS3Version}.lex"/>
  </target>
  <target name="check-hibernate" depends="check-cache" unless="hibernate.present">
      <get src="${extURL}${extHibernate}?version=${extHibernateVersion}" dest="${cache}/${extHibernate}-${extHibernateVersion}.lex"/>
  </target>
  <target name="check-lucene" depends="check-cache" unless="lucene.present">
      <get src="${extURL}${extLucene}?version=${extLuceneVersion}" dest="${cache}/${extLucene}-${extLuceneVersion}.lex"/>
  </target>
  <target name="check-pdf" depends="check-cache" unless="pdf.present">
      <get src="${extURL}${extPDF}?version=${extPDFVersion}" dest="${cache}/${extPDF}-${extPDFVersion}.lex"/>
  </target>
  <target name="check-admin" depends="check-cache" unless="admin.present">
      <get src="${extURL}${extAdmin}?version=${extAdminVersion}" dest="${cache}/${extAdmin}-${extAdminVersion}.lex"/>
  </target>
  <target name="check-doc" depends="check-cache" unless="doc.present">
      <get src="${extURL}${extDoc}?version=${extDocVersion}" dest="${cache}/${extDoc}-${extDocVersion}.lex"/>
  </target>
  <target name="check-testbox" depends="check-cache" unless="testbox.present">
      <get src="${testboxURL}" dest="${cache}/testbox-${testboxVersion}.zip"/>
  </target> 

  <target name="check" depends="check-mysql,check-mssql,check-postgre,check-jdts,check-chart,check-s3,check-hibernate,check-lucene,check-pdf,check-admin,check-doc,check-testbox">
    
    <mkdir dir="${temp}/loader/extensions/"/>

    <!-- testbox -->
    <copy 
      file="${cache}/testbox-${testboxVersion}.zip" 
      todir="${temp}"/>

  </target> 

  
  <target name="copyDeployFiles" depends="init,check" description="copy files from source/cfml to source/java/core/src/resource">
    <echots message="copy files from source/cfml to source/java/core/src/resource"/>

    <copy todir="${srcCore}/resource/context/" overwrite="true">
      <fileset dir="${srcCFML}/context/">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/admin/resources/language/" overwrite="true">
      <fileset dir="${srcCFML}/context/admin/resources/language/">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/gateway"  overwrite="true">
      <fileset dir="${srcCFML}/context/gateway">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/templates/error"  overwrite="true">
      <fileset dir="${srcCFML}/context/templates/error">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/admin/plugin"  overwrite="true">
      <fileset dir="${srcCFML}/context/admin/plugin">
        <include name="**/*.cfm"/>
        <include name="**/*.cfc"/>
        <include name="**/*.lucee"/>
        <include name="**/*.xml"/>
      </fileset>
    </copy>
  </target>

  <target name="agent" depends="copyDeployFiles" description="create external-agent  jar used as backup when dynamic agent fails" >
    <echots message="create external-agent.jar used as backup when dynamic agent fails"/>
    
    <!-- compie the source -->
    <javac 
      srcdir="${srcInst}" 
      target="1.7" 
      destdir="${temp}/agent"
      debug="true" debuglevel="lines,vars,source" classpath="${dependencies}">
    </javac>

    <!-- create the manifest file -->
    <jar 
        basedir="${temp}/agent" 
        jarfile="${core}/resource/lib/lucee-external-agent.jar" 
        manifest="${srcInst}/META-INF/MANIFEST.MF"/> 
    

  </target>

  <target name="_loader" depends="agent" description="compile the source" >
    <echots message="compile loader"/>
    <!-- compie the source -->
    <javac 
      srcdir="${srcLoader}" 
      target="1.7" 
      destdir="${temp}/loader"
      debug="true" debuglevel="lines,vars,source" classpath="${dependencies}">
    </javac>
    
    <!-- copy all non java files -->
    <copy todir="${temp}/loader">
      <fileset dir="${srcLoader}">
        <exclude name="**/*.java"/>
        <exclude name=".*"/>
      </fileset>
    </copy>

    <!-- set lucee/version file -->
    <currentTime property="ct" />
    <echo file="${temp}/loader/lucee/version" message="${version}:${ct}" encoding="UTF-8"/>


  </target>


  <target name="_core" depends="_loader" description="compile the source" >
    
    <echots message="compile core"/>
    <!-- set the loader as classpath -->
    <path id="classpath">
      <pathelement location="${temp}/loader" />
      <pathelement path="${dependencies}"/>
    </path>

    <!-- <pathconvert property="classpathProp" refid="classpath"/> -->
   
    <!-- compile the core -->
    <javac 
      srcdir="${srcCore}" 
      target="1.7" 
      destdir="${core}"
      debug="true" debuglevel="lines,vars,source">
       <classpath refid="classpath" />
    </javac>

    <!-- copy all non java files -->
    <copy todir="${core}">
      <fileset dir="${srcCore}">
        <exclude name="**/*.java"/>
        <exclude name=".*"/>
      </fileset>
    </copy>

    <!-- set date in default properties -->
    <loadfile property="defprop"
      srcFile="${core}/default.properties"/>
    <updatedate text="${defprop}" date="${NOW}" property="moddefprop" />
    <echo file="${core}/default.properties" message="${moddefprop}"/>

    <!-- create the manifest file -->
    <manifest file="${core}/META-INF/MANIFEST.MF" mode="update">
      <attribute name="Bundle-Version" value="${version}"/>
      <attribute name="Bundle-Name" value="${bundleName}"/>
      <attribute name="Bundle-SymbolicName" value="${bundleSymbolicName}"/>
      <attribute name="Bundle-ManifestVersion" value="2"/>
      <attribute name="Built-Date" value="${NOW}"/>
      <attribute name="State" value="${state}"/>
      <attribute name="Minor-Name" value="${name}"/>
      <attribute name="Minor-Name-Explanation" value="${name.explanation}"/>
    </manifest>
  </target>


  <target name="buildJars" depends="_core" description="generate temporary jars used to generate the archive" >
    
    <echots message="generate temporary jars used to generate the archive"/>
    <!-- generates a jar from the core 
          this jars are only 
    -->
    <jar 
        basedir="${core}" 
        jarfile="${temp}/loader/core/core.lco" 
        manifest="${core}/META-INF/MANIFEST.MF"/> 


    <!-- genrates the jar from the loader -->
    <jar 
      basedir="${temp}/loader" 
      jarfile="${temp}/lucee.jar" 
      manifest="${srcLoader}/META-INF/MANIFEST.MF"/>

  </target>

<target name="__build_archives" depends="buildJars">


    <!-- first we copy the jars in place otherwise, Lucee downloads them  -->
    <echots message="copy bundles in place"/>
    <copy todir="${temp}/archive/base/lucee-server/bundles" flatten="true">
      <path>
        <pathelement path="${dependencies}"/>
      </path>
    </copy>
    
    <!-- no we copy the extension in place otherwise, Lucee downloads them as well  -->
    <echots message="copy extensions in place"/>
    <copy todir="${temp}/archive/base/lucee-server/context/extensions/available" flatten="true">
      <fileset dir="${cache}">
        <include name="**/*.lex"/>
      </fileset>
    </copy>



    <echots message="getting and unzip testbox"/>
    <!-- now we need to get the testbox source -->
    <unzip src="${temp}/testbox-${testboxVersion}.zip" dest="${temp}/testbox"/>
    <delete dir="${temp}/testbox-${testboxVersion}.zip"/>


    <echots message="building different archives that get bundled (admin,doc) with help of the temporary generated lucee.jar"/>
    <!-- build the lucee-context.lar -->
    <java classname="org.apache.tools.ant.launch.Launcher" dir="${ant}" fork="true" failonerror="false" errorproperty="exc">
      <classpath path="${java.class.path}">
          <pathelement location="${temp}/lucee.jar"/>
          <pathelement path="${runtime_classpath}"/>
      </classpath>

      <arg value="-f"/>
      <arg value="${ant}/build-create-archive.xml"/>

      <jvmarg value="-Dsrc=${srcCFML}/context"/>
      <jvmarg value="-Dtemp=${temp}/archive"/>
      <jvmarg value="-Dtestbox=${temp}/testbox/testbox"/>
      <jvmarg value="-Dlucee.base.dir=${temp}/archive/base"/>
      <jvmarg value="-Dlucee.web.dir=${temp}/archive/webroot"/>
      <jvmarg value="-Dlucee.enable.dialect=true"/>
    </java>
    <echo>${exc}</echo>

</target>
<target name="__build_testbox" if="testcases">

    <echots message="execute testcases ${testcases}"/>
    <!-- execute CFML testcases -->
    <java classname="org.apache.tools.ant.launch.Launcher" dir="${ant}" fork="true" failonerror="true" errorproperty="exc2">
      <classpath path="${java.class.path}">
          <pathelement location="${temp}/lucee.jar"/>
          <pathelement path="${runtime_classpath}"/>
      </classpath>

      <arg value="-f"/>
      <arg value="${ant}/run-testcases.xml"/>

      <jvmarg value="-Dtest=${test}"/>
      <jvmarg value="-Dtemp=${temp}"/>
      <jvmarg value="-DtestboxArchive=${temp}/archive/testbox.lar"/>
      <jvmarg value="-Dexecute=${testcases}"/>

      <jvmarg value="-Dlucee.base.dir=${temp}/archive/base"/>
      <jvmarg value="-Dlucee.web.dir=${temp}/archive/webroot"/>
      <jvmarg value="-Dlucee-extensions=${extH2},${extMongo};"/>
      <jvmarg value="-Dlucee.enable.dialect=true"/>
    </java>
    <echo>${exc2}</echo>

</target>


  <target name="__build" depends="__build_archives,__build_testbox">

    <!-- now we have to build the lucee.jar again, this time with the lar files -->
    <echots message="copy generated archive in place"/>
    <!-- copy the lucee lar -->
    <copy file="${temp}/archive/lucee-context.lar" tofile="${core}/resource/context/lucee-context.lar"/>
    <copy file="${temp}/archive/lucee-admin.lar" tofile="${core}/resource/context/lucee-admin.lar"/> 
    <copy file="${temp}/archive/lucee-doc.lar" tofile="${core}/resource/context/lucee-doc.lar"/> 

  </target>


  <target name="buildCore" depends="__build">

    <!-- copy all the source to the classes folder -->
    <echots message="copy everything to the classes folder"/>
    <copy todir="${outputDir}">
      <fileset dir="${core}">
        <exclude name=".*"/>
      </fileset>
    </copy>
  </target>

  <target name="addFelix">

    <echots message="copy the content of the felix jar to the classes folder"/>
    
    <!-- get the path for the felix jar TODO this impl could be better -->
    <felix property="felix" separator="${path.separator}" dependencies="${dependencies}"/>
    
    <!-- unzip the content to target -->
    <unzip src="${felix}" dest="${goal}">
        <!-- <patternset>
            <exclude name="**/MANIFEST.MF"/>
        </patternset> -->
    </unzip>


    <!-- Manifest need merging -->
    <loadproperties 
      srcFile="${srcLoader}/META-INF/MANIFEST.MF"
      prefix="mani.core."/>
    <manifest file="${goal}/META-INF/MANIFEST.MF" mode="update">
      <attribute name="Premain-Class" value="${mani.core.Premain-Class}"/>
      <attribute name="Agent-Class" value="${mani.core.Agent-Class}"/>
      <attribute name="Can-Redefine-Classes" value="${mani.core.Can-Redefine-Classes}"/>
      <attribute name="Can-Retransform-Classes" value="${mani.core.Can-Retransform-Classes}"/>
      <attribute name="Main-Class" value="${mani.core.Main-Class}"/>
      <attribute name="Bundle-Description" value="${mani.core.Bundle-Description}"/>
      <attribute name="Bundle-DocURL" value="${mani.core.Bundle-DocURL}"/>
      <attribute name="Bundle-License" value="${mani.core.Bundle-License}"/>
      <attribute name="Bundle-Vendor" value="${mani.core.Bundle-Vendor}"/>

      <attribute name="Built-By" value="Lucee build process"/>
      <attribute name="Created-By" value="Lucee build process"/>

    </manifest>
    <!-- TODO load dyn -->
  </target>


  <target name="addExtensions">
    <echots message="add extensions"/>
    
    <mkdir dir="${goal}/extensions/"/>

    <!-- add extension MySQL -->
    <loadmf jar="${cache}/${extMySQL}-${extMySQLVersion}.lex" prefix="ext_mysql."/>
    <toFileName name="${ext_mysql.name}" version="${ext_mysql.version}" property="ext_mysql.filename"/>
    <copy 
      file="${cache}/${extMySQL}-${extMySQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extMySQL}-${extMySQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_mysql.filename}"/>
    <echo>add:${goal}/extensions/${ext_mysql.filename}</echo>
    <echo file="${goal}/extensions/.index">${ext_mysql.filename};</echo>

    <!-- add extension MSSQL -->
    <loadmf jar="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" prefix="ext_mssql."/>
    <toFileName name="${ext_mssql.name}" version="${ext_mssql.version}" property="ext_mssql.filename"/>
    <copy 
      file="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extMSSQL}-${extMSSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_mssql.filename}"/>
    <echo>add:${goal}/extensions/${ext_mssql.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_mssql.filename};</echo>

    <!-- add extension Postgre -->
    <loadmf jar="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" prefix="ext_postgre."/>
    <toFileName name="${ext_postgre.name}" version="${ext_postgre.version}" property="ext_postgre.filename"/>
    <copy 
      file="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extPostgreSQL}-${extPostgreSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_postgre.filename}"/>
    <echo>add:${goal}/extensions/${ext_postgre.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_postgre.filename};</echo>

    <!-- add extension JDTS -->
    <loadmf jar="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" prefix="ext_jdts."/>
    <toFileName name="${ext_jdts.name}" version="${ext_jdts.version}" property="ext_jdts.filename"/>
    <copy 
      file="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extJDTsSQL}-${extJDTsSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_jdts.filename}"/>
    <echo>add:${goal}/extensions/${ext_jdts.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_jdts.filename};</echo>

    <!-- add extension Chart -->
    <loadmf jar="${cache}/${extChart}-${extChartVersion}.lex" prefix="ext_chart."/>
    <toFileName name="${ext_chart.name}" version="${ext_chart.version}" property="ext_chart.filename"/>
    <copy 
      file="${cache}/${extChart}-${extChartVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extChart}-${extChartVersion}.lex" 
      tofile="${goal}/extensions/${ext_chart.filename}"/>
    <echo>add:${goal}/extensions/${ext_chart.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_chart.filename};</echo>

    <!-- add extension S3 -->
    <loadmf jar="${cache}/${extS3}-${extS3Version}.lex" prefix="ext_s3."/>
    <toFileName name="${ext_s3.name}" version="${ext_s3.version}" property="ext_s3.filename"/>
    <copy 
      file="${cache}/${extS3}-${extS3Version}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extS3}-${extS3Version}.lex" 
      tofile="${goal}/extensions/${ext_s3.filename}"/>
    <echo>add:${goal}/extensions/${ext_s3.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_s3.filename};</echo>

    <!-- add extension Hibernate -->
    <loadmf jar="${cache}/${extHibernate}-${extHibernateVersion}.lex" prefix="ext_hibernate."/>
    <toFileName name="${ext_hibernate.name}" version="${ext_hibernate.version}" property="ext_hibernate.filename"/>
    <copy 
      file="${cache}/${extHibernate}-${extHibernateVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extHibernate}-${extHibernateVersion}.lex" 
      tofile="${goal}/extensions/${ext_hibernate.filename}"/>
    <echo>add:${goal}/extensions/${ext_hibernate.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_hibernate.filename};</echo>


    <!-- add extension Lucene -->
    <loadmf jar="${cache}/${extLucene}-${extLuceneVersion}.lex" prefix="ext_lucene."/>
    <toFileName name="${ext_lucene.name}" version="${ext_lucene.version}" property="ext_lucene.filename"/>
    <copy 
      file="${cache}/${extLucene}-${extLuceneVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extLucene}-${extLuceneVersion}.lex" 
      tofile="${goal}/extensions/${ext_lucene.filename}"/>
    <echo>add:${goal}/extensions/${ext_lucene.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_lucene.filename};</echo>

    <!-- add extension PDF -->
    <loadmf jar="${cache}/${extPDF}-${extPDFVersion}.lex" prefix="ext_pdf."/>
    <toFileName name="${ext_pdf.name}" version="${ext_pdf.version}" property="ext_pdf.filename"/>
    <copy 
      file="${cache}/${extPDF}-${extPDFVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extPDF}-${extPDFVersion}.lex" 
      tofile="${goal}/extensions/${ext_pdf.filename}"/>
    <echo>add:${goal}/extensions/${ext_pdf.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_pdf.filename};</echo>

    <!-- add extension Admin -->
    <loadmf jar="${cache}/${extAdmin}-${extAdminVersion}.lex" prefix="ext_admin."/>
    <toFileName name="${ext_admin.name}" version="${ext_admin.version}" property="ext_admin.filename"/>
    <copy 
      file="${cache}/${extAdmin}-${extAdminVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extAdmin}-${extAdminVersion}.lex" 
      tofile="${goal}/extensions/${ext_admin.filename}"/>
    <echo>add:${goal}/extensions/${ext_admin.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_admin.filename};</echo>

    <!-- add extension Doc -->
    <loadmf jar="${cache}/${extDoc}-${extDocVersion}.lex" prefix="ext_doc."/>
    <toFileName name="${ext_doc.name}" version="${ext_doc.version}" property="ext_doc.filename"/>
    <copy 
      file="${cache}/${extDoc}-${extDocVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extDoc}-${extDocVersion}.lex" 
      tofile="${goal}/extensions/${ext_doc.filename}"/>
    <echo>add:${goal}/extensions/${ext_doc.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_doc.filename};</echo>


  </target>


  <target name="setMvnEnv" description="set the variable right for ant">
    <property name="goal" location="${outputDir}"/>
  </target>

  <target name="buildLoaderMaven" depends="__build,setMvnEnv,addExtensions,addFelix" description="generate the loader jar" >  
    <echots message="build core"/>
    <!-- create the luce core -->
    <jar 
        basedir="${core}" 
        jarfile="${trgLoader}/${version}.lco" 
        manifest="${core}/META-INF/MANIFEST.MF"/>

    <!-- copy to core to the classes folder -->
    <copy 
        file="${trgLoader}/${version}.lco" 
        tofile="${outputDir}/core/core.lco"/>

    <!-- version -->
    <currentTime property="ct" />
    <echo file="${outputDir}/lucee/version" message="${version}:${ct}" encoding="UTF-8"/>

    
    <delete dir="${temp}"/>
    <echots message="done with the ant part, now maven build the loader"/>
    
  </target>


  <target name="setAntEnv" description="set the variable right for ant">
    <echo>before:${goal}</echo>
    <property name="goal" location="${temp}/loader"/>
<echo>after:${goal}</echo>
    

  </target>

  <target name="buildLoaderAnt" depends="__build,setAntEnv,addExtensions,addFelix" description="generate the loader jar" >  
    <echots message="build core"/>
    <commit_msg>check iw we can deploy multiple artifacts<commit_after><?xml version="1.0" encoding="UTF-8"?>
<project default="susi" basedir="${rootDir}" name="LuceeCore" ><!-- TODO maybe there is a better way for this -->
  <description>
        Build Lucee Core
  </description>
  


  <property name="build.compiler" value="extJavac"/>
  <property name="agent" value="lucee.runtime.instrumentation.ExternalAgent"/>
  <property name="bundleName" value="Lucee Core"/>
  <property name="bundleSymbolicName" value="lucee.core"/>
  
  <property name="testboxVersion" value="2.2.0"/>
  <property name="testboxURL" 
    value="http://downloads.ortussolutions.com/ortussolutions/testbox/${testboxVersion}/testbox-${testboxVersion}.zip"/>
  <property name="extURL" value="http://extension.lucee.org/rest/extension/provider/full/"/>
  
  <property name="extMongo"       value="E6634E1A-4CC5-4839-A83C67549ECA8D5B"/>
  <property name="extH2"          value="465E1E35-2425-4F4E-8B3FAB638BD7280A"/>


<!-- TODO get the version number from manifest.mf -->
  
  <!-- http://www.coldbox.org/download/testbox -->
  <tstamp>
      <format property="NOW" pattern="yyyy/MM/dd HH:mm:ss z" locale="en,GB"/>
  </tstamp>

  <scriptdef name="readManifestEntry" language="javascript" loaderRef="sharedbuild-loaderRef">
    <attribute name="file" />
    <attribute name="variable" />
    <attribute name="key" />
    <![CDATA[
        var filename = attributes.get("file");
        var variable = attributes.get("variable");
        var key = attributes.get("key");
        
        var manifest;
        if (filename != null) {
            manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
        } else {
            self.fail("missing file definition!");
        }

        var attrs=manifest.getMainAttributes();
        project.setProperty(variable, attrs.getValue(key));
    ]]>
</scriptdef>

  <scriptdef name="readRequiredExtensions" language="javascript" loaderRef="sharedbuild-loaderRef">
    <attribute name="file" />
    <![CDATA[
        var filename = attributes.get("file");
        var manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
        var attrs=manifest.getMainAttributes();
        var str=attrs.getValue("Require-Extension");
        var arr=str.split(",");
        var count=0;
        var ids="";
        var data="";
        var versions="";
        var labels="";
        for (var i=0;i<arr.length;i++) {
          var line=arr[i];
          var extArr=line.split(';');
          if(extArr.length<1) continue;
          count++;
          // the first is the id
          if(ids.length>0)ids+=",";
          ids+=extArr[0];
          if(data.length>0)data+=",";
          data+=extArr[0];
          var _id=extArr[0];
          project.setProperty("reqExt.ID"+(i+1), _id);

          // the rest has names
          var _version="";
          var _name="";
          for (var y=1;y<extArr.length;y++) {
            var ext=extArr[y];
            var index=ext.indexOf('=');
            if(index==-1) continue;
              var name=ext.substring(0,index).trim();
              var value=ext.substring(index+1).trim();
              if(name=="version") {
                if(versions.length>0)versions+=",";
                versions+=value;
                data+=";"+value;
                _version=value;
              }
              if(name=="label") {
                if(labels.length>0)labels+=",";
                labels+=value;
              }
              else if(name=="name") {
                _name=value;
              }
             project.setProperty("reqExt."+name+(i+1), value);
          }
          project.setProperty("reqExt."+_name, _version);
          project.setProperty("ext"+_name+"Version", _version);
          project.setProperty("ext"+_name, _id);

        }
        project.setProperty("reqExt.length", count+"");
        project.setProperty("reqExt.ids", ids);
        project.setProperty("reqExt.versions", versions);
        project.setProperty("reqExt.labels", labels);
        project.setProperty("reqExt.data", data);


        //
    ]]>
  </scriptdef>
  <scriptdef name="splitIdVersion" language="javascript">
     <attribute name="prefix" />
     <attribute name="value" />
     <![CDATA[
      var prefix = attributes.get("prefix");
      var value = attributes.get("value");
      
      var index=value.indexOf(";");
      var id;
      var version="";
      // no version
      if(index==-1) {
        id=value.trim();
      }
      else {
        id=value.substring(0,index);
        version=value.substring(index+1);
      }
      project.setProperty(prefix+"id", id);
      project.setProperty(prefix+"version", version);
     ]]>
  </scriptdef>



  <macrodef name="echots">
    <attribute name="message"/>
    <sequential>
      <local name="timestamp" />
      <tstamp>
        <format property="timestamp" pattern="yyyy-MM-dd HH:mm:ss" />
      </tstamp>
      <echo message="---------- ${timestamp} - @{message} ----------" />
    </sequential>
  </macrodef>

  <scriptdef name="unwrap" language="javascript">
     <attribute name="text" />
     <attribute name="property" />
     <![CDATA[
      var text = attributes.get("text");
      text=text.trim();
      if(text.startsWith('"') && text.endsWith('"')) {
        text=text.substring(1,text.length()-1);
      }
      project.setProperty(attributes.get("property"), text);
     ]]>
  </scriptdef>

  <scriptdef name="updatedate" language="javascript">
     <attribute name="text" />
     <attribute name="date" />
     <attribute name="property" />
     <![CDATA[
      var text = attributes.get("text");
      var date = attributes.get("date");
      
      var index=text.indexOf("lucee.core.release.date");
      if(index!=-1) {
        var start=text.indexOf('"',index);
        var end=text.indexOf('"',start+1);
        if(start!=-1 && end!=-1) {
          text=text.substring(0,start+1)+date+text.substring(end);
        }
      }

      project.setProperty(attributes.get("property"), text);
     ]]>
  </scriptdef>

  <scriptdef name="felix" language="javascript">
     <attribute name="property" />
     <attribute name="dependencies" />
     <attribute name="separator" />
     <![CDATA[
      var dep = attributes.get("dependencies");
      var sep = attributes.get("separator");
      var arr=dep.split(sep);
      
      var rtn="";
      for(var i=0;i<arr.length;i++){
        if(arr[i].indexOf("felix")!=-1) {
          rtn=arr[i];
          break;
        } 
      }

      var res=arr[0];
      project.setProperty(attributes.get("property"), rtn);
     ]]>
  </scriptdef>
  
  <scriptdef name="currentTime" language="javascript">
     <attribute name="property" />
     <![CDATA[
      project.setProperty(attributes.get("property"), new Date().getTime());
     ]]>
  </scriptdef>

  <scriptdef name="toFileName" language="javascript">
     <attribute name="name" />
     <attribute name="version" />
     <attribute name="property" />
     <![CDATA[
      var name = attributes.get("name").trim();
      var version = attributes.get("version").trim();
      
      var needle = ' ';
      //var regex = new RegExp(needle,'g');
      var repl = '-';
      
      // removes quotes
      if(name.startsWith('"') && name.endsWith('"')) {
        name=name.substring(1,name.length()-1).trim();
      }

      // remove brackets
      var start,end;
      while((start=name.indexOf('('))!=-1) {
        end=name.indexOf(')',start+1);
        if(end==-1) break;
        name=(name.substring(0,start) + name.substring(end+1)).trim();
      }

      // version
      if(version.startsWith('"') && version.endsWith('"')) {
        version=version.substring(1,version.length()-1).trim();
      }

      name=name.trim();
      name=name.replace(" ","-").toLowerCase();
      name=name.replace(" ","-"); // TODO make better but not with regex some ant version will fail
      name=name.replace(" ","-");
      name=name.replace(" ","-");
      name=name.replace(" ","-");
      name=name.replace(" ","-");

      project.setProperty(attributes.get("property"), name+"-"+version+".lex");
     ]]>
  </scriptdef>


<!-- TPDO make extension handling more dynamic
<target name="setVar">
    <splitIdVersion prefix="ext." value="${var}"/>
    
    <available file="${cache}/${ext.id}-${ext.version}.lex" property="ext.available"/>
    <echo>available: ${ext.id}:${ext.available}</echo>

</target>
-->


  <target name="init">
    

    <property name="srcLoader" location="${rootDir}/loader/src/main/java"/>
    <property name="srcCore" location="${rootDir}/core/src/main/java"/>
    <property name="coreManifest" location="${srcCore}/META-INF/MANIFEST.MF"/>
    <property name="cache" location="${rootDir}/cache"/>
    <property name="trgLoader" location="${rootDir}/loader/target"/>
    <property name="trgCore" location="${rootDir}/core/target"/>
    <property name="srcCFML" location="${rootDir}/core/src/main/cfml"/>
    <property name="srcInst" location="${rootDir}/instrumentation/src/main/java"/> 
    <property name="ant" location="${rootDir}/ant"/>
    <property name="test" location="${rootDir}/test"/>
    <property name="temp" location="${rootDir}/temp"/>
    <property name="loader" location="${temp}/loader"/>
    <property name="core" location="${temp}/core"/>
    <property file="${rootDir}/build.properties"/>


    <!-- get the extensions from manifest -->
    <!-- TODO extension handling must be more dynamic! -->
    <readRequiredExtensions file="${coreManifest}"/>
    <fail message="Missing data from [Require-Extension] inside ${coreManifest}">
    <condition>
        <or>
        <!-- Lucene -->
        <not><isset property="extLucene"/></not>
        <not><isset property="extLuceneVersion"/></not>
        <!-- Hibernate -->
        <not><isset property="extHibernate"/></not>
        <not><isset property="extHibernateVersion"/></not>
        <!-- PDF -->
        <not><isset property="extPDF"/></not>
        <not><isset property="extPDFVersion"/></not>
        <!-- S3 -->
        <not><isset property="extS3"/></not>
        <not><isset property="extS3Version"/></not>
        <!-- Chart -->
        <not><isset property="extChart"/></not>
        <not><isset property="extChartVersion"/></not>
        <!-- MySQL -->
        <not><isset property="extMySQL"/></not>
        <not><isset property="extMySQLVersion"/></not>
        <!-- MSSQL -->
        <not><isset property="extMSSQL"/></not>
        <not><isset property="extMSSQLVersion"/></not>
        <!-- PostgreSQL -->
        <not><isset property="extPostgreSQL"/></not>
        <not><isset property="extPostgreSQLVersion"/></not>
        <!-- JDTsSQL -->
        <not><isset property="extJDTsSQL"/></not>
        <not><isset property="extJDTsSQLVersion"/></not>
        <!-- Admin -->
        <not><isset property="extAdmin"/></not>
        <not><isset property="extAdminVersion"/></not>
        <!-- Doc -->
        <not><isset property="extDoc"/></not>
        <not><isset property="extDocVersion"/></not>
        </or>
    </condition>
    </fail>

<echo>                                                              
           `@@@@                                                               
           @@@@@@                                                              
          ``#@@@@#                                                             
          '@`@@@@@                                                             
          +@@+@@@@.                                                            
          ,@@.@@@@'                                                            
           @@ @@@@#                                                            
           ;@ @@@@#                                                            
            ; @@@@+                                                            
              @@@@'                                                            
             .@@@@,                                                            
             ;@@@@                                                             
             #@@@@                                                             
             @@@@@                                                             
             @@@@#                                                             
            ,@@@@`                                                             
            @@@@@                                                              
            @@@@#             `'@`     ,+@       :@@@#      ;@@@'       #@@@`  
           ;@@@@`            @@@@    .@@@@      @@:@@@@    @@.+@@#    +@#`@@@` 
           @@@@@            ,@@@#    @@@@,     @@   @@@  `@@   @@@   #@#  :@@# 
          ;@@@@,            @@@@`    @@@@     @@:   @@@  @@:   @@@  ;@@   ;@@' 
          @@@@@             @@@@    `@@@@    @@@    @:  @@@   .@@#  @@@   @@@  
         @@@@@..`          .@@@@    #@@@;    @@@       `@@@   @@@  #@@'  `@@#  
      +@.@@@@@:@@@@+       +@@@,    @@@@    #@@#       #@@@  @@@   @@@,  @@@   
    +@@ @@@@@ @@@@@@@`     @@@@     @@@@    @@@#       @@@@ @@@    @@@.,@@;    
    @@`@@@@@'@@@@@@@@,@'   @@@@    +@@@@   @@@@@       @@@@@@'    .@@@@@@     ;
  @; @@@@@@@'###@@@@@`@@@  @@@@    @@@@'  .@@@@@       @@@@#      ,@@@@`     '#
 ,@@@@@@@@@       .@@:@@@: @@@@   @'@@@#  @`@@@@@     `@@@@       ;@@@@     @@,
 :@@@@@@@@          +@@@@@ @@@@,:@;`@@@@@@@ @@@@@@,`+@@@@@@@.   '@@@@@@@,.#@@, 
  @@@@@@#            @@@@@ @@@@@@:  @@@@@@   @@@@@@@@@  @@@@@@@@@# `@@@@@@@@`  
   +@@#              #@@@:  @@@@    ;@@@;     @@@@@@`    @@@@@@#    `@@@@@#    
                      .+.    `                                                 
                                                                               


          In every job that must be done. There is an element of fun!                  
    </echo>

    <echo message="${version}"/>
    <echo message="${name}"/>
    <echo message="${name.explanation}"/>
    <echo message="Root: ${rootDir}"/>
    <echo message="Required-Extensions: ${reqExt.labels}"/>
                    
    
    <!-- Create the time stamp -->
    <tstamp/>
    
    <delete dir="${temp}"/>
    
    <!-- Create the  directory structure needed -->
    <mkdir dir="${core}"/>
    <mkdir dir="${loader}"/>
    <mkdir dir="${temp}/agent"/>
    <mkdir dir="${cache}"/>

  </target>




    <macrodef name="loadmf">
        <attribute name="jar"/>
        <attribute name="prefix" default=""/>
        <sequential>
            <loadproperties>
                <!-- Load the manifest entries -->
                <zipentry zipfile="@{jar}" name="META-INF/MANIFEST.MF"/>
                <!-- Add the prefix -->
                <filterchain>
                    <prefixlines prefix="@{prefix}"/>
                </filterchain>
            </loadproperties>
        </sequential>
    </macrodef>

  <target name="check-cache">

    <available file="${cache}/testbox-${testboxVersion}.zip" property="testbox.present"/>

    <available file="${cache}/${extMySQL}-${extMySQLVersion}.lex" property="mysql.present"/>
    <available file="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" property="mssql.present"/>
    <available file="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" property="postgre.present"/>
    <available file="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" property="jdts.present"/>

    <available file="${cache}/${extChart}-${extChartVersion}.lex" property="chart.present"/>
    <available file="${cache}/${extS3}-${extS3Version}.lex" property="s3.present"/>
    <available file="${cache}/${extAdmin}-${extAdminVersion}.lex" property="admin.present"/>
    <available file="${cache}/${extDoc}-${extDocVersion}.lex" property="doc.present"/>
    <available file="${cache}/${extHibernate}-${extHibernateVersion}.lex" property="hibernate.present"/>
    <available file="${cache}/${extLucene}-${extLuceneVersion}.lex" property="lucene.present"/>
    <available file="${cache}/${extPDF}-${extPDFVersion}.lex" property="pdf.present"/>


  </target>


  <target name="check-mysql" depends="check-cache" unless="mysql.present">
      <get src="${extURL}${extMySQL}?version=${extMySQLVersion}" dest="${cache}/${extMySQL}-${extMySQLVersion}.lex"/>
  </target> 
  <target name="check-mssql" depends="check-cache" unless="mssql.present">
      <get src="${extURL}${extMSSQL}?version=${extMSSQLVersion}" dest="${cache}/${extMSSQL}-${extMSSQLVersion}.lex"/>
  </target> 
  <target name="check-postgre" depends="check-cache" unless="postgre.present">
      <get src="${extURL}${extPostgreSQL}?version=${extPostgreSQLVersion}" dest="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex"/>
  </target> 
  <target name="check-jdts" depends="check-cache" unless="jdts.present">
      <get src="${extURL}${extJDTsSQL}?version=${extJDTsSQLVersion}" dest="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex"/>
  </target>
  <target name="check-chart" depends="check-cache" unless="chart.present">
      <get src="${extURL}${extChart}?version=${extChartVersion}" dest="${cache}/${extChart}-${extChartVersion}.lex"/>
  </target>
  <target name="check-s3" depends="check-cache" unless="s3.present">
      <get src="${extURL}${extS3}?version=${extS3Version}" dest="${cache}/${extS3}-${extS3Version}.lex"/>
  </target>
  <target name="check-hibernate" depends="check-cache" unless="hibernate.present">
      <get src="${extURL}${extHibernate}?version=${extHibernateVersion}" dest="${cache}/${extHibernate}-${extHibernateVersion}.lex"/>
  </target>
  <target name="check-lucene" depends="check-cache" unless="lucene.present">
      <get src="${extURL}${extLucene}?version=${extLuceneVersion}" dest="${cache}/${extLucene}-${extLuceneVersion}.lex"/>
  </target>
  <target name="check-pdf" depends="check-cache" unless="pdf.present">
      <get src="${extURL}${extPDF}?version=${extPDFVersion}" dest="${cache}/${extPDF}-${extPDFVersion}.lex"/>
  </target>
  <target name="check-admin" depends="check-cache" unless="admin.present">
      <get src="${extURL}${extAdmin}?version=${extAdminVersion}" dest="${cache}/${extAdmin}-${extAdminVersion}.lex"/>
  </target>
  <target name="check-doc" depends="check-cache" unless="doc.present">
      <get src="${extURL}${extDoc}?version=${extDocVersion}" dest="${cache}/${extDoc}-${extDocVersion}.lex"/>
  </target>
  <target name="check-testbox" depends="check-cache" unless="testbox.present">
      <get src="${testboxURL}" dest="${cache}/testbox-${testboxVersion}.zip"/>
  </target> 

  <target name="check" depends="check-mysql,check-mssql,check-postgre,check-jdts,check-chart,check-s3,check-hibernate,check-lucene,check-pdf,check-admin,check-doc,check-testbox">
    
    <mkdir dir="${temp}/loader/extensions/"/>

    <!-- testbox -->
    <copy 
      file="${cache}/testbox-${testboxVersion}.zip" 
      todir="${temp}"/>

  </target> 

  
  <target name="copyDeployFiles" depends="init,check" description="copy files from source/cfml to source/java/core/src/resource">
    <echots message="copy files from source/cfml to source/java/core/src/resource"/>

    <copy todir="${srcCore}/resource/context/" overwrite="true">
      <fileset dir="${srcCFML}/context/">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/admin/resources/language/" overwrite="true">
      <fileset dir="${srcCFML}/context/admin/resources/language/">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/gateway"  overwrite="true">
      <fileset dir="${srcCFML}/context/gateway">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/templates/error"  overwrite="true">
      <fileset dir="${srcCFML}/context/templates/error">
        <include name="*.cfm"/>
        <include name="*.cfc"/>
        <include name="*.lucee"/>
        <include name="*.xml"/>
      </fileset>
    </copy>

    <copy todir="${srcCore}/resource/context/admin/plugin"  overwrite="true">
      <fileset dir="${srcCFML}/context/admin/plugin">
        <include name="**/*.cfm"/>
        <include name="**/*.cfc"/>
        <include name="**/*.lucee"/>
        <include name="**/*.xml"/>
      </fileset>
    </copy>
  </target>

  <target name="agent" depends="copyDeployFiles" description="create external-agent  jar used as backup when dynamic agent fails" >
    <echots message="create external-agent.jar used as backup when dynamic agent fails"/>
    
    <!-- compie the source -->
    <javac 
      srcdir="${srcInst}" 
      target="1.7" 
      destdir="${temp}/agent"
      debug="true" debuglevel="lines,vars,source" classpath="${dependencies}">
    </javac>

    <!-- create the manifest file -->
    <jar 
        basedir="${temp}/agent" 
        jarfile="${core}/resource/lib/lucee-external-agent.jar" 
        manifest="${srcInst}/META-INF/MANIFEST.MF"/> 
    

  </target>

  <target name="_loader" depends="agent" description="compile the source" >
    <echots message="compile loader"/>
    <!-- compie the source -->
    <javac 
      srcdir="${srcLoader}" 
      target="1.7" 
      destdir="${temp}/loader"
      debug="true" debuglevel="lines,vars,source" classpath="${dependencies}">
    </javac>
    
    <!-- copy all non java files -->
    <copy todir="${temp}/loader">
      <fileset dir="${srcLoader}">
        <exclude name="**/*.java"/>
        <exclude name=".*"/>
      </fileset>
    </copy>

    <!-- set lucee/version file -->
    <currentTime property="ct" />
    <echo file="${temp}/loader/lucee/version" message="${version}:${ct}" encoding="UTF-8"/>


  </target>


  <target name="_core" depends="_loader" description="compile the source" >
    
    <echots message="compile core"/>
    <!-- set the loader as classpath -->
    <path id="classpath">
      <pathelement location="${temp}/loader" />
      <pathelement path="${dependencies}"/>
    </path>

    <!-- <pathconvert property="classpathProp" refid="classpath"/> -->
   
    <!-- compile the core -->
    <javac 
      srcdir="${srcCore}" 
      target="1.7" 
      destdir="${core}"
      debug="true" debuglevel="lines,vars,source">
       <classpath refid="classpath" />
    </javac>

    <!-- copy all non java files -->
    <copy todir="${core}">
      <fileset dir="${srcCore}">
        <exclude name="**/*.java"/>
        <exclude name=".*"/>
      </fileset>
    </copy>

    <!-- set date in default properties -->
    <loadfile property="defprop"
      srcFile="${core}/default.properties"/>
    <updatedate text="${defprop}" date="${NOW}" property="moddefprop" />
    <echo file="${core}/default.properties" message="${moddefprop}"/>

    <!-- create the manifest file -->
    <manifest file="${core}/META-INF/MANIFEST.MF" mode="update">
      <attribute name="Bundle-Version" value="${version}"/>
      <attribute name="Bundle-Name" value="${bundleName}"/>
      <attribute name="Bundle-SymbolicName" value="${bundleSymbolicName}"/>
      <attribute name="Bundle-ManifestVersion" value="2"/>
      <attribute name="Built-Date" value="${NOW}"/>
      <attribute name="State" value="${state}"/>
      <attribute name="Minor-Name" value="${name}"/>
      <attribute name="Minor-Name-Explanation" value="${name.explanation}"/>
    </manifest>
  </target>


  <target name="buildJars" depends="_core" description="generate temporary jars used to generate the archive" >
    
    <echots message="generate temporary jars used to generate the archive"/>
    <!-- generates a jar from the core 
          this jars are only 
    -->
    <jar 
        basedir="${core}" 
        jarfile="${temp}/loader/core/core.lco" 
        manifest="${core}/META-INF/MANIFEST.MF"/> 


    <!-- genrates the jar from the loader -->
    <jar 
      basedir="${temp}/loader" 
      jarfile="${temp}/lucee.jar" 
      manifest="${srcLoader}/META-INF/MANIFEST.MF"/>

  </target>

<target name="__build_archives" depends="buildJars">


    <!-- first we copy the jars in place otherwise, Lucee downloads them  -->
    <echots message="copy bundles in place"/>
    <copy todir="${temp}/archive/base/lucee-server/bundles" flatten="true">
      <path>
        <pathelement path="${dependencies}"/>
      </path>
    </copy>
    
    <!-- no we copy the extension in place otherwise, Lucee downloads them as well  -->
    <echots message="copy extensions in place"/>
    <copy todir="${temp}/archive/base/lucee-server/context/extensions/available" flatten="true">
      <fileset dir="${cache}">
        <include name="**/*.lex"/>
      </fileset>
    </copy>



    <echots message="getting and unzip testbox"/>
    <!-- now we need to get the testbox source -->
    <unzip src="${temp}/testbox-${testboxVersion}.zip" dest="${temp}/testbox"/>
    <delete dir="${temp}/testbox-${testboxVersion}.zip"/>


    <echots message="building different archives that get bundled (admin,doc) with help of the temporary generated lucee.jar"/>
    <!-- build the lucee-context.lar -->
    <java classname="org.apache.tools.ant.launch.Launcher" dir="${ant}" fork="true" failonerror="false" errorproperty="exc">
      <classpath path="${java.class.path}">
          <pathelement location="${temp}/lucee.jar"/>
          <pathelement path="${runtime_classpath}"/>
      </classpath>

      <arg value="-f"/>
      <arg value="${ant}/build-create-archive.xml"/>

      <jvmarg value="-Dsrc=${srcCFML}/context"/>
      <jvmarg value="-Dtemp=${temp}/archive"/>
      <jvmarg value="-Dtestbox=${temp}/testbox/testbox"/>
      <jvmarg value="-Dlucee.base.dir=${temp}/archive/base"/>
      <jvmarg value="-Dlucee.web.dir=${temp}/archive/webroot"/>
      <jvmarg value="-Dlucee.enable.dialect=true"/>
    </java>
    <echo>${exc}</echo>

</target>
<target name="__build_testbox" if="testcases">

    <echots message="execute testcases ${testcases}"/>
    <!-- execute CFML testcases -->
    <java classname="org.apache.tools.ant.launch.Launcher" dir="${ant}" fork="true" failonerror="true" errorproperty="exc2">
      <classpath path="${java.class.path}">
          <pathelement location="${temp}/lucee.jar"/>
          <pathelement path="${runtime_classpath}"/>
      </classpath>

      <arg value="-f"/>
      <arg value="${ant}/run-testcases.xml"/>

      <jvmarg value="-Dtest=${test}"/>
      <jvmarg value="-Dtemp=${temp}"/>
      <jvmarg value="-DtestboxArchive=${temp}/archive/testbox.lar"/>
      <jvmarg value="-Dexecute=${testcases}"/>

      <jvmarg value="-Dlucee.base.dir=${temp}/archive/base"/>
      <jvmarg value="-Dlucee.web.dir=${temp}/archive/webroot"/>
      <jvmarg value="-Dlucee-extensions=${extH2},${extMongo};"/>
      <jvmarg value="-Dlucee.enable.dialect=true"/>
    </java>
    <echo>${exc2}</echo>

</target>


  <target name="__build" depends="__build_archives,__build_testbox">

    <!-- now we have to build the lucee.jar again, this time with the lar files -->
    <echots message="copy generated archive in place"/>
    <!-- copy the lucee lar -->
    <copy file="${temp}/archive/lucee-context.lar" tofile="${core}/resource/context/lucee-context.lar"/>
    <copy file="${temp}/archive/lucee-admin.lar" tofile="${core}/resource/context/lucee-admin.lar"/> 
    <copy file="${temp}/archive/lucee-doc.lar" tofile="${core}/resource/context/lucee-doc.lar"/> 

  </target>


  <target name="buildCore" depends="__build">

    <!-- copy all the source to the classes folder -->
    <echots message="copy everything to the classes folder"/>
    <copy todir="${outputDir}">
      <fileset dir="${core}">
        <exclude name=".*"/>
      </fileset>
    </copy>
  </target>

  <target name="addFelix">

    <echots message="copy the content of the felix jar to the classes folder"/>
    
    <!-- get the path for the felix jar TODO this impl could be better -->
    <felix property="felix" separator="${path.separator}" dependencies="${dependencies}"/>
    
    <!-- unzip the content to target -->
    <unzip src="${felix}" dest="${goal}">
        <!-- <patternset>
            <exclude name="**/MANIFEST.MF"/>
        </patternset> -->
    </unzip>


    <!-- Manifest need merging -->
    <loadproperties 
      srcFile="${srcLoader}/META-INF/MANIFEST.MF"
      prefix="mani.core."/>
    <manifest file="${goal}/META-INF/MANIFEST.MF" mode="update">
      <attribute name="Premain-Class" value="${mani.core.Premain-Class}"/>
      <attribute name="Agent-Class" value="${mani.core.Agent-Class}"/>
      <attribute name="Can-Redefine-Classes" value="${mani.core.Can-Redefine-Classes}"/>
      <attribute name="Can-Retransform-Classes" value="${mani.core.Can-Retransform-Classes}"/>
      <attribute name="Main-Class" value="${mani.core.Main-Class}"/>
      <attribute name="Bundle-Description" value="${mani.core.Bundle-Description}"/>
      <attribute name="Bundle-DocURL" value="${mani.core.Bundle-DocURL}"/>
      <attribute name="Bundle-License" value="${mani.core.Bundle-License}"/>
      <attribute name="Bundle-Vendor" value="${mani.core.Bundle-Vendor}"/>

      <attribute name="Built-By" value="Lucee build process"/>
      <attribute name="Created-By" value="Lucee build process"/>

    </manifest>
    <!-- TODO load dyn -->
  </target>


  <target name="addExtensions">
    <echots message="add extensions"/>
    
    <mkdir dir="${goal}/extensions/"/>

    <!-- add extension MySQL -->
    <loadmf jar="${cache}/${extMySQL}-${extMySQLVersion}.lex" prefix="ext_mysql."/>
    <toFileName name="${ext_mysql.name}" version="${ext_mysql.version}" property="ext_mysql.filename"/>
    <copy 
      file="${cache}/${extMySQL}-${extMySQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extMySQL}-${extMySQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_mysql.filename}"/>
    <echo>add:${goal}/extensions/${ext_mysql.filename}</echo>
    <echo file="${goal}/extensions/.index">${ext_mysql.filename};</echo>

    <!-- add extension MSSQL -->
    <loadmf jar="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" prefix="ext_mssql."/>
    <toFileName name="${ext_mssql.name}" version="${ext_mssql.version}" property="ext_mssql.filename"/>
    <copy 
      file="${cache}/${extMSSQL}-${extMSSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extMSSQL}-${extMSSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_mssql.filename}"/>
    <echo>add:${goal}/extensions/${ext_mssql.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_mssql.filename};</echo>

    <!-- add extension Postgre -->
    <loadmf jar="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" prefix="ext_postgre."/>
    <toFileName name="${ext_postgre.name}" version="${ext_postgre.version}" property="ext_postgre.filename"/>
    <copy 
      file="${cache}/${extPostgreSQL}-${extPostgreSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extPostgreSQL}-${extPostgreSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_postgre.filename}"/>
    <echo>add:${goal}/extensions/${ext_postgre.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_postgre.filename};</echo>

    <!-- add extension JDTS -->
    <loadmf jar="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" prefix="ext_jdts."/>
    <toFileName name="${ext_jdts.name}" version="${ext_jdts.version}" property="ext_jdts.filename"/>
    <copy 
      file="${cache}/${extJDTsSQL}-${extJDTsSQLVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extJDTsSQL}-${extJDTsSQLVersion}.lex" 
      tofile="${goal}/extensions/${ext_jdts.filename}"/>
    <echo>add:${goal}/extensions/${ext_jdts.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_jdts.filename};</echo>

    <!-- add extension Chart -->
    <loadmf jar="${cache}/${extChart}-${extChartVersion}.lex" prefix="ext_chart."/>
    <toFileName name="${ext_chart.name}" version="${ext_chart.version}" property="ext_chart.filename"/>
    <copy 
      file="${cache}/${extChart}-${extChartVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extChart}-${extChartVersion}.lex" 
      tofile="${goal}/extensions/${ext_chart.filename}"/>
    <echo>add:${goal}/extensions/${ext_chart.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_chart.filename};</echo>

    <!-- add extension S3 -->
    <loadmf jar="${cache}/${extS3}-${extS3Version}.lex" prefix="ext_s3."/>
    <toFileName name="${ext_s3.name}" version="${ext_s3.version}" property="ext_s3.filename"/>
    <copy 
      file="${cache}/${extS3}-${extS3Version}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extS3}-${extS3Version}.lex" 
      tofile="${goal}/extensions/${ext_s3.filename}"/>
    <echo>add:${goal}/extensions/${ext_s3.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_s3.filename};</echo>

    <!-- add extension Hibernate -->
    <loadmf jar="${cache}/${extHibernate}-${extHibernateVersion}.lex" prefix="ext_hibernate."/>
    <toFileName name="${ext_hibernate.name}" version="${ext_hibernate.version}" property="ext_hibernate.filename"/>
    <copy 
      file="${cache}/${extHibernate}-${extHibernateVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extHibernate}-${extHibernateVersion}.lex" 
      tofile="${goal}/extensions/${ext_hibernate.filename}"/>
    <echo>add:${goal}/extensions/${ext_hibernate.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_hibernate.filename};</echo>


    <!-- add extension Lucene -->
    <loadmf jar="${cache}/${extLucene}-${extLuceneVersion}.lex" prefix="ext_lucene."/>
    <toFileName name="${ext_lucene.name}" version="${ext_lucene.version}" property="ext_lucene.filename"/>
    <copy 
      file="${cache}/${extLucene}-${extLuceneVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extLucene}-${extLuceneVersion}.lex" 
      tofile="${goal}/extensions/${ext_lucene.filename}"/>
    <echo>add:${goal}/extensions/${ext_lucene.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_lucene.filename};</echo>

    <!-- add extension PDF -->
    <loadmf jar="${cache}/${extPDF}-${extPDFVersion}.lex" prefix="ext_pdf."/>
    <toFileName name="${ext_pdf.name}" version="${ext_pdf.version}" property="ext_pdf.filename"/>
    <copy 
      file="${cache}/${extPDF}-${extPDFVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extPDF}-${extPDFVersion}.lex" 
      tofile="${goal}/extensions/${ext_pdf.filename}"/>
    <echo>add:${goal}/extensions/${ext_pdf.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_pdf.filename};</echo>

    <!-- add extension Admin -->
    <loadmf jar="${cache}/${extAdmin}-${extAdminVersion}.lex" prefix="ext_admin."/>
    <toFileName name="${ext_admin.name}" version="${ext_admin.version}" property="ext_admin.filename"/>
    <copy 
      file="${cache}/${extAdmin}-${extAdminVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extAdmin}-${extAdminVersion}.lex" 
      tofile="${goal}/extensions/${ext_admin.filename}"/>
    <echo>add:${goal}/extensions/${ext_admin.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_admin.filename};</echo>

    <!-- add extension Doc -->
    <loadmf jar="${cache}/${extDoc}-${extDocVersion}.lex" prefix="ext_doc."/>
    <toFileName name="${ext_doc.name}" version="${ext_doc.version}" property="ext_doc.filename"/>
    <copy 
      file="${cache}/${extDoc}-${extDocVersion}.lex" 
      todir="${goal}/extensions/"/>
    <move 
      file="${goal}/extensions/${extDoc}-${extDocVersion}.lex" 
      tofile="${goal}/extensions/${ext_doc.filename}"/>
    <echo>add:${goal}/extensions/${ext_doc.filename}</echo>
    <echo file="${goal}/extensions/.index" append="true">${ext_doc.filename};</echo>


  </target>


  <target name="setMvnEnv" description="set the variable right for ant">
    <property name="goal" location="${outputDir}"/>
  </target>

  <target name="buildLoaderMaven" depends="__build,setMvnEnv,addExtensions,addFelix" description="generate the loader jar" >  
    <echots message="build core"/>
    <!-- create the luce core -->
    <jar 
        basedir="${core}" 
        jarfile="${trgLoader}/${version}.lco" 
        manifest="${core}/META-INF/MANIFEST.MF"/>

    <!-- copy to core to the classes folder -->
    <copy 
        file="${trgLoader}/${version}.lco" 
        tofile="${outputDir}/core/core.lco"/>

    <!-- copy to core to the target folder -->
    <copy 
        file="${outputDir}/core/core.lco" 
        tofile="${trgLoader}/${version}.lco"/>

    <!-- version -->
    <currentTime property="ct" />
    <echo file="${outputDir}/lucee/version" message="${version}:${ct}" encoding="UTF-8"/>

    
    <delete dir="${temp}"/>
    <echots message="done with the ant part, now maven build the loader"/>
    
  </target>


  <target name="setAntEnv" description="set the variable right for ant">
    <echo>before:${goal}</echo>
    <property name="goal" location="${temp}/loader"/>
<echo>after:${goal}</echo>
    

  </target>

  <target name="buildLoaderAnt" depends="__build,setAntEnv,addExtensions,addFelix" description="generate the loader jar" >  
    <echots message="build core"/>
    
{'fraction_non_alphanumeric': 0.2087468037467375, 'fraction_numerical': 0.0033386769830018944, 'mean_word_length': 2.6410998552822, 'pattern_counts': {'":': 0, '<': 1225, '<?xml version=': 2, '>': 1225, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 16}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 90, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1954696', 'n_tokens_mistral': 23360, 'n_tokens_neox': 22405, 'n_words': 3490}