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

pkgname=mockito
pkgver=1.10.19
pkgrel=1
pkgdesc="Mocking framework for Java"
arch=('any')
url="https://github.com/mockito/mockito"
license=('MIT')
depends=('java-runtime')
makedepends=('cglib' 'java-environment' 'java-hamcrest' 'jh' 'junit' 'objenesis')
source=("https://github.com/${pkgname}/${pkgname}/archive/v${pkgver}.tar.gz"
        "https://repo1.maven.org/maven2/org/${pkgname}/${pkgname}-core/${pkgver}/${pkgname}-core-${pkgver}.pom"
        "mockito-use_system_libraries.patch"
        "mockito-hamcrest_interfaces.patch")
md5sums=('6e7d57d5f58fc551880d3e4685c7f569'
         'a96d6f1ec0e75e890e98cc4a8d4bed62'
         '802ddd127fdedfa2f8f9390ca0292ca3'
         '00a64b1b14a9ce6e7be878d16dbecaa8')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  patch -Np1 -i "${srcdir}/mockito-use_system_libraries.patch"
  patch -Np1 -i "${srcdir}/mockito-hamcrest_interfaces.patch"
  rm -v $(find . -name \*.jar)
  mkdir -p build/classes
}

build() {
  cd "${srcdir}/${pkgname}-${pkgver}"

  CLASSPATH="/usr/share/java/cglib.jar:/usr/share/java/hamcrest-core.jar"
  CLASSPATH="$CLASSPATH:/usr/share/java/junit.jar:/usr/share/java/objenesis.jar"
  javac -classpath $CLASSPATH -d "build/classes" \
    $(find "src" -name \*.java)
  javadoc -classpath $CLASSPATH -d "build/javadoc" \
    -sourcepath "src" -subpackages org

  jar -cvf "${pkgname}.jar" -C "build/classes" .
}

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

  # 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 "org.mockito" "${pkgname}-core" ${pkgver} \
    "${srcdir}/${pkgname}-core-${pkgver}.pom" \
    "${pkgname}.jar" \
    "${pkgname}.jar"
  ln -s "/usr/share/java/${pkgname}.jar" \
    "${pkgdir}/usr/share/java/${pkgname}-${pkgver}.jar"
}
