guix: maven: Simplify finding version and group information.

* guix/build/maven/pom.scm (pom-version, pom-groupid): Do not use inputs
and local packages information anymore. Adapt file to new arguments.
* guix/build/maven-build-system.scm: Adapt to new arguments.
* guix/build/java-utils.scm: Adapt to new arguments.
This commit is contained in:
Julien Lepiller 2021-06-01 00:44:15 +02:00
parent 4c98db94b0
commit 573b43c116
No known key found for this signature in database
GPG key ID: 53D457B2D636EE82
3 changed files with 24 additions and 26 deletions

View file

@ -2,7 +2,7 @@
;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com> ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net> ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com> ;;; Copyright © 2018 Alex Vong <alexvong1995@gmail.com>
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu> ;;; Copyright © 2020, 2021 Julien Lepiller <julien@lepiller.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -69,9 +69,9 @@ (define* (install-pom-file pom-file)
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(java-inputs (append (map cdr inputs) (map cdr outputs))) (java-inputs (append (map cdr inputs) (map cdr outputs)))
(pom-content (get-pom pom-file)) (pom-content (get-pom pom-file))
(version (pom-version pom-content java-inputs)) (version (pom-version pom-content))
(artifact (pom-artifactid pom-content)) (artifact (pom-artifactid pom-content))
(group (group->dir (pom-groupid pom-content java-inputs))) (group (group->dir (pom-groupid pom-content)))
(repository (string-append out "/lib/m2/" group "/" artifact "/" (repository (string-append out "/lib/m2/" group "/" artifact "/"
version "/")) version "/"))
(pom-name (string-append repository artifact "-" version ".pom"))) (pom-name (string-append repository artifact "-" version ".pom")))
@ -87,8 +87,8 @@ (define (install-jar-file-with-pom jar pom-file inputs)
(manifest (string-append dir "/META-INF/MANIFEST.MF")) (manifest (string-append dir "/META-INF/MANIFEST.MF"))
(pom (get-pom pom-file)) (pom (get-pom pom-file))
(artifact (pom-artifactid pom)) (artifact (pom-artifactid pom))
(group (pom-groupid pom inputs)) (group (pom-groupid pom))
(version (pom-version pom inputs)) (version (pom-version pom))
(pom-dir (string-append "META-INF/maven/" group "/" artifact))) (pom-dir (string-append "META-INF/maven/" group "/" artifact)))
(mkdir-p (string-append dir "/" pom-dir)) (mkdir-p (string-append dir "/" pom-dir))
(copy-file pom-file (string-append dir "/" pom-dir "/pom.xml")) (copy-file pom-file (string-append dir "/" pom-dir "/pom.xml"))
@ -113,9 +113,9 @@ (define* (install-from-pom pom-file)
(let* ((out (assoc-ref outputs "out")) (let* ((out (assoc-ref outputs "out"))
(java-inputs (append (map cdr inputs) (map cdr outputs))) (java-inputs (append (map cdr inputs) (map cdr outputs)))
(pom-content (get-pom pom-file)) (pom-content (get-pom pom-file))
(version (pom-version pom-content java-inputs)) (version (pom-version pom-content))
(artifact (pom-artifactid pom-content)) (artifact (pom-artifactid pom-content))
(group (group->dir (pom-groupid pom-content java-inputs))) (group (group->dir (pom-groupid pom-content)))
(repository (string-append out "/lib/m2/" group "/" artifact "/" (repository (string-append out "/lib/m2/" group "/" artifact "/"
version "/")) version "/"))
;; We try to find the file that was built. If it was built from our ;; We try to find the file that was built. If it was built from our
@ -180,9 +180,9 @@ (define* (generate-plugin.xml pom-file goal-prefix directory source-groups
(name (pom-name pom-content)) (name (pom-name pom-content))
(description (pom-description pom-content)) (description (pom-description pom-content))
(dependencies (pom-dependencies pom-content)) (dependencies (pom-dependencies pom-content))
(version (pom-version pom-content java-inputs)) (version (pom-version pom-content))
(artifact (pom-artifactid pom-content)) (artifact (pom-artifactid pom-content))
(groupid (pom-groupid pom-content java-inputs)) (groupid (pom-groupid pom-content))
(mojos (mojos
`(mojos `(mojos
,@(with-directory-excursion directory ,@(with-directory-excursion directory

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2020 Julien Lepiller <julien@lepiller.eu> ;;; Copyright © 2020, 2021 Julien Lepiller <julien@lepiller.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -82,8 +82,8 @@ (define (fix-pom pom-file inputs local-packages excludes)
(let* ((pom (get-pom pom-file)) (let* ((pom (get-pom pom-file))
(java-inputs (map cdr inputs)) (java-inputs (map cdr inputs))
(artifact (pom-artifactid pom)) (artifact (pom-artifactid pom))
(group (pom-groupid pom java-inputs local-packages)) (group (pom-groupid pom))
(version (pom-version pom java-inputs local-packages))) (version (pom-version pom)))
(let loop ((modules (pom-ref pom "modules")) (let loop ((modules (pom-ref pom "modules"))
(local-packages (local-packages
(add-local-package local-packages group artifact version))) (add-local-package local-packages group artifact version)))

View file

@ -1,5 +1,5 @@
;;; GNU Guix --- Functional package management for GNU ;;; GNU Guix --- Functional package management for GNU
;;; Copyright © 2019, 2020 Julien Lepiller <julien@lepiller.eu> ;;; Copyright © 2019-2021 Julien Lepiller <julien@lepiller.eu>
;;; ;;;
;;; This file is part of GNU Guix. ;;; This file is part of GNU Guix.
;;; ;;;
@ -93,13 +93,12 @@ (define* (find-parent content inputs #:optional local-packages)
(get-pom (car java-inputs)))) (get-pom (car java-inputs))))
#f))) #f)))
(define* (pom-groupid content inputs #:optional local-packages) (define* (pom-groupid content)
"Find the groupID of a pom file, potentially looking at its parent pom file. "Find the groupID of a pom file, potentially looking at its parent pom file.
See @code{find-parent} for the meaning of the arguments." See @code{find-parent} for the meaning of the arguments."
(if content (if content
(let ((res (or (pom-ref content "groupId") (let ((res (or (pom-ref content "groupId")
(pom-groupid (find-parent content inputs local-packages) (pom-ref (pom-ref content "parent") "groupId"))))
inputs))))
(cond (cond
((string? res) res) ((string? res) res)
((null? res) #f) ((null? res) #f)
@ -114,13 +113,12 @@ (define (pom-artifactid content)
(car res) (car res)
#f))) #f)))
(define* (pom-version content inputs #:optional local-packages) (define* (pom-version content)
"Find the version of a pom file, potentially looking at its parent pom file. "Find the version of a pom file, potentially looking at its parent pom file.
See @code{find-parent} for the meaning of the arguments." See @code{find-parent} for the meaning of the arguments."
(if content (if content
(let ((res (or (pom-ref content "version") (let ((res (or (pom-ref content "version")
(pom-version (find-parent content inputs local-packages) (pom-ref (pom-ref content "parent") "version"))))
inputs))))
(cond (cond
((string? res) res) ((string? res) res)
((null? res) #f) ((null? res) #f)
@ -344,7 +342,7 @@ (define* (fix-plugins plugins #:optional optional?)
((tag rest ...) ((tag rest ...)
(match tag (match tag
(('http://maven.apache.org/POM/4.0.0:plugin plugin ...) (('http://maven.apache.org/POM/4.0.0:plugin plugin ...)
(let ((group (or (pom-groupid plugin inputs) "org.apache.maven.plugins")) (let ((group (or (pom-groupid plugin) "org.apache.maven.plugins"))
(artifact (pom-artifactid plugin))) (artifact (pom-artifactid plugin)))
(if (member artifact (or (assoc-ref excludes group) '())) (if (member artifact (or (assoc-ref excludes group) '()))
(fix-plugins rest optional?) (fix-plugins rest optional?)
@ -355,11 +353,11 @@ (define* (fix-plugins plugins #:optional optional?)
(define* (fix-plugin plugin #:optional optional?) (define* (fix-plugin plugin #:optional optional?)
(let* ((artifact (pom-artifactid plugin)) (let* ((artifact (pom-artifactid plugin))
(group (or (pom-groupid plugin inputs) "org.apache.maven.plugins")) (group (or (pom-groupid plugin) "org.apache.maven.plugins"))
(version (or (assoc-ref (assoc-ref local-packages group) artifact) (version (or (assoc-ref (assoc-ref local-packages group) artifact)
(find-version inputs group artifact optional?) (find-version inputs group artifact optional?)
(pom-version plugin inputs)))) (pom-version plugin))))
(if (pom-version plugin inputs) (if (pom-version plugin)
(map (map
(lambda (tag) (lambda (tag)
(match tag (match tag
@ -373,7 +371,7 @@ (define* (fix-plugin plugin #:optional optional?)
(define* (fix-dep dep #:optional optional?) (define* (fix-dep dep #:optional optional?)
(let* ((artifact (pom-artifactid dep)) (let* ((artifact (pom-artifactid dep))
(group (or (pom-groupid dep inputs) (pom-groupid pom inputs))) (group (or (pom-groupid dep) (pom-groupid pom)))
(scope (pom-ref dep "scope")) (scope (pom-ref dep "scope"))
(is-optional? (equal? (pom-ref dep "optional") '("true")))) (is-optional? (equal? (pom-ref dep "optional") '("true"))))
(format (current-error-port) "maven: ~a:~a :: ~a (optional: ~a)~%" (format (current-error-port) "maven: ~a:~a :: ~a (optional: ~a)~%"
@ -382,8 +380,8 @@ (define* (fix-dep dep #:optional optional?)
with-build-dependencies?) with-build-dependencies?)
(let ((version (or (assoc-ref (assoc-ref local-packages group) artifact) (let ((version (or (assoc-ref (assoc-ref local-packages group) artifact)
(find-version inputs group artifact optional?) (find-version inputs group artifact optional?)
(pom-version dep inputs)))) (pom-version dep))))
(if (pom-version dep inputs) (if (pom-version dep)
(map (map
(lambda (tag) (lambda (tag)
(match tag (match tag