# Maintainer (arch): Lukas Fleischer <lfleischer@archlinux.org>
# Contributor: Stefan Husmann <stefan-husmann@t-online.de>
# Contributor: Simon Lipp <sloonz+aur@gmail.com>
# Maintainer: Omar Vega Ramos <ovruni@gnu.org.pe>

pkgname=fop
pkgver=2.2
pkgrel=1.parabola1
pkgdesc='XSL-FO implementation in Java.'
arch=('any')
url='http://xmlgraphics.apache.org/fop/'
license=('APACHE')
depends=('java-xmlgraphics-commons' 'java-commons-logging' 'java-commons-io' 'java-batik'
         'java-avalon-framework' 'java-qdox' 'fontbox' 'tomcat8')
makedepends=('apache-ant' 'jh')
source=("http://ftp-stud.hs-esslingen.de/pub/Mirrors/ftp.apache.org/dist/xmlgraphics/$pkgname/source/$pkgname-$pkgver-src.tar.gz"
        'fop.conf')
sha256sums=('5052fef87fc4b888bd49d29bf626255c9d3443b628f21393c11ea121d44a6552'
            'd2900605dc271f5938d0820ca30bdec8060724976b56e43d827157bd6975da96')
backup=('etc/fop.conf')

prepare() {
  cd "$srcdir/$pkgname-$pkgver/fop"
  rm -rv lib/*
  mkdir -p lib/build

  ln -sf /usr/share/java/qdox.jar lib/build/qdox.jar
}

build() {
  cd "$srcdir/$pkgname-$pkgver"
  ant -f "$pkgname/build.xml" package \
    -lib /usr/share/java/serializer.jar \
    -lib /usr/share/java/xmlgraphics-commons.jar \
    -lib /usr/share/java/avalon-framework-api.jar \
    -lib /usr/share/java/avalon-framework-impl.jar \
    -lib /usr/share/java/commons-io.jar \
    -lib /usr/share/java/batik/batik-all.jar \
    -lib /usr/share/java/batik/batik-libs.jar \
    -lib /usr/share/java/tomcat8/servlet-api.jar \
    -lib /usr/share/java/xml-apis-ext.jar \
    -lib /usr/share/java/fontbox.jar
}

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

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

  # Install documentation
  #install -d "$pkgdir/usr/share/doc/$pkgname"
  #cp -r build/javadocs "$pkgdir/usr/share/doc/$pkgname"

  # Install Maven artifacts
  export DESTDIR=$pkgdir
  jh mvn-install org.apache.xmlgraphics $pkgname $pkgver \
    "$pkgname/pom.xml" \
    "$pkgname/build/$pkgname.jar" \
    "$pkgname-$pkgver.jar"
  ln -s "/usr/share/java/$pkgname-$pkgver.jar" \
    "$pkgdir/usr/share/java/$pkgname.jar"

  install -d "$pkgdir/usr/share/java/$pkgname"
  ln -s "/usr/share/java/$pkgname.jar" \
    "$pkgdir/usr/share/java/$pkgname/$pkgname.jar"

  install -Dm0644 "../fop.conf" "$pkgdir/etc/fop.conf"
  install -Dm0755 "$pkgname/$pkgname" "$pkgdir/usr/bin/$pkgname"
}
