/*
 * build.gradle
 * NfcLibrary project.
 *
 * Created by : Daneo van Overloop - 17/6/2014.
 *
 * The MIT License (MIT)
 *
 * Copyright (c) 2014 AppFoundry. All rights reserved.
 *
 * 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.
 */

import com.android.builder.core.BuilderConstants

apply plugin: 'com.android.library'
//apply plugin: 'maven-publish'
apply plugin: 'maven'
apply plugin: 'signing'

//publishing {
//    publications {
//        maven(MavenPublication) {
//            groupId 'be.idamediafoundry'
//            artifactId 'nfc-lib'
//            version '1.0'
//            pom.withXml {
//                asNode().appendNode('description', 'Library facilitating the use of NFC on the Android platform.' +
//                        '')
//            }
////
////            from components.java
//        }
//    }
//}

android {
    compileSdkVersion 29
    buildToolsVersion "29.0.2"

    defaultConfig {
        minSdkVersion 16
        targetSdkVersion 29
        versionCode 12
        versionName "1.2"
    }
    buildTypes {
        release {
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
       }
        debug {
            minifyEnabled false
            proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.txt'
        }
    }
    lintOptions {
        disable 'InvalidPackage'
        abortOnError false
    }
}

dependencies {
    implementation fileTree(dir: 'libs', include: ['*.jar'])
    implementation 'androidx.appcompat:appcompat:1.1.0'
    implementation 'com.intellij:annotations:12.0'
}

android.libraryVariants.all { variant ->

    task("generate${variant.name.capitalize()}Javadoc", type: Javadoc) {

        //JavaDoc stuff
        description "Generates Javadoc for $variant.name."
        source = variant.javaCompile.source
        ext.androidJar = "${android.sdkDirectory}/platforms/${android.compileSdkVersion}/android.jar"
        doFirst { classpath = files(variant.javaCompile.classpath.files) + files(ext.androidJar) }
        String path = buildDir.absolutePath + ("/javadoc/javadoc-${variant.name}")
        File output_dir = new File(path)

        output_dir.mkdirs()
        destinationDir = output_dir


        // Packaging stuff
        def name = variant.buildType.name
        if (name == BuilderConstants.DEBUG) {
            return // Skip debug builds.
        }
        def task = project.tasks.create "jar${name.capitalize()}", Jar
        task.dependsOn variant.javaCompile
        task.from variant.javaCompile.destinationDir
        artifacts.add('archives', task)
    }

}


build.doLast {
    File javaDocDir = new File(buildDir.absolutePath + "/javadoc/")
    javaDocDir.deleteDir()
    tasks.findAll { it.name.startsWith("generate") && it.name.endsWith("Javadoc")}.each {
        it.execute()
    }
}

/**
 * Maven publishing info
 */

signing {
    required { gradle.taskGraph.hasTask("uploadArchives") }
    sign configurations.archives
}
def coreAarFile = file('build/outputs/aar/nfclib.aar')
artifacts {
    archives coreAarFile
}
uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "file:///Users/daneo/.m2/repository")

            pom.project {
                name 'AppFoundry\'s NFC Lib '
                groupId 'be.appfoundry'
                artifactId 'nfc-lib'
                packaging 'aar'
                version '1.0'
                organization {
                    name 'AppFoundry'
                    url 'http://www.appfoundry.be'
                }
                url 'http://dproductions.be/mvn'
                // optionally artifactId can be defined here
                description 'NFC Library meant to facilitate the use of NFC on the Android platform'

//
//                scm {
//                    connection 'scm:svn:http://foo.googlecode.com/svn/trunk/'
//                    developerConnection 'scm:svn:https://foo.googlecode.com/svn/trunk/'
//                    url 'http://foo.googlecode.com/svn/trunk/'
//                }

                developers {
                    developer {
                        id 'daneov'
                        name 'Daneo van Overloop'
                        roles{
                            role 'developer'
                        }
                        organization {
                            name 'AppFoundry'
                        }
                        email 'daneo.vanoverloop@ida-mediafoundry.be'
                    }
                }
            }
        }
    }
}

