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

pkgname=easymock
pkgver=3.4
pkgrel=1
pkgdesc="Java library to generate Mock Objects for given interfaces"
arch=('any')
url="http://easymock.org/"
license=('APACHE')
depends=('java-runtime')
makedepends=('cglib' 'java-environment' 'jh' 'junit' 'objenesis')
source=("https://github.com/${pkgname}/${pkgname}/archive/${pkgname}-${pkgver}.tar.gz"
        "easymock-no_android.patch")
md5sums=('2c17cff0e93bb88ddb30f09eb3b684ee'
         '8d9cb4aabfd48b88bc8a0c932e0399df')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgname}-${pkgver}"
  mkdir -p build/classes
  rm -v "core/src/main/java/org/easymock/internal/AndroidClassProxyFactory.java"
  patch -Np1 -i "${srcdir}/easymock-no_android.patch"
}

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

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

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

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

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

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