From 573b43c11675a2a125ab8c7d930f32e11f9d3acb Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:15 +0200 Subject: 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. --- guix/build/maven/pom.scm | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) (limited to 'guix/build/maven') diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index c92d409d2b..327d5f75e8 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -1,5 +1,5 @@ ;;; GNU Guix --- Functional package management for GNU -;;; Copyright © 2019, 2020 Julien Lepiller +;;; Copyright © 2019-2021 Julien Lepiller ;;; ;;; This file is part of GNU Guix. ;;; @@ -93,13 +93,12 @@ If no result is found, the result is @code{#f}." (get-pom (car java-inputs)))) #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. See @code{find-parent} for the meaning of the arguments." (if content (let ((res (or (pom-ref content "groupId") - (pom-groupid (find-parent content inputs local-packages) - inputs)))) + (pom-ref (pom-ref content "parent") "groupId")))) (cond ((string? res) res) ((null? res) #f) @@ -114,13 +113,12 @@ See @code{find-parent} for the meaning of the arguments." (car res) #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. See @code{find-parent} for the meaning of the arguments." (if content (let ((res (or (pom-ref content "version") - (pom-version (find-parent content inputs local-packages) - inputs)))) + (pom-ref (pom-ref content "parent") "version")))) (cond ((string? res) res) ((null? res) #f) @@ -344,7 +342,7 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." ((tag rest ...) (match tag (('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))) (if (member artifact (or (assoc-ref excludes group) '())) (fix-plugins rest optional?) @@ -355,11 +353,11 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." (define* (fix-plugin plugin #:optional optional?) (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) (find-version inputs group artifact optional?) - (pom-version plugin inputs)))) - (if (pom-version plugin inputs) + (pom-version plugin)))) + (if (pom-version plugin) (map (lambda (tag) (match tag @@ -373,7 +371,7 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." (define* (fix-dep dep #:optional optional?) (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")) (is-optional? (equal? (pom-ref dep "optional") '("true")))) (format (current-error-port) "maven: ~a:~a :: ~a (optional: ~a)~%" @@ -382,8 +380,8 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." with-build-dependencies?) (let ((version (or (assoc-ref (assoc-ref local-packages group) artifact) (find-version inputs group artifact optional?) - (pom-version dep inputs)))) - (if (pom-version dep inputs) + (pom-version dep)))) + (if (pom-version dep) (map (lambda (tag) (match tag -- cgit v1.2.3 From 6ec2109ab6ea8c8503288a5729a795939e6db41e Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:16 +0200 Subject: guix: maven: Simplify finding local packages and modules. * guix/build/maven-build-system (fix-pom): Fix a single pom file without recursing (fix-pom-files): Find local packages and all submodules, and fix them all at once. (add-local-package): Move to... * guix/build/maven/pom.scm (add-local-package): ...here. (pom-and-submodules, pom-local-packages): New procedures. --- guix/build/maven-build-system.scm | 41 ++++++------------------------ guix/build/maven/pom.scm | 53 ++++++++++++++++++++++++++++++++++++++- 2 files changed, 60 insertions(+), 34 deletions(-) (limited to 'guix/build/maven') diff --git a/guix/build/maven-build-system.scm b/guix/build/maven-build-system.scm index 0456bfdf61..374fa2fdb8 100644 --- a/guix/build/maven-build-system.scm +++ b/guix/build/maven-build-system.scm @@ -60,47 +60,22 @@ (invoke "mvn" "-v") #t) -(define (add-local-package local-packages group artifact version) - (define (alist-set lst key val) - (match lst - ('() (list (cons key val))) - (((k . v) lst ...) - (if (equal? k key) - (cons (cons key val) lst) - (cons (cons k v) (alist-set lst key val)))))) - (alist-set local-packages group - (alist-set (or (assoc-ref local-packages group) '()) artifact - version))) - (define (fix-pom pom-file inputs local-packages excludes) (chmod pom-file #o644) (format #t "fixing ~a~%" pom-file) (fix-pom-dependencies pom-file (map cdr inputs) #:with-plugins? #t #:with-build-dependencies? #t #:local-packages local-packages - #:excludes excludes) - (let* ((pom (get-pom pom-file)) - (java-inputs (map cdr inputs)) - (artifact (pom-artifactid pom)) - (group (pom-groupid pom)) - (version (pom-version pom))) - (let loop ((modules (pom-ref pom "modules")) - (local-packages - (add-local-package local-packages group artifact version))) - (pk 'local-packages local-packages) - (match modules - (#f local-packages) - ('() local-packages) - (((? string? _) modules ...) - (loop modules local-packages)) - (((_ module) modules ...) - (loop - modules - (fix-pom (string-append (dirname pom-file) "/" module "/pom.xml") - inputs local-packages excludes))))))) + #:excludes excludes)) (define* (fix-pom-files #:key inputs local-packages exclude #:allow-other-keys) - (fix-pom "pom.xml" inputs local-packages exclude) + (let ((local-packages (pom-local-packages "pom.xml" #:local-packages local-packages))) + (format (current-error-port) "Fix pom files with local packages: ~a~%" local-packages) + (for-each + (lambda (pom) + (when (file-exists? pom) + (fix-pom pom inputs local-packages exclude))) + (pom-and-submodules "pom.xml"))) #t) (define* (build #:key outputs #:allow-other-keys) diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index 327d5f75e8..8f16cf4d26 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -21,7 +21,8 @@ #:use-module (system foreign) #:use-module (ice-9 match) #:use-module (srfi srfi-1) - #:export (get-pom + #:export (add-local-package + get-pom pom-ref pom-description pom-name @@ -30,8 +31,24 @@ pom-groupid pom-dependencies group->dir + pom-and-submodules + pom-local-packages fix-pom-dependencies)) +(define (add-local-package local-packages group artifact version) + "Takes @var{local-packages}, a list of local packages, and adds a new one +for @var{group}:@var{artifact} at @var{version}." + (define (alist-set lst key val) + (match lst + ('() (list (cons key val))) + (((k . v) lst ...) + (if (equal? k key) + (cons (cons key val) lst) + (cons (cons k v) (alist-set lst key val)))))) + (alist-set local-packages group + (alist-set (or (assoc-ref local-packages group) '()) artifact + version))) + (define (get-pom file) "Return the content of a @file{.pom} file." (let ((pom-content (call-with-input-file file xml->sxml))) @@ -234,6 +251,40 @@ to re-declare the namespaces in the top-level element." http://maven.apache.org/xsd/maven-4.0.0.xsd")) ,(map fix-xml sxml))))) +(define (pom-and-submodules pom-file) + "Given @var{pom-file}, the file name of a pom, return the list of pom file +names that correspond to itself and its submodules, recursively." + (define (get-modules modules) + (match modules + (#f '()) + ('() '()) + (((? string? _) rest ...) (get-modules rest)) + ((('http://maven.apache.org/POM/4.0.0:module mod) rest ...) + (let ((pom (string-append (dirname pom-file) "/" mod "/pom.xml"))) + (if (file-exists? pom) + (cons pom (get-modules rest)) + (get-modules rest)))))) + + (let* ((pom (get-pom pom-file)) + (modules (get-modules (pom-ref pom "modules")))) + (cons pom-file + (apply append (map pom-and-submodules modules))))) + +(define* (pom-local-packages pom-file #:key (local-packages '())) + "Given @var{pom-file}, a pom file name, return a list of local packages that +this repository contains." + (let loop ((modules (pom-and-submodules pom-file)) + (local-packages local-packages)) + (match modules + (() local-packages) + ((module modules ...) + (let* ((pom (get-pom module)) + (version (pom-version pom)) + (artifactid (pom-artifactid pom)) + (groupid (pom-groupid pom))) + (loop modules + (add-local-package local-packages groupid artifactid version))))))) + (define (group->dir group) "Convert a group ID to a directory path." (string-join (string-split group #\.) "/")) -- cgit v1.2.3 From 9711970c99cfbf1b5546c395d5407d67b954c343 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:17 +0200 Subject: guix: maven: Support fixing extensions. * guix/build/maven/pom.scm (fix-pom-dependencies): Add support for fixing extension versions. --- guix/build/maven/pom.scm | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'guix/build/maven') diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index 8f16cf4d26..3a4ad7a216 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -374,8 +374,27 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." `((http://maven.apache.org/POM/4.0.0:plugins ,(fix-plugins plugins)) ,@(fix-build rest))) + (('http://maven.apache.org/POM/4.0.0:extensions extensions ...) + `((http://maven.apache.org/POM/4.0.0:extensions + ,(fix-extensions extensions)) + ,@(fix-build rest))) (tag (cons tag (fix-build rest))))))) + (define* (fix-extensions extensions #:optional optional?) + (match extensions + ('() '()) + ((tag rest ...) + (match tag + (('http://maven.apache.org/POM/4.0.0:extension extension ...) + (let ((group (or (pom-groupid extension) "org.apache.maven.plugins")) + (artifact (pom-artifactid extension))) + (if (member artifact (or (assoc-ref excludes group) '())) + (fix-extensions rest optional?) + `((http://maven.apache.org/POM/4.0.0:extension + ,(fix-plugin extension optional?)); extensions are similar to plugins + ,@(fix-extensions rest optional?))))) + (tag (cons tag (fix-extensions rest optional?))))))) + (define fix-management (match-lambda ('() '()) -- cgit v1.2.3 From 0db1393b732304220aff978676b5354bfa186a65 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:18 +0200 Subject: guix: maven: Support fixing modules. * guix/build/maven/pom.scm (fix-pom-dependencies): Support fixing modules that do not exist. * guix/build/maven-build-system.scm (fix-pom): Fix modules. --- guix/build/maven-build-system.scm | 1 + guix/build/maven/pom.scm | 19 ++++++++++++++++++- 2 files changed, 19 insertions(+), 1 deletion(-) (limited to 'guix/build/maven') diff --git a/guix/build/maven-build-system.scm b/guix/build/maven-build-system.scm index 374fa2fdb8..b3d97c81ea 100644 --- a/guix/build/maven-build-system.scm +++ b/guix/build/maven-build-system.scm @@ -65,6 +65,7 @@ (format #t "fixing ~a~%" pom-file) (fix-pom-dependencies pom-file (map cdr inputs) #:with-plugins? #t #:with-build-dependencies? #t + #:with-modules? #t #:local-packages local-packages #:excludes excludes)) diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index 3a4ad7a216..ffb4515179 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -291,7 +291,8 @@ this repository contains." (define* (fix-pom-dependencies pom-file inputs #:key with-plugins? with-build-dependencies? - (excludes '()) (local-packages '())) + with-modules? (excludes '()) + (local-packages '())) "Open @var{pom-file}, and override its content, rewritting its dependencies to set their version to the latest version available in the @var{inputs}. @@ -339,8 +340,24 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." `((http://maven.apache.org/POM/4.0.0:build ,(fix-build build)) ,@(fix-pom rest)) (cons tag (fix-pom rest)))) + (('http://maven.apache.org/POM/4.0.0:modules modules ...) + (if with-modules? + `((http://maven.apache.org/POM/4.0.0:modules ,(fix-modules modules)) + ,@(fix-pom rest)) + (cons tag (fix-pom rest)))) (tag (cons tag (fix-pom rest))))))) + (define fix-modules + (match-lambda + ('() '()) + ((tag rest ...) + (match tag + (('http://maven.apache.org/POM/4.0.0:module module) + (if (file-exists? (string-append (dirname pom-file) "/" module "/pom.xml")) + `((http://maven.apache.org/POM/4.0.0:module ,module) ,@(fix-modules rest)) + (fix-modules rest))) + (tag (cons tag (fix-modules rest))))))) + (define fix-dep-management (match-lambda ('() '()) -- cgit v1.2.3 From 5bb3395c42c3475cd4d71d475ae050f1b80fbe2d Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:19 +0200 Subject: guix: maven: Look in local packages when searching for package version. * guix/build/maven/pom.scm (fix-pom-dependencies): Also look at local packages when looking for a package version. --- guix/build/maven/pom.scm | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) (limited to 'guix/build/maven') diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index ffb4515179..9c0669c7cd 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -481,7 +481,7 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." (cons `(http://maven.apache.org/POM/4.0.0:version ,version) dep))) dep))) - (define* (find-version inputs group artifact #:optional optional?) + (define (find-packaged-version inputs group artifact) (let* ((directory (string-append "lib/m2/" (group->dir group) "/" artifact)) (java-inputs (filter @@ -493,13 +493,19 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." (versions (append-map ls java-inputs)) (versions (sort versions version>?))) (if (null? versions) - (if optional? #f - (begin - (format (current-error-port) "maven: ~a:~a is missing from inputs~%" - group artifact) - (throw 'no-such-input group artifact))) - (car versions)))) + (car versions)))) + + (define* (find-version inputs group artifact #:optional optional?) + (let ((packaged-version (find-packaged-version inputs group artifact)) + (local-version (assoc-ref (assoc-ref local-packages group) artifact))) + (or local-version packaged-version + (if optional? + #f + (begin + (format (current-error-port) "maven: ~a:~a is missing from inputs~%" + group artifact) + (throw 'no-such-input group artifact)))))) (let ((tmpfile (string-append pom-file ".tmp"))) (with-output-to-file pom-file -- cgit v1.2.3 From cc09453862d1604bbbb4a2a9487e395d9a459708 Mon Sep 17 00:00:00 2001 From: Julien Lepiller Date: Tue, 1 Jun 2021 00:44:20 +0200 Subject: guix: maven: Use a temporary file to fix pom files. * guix/build/maven/pom.scm (fix-pom-dependencies): Actually use the temporary file that was created. --- guix/build/maven/pom.scm | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'guix/build/maven') diff --git a/guix/build/maven/pom.scm b/guix/build/maven/pom.scm index 9c0669c7cd..9e35e47a7f 100644 --- a/guix/build/maven/pom.scm +++ b/guix/build/maven/pom.scm @@ -508,6 +508,7 @@ Returns nothing, but overrides the @var{pom-file} as a side-effect." (throw 'no-such-input group artifact)))))) (let ((tmpfile (string-append pom-file ".tmp"))) - (with-output-to-file pom-file + (with-output-to-file tmpfile (lambda _ - (sxml->xml (fix-maven-xml (fix-pom pom))))))) + (sxml->xml (fix-maven-xml (fix-pom pom))))) + (rename-file tmpfile pom-file))) -- cgit v1.2.3