buildscript {
    repositories {
        mavenCentral()
        maven {
            url "https://plugins.gradle.org/m2/"
        }
    }

    dependencies {
        classpath "gradle.plugin.com.hierynomus.gradle.plugins:license-gradle-plugin:0.16.1"
        classpath "me.champeau.gradle:jmh-gradle-plugin:0.5.3"
        classpath 'ru.vyarus:gradle-animalsniffer-plugin:1.6.0'
        classpath "biz.aQute.bnd:biz.aQute.bnd.gradle:6.4.0"
        classpath 'com.vanniktech:gradle-maven-publish-plugin:0.18.0'
    }
}

apply plugin: 'java-library'
apply plugin: 'eclipse'
apply plugin: "me.champeau.gradle.jmh"
apply plugin: 'pmd'
apply plugin: 'jacoco'
apply plugin: 'ru.vyarus.animalsniffer'
apply plugin: "com.github.hierynomus.license"

sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8

group = "com.github.akarnokd" 
ext.githubProjectName = 'rxjava3-interop'

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

if (!hasProperty('mainClass')) {
    ext.mainClass = ''
}

repositories {
    mavenCentral()
    maven { url 'https://oss.sonatype.org/content/repositories/snapshots' }
    maven { url 'https://oss.sonatype.org/content/groups/public' }
    maven { url 'https://repo.spring.io/libs-snapshot' }
}

dependencies {
    signature 'org.codehaus.mojo.signature:java18:1.0@signature'

    api "org.reactivestreams:reactive-streams:1.0.4"
    api "io.reactivex:rxjava:1.3.8"
    api "io.reactivex.rxjava3:rxjava:3.1.6"

    testImplementation group: 'junit', name: 'junit', version: '4.13.2'
    testImplementation 'org.mockito:mockito-core:4.9.0'
}

apply plugin: 'biz.aQute.bnd.builder'

jar {
    bnd ('Bundle-Name': 'rxjava3-interop',
            'Bundle-Vendor': 'akarnokd',
            'Bundle-Description': 'Library to convert between RxJava 1.x and 3.x reactive types, schedulers and resource handles.',
            'Import-Package': '!org.junit,!junit.framework,!org.mockito.*,*',
            'Bundle-DocURL': 'https://github.com/akarnokd/RxJavaInterop',
            'Export-Package': 'hu.akarnokd.rxjava3.interop.*'
        )
}

apply plugin: "com.vanniktech.maven.publish"

jmh {
    jmhVersion = '1.21'
    humanOutputFile = null
    if (project.hasProperty('jmh')) {
        include = ".*" + project.jmh + ".*"
    } else {
        include = ".*"
    }
}

plugins.withType(EclipsePlugin) {
    project.eclipse.classpath.plusConfigurations += [ configurations.jmh ]
}

javadoc {
    failOnError = false
    
    options.links(
        "http://docs.oracle.com/javase/7/docs/api/",
        "http://reactivex.io/RxJava/1.x/javadoc", 
        "http://reactivex.io/RxJava/3.x/javadoc"
    )
}

test {
    maxHeapSize = "2g"
    testLogging  {
        events "started", "failed" // "skipped", "passed"
    //    showStandardStreams = true
    }
}

license {
    header rootProject.file('HEADER')
    ext.year = Calendar.getInstance().get(Calendar.YEAR)
    skipExistingHeaders true
    ignoreFailures true
    excludes(["**/*.md", "**/*.txt"])
}

jacoco {
    toolVersion = '0.8.5' // See http://www.eclemma.org/jacoco/.
}

jacocoTestReport {
    reports {
        xml.enabled = true
        html.enabled = true
    }
}

build.dependsOn jacocoTestReport

check.dependsOn jacocoTestReport

pmd {
    toolVersion = '6.21.0'
    ignoreFailures = true
    sourceSets = [sourceSets.main]
    ruleSets = []
    ruleSetFiles = files('pmd.xml')
}

pmdMain {
    reports {
        html.enabled = true
        xml.enabled = true
    }
}

task pmdPrint(dependsOn: 'pmdMain') doLast {
    File file = rootProject.file('build/reports/pmd/main.xml')
    if (file.exists()) {

        println("Listing first 100 PMD violations")

        file.eachLine { line, count ->
            if (count <= 100) {
               println(line)
            }
        }

    } else {
        println("PMD file not found.")
    }
}

build.dependsOn pmdPrint
check.dependsOn pmdPrint

animalsniffer {
    annotation = 'rx.internal.util.SuppressAnimalSniffer'
}
