# -*- 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.2.0
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
distname            ${name}-${version}-bin
master_sites        https://services.gradle.org/distributions
conflicts           ${name}8

# Update checksums for variant when updating these!
checksums           rmd160  ab857793898fda29a28ba0f0e5a37d322c00f0e2 \
                    sha256  df67a32e86e3276d011735facb1535f64d0d88df84fa87521e90becc2d735444 \
                    size    135534361

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  600d38c5408d6723c1bd53ac3fb829f9e8d6c19a \
                    sha256  16f2b95838c1ddcf7242b1c39e7bbbb43c842f1f1a1a0dc4959b6d4d68abcac3 \
                    size    233372472

        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.3

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

    conflicts       ${name}

    java.version    1.8+
    java.fallback   openjdk8

    checksums       rmd160  a933fdefa4f255db5b7a14f8e53ba7ae8cc311d5 \
                    sha256  bd71102213493060956ec229d946beee57158dbd89d0e62b91bca0fa2c5f3531 \
                    size    137393837

    livecheck.type  none
}

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