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

pkgname=jericho-html
pkgver=3.3
pkgrel=1
pkgdesc='Java based library for HTML Parsing'
arch=('any')
url='http://jericho.htmlparser.net'
license=('LGPL')
depends=('java-runtime')
makedepends=('java-environment' 'java-commons-logging' 'log4j-1.2' 'slf4j')
source=("http://downloads.sourceforge.net/jerichohtml/$pkgname-$pkgver.zip")
sha256sums=('236bc63259da9fe1b13d54f2b84e6c74ca5d9bea46b4db66eb136027dc821f5b')

prepare() {
  cd "$srcdir/$pkgname-$pkgver"
  rm -rv {compile-time-dependencies,dist,docs,samples,test/lib}
  mkdir -p build/classes
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  CLASSPATH="/usr/share/java/commons-logging.jar"
  CLASSPATH+=":/usr/share/java/log4j-1.2.jar"
  CLASSPATH+=":/usr/share/java/slf4j-api.jar"
  javac -cp $CLASSPATH -d build/classes -encoding ISO-8859-1 \
    $(find src/java -name \*.java)
  javadoc -classpath $CLASSPATH -d build/javadoc -encoding ISO-8859-1 \
    -sourcepath src/java -subpackages net

  jar -cvf $pkgname-$pkgver.jar -C build/classes .
}

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

  # Install license file
  install -Dm644 licence.txt \
    "$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 jar
  install -Dm755 "$pkgname-$pkgver.jar" \
    "$pkgdir/usr/share/java/$pkgname/$pkgname-$pkgver.jar"
  ln -s "/usr/share/java/$pkgname/$pkgname-$pkgver.jar" \
    "$pkgdir/usr/share/java/$pkgname.jar"
}
