# Copyright (C) 2022 Denis 'GNUtoo' Carikli <GNUtoo@cyberdimension.org>
# This program is free software: you can redistribute it and/or modify
# it under the terms of the CC0 1.0 License.
# Maintainer: Parabola Hackers <dev@lists.parabola.nu>

pkgname=apiguardian
pkgver=1.1.2
pkgrel=4
pkgdesc='Java library that provides the `@API` annotation'
arch=('any')
url='https://apiguardian-team.github.io/apiguardian/docs/current/api/'
license=('Apache')
depends=('java-environment' 'java-runtime')
makedepends=('jh')
source=("https://github.com/${pkgname}-team/${pkgname}/archive/refs/tags/r${pkgver}.tar.gz")
sha512sums=('7c56ee15e0aba07e95b6f2fe7cedd98e449e774958eb63b2467066c381e1e82ad67c982c2885e18154c62e55fda80a1c2e0f689253afe449db9f7e7563122db6')

build() {
    cd "${srcdir}/${pkgname}-r${pkgver}"

    mkdir -p build/classes
    mkdir -p build/javadoc

    javac -d "build/classes" -encoding UTF-8 \
          "src/main/java/org/${pkgname}/api/API.java"

    javadoc -d build/javadoc/ \
            -sourcepath  src/main/java/ \
            -encoding UTF-8 \
            org.apiguardian.api

    jar -cvf "${pkgname}.jar" -C build/classes .
}

package() {
    cd "${srcdir}/${pkgname}-r${pkgver}"

    # Install license file
    install -Dm644 LICENSE "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"

    # Install documentation
    install -d "${pkgdir}/usr/share/doc/${pkgname}"
    cp -r build/javadoc "${pkgdir}/usr/share/doc/${pkgname}"

    # Install Maven artifacts
    export DESTDIR=${pkgdir}
    jh mvn-install "org.apiguardian.api" "${pkgname}" ${pkgver} \
                   build.gradle.kts "${pkgname}.jar" "${pkgname}.jar"

    ln -s "/usr/share/java/${pkgname}.jar" \
          "$pkgdir/usr/share/java/${pkgname}-${pkgver}.jar"
}
