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

pkgname=xz-java
pkgver=1.6
pkgrel=1
pkgdesc="Java library for XZ and LZMA compression"
arch=('any')
url="http://tukaani.org/xz/java.html"
license=('Public Domain')
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("http://tukaani.org/xz/$pkgname-$pkgver.zip")
sha256sums=('1da9c5534656da8197457feeea7ee6c7a2c908e94f01db6d3c80ee17620e77fc')

prepare() {
  cd $srcdir
  cp maven/pom_template.xml pom.xml
  sed -i "s,@VERSION@,$pkgver,g; \
          s,@TITLE@,XZ data compression,g; \
          s,@HOMEPAGE@,$url,g" pom.xml
  mkdir -p build/classes
}

build() {
  cd $srcdir
  javac -d build/classes $(find src/org -name \*.java)
  javadoc -d build/javadoc -sourcepath src -subpackages org
  jar -cvf xz.jar -C build/classes .
}

package() {
  cd $srcdir

  # Install license file
  install -Dm644 COPYING "$pkgdir/usr/share/licenses/$pkgname/COPYING.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.tukaani xz $pkgver \
    pom.xml xz.jar "xz-$pkgver.jar"

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