forked from SolrNet/SolrNet
-
Notifications
You must be signed in to change notification settings - Fork 1
/
fake.fsx
77 lines (66 loc) · 2.84 KB
/
fake.fsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#I @"lib"
#r "FakeLib.dll"
#r "NuGet.exe"
#r "System.Xml.Linq"
open System
open System.IO
open Fake
open Fake.FileUtils
let solr = "solr"
// helper functions
let httpGet = Fake.REST.ExecuteGetCommand null null
let ignoreEx (f: 'a -> 'b) a = try f a with e -> Unchecked.defaultof<'b>
[<AutoOpen>]
module Xml =
open System.Xml.Linq
let (.>) (a: #seq<XElement>) (b: string) = Extensions.Descendants(a, xname b)
let startsWith s (n: XElement) = n.Value.StartsWith s
let contains s (n: XElement) = n.Value.Contains s
let setValue s (n: XElement) = n.Value <- s
let replaceValue orig repl (n: XElement) = n.Value <- n.Value.Replace((orig:string), (repl:string))
module Nu =
open NuGet
let build (version: string) name desc dependencies =
let builder =
PackageBuilder(
Id = name,
Title = name,
Version = SemanticVersion version,
Description = desc,
LicenseUrl = Uri("http://www.apache.org/licenses/LICENSE-2.0"),
Language = "en-US",
ProjectUrl = Uri("http://code.google.com/p/solrnet")
)
builder.Authors.Add "Mauricio Scheffer and contributors" |> ignore
builder.Owners.Add "Mauricio Scheffer" |> ignore
let buildFiles d =
!+ ("nuget" @@ d @@ "*") -- ("nuget" @@ d)
|> Scan
|> Seq.map (fun f -> PhysicalPackageFile(SourcePath = f, TargetPath = d @@ Path.GetFileName(f)))
let files = ["lib";"content"] |> Seq.collect buildFiles
builder.Files.AddRange (files |> Seq.map (fun i -> upcast i))
let deps =
dependencies
|> Seq.map (fun (id,v) -> PackageDependency(id = id, versionSpec = VersionUtility.ParseVersionSpec v))
builder.DependencySets.Add(PackageDependencySet(null, deps))
use fs = File.Create (sprintf "%s.%s%s" name version Constants.PackageExtension)
builder.Save fs
module Solr =
let private cmdline = "-DSTOP.PORT=8079 -DSTOP.KEY=secret -jar start.jar"
let start() =
Shell.AsyncExec("java", cmdline, dir = solr) |> Async.Ignore |> Async.Start
let watch = System.Diagnostics.Stopwatch.StartNew()
while httpGet "http://localhost:8983/solr/admin/ping" = null do
if watch.Elapsed > (TimeSpan.FromSeconds 10.)
then failwith "Solr test instance didn't work"
System.Threading.Thread.Sleep 500
{ new IDisposable with
member x.Dispose() =
Shell.Exec("java", cmdline + " --stop", dir = solr) |> ignore }
module Git =
let sha1() =
try
let headref = (File.ReadAllLines ".git\\HEAD").[0]
let headref = headref.Substring(5) // assume ref
(File.ReadAllLines (".git" @@ headref)).[0]
with :? DirectoryNotFoundException as e -> null