# -*- 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 select 1.0
PortGroup java 1.0

name            maven4
# Until the final 4.0.0 release is out, we use a version that sorts before 4.0.0 to avoid upgrade problems
version         3.9.9-rc4
set real_version 4.0.0-rc-4
revision        1

categories      java devel
license         Apache-2
maintainers     {breun @breun} openmaintainer
platforms       any
supported_archs noarch

description     Apache Maven 4
long_description \
                Apache Maven is a software project management and \
                comprehension tool. Based on the concept of a project object \
                model (POM), Maven can manage a project's build, reporting \
                and documentation from a central piece of information.

homepage        https://maven.apache.org/

master_sites    apache:maven/maven-4/${real_version}/binaries
distname        apache-maven-${real_version}-bin
worksrcdir      apache-maven-${real_version}

checksums       rmd160  7e0ae39764b17d90ceac0bd47cf1b97494281e11 \
                sha256  454ab0fb07e6e9e365f7f56e6bcef18df1d619aa57e2bd6de527f0e0c85bdbbb \
                size    14687761

java.version    17+
java.fallback   openjdk21

depends_run     port:maven_select

use_configure   no

select.group    maven
select.file     ${filespath}/${name}

# Source builds of maven are not possible. So, the default build is a binary
# install of the jars.
build {
}

destroot {
    set mavendir ${destroot}${prefix}/share/java/${name}

    # Create the target java directory exists
    xinstall -m 755 -d ${mavendir}

    # Copy over the needed elements of our directory tree
    file copy \
        ${worksrcpath}/bin \
        ${worksrcpath}/boot \
        ${worksrcpath}/conf \
        ${worksrcpath}/lib \
        ${mavendir}

    # Reduce the permissions on the distribution files.
    file attributes ${mavendir}/conf -permissions 0755
    file attributes ${mavendir}/conf/settings.xml -permissions 0644
    foreach f [glob -directory ${mavendir}/boot *.jar] {
        file attributes $f -permissions 0644
    }
    foreach f [glob -directory ${mavendir}/lib *.jar] {
        file attributes $f -permissions 0644
    }

    # Symlink Maven binaries into the bin directory
    ln -s ../share/java/${name}/bin/mvn ${destroot}${prefix}/bin/mvn4
    ln -s ../share/java/${name}/bin/mvnDebug ${destroot}${prefix}/bin/mvnDebug4
    ln -s ../share/java/${name}/bin/mvnenc ${destroot}${prefix}/bin/mvnenc4
    ln -s ../share/java/${name}/bin/mvnsh ${destroot}${prefix}/bin/mvnsh4
    ln -s ../share/java/${name}/bin/mvnup ${destroot}${prefix}/bin/mvnup4
}

test.run    yes
test.cmd    bin/mvn
test.target
test.args   --version

notes \
"- To make maven ${real_version} the default, please run: sudo port select --set ${select.group} ${name}
- To add bash completions, install port maven-completion"

livecheck.type  regex
livecheck.url   ${homepage}docs/history.html
livecheck.regex >(4\\.\[0-9.\]+\\.\[0-9.\]+)</
