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

_pkgname=javax.inject
pkgname=java-atinject
pkgver=1
pkgrel=1
pkgdesc="Java API for JSR-330 Dependency Injection"
arch=('any')
url="https://code.google.com/p/atinject/"
license=('APACHE')
depends=('java-runtime')
makedepends=('java-environment' 'jh' 'junit' 'subversion')
source=("${pkgname}-${pkgver}::svn+https://atinject.googlecode.com/svn/tags/${pkgver}/"
        "https://repo1.maven.org/maven2/javax/inject/${_pkgname}-tck/${pkgver}/${_pkgname}-tck-${pkgver}.pom")
md5sums=('SKIP'
         '4895a3d4064b3197f2f8c1aa65bae3c3')

prepare() {
  cd "${srcdir}/${pkgname}-${pkgver}"
  rm -rv lib
  rm -v "atinject."{iml,ipr}
  rm -v build.sh
  rm -v tck/tck.iml
  mkdir -p build/classes
  mkdir -p build/tck/classes
}

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

  CLASSPATH="build/classes:/usr/share/java/junit.jar"
  javac -d build/classes $(find src -name \*.java)
  javac -classpath $CLASSPATH -d build/tck/classes $(find tck -name \*.java)
  javadoc -classpath $CLASSPATH -sourcepath "src:tck" -d build/javadoc \
    javax.inject org.atinject.tck org.atinject.tck.auto org.atinject.tck.auto.accessories

  jar -cvf "${_pkgname}.jar" -C build/classes .
  jar -cvf "${_pkgname}-tck.jar" -C build/tck/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 ${_pkgname} ${_pkgname} ${pkgver} \
    "${srcdir}/${pkgname}-${pkgver}/pom.xml" \
    "${srcdir}/${pkgname}-${pkgver}/${_pkgname}.jar" \
    "${_pkgname}.jar"
  jh mvn-install ${_pkgname} "${_pkgname}-tck" ${pkgver} \
    "${srcdir}/${_pkgname}-tck-${pkgver}.pom" \
    "${srcdir}/${pkgname}-${pkgver}/${_pkgname}-tck.jar" \
    "${_pkgname}-tck.jar"
  ln -s "/usr/share/java/${_pkgname}.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}-${pkgver}.jar"
  ln -s "/usr/share/java/${_pkgname}-tck.jar" \
    "${pkgdir}/usr/share/java/${_pkgname}-tck-${pkgver}.jar"
}