# -*- 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

name                gradle
version             9.6.1
revision            0
categories          devel java groovy
license             Apache-2
maintainers         {amake @amake} openmaintainer

description         An open-source build system that is based on the Groovy language
long_description    Gradle is a build system which offers you ease, power and freedom. \
                    You can choose the balance for yourself. It has powerful multi-project build \
                    support. It has a layer on top of Ivy that provides a build-by-convention \
                    integration for Ivy. It gives you always the choice between the flexibility \
                    of Ant and the convenience of a build-by-convention behavior.

homepage            https://gradle.org/
platforms           {darwin any}
supported_archs     noarch
default distname    {${name}-${version}-bin}
master_sites        https://services.gradle.org/distributions

# Update checksums for variant when updating these!
checksums           rmd160  82b8a4514f17cbfa147f2cff3c11f5d4e816a8eb \
                    sha256  9c0f7faeeb306cb14e4279a3e084ca6b596894089a0638e68a07c945a32c9e14 \
                    size    140682664

default worksrcdir  {${name}-${version}}

use_zip             yes
use_configure       no

if {${subport} eq ${name}} {
    java.version    17+
    java.fallback   openjdk17
}

build {}

pre-destroot {
    # Remove extraneous bat files
    delete {*}[glob ${worksrcpath}/bin/*.bat]
}

destroot {
    # Create the target java directory
    xinstall -m 0755 -d ${destroot}${prefix}/share/java/${name}

    # Copy over the needed elements of our directory tree
    copy ${worksrcpath}/bin \
        ${worksrcpath}/lib \
        ${worksrcpath}/LICENSE \
        ${worksrcpath}/NOTICE \
        ${worksrcpath}/README \
        ${destroot}${prefix}/share/java/${name}

    # Symlink gradle into the bin directory
    ln -s ${prefix}/share/java/${name}/bin/gradle ${destroot}${prefix}/bin
}

if {${subport} eq ${name}} {
    variant all description {Install supplemental documentation and source code} {
        distname    ${name}-${version}-all

        checksums   rmd160  93ec80c8e63724fe6ab315abc96d343d4d21d53c \
                    sha256  61ba77b3ff7167e60962763eb4bae79db7120c189b9544358d0ade3c1e712a83 \
                    size    239601473

        post-destroot {
            xinstall -m 0755 -d ${destroot}${prefix}/share/doc/${name}
            copy ${worksrcpath}/src \
                ${worksrcpath}/docs \
                ${destroot}${prefix}/share/doc/${name}
        }
    }
}

livecheck.type  regex
livecheck.url   ${master_sites}
livecheck.regex ${name}-(\\d+\\.\\d+(\\.\\d+)?)-all\\.zip

subport ${name}8 {
    version         8.14.5
    revision        0

    maintainers     nomaintainer
    description-append\
                    (version 8 for compatibility with older projects)

    java.version    1.8+
    java.fallback   openjdk8

    checksums       rmd160  979403ccd77871395444d68776162ce23868ad8a \
                    sha256  6f74b601422d6d6fc4e1f9a1ab6522f642c2fdcbc15ae33ebd30ba3d7198e854 \
                    size    138068841

    post-destroot {
        move ${destroot}${prefix}/share/java/${name} ${destroot}${prefix}/share/java/${subport}
        delete ${destroot}${prefix}/bin/${name}
        ln -s ${prefix}/share/java/${subport}/bin/gradle ${destroot}${prefix}/bin/${subport}
    }

    livecheck.regex ${name}-(8\\.\\d+(\\.\\d+)?)-all\\.zip
}

notes {
  For Bash and Zsh completion support, install port 'gradle-completion'.
}
