# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

_pkgname=osgi.annotation
pkgname=osgi-annotation
pkgver=6.0.0
pkgrel=3
pkgdesc="Java OSGi API - annotation module"
arch=('any')
url='https://www.osgi.org/developer/specifications/'
license=('APACHE')
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("https://repo1.maven.org/maven2/org/osgi/org.${_pkgname}/${pkgver}/org.${_pkgname}-${pkgver}-sources.jar"
        "https://repo1.maven.org/maven2/org/osgi/org.${_pkgname}/${pkgver}/org.${_pkgname}-${pkgver}.pom")
sha1sums=('d7ebeed8c7afb937ddb4652d90517c8c05294ee0'
          'dfa6ed7265c0e8aa37b7056166edb4357747e459')

prepare() {
  cd ${srcdir}
  mkdir -p build/classes
}

build() {
  cd ${srcdir}
  javac -d build/classes -encoding UTF-8 \
    $(find . -name \*.java)
  javadoc -d "build/javadoc" -encoding UTF-8 \
    -sourcepath . -subpackages org

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

package() {
  cd ${srcdir}

  # 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.osgi "org.${_pkgname}" ${pkgver} \
    "org.${_pkgname}-${pkgver}.pom" \
    ${_pkgname}.jar \
    ${_pkgname}-${pkgver}.jar
  ln -s "/usr/share/java/${_pkgname}-${pkgver}.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}.jar"
}