packages: 'package-grafts' trims native inputs.
[guix.git] / guix / build / java-utils.scm
blob402d377bf83a7612557c0ddcb4e45385254eb1ba
1 ;;; GNU Guix --- Functional package management for GNU
2 ;;; Copyright © 2016 Hartmut Goebel <h.goebel@crazy-compilers.com>
3 ;;; Copyright © 2016 Ricardo Wurmus <rekado@elephly.net>
4 ;;;
5 ;;; This file is part of GNU Guix.
6 ;;;
7 ;;; GNU Guix is free software; you can redistribute it and/or modify it
8 ;;; under the terms of the GNU General Public License as published by
9 ;;; the Free Software Foundation; either version 3 of the License, or (at
10 ;;; your option) any later version.
11 ;;;
12 ;;; GNU Guix is distributed in the hope that it will be useful, but
13 ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
14 ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 ;;; GNU General Public License for more details.
16 ;;;
17 ;;; You should have received a copy of the GNU General Public License
18 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
20 (define-module (guix build java-utils)
21   #:use-module (guix build utils)
22   #:export (ant-build-javadoc
23             install-jars
24             install-javadoc))
26 ;; Copied from haskell-build-system.scm
27 (define (package-name-version store-dir)
28   "Given a store directory STORE-DIR return 'name-version' of the package."
29   (let* ((base (basename store-dir)))
30     (string-drop base (+ 1 (string-index base #\-)))))
32 (define* (ant-build-javadoc #:key (target "javadoc") (make-flags '())
33                             #:allow-other-keys)
34   (zero? (apply system* `("ant" ,target ,@make-flags))))
36 (define* (install-jars jar-directory)
37   "Install jar files from JAR-DIRECTORY to the default target directory.  This
38 is used in case the build.xml does not include an install target."
39   (lambda* (#:key outputs #:allow-other-keys)
40     (let ((share (string-append (assoc-ref outputs "out")
41                                 "/share/java")))
42       (for-each (lambda (f) (install-file f share))
43                 (find-files jar-directory "\\.jar$"))
44       #t)))
46 (define* (install-javadoc apidoc-directory)
47   "Install the APIDOC-DIRECTORY to the target directory.  This is used to
48 install javadocs when this is not done by the install target."
49   (lambda* (#:key outputs #:allow-other-keys)
50     (let* ((out (assoc-ref outputs "out"))
51            (docs (string-append (or (assoc-ref outputs "doc") out)
52                                 "/share/doc/" (package-name-version out) "/")))
53       (mkdir-p docs)
54       (copy-recursively apidoc-directory docs)
55       #t)))