aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program/aedifex/pom.lux
blob: afcfc29f6402ee60e078ffd381489c764a92fb08 (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
(.require
 [library
  [lux (.except)
   [abstract
    [monad (.only do)]]
   [control
    ["<>" parser]
    ["[0]" pipe]
    ["[0]" maybe (.use "[1]#[0]" functor)]
    ["[0]" try (.only Try)]
    ["[0]" exception]]
   [data
    ["[0]" text]
    [format
     ["[0]" xml (.only Tag XML)
      ["<[1]>" \\parser (.only Parser)]]]
    [collection
     ["[0]" list (.use "[1]#[0]" monoid functor mix)]
     ["[0]" set]
     ["[0]" dictionary]]]
   [meta
    ["[0]" symbol]]
   [world
    ["[0]" file]]]]
 ["[0]" //
  ["/" profile]
  ["[1][0]" dependency (.only Dependency)]
  [repository
   [remote (.only Address)]]
  ["[1][0]" artifact (.only Artifact)
   ["[1]/[0]" type]]])

... https://maven.apache.org/pom.html

(def project_tag "project")
(def dependency_tag "dependency")
(def dependencies_tag "dependencies")
(def repositories_tag "repositories")
(def repository_tag "repository")
(def url_tag "url")
(def group_tag "groupId")
(def artifact_tag "artifactId")
(def version_tag "version")

(def .public file
  file.Path
  "pom.xml")

(def version
  XML
  {xml.#Node ["" "modelVersion"] xml.attributes
             (list {xml.#Text "4.0.0"})})

(def (property tag value)
  (-> Text Text XML)
  {xml.#Node ["" tag]
             xml.attributes
             (list {xml.#Text value})})

(def (artifact value)
  (-> Artifact (List XML))
  (list (..property ..group_tag (the //artifact.#group value))
        (..property ..artifact_tag (the //artifact.#name value))
        (..property ..version_tag (the //artifact.#version value))))

(def distribution
  (-> /.Distribution XML)
  (|>> (pipe.when
         {/.#Repo} "repo"
         {/.#Manual} "manual")
       (..property "distribution")))

(def (license [name url distribution])
  (-> /.License XML)
  (|> (list (..property "name" name)
            (..property ..url_tag url)
            (..distribution distribution))
      {xml.#Node ["" "license"] xml.attributes}))

(def repository
  (-> Address XML)
  (|>> (..property ..url_tag)
       list
       {xml.#Node ["" ..repository_tag] xml.attributes}))

(def (dependency value)
  (-> Dependency XML)
  {xml.#Node ["" ..dependency_tag]
             xml.attributes
             (list#composite (..artifact (the //dependency.#artifact value))
                             (list (..property "type" (the //dependency.#type value))))})

(def (group tag)
  (-> Text (-> (List XML) XML))
  (|>> {xml.#Node ["" tag] xml.attributes}))

(def scm
  (-> /.SCM XML)
  (|>> (..property ..url_tag)
       list
       {xml.#Node ["" "scm"] xml.attributes}))

(def (organization [name url])
  (-> /.Organization XML)
  (|> (list (..property "name" name)
            (..property ..url_tag url))
      {xml.#Node ["" "organization"] xml.attributes}))

(def (developer_organization [name url])
  (-> /.Organization (List XML))
  (list (..property "organization" name)
        (..property "organizationUrl" url)))

(def (developer' [name email organization])
  (-> /.Developer (List XML))
  (list.partial (..property "name" name)
                (..property "email" email)
                (|> organization (maybe#each ..developer_organization) (maybe.else (list)))))

(with_template [<name> <type> <tag>]
  [(def <name>
     (-> <type> XML)
     (|>> ..developer' {xml.#Node ["" <tag>] xml.attributes}))]

  [developer /.Developer "developer"]
  [contributor /.Contributor "contributor"]
  )

(def (info identity value)
  (-> Artifact /.Info (List XML))
  (all list#composite
       (|> identity (the //artifact.#name) (..property "name") list)
       (|> value (the /.#url) (maybe#each (..property ..url_tag)) maybe.list)
       (|> value (the /.#description) (maybe#each (..property "description")) maybe.list)
       (|> value (the /.#licenses) (list#each ..license) (..group "licenses") list)
       (|> value (the /.#scm) (maybe#each ..scm) maybe.list)
       (|> value (the /.#organization) (maybe#each ..organization) maybe.list)
       (|> value (the /.#developers) (list#each ..developer) (..group "developers") list)
       (|> value (the /.#contributors) (list#each ..contributor) (..group "contributors") list)
       ))

(def .public (write value)
  (-> /.Profile (Try XML))
  (when (the /.#identity value)
    {.#Some identity}
    {try.#Success
     {xml.#Node ["" ..project_tag]
                xml.attributes
                (all list#composite
                     (list ..version)
                     (..artifact identity)
                     (|> value
                         (the /.#info)
                         (maybe#each (..info identity))
                         (maybe.else (list)))
                     (|> value
                         (the /.#repositories)
                         set.list
                         (list#each ..repository)
                         (..group "repositories")
                         list)
                     (|> value
                         (the /.#dependencies)
                         set.list
                         (list#each ..dependency)
                         (..group ..dependencies_tag)
                         list)
                     )}}

    _
    (exception.except /.no_identity [])))

(def property_parser
  (Parser [Tag Text])
  (do [! <>.monad]
    [tag <xml>.tag]
    (<| (<xml>.node tag)
        (of ! each (|>> [tag]))
        <xml>.text)))

(def (dependency_parser own_version parent_version)
  (-> Text Text (Parser Dependency))
  (do [! <>.monad]
    [properties (of ! each (dictionary.of_list symbol.hash)
                    (<| (<xml>.node ["" ..dependency_tag])
                        (<>.some ..property_parser)))]
    (<| <>.of_try
        try.of_maybe
        (do maybe.monad
          [group (dictionary.value ["" ..group_tag] properties)
           artifact (dictionary.value ["" ..artifact_tag] properties)]
          (in [//dependency.#artifact [//artifact.#group group
                                       //artifact.#name artifact
                                       //artifact.#version (|> properties
                                                               (dictionary.value ["" ..version_tag])
                                                               (maybe.else "")
                                                               (text.replaced "${project.version}" own_version)
                                                               (text.replaced "${project.parent.version}" parent_version))]
               //dependency.#type (|> properties
                                      (dictionary.value ["" "type"])
                                      (maybe.else //artifact/type.jvm_library))])))))

(def (dependencies_parser own_version parent_version)
  (-> Text Text (Parser (List Dependency)))
  (<| (<xml>.node ["" ..dependencies_tag])
      (<>.some (..dependency_parser own_version parent_version))))

(def repository_parser
  (Parser Address)
  (<| (<xml>.node ["" ..repository_tag])
      (<xml>.node ["" ..url_tag])
      <xml>.text))

(def repositories_parser
  (Parser (List Address))
  (<| (<xml>.node ["" ..repositories_tag])
      (<>.some ..repository_parser)))

(def own_version
  (Parser Text)
  (<| (<xml>.node ["" ..version_tag])
      <xml>.text))

(def parent_version
  (Parser Text)
  (<| (<xml>.node ["" "parent"])
      ..own_version))

(def .public parser
  (Parser /.Profile)
  (do [! <>.monad]
    [own_version (<>.else "" (<xml>.somewhere ..own_version))
     parent_version (<>.else "" (<xml>.somewhere ..parent_version))]
    (<| (<xml>.node ["" ..project_tag])
        (do !
          [dependencies (|> (..dependencies_parser own_version parent_version)
                            <xml>.somewhere
                            (<>.else (list)))
           repositories (|> ..repositories_parser
                            <xml>.somewhere
                            (<>.else (list)))
           _ (<>.some <xml>.any)]
          (in (|> (of /.monoid identity)
                  (revised /.#dependencies (function (_ empty)
                                             (list#mix set.has empty dependencies)))
                  (revised /.#repositories (function (_ empty)
                                             (list#mix set.has empty repositories)))))))))