plugins {
    id "org.jetbrains.intellij" version '0.4.5'
}
apply plugin: 'kotlin'
apply plugin: 'idea'
apply plugin: 'maven'
apply plugin: 'signing'

javadoc {
    options.tags = ["date"]
}

task javadocJar(type: Jar, dependsOn: javadoc) {
    classifier = 'javadoc'
    from 'build/docs/javadoc'
}

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

artifacts {
    archives jar
    archives javadocJar
    archives sourcesJar
}

def myPlugins = []
def versionDotIndex = idea_version.indexOf('.')
def intVersion = versionDotIndex == -1 ? Integer.parseInt(idea_version) : Integer.parseInt(idea_version.substring(0, versionDotIndex))
if (intVersion >= 2019 || (intVersion < 1000 && intVersion >= 193)) {
    myPlugins = ['java']
}

intellij {
    version idea_version
    plugins = myPlugins
    pluginName plugin_name
    updateSinceUntilBuild false
    sandboxDirectory "$project.buildDir/idea-sandbox/$idea_version"
}
version '2.0.1'

ext.isReleaseVersion = !version.endsWith("SNAPSHOT")

dependencies {
    compile group: 'org.freemarker', name: 'freemarker', version: '2.3.25-incubating'
    compile 'com.alibaba.p3c:p3c-pmd:2.1.0'
    compile group: 'org.javassist', name: 'javassist', version: '3.21.0-GA'
}

uploadArchives {
    repositories {
        mavenDeployer {
            beforeDeployment { MavenDeployment deployment -> signing.signPom(deployment) }

            repository(url: "https://oss.sonatype.org/service/local/staging/deploy/maven2/") {
                authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword'))
            }

            snapshotRepository(url: "https://oss.sonatype.org/content/repositories/snapshots/") {
                authentication(userName: findProperty('ossrhUsername'), password: findProperty('ossrhPassword'))
            }

            pom.project {
                name 'p3c-common'
                packaging 'jar'
                description 'P3c Idea Plugin Common.'
                url 'https://github.com/alibaba/p3c'

                scm {
                    url 'https://github.com/alibaba/p3c'
                    connection 'scm:git:https://git@github.com/alibaba/p3c.git'
                }

                licenses {
                    license {
                        name 'The Apache Software License, Version 2.0'
                        url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
                        distribution 'repo'
                    }
                }

                developers {
                    developer {
                        id 'junlie'
                        name 'Junlie'
                        email 'sean.caikang@gmail.com'
                    }
                    developer {
                        id 'ZengHou'
                        name 'ZengHou'
                        email 'fengwei1983@gmail.com'
                    }
                }
            }
        }
    }
}

signing {
    required {
        isReleaseVersion && gradle.taskGraph.hasTask("uploadArchives")
    }
    sign configurations.archives
}
