(.using [library [lux "*" [abstract [monad (.only do)]] [control ["[0]" pipe] ["[0]" maybe ("[1]#[0]" functor)] ["[0]" try (.only Try)] ["[0]" exception] ["<>" parser ["<[0]>" xml (.only Parser)]]] [data ["[0]" text] [format ["_" xml (.only Tag XML)]] [collection ["[0]" list ("[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 {_.#Node ["" "modelVersion"] _.attributes (list {_.#Text "4.0.0"})}) (def: (property tag value) (-> Text Text XML) {_.#Node ["" tag] _.attributes (list {_.#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.case {/.#Repo} "repo" {/.#Manual} "manual") (..property "distribution"))) (def: (license [name url distribution]) (-> /.License XML) (|> (list (..property "name" name) (..property ..url_tag url) (..distribution distribution)) {_.#Node ["" "license"] _.attributes})) (def: repository (-> Address XML) (|>> (..property ..url_tag) list {_.#Node ["" ..repository_tag] _.attributes})) (def: (dependency value) (-> Dependency XML) {_.#Node ["" ..dependency_tag] _.attributes (list#composite (..artifact (the //dependency.#artifact value)) (list (..property "type" (the //dependency.#type value))))}) (def: (group tag) (-> Text (-> (List XML) XML)) (|>> {_.#Node ["" tag] _.attributes})) (def: scm (-> /.SCM XML) (|>> (..property ..url_tag) list {_.#Node ["" "scm"] _.attributes})) (def: (organization [name url]) (-> /.Organization XML) (|> (list (..property "name" name) (..property ..url_tag url)) {_.#Node ["" "organization"] _.attributes})) (def: (developer_organization [name url]) (-> /.Organization (List XML)) (list (..property "organization" name) (..property "organizationUrl" url))) (def: (developer' [name email organization]) (-> /.Developer (List XML)) (partial_list (..property "name" name) (..property "email" email) (|> organization (maybe#each ..developer_organization) (maybe.else (list))))) (template [ ] [(def: (-> XML) (|>> ..developer' {_.#Node ["" ] _.attributes}))] [developer /.Developer "developer"] [contributor /.Contributor "contributor"] ) (def: (info value) (-> /.Info (List XML)) (all list#composite (|> value (the /.#name) (maybe#each (..property "name")) maybe.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)) (case (the /.#identity value) {.#Some identity} {try.#Success {_.#Node ["" ..project_tag] _.attributes (all list#composite (list ..version) (..artifact identity) (|> value (the /.#info) (maybe#each ..info) (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 .tag] (<| (.node tag) (# ! each (|>> [tag])) .text))) (def: (dependency_parser own_version parent_version) (-> Text Text (Parser Dependency)) (do [! <>.monad] [properties (# ! each (dictionary.of_list symbol.hash) (<| (.node ["" ..dependency_tag]) (<>.some ..property_parser)))] (<| <>.lifted 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))) (<| (.node ["" ..dependencies_tag]) (<>.some (..dependency_parser own_version parent_version)))) (def: repository_parser (Parser Address) (<| (.node ["" ..repository_tag]) (.node ["" ..url_tag]) .text)) (def: repositories_parser (Parser (List Address)) (<| (.node ["" ..repositories_tag]) (<>.some ..repository_parser))) (def: own_version (Parser Text) (<| (.node ["" ..version_tag]) .text)) (def: parent_version (Parser Text) (<| (.node ["" "parent"]) ..own_version)) (def: .public parser (Parser /.Profile) (do [! <>.monad] [own_version (<>.else "" (.somewhere ..own_version)) parent_version (<>.else "" (.somewhere ..parent_version))] (<| (.node ["" ..project_tag]) (do ! [dependencies (|> (..dependencies_parser own_version parent_version) .somewhere (<>.else (list))) repositories (|> ..repositories_parser .somewhere (<>.else (list))) _ (<>.some .any)] (in (|> (# /.monoid identity) (revised /.#dependencies (function (_ empty) (list#mix set.has empty dependencies))) (revised /.#repositories (function (_ empty) (list#mix set.has empty repositories)))))))))