/**
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

buildscript {
  ext {
    springBootVersion = '2.5.3'
  }
  repositories {
    mavenCentral()
    mavenLocal()
  }
  dependencies {
    classpath("org.springframework.boot:spring-boot-gradle-plugin:${springBootVersion}")
  }
}

plugins {
    id "com.github.ben-manes.versions" version "0.51.0"
    id "com.github.hierynomus.license" version "0.16.1"
    id "java"
    id "eclipse"
    id "idea"
}

repositories {
    mavenCentral()
    mavenLocal()
}

configurations {
    testPlugins {}
    all*.exclude group: 'org.bouncycastle', module: 'bc-fips'
    all*.exclude group: 'io.netty', module: 'netty-tcnative-classes'
    all*.exclude group: 'log4j', module: 'log4j'
}

dependencies {}

apply from: 'gradle/license.gradle'
apply plugin: 'io.spring.dependency-management'
apply plugin: 'application'

mainClassName = 'org.apache.pulsar.manager.PulsarManagerApplication'

task licenseFormatNode(type: com.hierynomus.gradle.license.tasks.LicenseFormat) {
    source = fileTree(dir: "src").include("**/*")
    source = fileTree(dir: "front-end/src").include("**/*")
}
licenseFormat.dependsOn licenseFormatNode

task licenseCheckNode(type: com.hierynomus.gradle.license.tasks.LicenseCheck) {
    source = fileTree(dir: "src").include("**/*")
}

// Add VERSION
task incrementVersion {
    doLast {
        new File(projectDir, "VERSION").text = version
    }
}

dependencyManagement {
  imports {
    mavenBom org.springframework.boot.gradle.plugin.SpringBootPlugin.BOM_COORDINATES
    mavenBom 'org.springframework.cloud:spring-cloud-dependencies:2020.0.6'
  }
  applyMavenExclusions = false
}

distributions {

    main {
        contents {
            from 'src/main/resources/application.properties'
            from 'src/main/resources/bkvm.conf'
        }
    }
}

distTar {
	archiveFileName = "pulsar-manager.tar"
}

jar {
    manifest {
        attributes(
                'Main-Class': mainClassName
        )
    }
}

ext['log4j2.version'] = '2.17.1'

dependencies {
    compileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    annotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    testCompileOnly group: 'org.projectlombok', name: 'lombok', version: lombokVersion
    testAnnotationProcessor group: 'org.projectlombok', name: 'lombok', version: lombokVersion

    implementation group: 'org.springframework.boot', name: 'spring-boot-starter', version: springBootVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-web', version: springBootVersion
    implementation group: 'org.springframework.cloud', name: 'spring-cloud-starter-netflix-zuul', version: '2.2.10.RELEASE'
    implementation group: 'org.mybatis.spring.boot', name: 'mybatis-spring-boot-starter', version: springMybatisVersion
    implementation group: 'com.github.pagehelper', name: 'pagehelper', version: pagehelperVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-thymeleaf', version: springBootVersion
    implementation group: 'org.postgresql', name: 'postgresql', version: postgresqlVersion
    implementation (group: 'org.herddb', name: 'herddb-jdbc', version: herddbVersion) {
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
        }
    implementation group: 'javax.validation', name: 'validation-api', version: javaxValidationVersion
    implementation group: 'org.hibernate', name: 'hibernate-validator', 'version': hibernateValidatorVersion
    implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: jsonWebTokenApiVersion
    implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: jsonWebTokenImplVersion
    implementation group: 'io.jsonwebtoken', name: 'jjwt-jackson', version: jsonWebTokenImplVersion
    implementation group: 'com.github.pagehelper', name: 'pagehelper-spring-boot-starter', version: pageHelperVersion
    implementation group: 'com.google.guava', name: 'guava', version: guavaVersion
    implementation group: 'com.google.code.gson', name: 'gson', version: gsonVersion
    implementation group: 'org.apache.pulsar', name: 'pulsar-common', version: pulsarVersion
    implementation group: 'org.apache.pulsar', name: 'pulsar-client-admin-original', version: pulsarVersion
    implementation group: 'org.apache.pulsar', name: 'pulsar-client-auth-athenz', version: pulsarVersion
    implementation group: 'org.apache.pulsar', name: 'pulsar-client-auth-sasl', version: pulsarVersion
    implementation group: 'com.yahoo.athenz', name: 'athenz-zts-java-client', version: athenzVersion
    implementation group: 'io.springfox', name: 'springfox-swagger2', version: swagger2Version
    implementation group: 'io.springfox', name: 'springfox-swagger-ui', version: swaggeruiVersion
    implementation group: 'org.apache.pulsar', name: 'pulsar-broker', version: pulsarVersion
    implementation group: 'commons-validator', name: 'commons-validator', version: commonsValidatorVersion
    implementation (group: 'org.bkvm', name: 'bkvm', version: bkvmVersion, ext: 'war', classifier:'war-no-libs') {
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
        exclude group: 'org.herddb', module: '*'
    }
    implementation (group: 'org.bkvm', name: 'bkvm', version: bkvmVersion, classifier:'classes') {
        exclude group: 'org.slf4j', module: 'slf4j-jdk14'
        exclude group: 'org.herddb', module: '*'
    }
    implementation (group: 'org.apache.tomcat.embed', name: 'tomcat-embed-core', version: tomcatVersion)
    implementation (group: 'org.apache.tomcat.embed', name: 'tomcat-embed-jasper', version: tomcatVersion)
    implementation group: 'org.glassfish.jersey.containers', name: 'jersey-container-servlet', version: jerseyVersion
    implementation group: 'org.glassfish.jersey.core', name: 'jersey-client', version: jerseyVersion
    implementation group: 'org.glassfish.jersey.inject', name: 'jersey-hk2', version: jerseyVersion
    implementation group: 'org.glassfish.jersey.media', name: 'jersey-media-json-jackson', version: jerseyVersion
    implementation group: 'org.springframework.boot', name: 'spring-boot-starter-security'
    implementation group: 'org.springframework.security', name: 'spring-security-config'
    implementation group: 'org.casbin', name: 'casdoor-spring-boot-starter', version: '1.3.0'
    compileOnly group: 'org.springframework.boot', name: 'spring-boot-devtools', version: springBootVersion
    testImplementation group: 'org.springframework.boot', name: 'spring-boot-starter-test', version: springBootVersion
    testImplementation group: 'org.mockito', name: 'mockito-core', version: mockitoVersion

    constraints {
        implementation("org.bouncycastle:bcprov-jdk15on:${bouncycastleVersion}")
        implementation("org.bouncycastle:bcprov-ext-jdk15on:${bouncycastleVersion}")
        implementation("org.bouncycastle:bcpkix-jdk15on:${bouncycastleVersion}")
    }
}
