aboutsummaryrefslogtreecommitdiff
path: root/stdlib/source/program
diff options
context:
space:
mode:
Diffstat (limited to 'stdlib/source/program')
-rw-r--r--stdlib/source/program/aedifex.lux5
-rw-r--r--stdlib/source/program/aedifex/artifact.lux48
-rw-r--r--stdlib/source/program/aedifex/artifact/extension.lux34
-rw-r--r--stdlib/source/program/aedifex/artifact/type.lux2
-rw-r--r--stdlib/source/program/aedifex/command/build.lux21
-rw-r--r--stdlib/source/program/aedifex/command/deploy.lux11
-rw-r--r--stdlib/source/program/aedifex/dependency.lux234
-rw-r--r--stdlib/source/program/aedifex/dependency/resolution.lux184
-rw-r--r--stdlib/source/program/aedifex/local.lux43
-rw-r--r--stdlib/source/program/aedifex/pom.lux168
10 files changed, 389 insertions, 361 deletions
diff --git a/stdlib/source/program/aedifex.lux b/stdlib/source/program/aedifex.lux
index c2fa69e11..f23ac26da 100644
--- a/stdlib/source/program/aedifex.lux
+++ b/stdlib/source/program/aedifex.lux
@@ -37,7 +37,8 @@
["#." pom]
["#." cli]
["#." local]
- ["#." dependency]
+ ["#." dependency #_
+ ["#" resolution]]
[command
["#." build]
["#." test]
@@ -68,7 +69,7 @@
(-> Path /.Profile (IO (Try Any)))
(do (try.with io.monad)
[file (!.use (:: file.system file) [path])
- pom (:: io.monad wrap (/pom.project profile))]
+ pom (:: io.monad wrap (/pom.write profile))]
(|> pom
(:: xml.codec encode)
encoding.to-utf8
diff --git a/stdlib/source/program/aedifex/artifact.lux b/stdlib/source/program/aedifex/artifact.lux
index 47a9027d0..dc0892eb1 100644
--- a/stdlib/source/program/aedifex/artifact.lux
+++ b/stdlib/source/program/aedifex/artifact.lux
@@ -5,7 +5,7 @@
["." hash (#+ Hash)]]
[data
["." text
- ["%" format (#+ format)]]
+ ["%" format (#+ Format)]]
[collection
["." list ("#@." monoid)]]]
[world
@@ -42,31 +42,41 @@
text.hash
))
-(def: group-separator
- ".")
+(template [<separator> <definition>]
+ [(def: <definition>
+ Text
+ <separator>)]
-(def: version-separator
- "-")
+ ["." group-separator]
+ ["-" version-separator]
+ [":" identity-separator]
+ )
(def: #export (identity artifact)
(-> Artifact Text)
- (format (get@ #name artifact)
- ..version-separator
- (get@ #version artifact)))
+ (%.format (get@ #name artifact)
+ ..version-separator
+ (get@ #version artifact)))
+
+(def: #export (format value)
+ (Format Artifact)
+ (%.format (get@ #group value)
+ ..identity-separator
+ (..identity value)))
(def: #export (path artifact)
(-> Artifact Text)
- (let [directory (format (|> artifact
- (get@ #group)
- (text.split-all-with ..group-separator)
- (text.join-with uri.separator))
- uri.separator
- (get@ #name artifact)
- uri.separator
- (get@ #version artifact))]
- (format directory
- uri.separator
- (..identity artifact))))
+ (let [directory (%.format (|> artifact
+ (get@ #group)
+ (text.split-all-with ..group-separator)
+ (text.join-with uri.separator))
+ uri.separator
+ (get@ #name artifact)
+ uri.separator
+ (get@ #version artifact))]
+ (%.format directory
+ uri.separator
+ (..identity artifact))))
(def: #export (local artifact)
(-> Artifact (List Text))
diff --git a/stdlib/source/program/aedifex/artifact/extension.lux b/stdlib/source/program/aedifex/artifact/extension.lux
index 04d40fec4..412bf699a 100644
--- a/stdlib/source/program/aedifex/artifact/extension.lux
+++ b/stdlib/source/program/aedifex/artifact/extension.lux
@@ -2,7 +2,9 @@
[lux #*
[data
[text
- ["%" format (#+ format)]]]]
+ ["%" format (#+ format)]]]
+ [macro
+ ["." template]]]
["." // #_
["#" type]])
@@ -16,22 +18,14 @@
(-> //.Type Extension)
(|>> (format ..separator)))
-(def: #export lux-library
- Extension
- (..extension //.lux-library))
-
-(def: #export jvm-library
- Extension
- (..extension //.jvm-library))
-
-(def: #export pom
- Extension
- (..extension //.pom))
-
-(def: #export sha1
- Extension
- (format ..separator "sha1"))
-
-(def: #export md5
- Extension
- (format ..separator "md5"))
+(template [<name>]
+ [(def: #export <name>
+ Extension
+ (..extension (template.identifier [//._] [<name>])))]
+
+ [lux-library]
+ [jvm-library]
+ [pom]
+ [sha1]
+ [md5]
+ )
diff --git a/stdlib/source/program/aedifex/artifact/type.lux b/stdlib/source/program/aedifex/artifact/type.lux
index e5836d13f..35035ebc4 100644
--- a/stdlib/source/program/aedifex/artifact/type.lux
+++ b/stdlib/source/program/aedifex/artifact/type.lux
@@ -13,4 +13,6 @@
["tar" lux-library]
["jar" jvm-library]
["pom" pom]
+ ["sha1" sha1]
+ ["md5" md5]
)
diff --git a/stdlib/source/program/aedifex/command/build.lux b/stdlib/source/program/aedifex/command/build.lux
index 2c4b26aed..6a1ab93d4 100644
--- a/stdlib/source/program/aedifex/command/build.lux
+++ b/stdlib/source/program/aedifex/command/build.lux
@@ -25,7 +25,8 @@
["#." action]
["#." command (#+ Command)]
["#." local]
- ["#." dependency (#+ Dependency Resolution)]
+ ["#." dependency (#+ Dependency)
+ ["#/." resolution (#+ Resolution)]]
["#." shell]
["#." artifact (#+ Group Name Artifact)
["#/." type]]])
@@ -36,11 +37,11 @@
(def: (dependency-finder group name)
(-> Group Name Finder)
(|>> dictionary.entries
- (list.search (function (_ [dependency package])
- (if (and (text@= group (get@ [#///dependency.artifact #///artifact.group] dependency))
- (text@= name (get@ [#///dependency.artifact #///artifact.name] dependency)))
- (#.Some dependency)
- #.None)))))
+ (list.one (function (_ [dependency package])
+ (if (and (text@= group (get@ [#///dependency.artifact #///artifact.group] dependency))
+ (text@= name (get@ [#///dependency.artifact #///artifact.name] dependency)))
+ (#.Some dependency)
+ #.None)))))
(def: lux-group
Group
@@ -125,11 +126,11 @@
(do ///action.monad
[cache (///local.all-cached (file.async file.system)
(set.to-list (get@ #///.dependencies profile))
- ///dependency.empty)
+ ///dependency/resolution.empty)
resolution (promise.future
- (///dependency.resolve-all (set.to-list (get@ #///.repositories profile))
- (set.to-list (get@ #///.dependencies profile))
- cache))
+ (///dependency/resolution.resolve-all (set.to-list (get@ #///.repositories profile))
+ (set.to-list (get@ #///.dependencies profile))
+ cache))
_ (///local.cache-all (file.async file.system)
resolution)
[resolution compiler] (promise@wrap (..compiler resolution))
diff --git a/stdlib/source/program/aedifex/command/deploy.lux b/stdlib/source/program/aedifex/command/deploy.lux
index b63aa2972..d7c7802b7 100644
--- a/stdlib/source/program/aedifex/command/deploy.lux
+++ b/stdlib/source/program/aedifex/command/deploy.lux
@@ -28,11 +28,12 @@
["//" upload (#+ User Password)]
["#." action (#+ Action)]
["#." command (#+ Command)]
- ["#." dependency]
["#." pom]
["#." hash]
["#." artifact
- ["#/." type]]])
+ ["#/." type]]
+ ["#." dependency
+ ["#/." resolution]]])
(exception: #export (cannot-find-repository {repository Text}
{options (Dictionary Text ///dependency.Repository)})
@@ -66,9 +67,9 @@
[library (:: @ map (binary.run tar.writer)
(export.library (file.async file.system)
(set.to-list (get@ #/.sources profile))))
- pom (promise@wrap (///pom.project profile))
+ pom (promise@wrap (///pom.write profile))
_ (deploy! ///artifact/type.pom (|> pom (:: xml.codec encode) encoding.to-utf8))
_ (deploy! ///artifact/type.lux-library library)
- _ (deploy! "sha1" (///hash.data (///hash.sha1 library)))
- _ (deploy! "md5" (///hash.data (///hash.md5 library)))]
+ _ (deploy! ///artifact/type.sha1 (///hash.data (///hash.sha1 library)))
+ _ (deploy! ///artifact/type.md5 (///hash.data (///hash.md5 library)))]
(wrap [])))))
diff --git a/stdlib/source/program/aedifex/dependency.lux b/stdlib/source/program/aedifex/dependency.lux
index de6a1e4cf..cdd0789ff 100644
--- a/stdlib/source/program/aedifex/dependency.lux
+++ b/stdlib/source/program/aedifex/dependency.lux
@@ -1,46 +1,22 @@
(.module:
- [lux (#- Name)
- ["." host (#+ import:)]
+ [lux (#- Type)
[abstract
- [codec (#+ Codec)]
- [monad (#+ do)]
["." equivalence (#+ Equivalence)]
["." hash (#+ Hash)]]
- [control
- ["." io (#+ IO)]
- ["." try (#+ Try)]
- ["." exception (#+ Exception exception:)]
- ["<>" parser
- ["<xml>" xml (#+ Parser)]]]
[data
- ["." binary (#+ Binary)]
- ["." name]
- ["." maybe]
- ["." text
- ["%" format (#+ format)]
- ["." encoding]]
- [number
- ["." i64]
- ["n" nat]]
- [format
- ["." xml (#+ Tag XML)]]
- [collection
- ["." dictionary (#+ Dictionary)]]]
+ ["." text]]
[world
- [net (#+ URL)
- ["." uri]]]]
+ [net (#+ URL)]]]
["." // #_
- ["#." hash]
["#." artifact (#+ Artifact)
- ["#/." type]
- ["#/." extension]]])
+ [type (#+ Type)]]])
(type: #export Repository
URL)
(type: #export Dependency
{#artifact Artifact
- #type //artifact/type.Type})
+ #type Type})
(def: #export equivalence
(Equivalence Dependency)
@@ -55,203 +31,3 @@
//artifact.hash
text.hash
))
-
-(import: java/lang/String)
-
-(import: java/lang/AutoCloseable
- (close [] #io #try void))
-
-(import: java/io/InputStream)
-
-(import: java/net/URL
- (new [java/lang/String])
- (openStream [] #io #try java/io/InputStream))
-
-(import: java/io/BufferedInputStream
- (new [java/io/InputStream])
- (read [[byte] int int] #io #try int))
-
-(def: buffer-size
- (n.* 512 1,024))
-
-(def: (download url)
- (-> URL (IO (Try Binary)))
- (do {@ (try.with io.monad)}
- [input (|> (java/net/URL::new url)
- java/net/URL::openStream
- (:: @ map (|>> java/io/BufferedInputStream::new)))
- #let [buffer (binary.create ..buffer-size)]]
- (loop [output (:: binary.monoid identity)]
- (do @
- [bytes-read (java/io/BufferedInputStream::read buffer +0 (.int ..buffer-size) input)]
- (case bytes-read
- -1 (do @
- [_ (java/lang/AutoCloseable::close input)]
- (wrap output))
- _ (if (n.= ..buffer-size bytes-read)
- (recur (:: binary.monoid compose output buffer))
- (do @
- [chunk (:: io.monad wrap (binary.slice 0 (.nat bytes-read) buffer))]
- (recur (:: binary.monoid compose output chunk)))))))))
-
-(template [<name>]
- [(exception: #export (<name> {dependency Dependency} {hash Text})
- (let [artifact (get@ #artifact dependency)
- type (get@ #type dependency)]
- (exception.report
- ["Artifact" (format (get@ #//artifact.group artifact)
- " " (get@ #//artifact.name artifact)
- " " (get@ #//artifact.version artifact))]
- ["Type" (%.text type)]
- ["Hash" (%.text hash)])))]
-
- [sha1-does-not-match]
- [md5-does-not-match]
- )
-
-(type: #export Package
- {#library Binary
- #pom XML
- #dependencies (List Dependency)
- #sha1 Text
- #md5 Text})
-
-(def: (verified-hash dependency library url hash codec exception)
- (All [h]
- (-> Dependency Binary URL
- (-> Binary (//hash.Hash h)) (Codec Text (//hash.Hash h))
- (Exception [Dependency Text])
- (IO (Try Text))))
- (do (try.with io.monad)
- [#let [expected (hash library)]
- actual (..download url)]
- (:: io.monad wrap
- (do try.monad
- [output (encoding.from-utf8 actual)
- actual (:: codec decode output)
- _ (exception.assert exception [dependency output]
- (:: //hash.equivalence = expected actual))]
- (wrap output)))))
-
-(def: parse-property
- (Parser [Tag Text])
- (do <>.monad
- [property <xml>.tag
- _ (<xml>.node property)
- value (<xml>.children <xml>.text)]
- (wrap [property value])))
-
-(def: parse-dependency
- (Parser Dependency)
- (do {@ <>.monad}
- [properties (:: @ map (dictionary.from-list name.hash)
- (<xml>.children (<>.some ..parse-property)))]
- (<| <>.lift
- try.from-maybe
- (do maybe.monad
- [group (dictionary.get ["" "groupId"] properties)
- artifact (dictionary.get ["" "artifactId"] properties)
- version (dictionary.get ["" "version"] properties)]
- (wrap {#artifact {#//artifact.group group
- #//artifact.name artifact
- #//artifact.version version}
- #type (|> properties
- (dictionary.get ["" "type"])
- (maybe.default //artifact/type.lux-library))})))))
-
-(def: parse-dependencies
- (Parser (List Dependency))
- (do {@ <>.monad}
- [_ (<xml>.node ["" "dependencies"])]
- (<xml>.children (<>.some ..parse-dependency))))
-
-(def: #export from-pom
- (-> XML (Try (List Dependency)))
- (<xml>.run (do {@ <>.monad}
- [_ (<xml>.node ["" "project"])]
- (<xml>.children (loop [_ []]
- (do @
- [?dependencies (<>.or ..parse-dependencies
- (<>.maybe <xml>.ignore))]
- (case ?dependencies
- (#.Left dependencies)
- (wrap dependencies)
-
- (#.Right #.None)
- (wrap (: (List Dependency)
- (list)))
-
- (#.Right (#.Some _))
- (recur []))))))))
-
-(def: #export (resolve repository dependency)
- (-> Repository Dependency (IO (Try Package)))
- (let [[artifact type] dependency
- prefix (format repository uri.separator (//artifact.path artifact))]
- (do (try.with io.monad)
- [library (..download (format prefix (//artifact/extension.extension type)))
- sha1 (..verified-hash dependency library (format prefix //artifact/extension.sha1) //hash.sha1 //hash.sha1-codec ..sha1-does-not-match)
- md5 (..verified-hash dependency library (format prefix //artifact/extension.md5) //hash.md5 //hash.md5-codec ..md5-does-not-match)
- pom (..download (format prefix //artifact/extension.pom))]
- (:: io.monad wrap
- (do try.monad
- [pom (encoding.from-utf8 pom)
- pom (:: xml.codec decode pom)
- dependencies (..from-pom pom)]
- (wrap {#library library
- #pom pom
- #dependencies dependencies
- #sha1 sha1
- #md5 md5}))))))
-
-(type: #export Resolution
- (Dictionary Dependency Package))
-
-(def: #export empty
- Resolution
- (dictionary.new ..hash))
-
-(exception: #export (cannot-resolve {dependency Dependency})
- (let [artifact (get@ #artifact dependency)
- type (get@ #type dependency)]
- (exception.report
- ["Artifact" (format (get@ #//artifact.group artifact)
- " " (get@ #//artifact.name artifact)
- " " (get@ #//artifact.version artifact))]
- ["Type" (%.text type)])))
-
-(def: (resolve-any repositories dependency)
- (-> (List Repository) Dependency (IO (Try Package)))
- (case repositories
- #.Nil
- (|> dependency
- (exception.throw ..cannot-resolve)
- (:: io.monad wrap))
-
- (#.Cons repository alternatives)
- (do io.monad
- [outcome (..resolve repository dependency)]
- (case outcome
- (#try.Success package)
- (wrap outcome)
-
- (#try.Failure error)
- (resolve-any alternatives dependency)))))
-
-(def: #export (resolve-all repositories dependencies resolution)
- (-> (List Repository) (List Dependency) Resolution (IO (Try Resolution)))
- (case dependencies
- #.Nil
- (:: (try.with io.monad) wrap resolution)
-
- (#.Cons head tail)
- (do (try.with io.monad)
- [package (case (dictionary.get head resolution)
- (#.Some package)
- (wrap package)
-
- #.None
- (..resolve-any repositories head))
- #let [resolution (dictionary.put head package resolution)]
- resolution (resolve-all repositories (get@ #dependencies package) resolution)]
- (resolve-all repositories tail resolution))))
diff --git a/stdlib/source/program/aedifex/dependency/resolution.lux b/stdlib/source/program/aedifex/dependency/resolution.lux
new file mode 100644
index 000000000..57df92d2a
--- /dev/null
+++ b/stdlib/source/program/aedifex/dependency/resolution.lux
@@ -0,0 +1,184 @@
+(.module:
+ [lux (#- Name)
+ ["." host (#+ import:)]
+ [abstract
+ [codec (#+ Codec)]
+ [monad (#+ do)]]
+ [control
+ ["." io (#+ IO)]
+ ["." try (#+ Try)]
+ ["." exception (#+ Exception exception:)]
+ ["<>" parser
+ ["<.>" xml (#+ Parser)]]]
+ [data
+ ["." binary (#+ Binary)]
+ ["." name]
+ ["." maybe]
+ [text
+ ["%" format (#+ format)]
+ ["." encoding]]
+ [number
+ ["." i64]
+ ["n" nat]]
+ [format
+ ["." xml (#+ Tag XML)]]
+ [collection
+ ["." dictionary (#+ Dictionary)]
+ ["." set]]]
+ [world
+ [net (#+ URL)
+ ["." uri]]]]
+ ["." // (#+ Repository Dependency)
+ ["/#" // #_
+ ["/" profile]
+ ["#." hash]
+ ["#." pom]
+ ["#." artifact
+ ["#/." extension]]]])
+
+(import: java/lang/String)
+
+(import: java/lang/AutoCloseable
+ (close [] #io #try void))
+
+(import: java/io/InputStream)
+
+(import: java/net/URL
+ (new [java/lang/String])
+ (openStream [] #io #try java/io/InputStream))
+
+(import: java/io/BufferedInputStream
+ (new [java/io/InputStream])
+ (read [[byte] int int] #io #try int))
+
+(def: buffer-size
+ (n.* 512 1,024))
+
+(def: (download url)
+ (-> URL (IO (Try Binary)))
+ (do {@ (try.with io.monad)}
+ [input (|> (java/net/URL::new url)
+ java/net/URL::openStream
+ (:: @ map (|>> java/io/BufferedInputStream::new)))
+ #let [buffer (binary.create ..buffer-size)]]
+ (loop [output (:: binary.monoid identity)]
+ (do @
+ [bytes-read (java/io/BufferedInputStream::read buffer +0 (.int ..buffer-size) input)]
+ (case bytes-read
+ -1 (do @
+ [_ (java/lang/AutoCloseable::close input)]
+ (wrap output))
+ _ (if (n.= ..buffer-size bytes-read)
+ (recur (:: binary.monoid compose output buffer))
+ (do @
+ [chunk (:: io.monad wrap (binary.slice 0 (.nat bytes-read) buffer))]
+ (recur (:: binary.monoid compose output chunk)))))))))
+
+(template [<name>]
+ [(exception: #export (<name> {dependency Dependency} {hash Text})
+ (let [artifact (get@ #//.artifact dependency)
+ type (get@ #//.type dependency)]
+ (exception.report
+ ["Artifact" (format (get@ #///artifact.group artifact)
+ " " (get@ #///artifact.name artifact)
+ " " (get@ #///artifact.version artifact))]
+ ["Type" (%.text type)]
+ ["Hash" (%.text hash)])))]
+
+ [sha1-does-not-match]
+ [md5-does-not-match]
+ )
+
+(type: #export Package
+ {#library Binary
+ #pom XML
+ #dependencies (List Dependency)
+ #sha1 Text
+ #md5 Text})
+
+(def: (verified-hash dependency library url hash codec exception)
+ (All [h]
+ (-> Dependency Binary URL
+ (-> Binary (///hash.Hash h)) (Codec Text (///hash.Hash h))
+ (Exception [Dependency Text])
+ (IO (Try Text))))
+ (do (try.with io.monad)
+ [#let [expected (hash library)]
+ actual (..download url)]
+ (:: io.monad wrap
+ (do try.monad
+ [output (encoding.from-utf8 actual)
+ actual (:: codec decode output)
+ _ (exception.assert exception [dependency output]
+ (:: ///hash.equivalence = expected actual))]
+ (wrap output)))))
+
+(def: #export (resolve repository dependency)
+ (-> Repository Dependency (IO (Try Package)))
+ (let [[artifact type] dependency
+ prefix (format repository uri.separator (///artifact.path artifact))]
+ (do (try.with io.monad)
+ [library (..download (format prefix (///artifact/extension.extension type)))
+ sha1 (..verified-hash dependency library (format prefix ///artifact/extension.sha1) ///hash.sha1 ///hash.sha1-codec ..sha1-does-not-match)
+ md5 (..verified-hash dependency library (format prefix ///artifact/extension.md5) ///hash.md5 ///hash.md5-codec ..md5-does-not-match)
+ pom (..download (format prefix ///artifact/extension.pom))]
+ (:: io.monad wrap
+ (do try.monad
+ [pom (encoding.from-utf8 pom)
+ pom (:: xml.codec decode pom)
+ profile (<xml>.run ///pom.parser pom)]
+ (wrap {#library library
+ #pom pom
+ #dependencies (set.to-list (get@ #/.dependencies profile))
+ #sha1 sha1
+ #md5 md5}))))))
+
+(type: #export Resolution
+ (Dictionary Dependency Package))
+
+(def: #export empty
+ Resolution
+ (dictionary.new //.hash))
+
+(exception: #export (cannot-resolve {dependency Dependency})
+ (let [artifact (get@ #//.artifact dependency)
+ type (get@ #//.type dependency)]
+ (exception.report
+ ["Artifact" (%.text (///artifact.format artifact))]
+ ["Type" (%.text type)])))
+
+(def: (resolve-any repositories dependency)
+ (-> (List Repository) Dependency (IO (Try Package)))
+ (case repositories
+ #.Nil
+ (|> dependency
+ (exception.throw ..cannot-resolve)
+ (:: io.monad wrap))
+
+ (#.Cons repository alternatives)
+ (do io.monad
+ [outcome (..resolve repository dependency)]
+ (case outcome
+ (#try.Success package)
+ (wrap outcome)
+
+ (#try.Failure error)
+ (resolve-any alternatives dependency)))))
+
+(def: #export (resolve-all repositories dependencies resolution)
+ (-> (List Repository) (List Dependency) Resolution (IO (Try Resolution)))
+ (case dependencies
+ #.Nil
+ (:: (try.with io.monad) wrap resolution)
+
+ (#.Cons head tail)
+ (do (try.with io.monad)
+ [package (case (dictionary.get head resolution)
+ (#.Some package)
+ (wrap package)
+
+ #.None
+ (..resolve-any repositories head))
+ #let [resolution (dictionary.put head package resolution)]
+ resolution (resolve-all repositories (get@ #dependencies package) resolution)]
+ (resolve-all repositories tail resolution))))
diff --git a/stdlib/source/program/aedifex/local.lux b/stdlib/source/program/aedifex/local.lux
index 626996ef3..bc2dbfb91 100644
--- a/stdlib/source/program/aedifex/local.lux
+++ b/stdlib/source/program/aedifex/local.lux
@@ -9,7 +9,9 @@
[concurrency
["." promise (#+ Promise)]]
[security
- ["!" capability]]]
+ ["!" capability]]
+ ["<>" parser
+ ["<.>" xml]]]
[data
[binary (#+ Binary)]
["." text
@@ -31,11 +33,12 @@
["." // #_
["/" profile (#+ Profile)]
["#." pom]
- ["#." dependency (#+ Package Resolution Dependency)]
["#." hash]
["#." artifact (#+ Artifact)
["#/." type]
- ["#/." extension]]])
+ ["#/." extension]]
+ ["#." dependency (#+ Dependency)
+ ["#/." resolution (#+ Package Resolution)]]])
(def: (local system)
(All [a] (-> (file.System a) Path))
@@ -80,7 +83,7 @@
package (export.library system (set.to-list (get@ #/.sources profile)))
_ (..save! system (binary.run tar.writer package)
(format artifact-name //artifact/extension.lux-library))
- pom (:: promise.monad wrap (//pom.project profile))]
+ pom (:: promise.monad wrap (//pom.write profile))]
(..save! system (|> pom (:: xml.codec encode) encoding.to-utf8)
(format artifact-name //artifact/extension.pom)))
@@ -95,16 +98,16 @@
directory (: (Promise (Try (Directory Promise)))
(file.get-directory promise.monad system directory))
_ (..save! system
- (get@ #//dependency.library package)
+ (get@ #//dependency/resolution.library package)
(format prefix (//artifact/extension.extension type)))
_ (..save! system
- (encoding.to-utf8 (get@ #//dependency.sha1 package))
+ (encoding.to-utf8 (get@ #//dependency/resolution.sha1 package))
(format prefix //artifact/extension.sha1))
_ (..save! system
- (encoding.to-utf8 (get@ #//dependency.md5 package))
+ (encoding.to-utf8 (get@ #//dependency/resolution.md5 package))
(format prefix //artifact/extension.md5))
_ (..save! system
- (|> package (get@ #//dependency.pom) (:: xml.codec encode) encoding.to-utf8)
+ (|> package (get@ #//dependency/resolution.pom) (:: xml.codec encode) encoding.to-utf8)
(format prefix //artifact/extension.pom))]
(wrap [])))
@@ -133,20 +136,20 @@
(do try.monad
[pom (encoding.from-utf8 pom)
pom (:: xml.codec decode pom)
- dependencies (//dependency.from-pom pom)]
- (wrap [pom dependencies])))
+ profile (<xml>.run //pom.parser pom)]
+ (wrap [pom (set.to-list (get@ #/.dependencies profile))])))
library (..read! system (format prefix (//artifact/extension.extension type)))
sha1 (..read! system (format prefix //artifact/extension.sha1))
md5 (..read! system (format prefix //artifact/extension.md5))]
- (wrap {#//dependency.library library
- #//dependency.pom pom
- #//dependency.dependencies dependencies
- #//dependency.sha1 (|> sha1
- (:coerce (//hash.Hash //hash.SHA-1))
- (:: //hash.sha1-codec encode))
- #//dependency.md5 (|> md5
- (:coerce (//hash.Hash //hash.MD5))
- (:: //hash.md5-codec encode))})))
+ (wrap {#//dependency/resolution.library library
+ #//dependency/resolution.pom pom
+ #//dependency/resolution.dependencies dependencies
+ #//dependency/resolution.sha1 (|> sha1
+ (:coerce (//hash.Hash //hash.SHA-1))
+ (:: //hash.sha1-codec encode))
+ #//dependency/resolution.md5 (|> md5
+ (:coerce (//hash.Hash //hash.MD5))
+ (:: //hash.md5-codec encode))})))
(def: #export (all-cached system dependencies resolution)
(-> (file.System Promise) (List Dependency) Resolution (Promise (Try Resolution)))
@@ -167,7 +170,7 @@
(#try.Success package)
(let [resolution (dictionary.put head package resolution)]
(do (try.with promise.monad)
- [resolution (all-cached system (get@ #//dependency.dependencies package) resolution)]
+ [resolution (all-cached system (get@ #//dependency/resolution.dependencies package) resolution)]
<next>))
(#try.Failure error)
diff --git a/stdlib/source/program/aedifex/pom.lux b/stdlib/source/program/aedifex/pom.lux
index 9370620f5..4f7d8a4fd 100644
--- a/stdlib/source/program/aedifex/pom.lux
+++ b/stdlib/source/program/aedifex/pom.lux
@@ -1,23 +1,36 @@
(.module:
[lux #*
+ [abstract
+ [monad (#+ do)]]
[control
[pipe (#+ case>)]
["." try (#+ Try)]
- ["." exception]]
+ ["." exception]
+ ["<>" parser
+ ["<xml>" xml (#+ Parser)]]]
[data
+ ["." name]
["." maybe ("#@." functor)]
[format
- ["_" xml (#+ XML)]]
+ ["_" xml (#+ Tag XML)]]
[collection
- ["." list ("#@." monoid functor)]
- ["." set]]]]
+ ["." list ("#@." monoid functor fold)]
+ ["." set]
+ ["." dictionary]]]]
["." // #_
["/" profile]
- ["#." artifact (#+ Artifact)]
- ["#." dependency (#+ Repository Dependency)]])
+ ["#." dependency (#+ Repository Dependency)]
+ ["#." artifact (#+ Artifact)
+ ["#/." type]]])
## https://maven.apache.org/pom.html
+(def: project-tag "project")
+(def: dependencies-tag "dependencies")
+(def: group-tag "groupId")
+(def: artifact-tag "artifactId")
+(def: version-tag "version")
+
(def: #export file
"pom.xml")
@@ -34,9 +47,9 @@
(def: (artifact value)
(-> Artifact (List XML))
- (list (..property "groupId" (get@ #//artifact.group value))
- (..property "artifactId" (get@ #//artifact.name value))
- (..property "version" (get@ #//artifact.version value))))
+ (list (..property ..group-tag (get@ #//artifact.group value))
+ (..property ..artifact-tag (get@ #//artifact.name value))
+ (..property ..version-tag (get@ #//artifact.version value))))
(def: distribution
(-> /.Distribution XML)
@@ -64,66 +77,109 @@
(list@compose (..artifact (get@ #//dependency.artifact value))
(list (..property "type" (get@ #//dependency.type value))))))
-(def: scm
- (-> /.SCM XML)
- (|>> (..property "url")
- list
- (#_.Node ["" "scm"] _.attrs)))
-
-(def: (organization [name url])
- (-> /.Organization XML)
- (|> (list (..property "name" name)
- (..property "url" url))
- (#_.Node ["" "organization"] _.attrs)))
-
-(def: (developer-organization [name url])
- (-> /.Organization (List XML))
- (list (..property "organization" name)
- (..property "organizationUrl" url)))
-
-(def: (developer' [name email organization])
- (-> /.Developer (List XML))
- (list& (..property "name" name)
- (..property "email" email)
- (|> organization (maybe@map ..developer-organization) (maybe.default (list)))))
-
-(template [<name> <type> <tag>]
- [(def: <name>
- (-> <type> XML)
- (|>> ..developer' (#_.Node ["" <tag>] _.attrs)))]
-
- [developer /.Developer "developer"]
- [contributor /.Contributor "contributor"]
- )
-
(def: (group tag)
(-> Text (-> (List XML) XML))
(|>> (#_.Node ["" tag] _.attrs)))
-(def: (info value)
- (-> /.Info (List XML))
- ($_ list@compose
- (|> value (get@ #/.url) (maybe@map (..property "url")) maybe.to-list)
- (|> value (get@ #/.description) (maybe@map (..property "description")) maybe.to-list)
- (|> value (get@ #/.licenses) (list@map ..license) (..group "licenses") list)
- (|> value (get@ #/.scm) (maybe@map ..scm) maybe.to-list)
- (|> value (get@ #/.organization) (maybe@map ..organization) maybe.to-list)
- (|> value (get@ #/.developers) (list@map ..developer) (..group "developers") list)
- (|> value (get@ #/.contributors) (list@map ..contributor) (..group "contributors") list)
- ))
-
-(def: #export (project value)
+(comment
+ (def: scm
+ (-> /.SCM XML)
+ (|>> (..property "url")
+ list
+ (#_.Node ["" "scm"] _.attrs)))
+
+ (def: (organization [name url])
+ (-> /.Organization XML)
+ (|> (list (..property "name" name)
+ (..property "url" url))
+ (#_.Node ["" "organization"] _.attrs)))
+
+ (def: (developer-organization [name url])
+ (-> /.Organization (List XML))
+ (list (..property "organization" name)
+ (..property "organizationUrl" url)))
+
+ (def: (developer' [name email organization])
+ (-> /.Developer (List XML))
+ (list& (..property "name" name)
+ (..property "email" email)
+ (|> organization (maybe@map ..developer-organization) (maybe.default (list)))))
+
+ (template [<name> <type> <tag>]
+ [(def: <name>
+ (-> <type> XML)
+ (|>> ..developer' (#_.Node ["" <tag>] _.attrs)))]
+
+ [developer /.Developer "developer"]
+ [contributor /.Contributor "contributor"]
+ )
+
+ (def: (info value)
+ (-> /.Info (List XML))
+ ($_ list@compose
+ (|> value (get@ #/.url) (maybe@map (..property "url")) maybe.to-list)
+ (|> value (get@ #/.description) (maybe@map (..property "description")) maybe.to-list)
+ (|> value (get@ #/.licenses) (list@map ..license) (..group "licenses") list)
+ (|> value (get@ #/.scm) (maybe@map ..scm) maybe.to-list)
+ (|> value (get@ #/.organization) (maybe@map ..organization) maybe.to-list)
+ (|> value (get@ #/.developers) (list@map ..developer) (..group "developers") list)
+ (|> value (get@ #/.contributors) (list@map ..contributor) (..group "contributors") list)
+ ))
+ )
+
+(def: #export (write value)
(-> /.Profile (Try XML))
(case (get@ #/.identity value)
(#.Some identity)
(#try.Success
- (#_.Node ["" "project"] _.attrs
+ (#_.Node ["" ..project-tag] _.attrs
($_ list@compose
(list ..version)
(..artifact identity)
(|> value (get@ #/.repositories) set.to-list (list@map ..repository) (..group "repositories") list)
- (|> value (get@ #/.dependencies) set.to-list (list@map ..dependency) (..group "dependencies") list)
+ (|> value (get@ #/.dependencies) set.to-list (list@map ..dependency) (..group ..dependencies-tag) list)
)))
_
(exception.throw /.no-identity [])))
+
+(def: parse-property
+ (Parser [Tag Text])
+ (<>.and <xml>.tag
+ (<xml>.children <xml>.text)))
+
+(def: parse-dependency
+ (Parser Dependency)
+ (do {@ <>.monad}
+ [properties (:: @ map (dictionary.from-list name.hash)
+ (<xml>.children (<>.some ..parse-property)))]
+ (<| <>.lift
+ try.from-maybe
+ (do maybe.monad
+ [group (dictionary.get ["" ..group-tag] properties)
+ artifact (dictionary.get ["" ..artifact-tag] properties)
+ version (dictionary.get ["" ..version-tag] properties)]
+ (wrap {#//dependency.artifact {#//artifact.group group
+ #//artifact.name artifact
+ #//artifact.version version}
+ #//dependency.type (|> properties
+ (dictionary.get ["" "type"])
+ (maybe.default //artifact/type.lux-library))})))))
+
+(def: parse-dependencies
+ (Parser (List Dependency))
+ (do {@ <>.monad}
+ [_ (<xml>.node ["" ..dependencies-tag])]
+ (<xml>.children (<>.some ..parse-dependency))))
+
+(def: #export parser
+ (Parser /.Profile)
+ (do {@ <>.monad}
+ [_ (<xml>.node ["" ..project-tag])]
+ (<xml>.children
+ (do @
+ [dependencies (<xml>.somewhere ..parse-dependencies)
+ _ (<>.some <xml>.ignore)]
+ (wrap (|> (:: /.monoid identity)
+ (update@ #/.dependencies (function (_ empty)
+ (list@fold set.add empty dependencies)))))))))