blob: 15d9a9323906816db2290ccdc465230b6c079477 (
plain)
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
78
79
80
81
82
83
84
85
86
|
(.module:
[lux #*
[abstract
["." monad (#+ do)]]
[control
["." io (#+ IO)]
["." try (#+ Try)]
[concurrency
["." promise (#+ Promise)]]
[security
["!" capability]]]
[data
[binary (#+ Binary)]
["." text
["%" format (#+ format)]
["." encoding]]
[collection
["." list ("#@." monoid)]]
[format
["." binary]
["." tar]
["." xml]]]
[world
["." file (#+ Path File Directory)]]]
[program
[compositor
["." export]]]
["." // #_
["#." project (#+ Project)]
["#." pom]
["#." dependency]])
(def: group-separator
".")
(def: (local system)
(All [a] (-> (file.System a) Path))
(format "~" (:: system separator) ".m2"))
(def: (repository system)
(All [a] (-> (file.System a) Path))
(format (..local system) (:: system separator) "repository"))
(def: (guarantee-repository! system project)
(-> (file.System Promise) Project (Promise (Try Path)))
(do {@ (try.with promise.monad)}
[_ (: (Promise (Try (Directory Promise)))
(file.get-directory promise.monad system (..local system)))
#let [root (..repository system)
identity (get@ #//project.identity project)]
_ (: (Promise (Try (Directory Promise)))
(file.get-directory promise.monad system root))]
(monad.fold @
(function (_ child parent)
(do @
[#let [path (format parent (:: system separator) child)]
_ (: (Promise (Try (Directory Promise)))
(file.get-directory promise.monad system path))]
(wrap path)))
root
(list@compose (|> identity
(get@ #//project.group)
(text.split-all-with ..group-separator))
(list (get@ #//project.name identity)
(get@ #//project.version identity))))))
(def: (save! system content file)
(-> (file.System Promise) Binary Path (Promise (Try Any)))
(do (try.with promise.monad)
[file (: (Promise (Try (File Promise)))
(file.get-file promise.monad system file))]
(!.use (:: file over-write) [content])))
(def: #export (install system project)
(-> (file.System Promise) Project (Promise (Try Any)))
(do (try.with promise.monad)
[repository (..guarantee-repository! system project)
#let [identity (get@ #//project.identity project)
artifact-name (format repository
(:: system separator) (get@ #//project.name identity)
"-" (get@ #//project.version identity))]
package (export.library system (get@ #//project.sources project))
_ (..save! system (binary.run tar.writer package)
(format artifact-name "." //dependency.lux-library))]
(..save! system (|> project //pom.project (:: xml.codec encode) encoding.to-utf8)
(format artifact-name //pom.extension))))
|