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

pkgname=jmdns
pkgver=3.4.1
pkgrel=1
pkgdesc="Java implementation of multi-cast DNS (Apple Rendezvous)"
arch=('any')
url="https://github.com/jmdns/jmdns"
license=('APACHE')
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("https://github.com/$pkgname/$pkgname/archive/$pkgname-$pkgver.tar.gz")
sha256sums=('2c9240647761645d48b73400f5f23dfde228ea56d6d955e7ee9529ab89b9d839')

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

build() {
  cd "$srcdir/$pkgname-$pkgname-$pkgver"
  javac -d build/classes $(find src/main/java -name \*.java)
  javadoc -d build/javadoc -sourcepath src/main/java -subpackages javax
  jar -cvf "$pkgname.jar" -C build/classes .
}

package() {
  cd "$srcdir/$pkgname-$pkgname-$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 "javax.$pkgname" $pkgname $pkgver \
    pom.xml "$pkgname.jar" "$pkgname-$pkgver.jar"

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