buildscript {
    repositories {
        mavenCentral()
    }
    dependencies {
        classpath 'org.owasp:dependency-check-gradle:8.4.3'
    }
}

plugins {
    id 'java-library'
    id 'maven-publish'
    id 'signing'
    id 'com.adarshr.test-logger' version '4.0.0'
    id 'org.owasp.dependencycheck' version "8.4.3"
}

dependencyCheck {
    failBuildOnCVSS=5
    suppressionFile="allow-list.xml"
}

def mamaVersion = project.findProperty('mamaVersion') ?: new File("${projectDir.absolutePath}/../../build/VERSION").text.trim() + "-1"
def mamaJniHeaderDir = project.findProperty('mamaJniHeaderDir') ?: 'mamajni'

if (!project.hasProperty('legacyNaming')) {
  group = "org.openmama"
  archivesBaseName = "openmama"
  version = mamaVersion
}

repositories {
    mavenCentral()
}

dependencies {
    testImplementation "junit:junit:4.13.2"  // Or whatever version
}

test {
    systemProperties = [
        dictionary: System.getProperty('dictionary')
    ]
    testLogging.showStandardStreams = true
    testLogging.showExceptions = true
    maxParallelForks = 1
}

javadoc {
    source = sourceSets.main.allJava
    title = 'MAMA (Middleware Agnostic Messaging API) JNI specification, v' + mamaVersion
    options.overview = 'doc/overview-jni.html'
    options.windowTitle = 'MAMA JNI ' + mamaVersion
    options.bottom = 'Copyright 2011 NYSE Technologies'
}

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

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

tasks.withType(JavaCompile) {
    options.compilerArgs += ["-h", mamaJniHeaderDir]
}

artifacts {
    archives javadocJar, sourcesJar
}

publishing {
  publications {
    mavenJava(MavenPublication) {
      artifactId = 'openmama'
      from components.java
      versionMapping {
          usage('java-api') {
              fromResolutionOf('runtimeClasspath')
          }
          usage('java-runtime') {
              fromResolutionResult()
          }
      }
      pom {
        name = 'OpenMAMA'
        // optionally artifactId can be defined here 
        description = 'OpenMAMA is a high performance vendor neutral lightweight wrapper that provides a common API interface to different middleware and messaging solutions across a variety of platforms and languages.'
        url = 'https://www.openmama.org'
  
        licenses {
          license {
            name = 'GNU LESSER GENERAL PUBLIC LICENSE 2.1'
            url = 'https://www.gnu.org/licenses/old-licenses/lgpl-2.1.en.html'
          }
        }

        developers {
          developer {
            id = 'fquinner'
            name = 'Frank Quinn'
            email = 'fquinn@cascadium.io'
          }
        }

        scm {
          connection = 'scm:https://github.com/OpenMAMA/OpenMAMA.git'
          developerConnection = 'scm:git@github.com:OpenMAMA/OpenMAMA.git'
          url = 'https://github.com/OpenMAMA/OpenMAMA'
        }
      }
    }
  }
  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
    }
  }
}

signing {
    sign publishing.publications.mavenJava
}
