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

_libname=saxon
pkgname=${_libname}6
pkgver=6.5.5
_pkgver=$(echo $pkgver | tr . -)
pkgrel=1
pkgdesc="XSLT 1.0 / XPath 1.0 processor for Java"
url="http://saxon.sourceforge.net/"
license=('MPL')
arch=('any')
depends=('java-runtime')
makedepends=('java-environment' 'java-jdom1' 'jh')
source=("http://sourceforge.net/projects/${_libname}/files/$pkgname/$pkgver/${_libname}${_pkgver}.zip"
        'pom.xml')
sha1sums=('15e25fcf561ff173751ae992f2608f6f2e6204ed'
          'f9352e1e204e4cf93f2a33335288ceff9b3e2f16')

prepare() {
  cd ${srcdir}
  rm -rv *.jar
  rm -rvf {doc,samples}
  mkdir -p {build/classes,src}
  bsdtar -zxf source.zip -C src
}

build() {
  cd $srcdir
  CLASSPATH="/usr/share/java/jdom1.jar"
  javac -cp $CLASSPATH -d build/classes -encoding ISO-8859-1 \
    $(find src -name \*.java)
  javadoc -classpath $CLASSPATH -d build/javadoc -encoding ISO-8859-1 \
    -sourcepath src -subpackages com:org

  jar -cvf "${_libname}-jdom.jar" -C build/classes/ com/icl/saxon/jdom

  rm -r build/classes/com/icl/saxon/jdom
  jar -cvf "${_libname}.jar" -C build/classes .
}

package() {
  cd $srcdir

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

  install -Dm644 "${_libname}-jdom.jar" \
    "$pkgdir/usr/share/java/${_libname}-jdom-$pkgver.jar"
  ln -s "/usr/share/java/${_libname}-jdom-$pkgver.jar" \
    "$pkgdir/usr/share/java/${_libname}-jdom.jar"
}
