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

_pkgname=commons-logging
pkgname=java-${_pkgname}
pkgver=1.2
pkgrel=1.parabola1
pkgdesc="Wrapper interface for logging APIs in Java"
arch=('any')
url="https://commons.apache.org/logging/"
license=('APACHE')
depends=('java-runtime')
makedepends=('apache-ant' 'jh' 'junit' 'tomcat8')
source=("https://archive.apache.org/dist/commons/logging/source/${_pkgname}-${pkgver}-src.tar.gz"
        "https://repo1.maven.org/maven2/${_pkgname}/${_pkgname}-api/1.1/${_pkgname}-api-1.1.pom")
md5sums=('ce977548f1cbf46918e93cd38ac35163'
         '48ed0c8f5fbfa18fb0ddc39830a9c0ac')

prepare() {
  cd "${srcdir}/${_pkgname}-${pkgver}-src"
  mv "../${_pkgname}-api-1.1.pom" pom-api.xml
  sed -i 's/1\.1/1\.2/g' pom-api.xml
}

build() {
  cd "${srcdir}/${_pkgname}-${pkgver}-src"
  ant dist \
    -Dservletapi.jar=/usr/share/java/tomcat8/servlet-api.jar

  # Build docs
  javadoc -sourcepath "src/main/java" -d "target/docs/apidocs" \
    org.apache.commons.logging org.apache.commons.logging.impl
}

package() {
  cd "${srcdir}/${_pkgname}-${pkgver}-src"

  # Install license file
  install -Dm644 LICENSE.txt "${pkgdir}/usr/share/licenses/${pkgname}/LICENSE.txt"

  # Install documentation
  install -d "${pkgdir}/usr/share/doc/${pkgname}"
  cp -r "target/docs/apidocs" "${pkgdir}/usr/share/doc/${pkgname}"

  # Install Maven artifacts
  export DESTDIR=${pkgdir}
  jh mvn-install ${_pkgname} ${_pkgname} ${pkgver} \
    "${srcdir}/${_pkgname}-${pkgver}-src/pom.xml" \
    "${srcdir}/${_pkgname}-${pkgver}-src/target/${_pkgname}-${pkgver}.jar" \
    "${_pkgname}.jar"
  jh mvn-install ${_pkgname} "${_pkgname}-api" ${pkgver} \
    "${srcdir}/${_pkgname}-${pkgver}-src/pom-api.xml" \
    "${srcdir}/${_pkgname}-${pkgver}-src/target/${_pkgname}-api-${pkgver}.jar" \
    "${_pkgname}-api.jar"

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

  # Install commons-logging-adapters.jar
  install -Dm644 "target/${_pkgname}-adapters-${pkgver}.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}-adapters-${pkgver}.jar"
  ln -s "/usr/share/java/${_pkgname}-adapters-${pkgver}.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}-adapters.jar"
}
