# -*- 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                NetBeans
set name_lower      [string tolower ${name}]
version             27
revision            0
categories          aqua devel java
# This port uses prebuilt binaries; 'NoMirror' makes sure MacPorts doesn't
# mirror/distribute these third-party binaries
license             Apache-2 NoMirror
maintainers         openmaintainer {amake @amake}
supported_archs     noarch

description         Java integrated development environment
long_description \
    NetBeans IDE lets you quickly and easily develop Java desktop, mobile, and \
    web applications, as well as HTML5 applications with HTML, JavaScript, and \
    CSS. The IDE also provides a great set of tools for PHP and C/C++ \
    developers. It is free and open source and has a large community of users \
    and developers around the world.

homepage            https://netbeans.apache.org/

platforms           {darwin any}

distname            ${name_lower}-${version}-bin
master_sites        apache:${name_lower}/${name_lower}/${version}

checksums           rmd160  10af6dea84be0882a3ac496e685f05c75063666d \
                    sha256  fc1f2a13f0f0bf52fa819f284cfb1fabeccb6f7704c90d980ddc3a5053629bc7 \
                    size    514762127

worksrcdir          ${name_lower}

use_zip             yes
use_configure       no

java.version        17+

build {}

post-extract {
    delete {*}[glob ${worksrcpath}/bin/*.exe]
}

destroot {
    xinstall -m 0755 -d ${destroot}${prefix}/share/java

    set target_dir ${prefix}/share/java/${name_lower}
    copy ${worksrcpath} ${destroot}/${target_dir}
    ln -s ${target_dir}/bin/${name_lower} ${destroot}${prefix}/bin/${name_lower}

    set app "${destroot}${applications_dir}/Apache ${name} ${version}.app"
    xinstall -d ${app}/Contents/MacOS
    ln -s ${target_dir}/bin/${name_lower} ${app}/Contents/MacOS/${name_lower}

    xinstall -d ${app}/Contents/Resources

    # Icon and Plist from official app
    xinstall -m 0644 ${filespath}/Info.plist ${app}/Contents/
    xinstall -m 0644 ${filespath}/${name_lower}.icns ${app}/Contents/Resources/

    reinplace "s|@@VERSION@@|${version}|g" ${app}/Contents/Info.plist

    # There is some arcane magic going into this binary:
    # https://github.com/apache/netbeans/blob/ba85468772292fd64f188f4022f9d49f77f00b89/profiler/lib.profiler/native/scripts/buildnative-mac.sh#L62-L92
    #
    # On PPC{,64}, and i386, this binary has a reference to
    # /System/Library/Frameworks/JavaVM.framework/Versions/A/JavaVM which
    # doesn't exist on modern systems, and MacPorts' rev-upgrade flags the
    # binary as broken. We remove these archs to make rev-upgrade pass, but it's
    # unclear what effect this has on systems of the relevant archs.
    system -W ${destroot}${prefix}/share/java/netbeans/profiler/lib/deployed/jdk15/mac/ \
        "lipo -remove ppc -remove ppc64 -remove i386 libprofilerinterface.jnilib -o libprofilerinterface.jnilib"
}

universal_variant   no

livecheck.type      regex
livecheck.url       https://netbeans.apache.org/download/archive/index.html
livecheck.regex     ${name} (\\d+(?:\\.\\d+)*)
