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

github.setup            iBotPeaches Apktool 3.0.3 v
github.tarball_from     archive
name                    [string tolower ${github.project}]

categories              java devel
supported_archs         x86_64 arm64
license                 Apache-2
maintainers             {i0ntempest @i0ntempest} openmaintainer

description             A tool for reverse engineering 3rd party, closed, binary Android apps
long_description        Apktool is a tool for reverse engineering 3rd party, closed, binary Android apps.\
                        It can decode resources to nearly original form and rebuild them after making\
                        some modifications. It also makes working with an app easier because of the\
                        project like file structure and automation of some repetitive tasks like\
                        building apk, etc.

homepage                https://apktool.org

checksums               rmd160  b769d238a2170826d42e57e053d1b9a49db22259 \
                        sha256  22b577d080ca53381c61cbeade7d80ff7a5f365faeb469ec80b2bce6bdd1f763 \
                        size    29566900

java.version            1.8+
java.fallback           openjdk11

use_configure           no
universal_variant       no

depends_build-append    port:gradle8

build.env-append        GRADLE_USER_HOME=${worksrcpath}
build.cmd               ${prefix}/bin/gradle8
build.args              --no-daemon --console=plain --stacktrace -p ${worksrcpath}
build.target            shadowJar

post-patch {
    reinplace "s|!in gradle.startParameter.taskNames|in gradle.startParameter.taskNames|g" ${worksrcpath}/build.gradle.kts
}

destroot {
    copy ${worksrcpath}/brut.apktool/apktool-cli/build/libs/apktool-cli.jar ${destroot}${prefix}/libexec/
    set script [open ${destroot}${prefix}/bin/apktool w]
    puts $script "#!/bin/sh"
    puts $script "\$(/usr/libexec/java_home)/bin/java -jar ${prefix}/libexec/apktool-cli.jar \"$@\""
    close $script
    file attributes ${destroot}${prefix}/bin/apktool -permissions ugo+x
}
