import com.install4j.gradle.Install4jTask

apply plugin: 'install4j'
apply plugin: 'bintray'

install4j {
    if (project.hasProperty('install4jHomeDir')) {
        installDir = file(install4jHomeDir)
    }
}

task clean << {
    delete mediaDir
}

task media(type: Install4jTask) {

    dependsOn ':dist', ':clean'
    projectFile = file('resources/jclasslib.install4j')
    release = version

    doFirst {
        if (!project.hasProperty('install4jHomeDir')) {
            throw new RuntimeException('Specify install4jHomeDir in gradle.properties and set it to an install4j installation directory')
        }
    }
}

bintray {
    if (project.hasProperty('bintrayUser')) {
        user = bintrayUser
        key = bintrayApiKey
        files = fileTree(dir: mediaDir, include: "*${version.toString().replace('.', '_')}.*")
        pkg {
            repo = 'generic'
            name = 'jclasslib'
            licenses = ['GPL-2.0']
        }
        dryRun = project.hasProperty('dryRun')
    }
}

bintrayUpload {
    doFirst {
        if (!project.hasProperty('bintrayUser')) {
            throw new RuntimeException('Specify bintrayUser and bintrayApiKey in gradle.properties')
        }
    }
}
