anchor.diff:          use p = Process.Start(psi)
           p.WaitForExit()
   
  -let IkvmVersion = "8.0.5449.1"
  -let LuceneVersion = "5.0.0"
  -let LuceneFullVersion = "5.0.0.0"
  -let FileVersion = "5.0.0.0"
  +// ---------------------------------------------
  +// Calculated Variables
  +// ---------------------------------------------
   let RootDirectory = __SOURCE_DIRECTORY__
   let WorkDirectory = RootDirectory <!!> "Work" |> CreateAndEmptyDirectory
   let IkvmPath = sprintf @"%s\ikvm\ikvmc.exe" RootDirectory
  
positive.code:     let Exec(path, argument) = 
          let psi = new ProcessStartInfo()
          psi.FileName <- path
          //        if File.Exists(psi.FileName) <> true && path <> "cmd.exe" then 
          //            failwithf "File from the path cannot be located: %s." path
          psi.Arguments <- argument
          psi.WorkingDirectory <- __SOURCE_DIRECTORY__
          psi.RedirectStandardOutput <- false
  
negative.code:        sprintf "lucene-spatial-%s" LuceneVersion
         sprintf "lucene-sandbox-%s" LuceneVersion |]
  
  let JarFiles = Directory.GetFiles(RootDirectory, "*.jar", System.IO.SearchOption.AllDirectories)
  let javaExec (args : string) = Exec(JAVA_HOME <!!> @"bin\java.exe", args)
  
  /// <summary>
  /// Compiles FlexSearch related custom Java code to a jar file using Maven
  /// </summary>
  let codecsCompilation() = 
      !>>"Compiling using MAVEN."
      Exec(FlexSearchJar <!!> "compile.bat", "")
      !>>"Copy FlexSearch.Codec-0.0.0.jar to Lucene Files directory"
      assert File.Exists(FlexSearchJar <!!> @"target\FlexSearch.Codec-0.0.0.jar")
      File.Copy(FlexSearchJar <!!> @"target\FlexSearch.Codec-0.0.0.jar", LuceneDirectory <!!> @"FlexSearch.Codec.jar")
  
  /// <summary>
  /// Copies all the required Lucene jar files to the target directory
  /// </summary>
  let copyLuceneFilesToTarget() = 
      LuceneJars |> Array.iter (fun jar -> 
                        match JarFiles.FirstOrDefault(fun x -> x.Contains(jar)) with
                        | null -> failwithf "Jar not found: %s" jar
                        | filePath -> 
                            !>>(sprintf "Copying: %s" filePath)
                            File.Copy(filePath, LuceneDirectory <!!> (Path.GetFileName(filePath))))
  
  /// <summary>
  /// Extracts meta data information from Lucene jars
  /// </summary>
  let extractMetaInformation() = 
      loopFiles LuceneDirectory |> Seq.iter (fun file -> 
                                       use archive = ZipFile.Open(file, ZipArchiveMode.Update)
                                       
                                       let toBeDeleted = 
                                           Seq.fold (fun (acc : string list) (entry : ZipArchiveEntry) -> 
                                               if entry.FullName.StartsWith(@"META-INF/services/") then 
                                                   let info = Directory.CreateDirectory(TempDirectory <!!> entry.Name)
                                                   entry.ExtractToFile(info.FullName <!!> (Guid.NewGuid().ToString()))
                                                   entry.FullName :: acc
                                               else if entry.FullName.StartsWith("META-INF") then entry.FullName :: acc
                                               else acc) [] archive.Entries
                                       toBeDeleted |> Seq.iter (fun res -> archive.GetEntry(res).Delete()))
  
  /// <summary>
  /// Builds FlexLucene compatible meta data information
  /// </summary>
  let generateMetaInformation() = 
      loopDir TempDirectory |> Seq.iter (fun dir -> 
                                   loopFiles dir |> Seq.iter (fun file -> 
                                                        let dirInfo = new DirectoryInfo(Path.GetDirectoryName(file))
                                                        let targetFileName = ConvertNamingConvention(dirInfo.Name)
                                                        let targetPath = ServicesDirectory <!!> targetFileName
                                                        File.AppendAllLines(targetPath, CreateServiceFile(file))))
      !>"Create meta data jar"
      ZipFile.CreateFromDirectory(MetaDirectory, LuceneDirectory <!!> "Metadata.jar")
  
  /// <summary>
  /// Copies related libraries which are needed for compilation
  /// </summary>
  let copyLibraries() = 
      loopFiles LibSrcDirectory |> Seq.iter (fun f -> File.Copy(f, LibTargetDirectory <!!> (Path.GetFileName(f))))
  
  /// <summary>
  /// Executes Proguard which create a fat FlexLucene jar file
  /// </summary>
  let executeProguard() = 
      !>>"Move proguard.cfg to work directory"
      File.Copy(RootDirectory <!!> "proguard.cfg", WorkDirectory <!!> "proguard.cfg")
      javaExec """-jar ProGuard.jar @work\proguard.cfg"""
  
  /// <summary>
  ///Generated IKVM build string
  /// </summary>
  let GetIkvmBuildString() = 
      let sb = new System.Text.StringBuilder()
      loopFiles LibTargetDirectory |> Seq.iter (fun f -> sb.Append(f).Append(" ") |> ignore)
  