pom.scm
| 1 | ;;; GNU Guix --- Functional package management for GNU |
| 2 | ;;; Copyright © 2019 Julien Lepiller <julien@lepiller.eu> |
| 3 | ;;; |
| 4 | ;;; This file is part of GNU Guix. |
| 5 | ;;; |
| 6 | ;;; GNU Guix is free software; you can redistribute it and/or modify it |
| 7 | ;;; under the terms of the GNU General Public License as published by |
| 8 | ;;; the Free Software Foundation; either version 3 of the License, or (at |
| 9 | ;;; your option) any later version. |
| 10 | ;;; |
| 11 | ;;; GNU Guix is distributed in the hope that it will be useful, but |
| 12 | ;;; WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | ;;; GNU General Public License for more details. |
| 15 | ;;; |
| 16 | ;;; You should have received a copy of the GNU General Public License |
| 17 | ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>. |
| 18 | |
| 19 | (define-module (more build maven pom) |
| 20 | #:use-module (sxml simple) |
| 21 | #:use-module (ice-9 match) |
| 22 | #:export (get-pom |
| 23 | pom-description |
| 24 | pom-name |
| 25 | pom-version |
| 26 | pom-artifactid |
| 27 | pom-groupid |
| 28 | pom-dependencies)) |
| 29 | |
| 30 | (define (get-pom file) |
| 31 | (let ((pom-content (call-with-input-file file xml->sxml))) |
| 32 | (match pom-content |
| 33 | (('*TOP* _ (_ ('@ _ ...) content ...)) |
| 34 | content)))) |
| 35 | |
| 36 | (define (pom-ref content attr) |
| 37 | (assoc-ref |
| 38 | content |
| 39 | (string->symbol |
| 40 | (string-append "http://maven.apache.org/POM/4.0.0:" attr)))) |
| 41 | |
| 42 | (define (pom-groupid content) |
| 43 | (string-join |
| 44 | (string-split |
| 45 | (car (pom-ref content "groupId")) |
| 46 | #\.) |
| 47 | "/")) |
| 48 | |
| 49 | (define (pom-artifactid content) |
| 50 | (car (pom-ref content "artifactId"))) |
| 51 | |
| 52 | (define (pom-version content) |
| 53 | (car (pom-ref content "version"))) |
| 54 | |
| 55 | (define (pom-name content) |
| 56 | (car (pom-ref content "name"))) |
| 57 | |
| 58 | (define (pom-description content) |
| 59 | (car (pom-ref content "description"))) |
| 60 | |
| 61 | (define (pom-dependencies content) |
| 62 | (filter |
| 63 | (lambda (a) a) |
| 64 | (map |
| 65 | (match-lambda |
| 66 | ((? string? _) #f) |
| 67 | (('http://maven.apache.org/POM/4.0.0:dependency content ...) |
| 68 | (let loop ((content content) (groupid #f) (artifactid #f) (version #f) (scope #f)) |
| 69 | (match content |
| 70 | ('() |
| 71 | `(dependency |
| 72 | (groupId ,groupid) |
| 73 | (artifactId ,artifactid) |
| 74 | (version ,version) |
| 75 | ,@(if scope `((scope ,scope)) '()))) |
| 76 | (((? string? _) content ...) |
| 77 | (loop content groupid artifactid version scope)) |
| 78 | ((('http://maven.apache.org/POM/4.0.0:scope scope) content ...) |
| 79 | (loop content groupid artifactid version scope)) |
| 80 | ((('http://maven.apache.org/POM/4.0.0:groupId groupid) content ...) |
| 81 | (loop content groupid artifactid version scope)) |
| 82 | ((('http://maven.apache.org/POM/4.0.0:artifactId artifactid) content ...) |
| 83 | (loop content groupid artifactid version scope)) |
| 84 | ((('http://maven.apache.org/POM/4.0.0:version version) content ...) |
| 85 | (loop content groupid artifactid version scope)))))) |
| 86 | (pom-ref content "dependencies")))) |
| 87 |