/*
 * MIT License
 *
 * Copyright (c) 2021 Todd Ginsberg
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in all
 * copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
}

ext {
    junitVersion = '5.8.1'
}

group 'com.ginsberg'
version '1.1.2'

repositories {
    mavenCentral()
}

dependencies {
    compileOnly("org.junit.jupiter:junit-jupiter-api:$junitVersion")

    testImplementation("org.junit.jupiter:junit-jupiter-api:$junitVersion")
    testImplementation("org.junit.jupiter:junit-jupiter-params:$junitVersion")
    testImplementation("org.junit.platform:junit-platform-launcher")
    testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
}

test {
    useJUnitPlatform()
    afterSuite { desc, result ->
        if (!desc.parent) {
            println "\nTest result: ${result.resultType}"
            println "Test summary: ${result.successfulTestCount} succeeded, " +
                    "${result.failedTestCount} failed"
        }
    }
}

task sourcesJar(type: Jar) {
    from sourceSets.main.allJava
    archiveClassifier = 'sources'
}

task javadocJar(type: Jar) {
    from javadoc
    archiveClassifier = 'javadoc'
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            groupId = project.group
            artifactId = project.name
            version = project.version
            from components.java
            artifact sourcesJar
            artifact javadocJar
            pom {
                name = 'junit5-system-exit'
                description = 'A JUnit5 Extension to help write tests that call System.exit()'
                url = 'https://github.com/tginsberg/junit5-system-exit'
                organization {
                    name = 'com.ginsberg'
                    url = 'https://github.com/tginsberg'
                }
                issueManagement {
                    system = 'GitHub'
                    url = 'https://github.com/tginsberg/junit5-system-exit/issues'
                }
                licenses {
                    license {
                        name = 'MIT License'
                        url = 'https://opensource.org/licenses/MIT'
                    }
                }
                scm {
                    connection = 'scm:git:https://github.com/tginsberg/junit5-system-exit.git'
                    developerConnection = 'scm:git:https://github.com/tginsberg/junit5-system-exit.git/'
                    url = 'https://github.com/tginsberg/junit5-system-exit'
                }
                developers {
                    developer {
                        id = 'tginsberg'
                        name = 'Todd Ginsberg'
                        email = 'todd@ginsberg.com'
                    }
                }
            }
        }
    }
    repositories {
        maven {
            def releasesRepoUrl = "https://oss.sonatype.org/service/local/staging/deploy/maven2/"
            def snapshotsRepoUrl = "https://oss.sonatype.org/content/repositories/snapshots/"
            url = version.endsWith('SNAPSHOT') ? snapshotsRepoUrl : releasesRepoUrl
            credentials {
                username sonatypeUsername
                password sonatypePassword
            }
        }
    }
}

javadoc {
    if(JavaVersion.current().isJava9Compatible()) {
        options.addBooleanOption('html4', true)
    }
}

signing {
    sign publishing.publications.mavenJava
}