/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */

def libRepoName = properties.libRepositoryName
def libUrl = properties.libUrl
def libVcsUrl = properties.libVcsUrl
def libLicense = properties.libLicense
def libLicenseUrl = properties.libLicenseUrl

ext.configurePublish = { groupIdArg, artifactIdArg, descriptionArg ->
    apply plugin: 'digital.wup.android-maven-publish'

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

    publishing {
        publications {
            aar(MavenPublication) {
                from components.android
                artifact sourcesJar

                pom {
                    groupId = groupIdArg
                    artifactId = artifactIdArg
                    description = descriptionArg
                    version = config.componentsVersion + (project.hasProperty('snapshot') ? '-SNAPSHOT' : '')

                    licenses {
                        license {
                            name = libLicense
                            url = libLicenseUrl
                        }
                    }

                    developers {
                        developer {
                            name = 'Mozilla Android Components Team'
                            email = 'android-components@lists.mozilla.org'
                        }
                    }

                    scm {
                        connection = libVcsUrl
                        developerConnection = libVcsUrl
                        url = libUrl
                    }
                }
            }
        }

        repositories {
            maven {
                url = "$buildDir/maven"
            }
        }
    }

    task zipMavenArtifacts(type: Zip) {
        from "${project.buildDir}/maven"

        include '**/*.aar'
        include '**/*.jar'
        include '**/*.pom'
        include '**/*.md5'
        include '**/*.sha1'

        // Metadata is generated by maven.mozilla.org directly
        exclude '**/*maven-metadata.xml*'

        archiveName "target.maven.zip"
        includeEmptyDirs = false
        destinationDir(file("${project.buildDir}"))
    }
}
