//
// Copyright (c) ZeroC, Inc. All rights reserved.
//

buildscript {
    repositories {
        mavenCentral()
    }

    dependencies {
        classpath "com.guardsquare:proguard-gradle:7.4.0-beta02"
    }
}

if(JavaVersion.current() == JavaVersion.VERSION_1_8) {
    ['rt.jar',
     'jsse.jar',
     'i386/default/jclSC170/vm.jar',
     'amd64/default/jclSC170/vm.jar',
     'ibmcertpathfw.jar',
     'math.jar'].each {
        def jfile = searchFile(["${System.properties['java.home']}"], ["${it}", "lib/${it}", "jre/lib/${it}"])
        if(jfile) {
            project.ext.libJars << jfile
        }
    }

    if(hasJavaFx) {
        project.ext.libJars << "${System.properties['java.home']}/${javafxJar}"
    }
}
else {
    ['java.base.jmod',
     'java.xml.jmod',
     'java.desktop.jmod',
     'java.prefs.jmod',
     'java.naming.jmod',
     'java.datatransfer.jmod',
     'jdk.unsupported.desktop.jmod',
     'javafx.base.jmod',
     'javafx.controls.jmod',
     'javafx.graphics.jmod',
     'javafx.swing.jmod',
     'java.logging.jmod'].each {
        project.ext.libJars << "${System.properties['java.home']}/jmods/${it}"
    }
}

task proguardJar(type: proguard.gradle.ProGuardTask, dependsOn: jar) {
    injars configurations.runtimeClasspath.resolve(), filter: "!META-INF/**"
    injars "${projectDir}/build/libs/${tmpJarName}"
    outjars "${libDir}/${jarName}"
    libraryjars project.ext.libJars
    configuration 'icegridgui.pro'
}

task copyJars(type: Copy, dependsOn: proguardJar) {
    from new File("${libDir}/${jarName}")
    into "${DESTDIR}${jarDir}"
}

task install(dependsOn: copyJars)

assemble.dependsOn(proguardJar)
