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

PortSystem              1.0
PortGroup               github 1.0
PortGroup               java 1.0

name                    junit5
github.setup            junit-team junit-framework 5.14.4 r
github.tarball_from     archive
github.livecheck.regex  "(5(\\.\[0-9]+)*)"

categories              java devel
license                 EPL-2
platforms               any
supported_archs         noarch
homepage                https://junit.org
maintainers             {sethm.id.au:dev @McDaMastR} \
                        openmaintainer

description             Programmer-friendly testing framework for Java
long_description        JUnit 5 is a simple framework to write repeatable \
                        tests.  It is an instance of the xUnit architecture \
                        for unit testing frameworks.

depends_build-append    bin:gradle8:gradle8

# Building requires Java == 8 and Java == 21
# Running requires Java >= 8
#
# Until the java PortGroup has a way to specify multiple required JDKs,
# just depend on JDK 8+ as required for running
# and let Gradle fetch any JDKs not found on the system.
#
# When this functionality is available, add
# --project-prop=org.gradle.java.installations.auto-download=false
# to the build and test arguments to prevent Gradle from fetching JDKs.
java.version            1.8+

set gradle_home         ${workpath}/.home/.gradle

# Build requires a Git repo
fetch.type              git

patchfiles              update-develocity-hostname.diff

use_configure           no

build.cmd               gradle8
build.target            build
build.args              --no-daemon \
                        --exclude-task=check \
                        --exclude-task=javadocJar \
                        --exclude-task=sourcesJar \
                        --gradle-user-home="${gradle_home}"

test.run                yes
test.target             check
test.args               --no-daemon \
                        --exclude-task=spotlessJava \
                        --gradle-user-home="${gradle_home}" \
                        --project-prop=publishing.signArtifacts=false \
                        --system-prop=platform.tooling.support.tests.enabled=false

destroot {
    set destdocdir  ${destroot}${prefix}/share/doc/${name}
    set destjavadir ${destroot}${prefix}/share/java/${name}

    set modules {
        junit-jupiter
        junit-jupiter-api
        junit-jupiter-engine
        junit-jupiter-migrationsupport
        junit-jupiter-params
        junit-platform-commons
        junit-platform-console
        junit-platform-console-standalone
        junit-platform-engine
        junit-platform-jfr
        junit-platform-launcher
        junit-platform-reporting
        junit-platform-runner
        junit-platform-suite
        junit-platform-suite-api
        junit-platform-suite-commons
        junit-platform-suite-engine
        junit-platform-testkit
        junit-vintage-engine
    }

    xinstall -d ${destjavadir}
    foreach module ${modules} {
        # Platform jar files are named *-1.x.x.jar instead of *-5.x.x.jar
        xinstall -m 644 \
            [glob -directory ${worksrcpath}/${module}/build/libs *.jar] \
            ${destjavadir}/${module}.jar
    }

    xinstall -d ${destdocdir}
    xinstall -m 644 \
        ${worksrcpath}/CODE_OF_CONDUCT.md \
        ${worksrcpath}/CONTRIBUTING.md \
        ${worksrcpath}/LICENSE.md \
        ${worksrcpath}/NOTICE.md \
        ${worksrcpath}/README.md \
        ${worksrcpath}/RELEASING.md \
        ${worksrcpath}/SECURITY.md \
        ${destjavadir}

    if {[variant_isset doc]} {
        xinstall -d ${destdocdir}/javadoc
        foreach module ${modules} {
            # Not all modules contain javadoc
            if {[file exists ${worksrcpath}/${module}/build/docs/javadoc]} {
                copy \
                    ${worksrcpath}/${module}/build/docs/javadoc \
                    ${destdocdir}/javadoc/${module}
            }
        }
    }
}

variant doc \
        description {Install javadoc} {
    build.target-append javadoc
}
