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

# Until 2.0.0 is released, use a version that sorts before 2.0.0
version         1.9.9-rc3
set real_version 2.0.0-rc-3
revision        1
name            mvnd2
categories      java
platforms       {darwin any}
maintainers     {breun @breun} openmaintainer
license         Apache-2

description     mvnd 2 -- The Maven Daemon based on Apache Maven 4

long_description mvnd aims at providing faster Maven builds using techniques known from Gradle and Takari.\
                \n\
                \n* mvnd embeds Maven (so there is no need to install Maven separately).\
                \n* The actual builds happen inside a long living background process, a.k.a. daemon.\
                \n* One daemon instance can serve multiple consecutive requests from the mvnd client.\
                \n* The mvnd client is a native executable built using GraalVM.\
                It starts faster and uses less memory compared to starting a traditional JVM.\
                \n* Multiple daemons can be spawned in parallel if there is no idle daemon to serve a build request.\
                \n* The JVM for running the actual builds does not need to get started anew for each build.\
                \n* The classloaders holding classes of Maven plugins are cached over multiple builds.\
                The plugin jars are thus read and parsed just once. SNAPSHOT versions of Maven plugins are not cached.\
                \n* The native code produced by the Just-In-Time (JIT) compiler inside the JVM is kept too.\
                Compared to stock Maven, less time is spent by the JIT compilation.\
                During the repeated builds the JIT-optimized code is available immediately.\
                This applies not only to the code coming from Maven plugins and Maven Core,\
                but also to all code coming from the JDK itself.

homepage        https://github.com/apache/maven-mvnd
supported_archs x86_64 arm64

master_sites    https://downloads.apache.org/maven/mvnd/${real_version}/

depends_run     port:mvnd_select

use_configure   no

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

if {${configure.build_arch} eq "x86_64"} {
    set arch_classifier amd64
    checksums       rmd160  bd3ef67d264d5d67589165f51bccf2517aa26e0b \
                    sha256  bc17fa11463bcd23ad1524a0f9a847042e0663cdde6db2be1f0683495eee4d29 \
                    size    27151628
} elseif {${configure.build_arch} eq "arm64"} {
    set arch_classifier aarch64
    checksums       rmd160  5442ca34d2365455f8ba3cae59b092995b212146 \
                    sha256  359980623981dda8eb00a39761eb130adb88259e1b145330b53981c66a7600fd \
                    size    27316340
} else {
    set arch_classifier unsupported_arch
}

distname maven-mvnd-${real_version}-darwin-${arch_classifier}

build {}

destroot {
    set target ${prefix}/share/java/${name}
    set dest_target ${destroot}${target}

    # Create the target directory in the destroot
    xinstall -m 755 -d ${dest_target}

    # Copy files into destroot
    foreach f [glob -directory ${worksrcpath} *] {
        copy ${f} ${dest_target}
    }

    # Remove files that are not needed on macOS
    delete ${dest_target}/bin/mvnd.cmd

    # Create launch script
    set launch_script [open ${destroot}${prefix}/bin/${name} w 0755]
    puts $launch_script "${target}/bin/mvnd $@"
    close $launch_script
}

notes \
"- To make mvnd ${real_version} the default, please run: sudo port select --set ${select.group} ${name}"
