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

_libname=jdom
pkgname=java-${_libname}1
pkgver=1.1.3
pkgrel=1.parabola2
pkgdesc="Older version of XML Parsing Library for Java"
arch=('any')
url="http://www.jdom.org"
license=('custom')
depends=('java-runtime')
conflicts=('java-jdom')
provides=("java-jdom=$pkgver")
makedepends=('apache-ant' 'jh')
source=("https://github.com/hunterhacker/${_libname}/archive/${_libname}-$pkgver.tar.gz")
sha1sums=('2a8d80da5046b62b3130ab22eda058e8f02a6ade')

prepare() {
  cd "$srcdir/${_libname}-${_libname}-$pkgver"
  rm -rv {core,contrib,test}/lib/*.jar
  sed -i "s/@artifactID@/${_libname}/g" maven.pom
  sed -i "s/@version@/$pkgver/g" maven.pom
  sed -i "s/@jdk@/1.2/g" maven.pom
}

build() {
  cd "$srcdir/${_libname}-${_libname}-$pkgver"
  ant build.core \
    -Dversion=$pkgver
}

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

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

  # Install documentation
  install -d "$pkgdir/usr/share/doc/$pkgname"
  cp -r core/build/apidocs "$pkgdir/usr/share/doc/$pkgname"
  cp -r core/samples "$pkgdir/usr/share/doc/$pkgname/examples"

  # Install Maven artifacts
  export DESTDIR=$pkgdir
  jh mvn-install "org.${_libname}" ${_libname} $pkgver \
    maven.pom \
    "core/build/${_libname}-$pkgver.jar" \
    "${_libname}-$pkgver.jar"
  ln -s "/usr/share/java/${_libname}-$pkgver.jar" \
    "${pkgdir}/usr/share/java/${_libname}1.jar"
}
