# -*- coding: utf-8; mode: tcl; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4

PortSystem          1.0
PortGroup           java 1.0
PortGroup           github 1.0

github.setup        openstreetmap osmosis 0.49.2
github.tarball_from archive
revision            0

categories          java gis
platforms           any
supported_archs     noarch
maintainers         {@frankdean fdsd.co.uk:frank.dean} openmaintainer

license             public-domain

description         A command line Java application for processing OSM data

long_description    The tool consists of a series of pluggable \
                    components that can be chained together to perform \
                    a larger operation. For example, it has components \
                    for reading from database and from file, \
                    components for writing to database and to file, \
                    components for deriving and applying change sets \
                    to data sources, components for sorting data, \
                    etc. It has been written so that it is easy to add \
                    new features without re-writing common tasks such \
                    as file or database handling.

checksums           rmd160  6e96abddad8137b2bef8c694a7e90c82f086e589 \
                    sha256  b355771c35f326ee45431916c2ebe3f81a09ba571c03c3302f5268103f7b7e3c \
                    size    529169

set appdir          ${prefix}/share/${name}
set docdir          ${prefix}/share/doc/${name}

java.version        17+
java.fallback       openjdk17

depends_build       port:gradle

use_configure       no

build.env-append    GRADLE_USER_HOME=${worksrcpath}/.gradle
build.cmd           ${prefix}/bin/gradle
build.target        assemble

test.run            yes
test.env-append     GRADLE_USER_HOME=${worksrcpath}/.gradle
test.cmd            ${prefix}/bin/gradle
test.target         build

patchfiles          build-gradle.diff

post-patch {
    reinplace "s|@VERSION@|${version}|g" \
        ${worksrcpath}/build.gradle
    reinplace "s|/usr/share|${prefix}/share|g" \
        ${worksrcpath}/osmosis/src/dist/script/munin/README
    reinplace "s|/etc|${prefix}/etc|g" \
        ${worksrcpath}/osmosis/src/dist/script/munin/README
    reinplace "s|#user osm|#user nobody|g" \
        ${worksrcpath}/osmosis/src/dist/script/munin/osm_replication.conf
    reinplace "s|#env.osmosis /opt/osmosis/bin|env.osmosis ${appdir}/bin|g" \
        ${worksrcpath}/osmosis/src/dist/script/munin/osm_replication.conf
    reinplace "s|#env.workingDirectory /path/to/state.txt|#env.workingDirectory ${prefix}/var/lib/mod_tile/.osmosis/state.txt|g" \
        ${worksrcpath}/osmosis/src/dist/script/munin/osm_replication.conf
}

pre-test {
    # Tests that fail, which are effectively integration tests
    # requiring databases that have been created and configured for
    # testing.
    file delete -force ${worksrcpath}/osmosis-apidb/src/test
    file delete -force ${worksrcpath}/osmosis-extract/src/test
    file delete -force ${worksrcpath}/osmosis-pgsimple/src/test
    file delete -force ${worksrcpath}/osmosis-pgsnapshot/src/test
}

destroot {
    system -W ${worksrcpath}/osmosis/build/distributions "tar -xf osmosis-${version}.tar"
    move ${worksrcpath}/osmosis/build/distributions/osmosis-${version} ${destroot}${appdir}

    xinstall -d ${destroot}${docdir}
    move {*}[glob ${destroot}${appdir}/*.txt] ${destroot}${docdir}

    delete ${destroot}${appdir}/bin/osmosis.bat

    ln -s ${appdir}/bin/${name} ${destroot}${prefix}/bin/${name}
}
