plugins {
    id 'library-publication' // buildSrc/src/main/groovy/library-publication.gradle
}

dependencies {
    internal platform(project(":platform")) // all library versions should be specified in the platform project
    implementation "org.slf4j:slf4j-api"
    implementation "org.springframework:spring-beans"
    implementation "org.springframework:spring-context"
    implementation "commons-cli:commons-cli"
    // jaxb was removed from Java 11 - jaxb dependencies are provided with Java 8
    implementation "javax.xml.bind:jaxb-api"
    implementation "org.eclipse.persistence:org.eclipse.persistence.moxy"

    // jaxb was removed from Java 11 - jaxb dependencies are provided with Java 8
    runtimeOnly "org.glassfish.jaxb:jaxb-runtime"

    testImplementation 'org.junit.jupiter:junit-jupiter-api'

    testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine'
    testRuntimeOnly 'org.apache.logging.log4j:log4j-slf4j-impl'
}

test {
    useJUnitPlatform()
}

task jaxbFiles(type: Exec) {
    workingDir project.projectDir
    commandLine 'grep', '-lR', 'XmlRootElement', 'src/main/java'
    standardOutput = new ByteArrayOutputStream()
    ext.output = {
        return standardOutput.toString()
    }
}

task schemagen(type: Exec, dependsOn: [jaxbFiles, compileJava]) {
    description "Generates an XML schema and puts it in ${rootProject.projectDir}/sample/model.xsd"
    doFirst {
        def argList = ['-d', "${sourceSets.main.output.classesDir}",
                '-cp', "${configurations.compile.asPath}${File.pathSeparatorChar}${sourceSets.main.output.classesDir}${File.pathSeparatorChar}src/main/java"]
        argList.addAll(jaxbFiles.output().split('\n'))
        args(argList as String[])
    }
    workingDir project.projectDir
    executable 'schemagen'
    ignoreExitValue true
    doLast {
        file("${sourceSets.main.output.classesDir}/schema1.xsd").renameTo(file("${rootProject.projectDir}/sample/model.xsd"))
    }
}

repositories {
    mavenCentral()
}