# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>
_libname=bcel
pkgname=java-${_libname}
pkgver=6.0
pkgrel=1.parabola1
pkgdesc="Java library to analyze, create, and manipulate (binary) Java class files"
arch=('any')
url='https://commons.apache.org/proper/commons-bcel/'
license=('APACHE')
depends=('java-runtime')
makedepends=('java-environment' 'jh')
source=("http://archive.apache.org/dist/jakarta/${_libname}/source/${_libname}-$pkgver-src.tar.gz")
sha256sums=('b963b9f0614f17de40da1de265e44476b80a8cc8a36c07a3acfe48f603306958')

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

build() {
  cd "$srcdir/${_libname}-$pkgver-src"
  javac -d build/classes -encoding UTF-8 \
    $(find src/main/java -name \*.java)
  javadoc -sourcepath src/main/java -d build/javadoc \
    -encoding UTF-8 -subpackages org

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

package() {
  cd "$srcdir/${_libname}-$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 build/javadoc "$pkgdir/usr/share/doc/$pkgname"

  # Install Maven artifacts
  export DESTDIR=$pkgdir
  jh mvn-install "org.apache.${_libname}" ${_libname} $pkgver \
    pom.xml "${_libname}.jar" "${_libname}.jar"

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