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

_libname=xerces2
pkgname=${_libname}-java
pkgver=2.11.0
pkgrel=3.parabola1
pkgdesc="High performance fully compliant Java XML parser"
arch=('any')
url="http://xml.apache.org/xerces2-j"
license=('APACHE')
depends=('java-runtime' 'java-resolver' 'java-xml-commons-external')
makedepends=('apache-ant' 'java-resolver' 'java-xml-commons-external' 'jh')
provides=("java-xerces2=${pkgver}")
conflicts=('java-xerces2')
replaces=('java-xerces2')
source=("http://archive.apache.org/dist/xerces/j/Xerces-J-src.${pkgver}.tar.gz"
        "http://repo.maven.apache.org/maven2/xerces/xercesImpl/${pkgver}/xercesImpl-${pkgver}.pom"
        "xerces2-java-taskdef.patch"
        "xerces2-java-dont_unzip.patch"
        "xerces2-java-HTMLObjectElementImpl.patch")
md5sums=('d01fc11eacbe43b45681cb85ac112ebf'
         '64288948e6420e49679348b0ce1963f8'
         '600788add1665864495e2bd0ab015613'
         '3bd20b2ea82f14d77031bf0e49c03516'
         'e1c26eeaedd33dc0a7af493a07a17211')

prepare() {
  cd "${srcdir}/xerces-${pkgver//./_}"
  mkdir -p tools
  patch -Np1 -i ../xerces2-java-taskdef.patch
  patch -Np1 -i ../xerces2-java-dont_unzip.patch
  patch -Np1 -i ../xerces2-java-HTMLObjectElementImpl.patch
}

build() {
  cd "${srcdir}/xerces-${pkgver//./_}"
  ln -sf /usr/share/java/resolver.jar tools/resolver.jar
  ln -sf /usr/share/java/xml-apis.jar tools/xml-apis.jar

  ant clean jar sampjar javadocs
}

package() {
  cd "${srcdir}/xerces-${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/docs/javadocs" "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r "build/samples" "${pkgdir}/usr/share/doc/${pkgname}/examples"

  # Install Maven artifacts
  export DESTDIR=${pkgdir}
  jh mvn-install xerces xercesImpl ${pkgver} \
    "${srcdir}/xercesImpl-${pkgver}.pom" \
    "build/xercesImpl.jar" \
    "xercesImpl.jar"

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