/*
 * Copyright (c) 2022, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * 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.
 *
 */

plugins {
    id "com.github.johnrengelman.shadow"
}

apply from: "$rootDir/gradle/javaProject.gradle"

description = 'Ballerina - C2C Tooling Module'

configurations {
    extraLibs
}

dependencies {
    implementation project(":cloud-util")
    
    implementation "org.ballerinalang:language-server-commons:${ballerinaLangVersion}"
    implementation "org.ballerinalang:ballerina-tools-api:${ballerinaLangVersion}"
    implementation "org.ballerinalang:ballerina-lang:${ballerinaLangVersion}"
    implementation "org.ballerinalang:ballerina-parser:${ballerinaLangVersion}"
    implementation "org.ballerinalang:toml-parser:${ballerinaLangVersion}"

    implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j:0.10.0'
    implementation 'org.eclipse.lsp4j:org.eclipse.lsp4j.jsonrpc:0.10.0'
    implementation 'commons-io:commons-io:2.6'
    implementation 'com.google.code.gson:gson:2.8.9'
    
    extraLibs (project (":cloud-util"))  {
        exclude group: "org.apache.commons", module: "commons-text"
    }
    configurations.implementation.extendsFrom(configurations.extraLibs)
}

sourceSets {
    main {
        resources {
            srcDir 'build/schema/'
        }
    }
}

task buildForDocker(type: Copy){
    from '../compiler-plugin/src/main/resources/c2c-schema.json'
    into 'build/schema/'
    rename { String fileName ->
        fileName.replace("c2c-schema", "c2c-schema-tooling")
    }
}

jar {
    dependsOn buildForDocker
    duplicatesStrategy = DuplicatesStrategy.EXCLUDE
    from {
        configurations.extraLibs.collect { it.isDirectory() ? it : zipTree(it) }
    }
}

task createArtifactZip(type: Zip) {
    dependsOn build
    from 'build/libs/'
    archiveFileName = "cloud-tooling-${version}.zip"
    destinationDirectory = file("${projectDir}/build/zip")
}

publishing {
    publications {
        mavenJava(MavenPublication) {
            artifact source: createArtifactZip, extension: 'zip'
        }
    }

    repositories {
        maven {
            name = "GitHubPackages"
            url = uri("https://maven.pkg.github.com/ballerina-platform/module-ballerina-c2c")
            credentials {
                username = System.getenv("packageUser")
                password = System.getenv("packagePAT")
            }
        }
    }
}

tasks.processResources.dependsOn(":cloud-tooling:buildForDocker")
tasks.jar.dependsOn(":cloud-util:jar")
