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

pkgname=objenesis
pkgver=2.2
pkgrel=1
pkgdesc="Java library to instantiate a new object of a particular class"
arch=('any')
url="http://objenesis.org/"
license=('APACHE')
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("https://github.com/easymock/${pkgname}/archive/${pkgver}.tar.gz")
md5sums=('92e3bd808297c684cdc95eccfb94ec61')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  mkdir -p build/classes
}

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

  CLASSPATH="build/classes"
  javac -encoding utf8 -classpath $CLASSPATH -d "build/classes" \
    $(find "main/src/main/java/" -name \*.java)
  javadoc -encoding utf8 -classpath $CLASSPATH -d "build/javadoc" \
    -sourcepath "main/src/main/java/" -subpackages org

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

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

  # 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 "build/javadoc" "${pkgdir}/usr/share/doc/${pkgname}"

  # Install Maven artifacts
  export DESTDIR=${pkgdir}
  jh mvn-install "org.objenesis" "${pkgname}-parent" ${pkgver} \
    "${srcdir}/${pkgname}-${pkgver}/pom.xml"
  jh mvn-install "org.objenesis" ${pkgname} ${pkgver} \
    "${srcdir}/${pkgname}-${pkgver}/main/pom.xml" \
    "${srcdir}/${pkgname}-${pkgver}/${pkgname}.jar" \
    "${pkgname}.jar"
  ln -s "/usr/share/java/${pkgname}.jar" \
    "${pkgdir}/usr/share/java/${pkgname}-${pkgver}.jar"
}
