plugins {
    id 'java'
    id 'com.github.ben-manes.versions' version '0.52.0'
}

group 'ovh.akio'
version '1.5.0'

repositories {
    mavenCentral()
}

jar {
    manifest {
        attributes "Main-Class": "ovh.akio.hmu.Application"
    }

    from {
        configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

dependencies {
    implementation group: 'info.picocli', name: 'picocli', version: '4.7.6'
    implementation group: 'me.tongfei', name: 'progressbar', version: '0.10.1'

    implementation group: 'net.sf.sevenzipjbinding', name: 'sevenzipjbinding', version: '16.02-2.01'
    implementation group: 'net.sf.sevenzipjbinding', name: 'sevenzipjbinding-all-platforms', version: '16.02-2.01'
}

static def isNonStable(String version) {
    def stableKeyword = ['RELEASE', 'FINAL', 'GA'].any { it -> version.toUpperCase().contains(it) }
    def regex = /^[0-9,.v-]+(-r)?$/
    return !stableKeyword && !(version ==~ regex)
}

dependencyUpdates {
    rejectVersionIf {
        isNonStable(it.candidate.version) && !isNonStable(it.currentVersion)
    }
}

tasks.register('bundle', Zip) {
    group = 'build'
    description = 'Deploy all files required to execute this program into a single archive'

    dependsOn build

    var name = project.name + '-' + version.toString()
    archiveFileName = name + '.zip'

    from('./build/libs/' + name + '.jar') {
        into ''
    }
    from('wrappers') {
        into 'wrappers'
    }
}
