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

_pkgname=log4j
pkgname=${_pkgname}-1.2
pkgver=1.2.17
pkgrel=1
pkgdesc="Logging library for java"
arch=('any')
url="http://logging.apache.org/log4j/1.2/"
license=('APACHE')
depends=('java-runtime')
makedepends=('apache-ant' 'javamail' 'java-geronimo-jms' 'jh')
source=("https://archive.apache.org/dist/logging/${_pkgname}/${pkgver}/${_pkgname}-${pkgver}.tar.gz"
        "apache-log4j-remove_activation_framework.patch"
        "apache-log4j-add_missing_classes.patch"
        "apache-log4j-build_fix.patch")
md5sums=('8218714e41ee0c6509dcfeafa2e1f53f'
         '4417d091786330e001dbaac991e17bfe'
         '36450de9f2659c813b7edb8185545f4c'
         'f1a4cf990676af4726facad677ebe801')

prepare() {
  cd "${srcdir}/apache-${_pkgname}-${pkgver}"
  patch -Np1 -i "${srcdir}/apache-log4j-remove_activation_framework.patch"
  patch -Np1 -i "${srcdir}/apache-log4j-add_missing_classes.patch"
  patch -Np1 -i "${srcdir}/apache-log4j-build_fix.patch"
  rm -rv {contribs,site,tests}
  rm -v $(find . -name \*.jar)
}

build() {
  cd "${srcdir}/apache-${_pkgname}-${pkgver}"
  ant clean jar javadoc \
    -Djavamail.jar=/usr/share/java/javax.mail.jar \
    -Dgeronimo-jms.jar=/usr/share/java/geronimo-jms_1.1_spec.jar
}

package() {
  cd "${srcdir}/apache-${_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 "docs/api" "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r "examples" "${pkgdir}/usr/share/doc/${pkgname}"

  # Install Maven artifacts
  export DESTDIR=${pkgdir}
  jh mvn-install ${_pkgname} ${_pkgname} ${pkgver} \
    "pom.xml" \
    "dist/lib/${_pkgname}-${pkgver}.jar" \
    "${_pkgname}-1.2.jar"
  ln -s "/usr/share/java/${_pkgname}-1.2.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}-${pkgver}.jar"
}
