// This gradle build depends on Mendix internal resources, the lastest commit
// which did not is 6e1527a5e31347c6914bc34deab31ef4ab46953b. You may restore
// the gradle scripts to that commit if you which to use them at your own risk.
// We don't guarantee that those will keep working in the future.

plugins {
    id 'java'
    id 'com.mendix.gradle.publish-module-plugin' version '1.1'
}

sourceCompatibility = '11'
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'

project.ext {
    mendixVersion = '8.12.7'
}

mxMarketplace {
    mxProjectDirectory = "src/CommunityCommons"
}

def userLibDir = "$projectDir/src/CommunityCommons/userlib"

repositories {
    maven {
        url 'https://nexus.rnd.mendix.com/repository/repo1-proxy/'
    }
    maven {
        url 'https://nexus.rnd.mendix.com/repository/maven-hosted/'
    }
}

dependencies {
    testImplementation(
            [group: 'com.mendix', name: 'public-api', version: "$mendixVersion"],
            [group: 'junit', name: 'junit', version: '4.13.2'],
            [group: 'org.apache.httpcomponents', name: 'httpcore', version: '4.4.14'],
            [group: 'org.apache.httpcomponents', name: 'httpclient', version: '4.5.13']
    )

    compileOnly([group: 'com.mendix', name: 'public-api', version: "$mendixVersion"])

    implementation(
            [group: 'com.google.guava', name: 'guava', version: '30.1.1-jre'],
            [group: 'com.googlecode.owasp-java-html-sanitizer', name: 'owasp-java-html-sanitizer', version: '20200713.1'],
            [group: 'commons-io', name: 'commons-io', version: '2.8.0'],
            [group: 'org.apache.pdfbox', name: 'pdfbox', version: '2.0.24'],
            [group: 'org.apache.commons', name: 'commons-lang3', version: '3.11']
    )
}

sourceSets {
    main {
        java {
            srcDir 'src/CommunityCommons/javasource'
            exclude 'unittesting/**'
            exclude 'system/UserActionsRegistrar.java'
        }
    }
    test {
        java {
            srcDirs = ["src/test", "src/CommunityCommons/javasource"]
        }
    }
}

test {
    exclude 'unittesting/*'
}

task copyAllToUserlib(type: Copy) {
    from configurations.testCompileClasspath
    into userLibDir
    eachFile { fileCopyDetails -> new File(destinationDir, "${fileCopyDetails.name}.${project.name}.RequiredLib").write '' }
}

task copyRuntimeToUserlib(type: Copy) {
    from configurations.runtimeClasspath
    into userLibDir
    eachFile { fileCopyDetails -> new File(destinationDir, "${fileCopyDetails.name}.${project.name}.RequiredLib").write '' }
}

clean {
    delete "$userLibDir"
}
