// SPDX-FileCopyrightText: Copyright 2023-2025 Mark Rotteveel
// SPDX-License-Identifier: LGPL-2.1-or-later
plugins {
    id 'java-library'
    id 'nu.studer.credentials' version '3.0'
    id 'maven-publish'
    id 'signing'
}

group = 'org.firebirdsql.jdbc'
version = project.'version.maven'

dependencies {
    // NOTE: ':' represents the root module, which contains the main Jaybird driver
    api project(':')
    implementation libs.bcprov.jdk18on

    // Use JUnit Jupiter API for testing.
    testImplementation platform(testLibs.junit.bom)
    testImplementation testLibs.bundles.junit
    testRuntimeOnly testLibs.junit.platform.launcher
}

java {
    sourceCompatibility = JavaVersion.VERSION_17
    targetCompatibility = JavaVersion.VERSION_17
    withJavadocJar()
    withSourcesJar()
}

test {
    useJUnitPlatform()
}

// REUSE-IgnoreStart
jar {
    manifest {
        attributes(
                'Created-By': "${System.getProperty('java.vm.version')} (${System.getProperty('java.vm.vendor')})",
                'Implementation-Title': 'Jaybird ChaCha64 wire encryption',
                'Implementation-Url': project.'implementation.url',
                'Implementation-Version': "$project.version (build: variant=$project.mavenName tag=${project.'version.svntag'} date=${project.'build.id'})",
                'Implementation-Vendor': project.'implementation.vendor',
                'Implementation-Vendor-Id': project.'implementation.vendor.id',
                'Bundle-License': 'LGPL-2.1-or-later OR LGPL-2.1-or-later AND BSD-3-Clause',
                'SPDX-License-Identifier': 'LGPL-2.1-or-later OR LGPL-2.1-or-later AND BSD-3-Clause',
                'SPDX-FileCopyrightText': "Copyright 2001-${project.YEAR} Firebird development team and individual contributors"
        )
    }
}
// REUSE-IgnoreEnd

javadoc {
    options.author()
    options.windowTitle = "$project.capitalizedName ChaCha64 ${project.'version.maven'} "
    options.docTitle = "$project.capitalizedName ChaCha64 ${project.'version.maven'}"
    options.bottom = "Copyright &copy; 2023-${project.YEAR} Firebird development team and individual contributors. All rights reserved."
    options.addBooleanOption('html5', true)
    options.addBooleanOption('Xdoclint:none', true)
}

parent.tasks.named('dist', Zip) {
    from jar.outputs
    from javadocJar.outputs
    from sourcesJar.outputs
    from(configurations.runtimeClasspath) {
        exclude 'jaybird-*'
        exclude 'jspecify-*'
        into 'lib'
    }
}

publishing {
    publications {
        // chacha-64 maven artifact
        chacha64(MavenPublication) {
            from components.java
            suppressPomMetadataWarningsFor 'nativeApiElements'
            suppressPomMetadataWarningsFor 'nativeRuntimeElements'
            pom {
                name = 'ChaCha64 plugin for Jaybird'
                packaging = 'jar'
                description = 'ChaCha64 plugin for Jaybird JDBC Driver'
                url = 'https://www.firebirdsql.org/en/devel-jdbc-driver/'
                inceptionYear = '2023'

                developers {
                    developer {
                        id = 'mrotteveel'
                        name = 'Mark Rotteveel'
                        email = 'mark@lawinegevaar.nl'
                        roles = ['Administrator', 'Developer']
                    }
                }

                mailingLists {
                    mailingList {
                        name = 'firebird-java'
                        subscribe = 'firebird-java+subscribe@googlegroups.com'
                        unsubscribe = 'firebird-java+unsubscribe@googlegroups.com'
                        post = 'firebird-java@googlegroups.com'
                        archive = 'https://groups.google.com/g/firebird-java'
                        otherArchives = ['http://fb-list-archive.s3-website-eu-west-1.amazonaws.com/firebird-java/index.html']
                    }
                }

                licenses {
                    license {
                        name = 'GNU Lesser General Public License'
                        url = 'https://www.gnu.org/copyleft/lesser.html'
                        distribution = 'repo'
                        comments = 'The ChaCha 64 plugin for Jaybird JDBC driver is distributed free of charge under ' +
                                'the GNU Lesser General Public License (LGPL). Text of the license can be obtained ' +
                                'from https://www.gnu.org/copyleft/lesser.html'
                    }
                }

                scm {
                    connection = 'scm:git:https://github.com/FirebirdSQL/jaybird.git'
                    developerConnection = 'scm:git:https://github.com/FirebirdSQL/jaybird.git'
                    url = 'https://github.com/FirebirdSQL/jaybird'
                }

                issueManagement {
                    system = 'GitHub'
                    url = 'https://github.com/FirebirdSQL/jaybird/issues/'
                }
            }
        }
    }
    repositories {
        maven {
            url = project.isReleaseVersion.get() ? project.releaseRepository : project.snapshotRepository
            credentials {
                username = findProperty('centralUsername') ?: null
                password = findProperty('centralPassword') ?: null
            }
        }
    }
}

signing {
    required = { isReleaseVersion && gradle.taskGraph.hasTask(':publish') }
    sign publishing.publications.chacha64
}