# -*- 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               github 1.0
PortGroup               maven 1.0

github.setup            checkstyle checkstyle 14.4.0 checkstyle-
github.tarball_from     archive

categories              java devel
license                 LGPL-2.1+
platforms               any
supported_archs         noarch
homepage                https://checkstyle.org
maintainers             {sethm.id.au:dev @McDaMastR} \
                        openmaintainer

description             Configurable Java source code analyzer
long_description        Checkstyle automates the process of checking Java code \
                        against configurable rules and can support almost any \
                        coding standard.  It can account for naming, imports, \
                        formatting, Javadoc, class design, and more.

if {[variant_isset doc]} {
    java.version        21
    java.fallback       openjdk21
} else {
    java.version        21+
}

checksums               rmd160  2408b473a1fa40e849e63ca34f0ba4e09fe3ad60 \
                        sha256  d2249823d9906097e76828d2628704ef8417eea4b1581953e069c76b48e3a539 \
                        size    10259812

build.args              --activate-profiles=assembly \
                        --activate-profiles=no-validations \
                        --define=maven.source.skip

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

    xinstall -d ${destbindir}
    xinstall ${filespath}/${name} ${destbindir}
    reinplace "s|@@PREFIX@@|${prefix}|g" ${destbindir}/${name}

    xinstall -d ${destjavadir}
    xinstall -W ${worksrcpath} -m 644 \
        target/${name}-${version}-all.jar \
        ${destjavadir}/${name}-all.jar

    xinstall -d ${destxmldir}
    xinstall -m 644 \
        {*}[glob -directory ${worksrcpath}/src/main/resources *.xml] \
        ${destxmldir}

    xinstall -d ${destdocdir}
    xinstall -W ${worksrcpath} -m 644 \
        LICENSE \
        README.md \
        SECURITY.md \
        {*}[glob -directory ${worksrcpath}/docs *] \
        ${destdocdir}

    if {[variant_isset doc]} {
        copy ${worksrcpath}/target/reports/apidocs ${destdocdir}/javadoc
    }
}

variant doc \
        description {Install javadoc} {
    build.target-append javadoc:javadoc
    build.args-append   --define=maven.javadoc.skip=false
}
