import org.gradle.crypto.checksum.Checksum

/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You 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 'distribution'
    id 'signing'
    alias(libs.plugins.nebula)
    alias(libs.plugins.checksum)
}

apply from: "$rootDir/buildscripts/utils.gradle"

configurations {
    dotNetClient
}

dependencies {
    dotNetClient(project(path: ":platforms", configuration: "dotNet"))
}

def tokens = [
        LIB_DIR     : "/usr/lib/ignite3-dotnet-client",
]

configurations {
    dotNetClientZip {
        canBeConsumed = true
        canBeResolved = false
    }
}

artifacts {
    dotNetClientZip(distZip)
}

distributions {
    main {
        distributionBaseName = 'ignite3-dotnet-client'
        contents {
            into('') {
                from "$rootDir/LICENSE"
                from "$rootDir/NOTICE"
            }

            into('lib') {
                from configurations.dotNetClient
            }
        }
    }
}

distZip {
    onlyIf {
        project.hasProperty('platforms.enable')
    }
}

// Explicitly create task so that the resulting artifact is not added to the configuration
def signDotNetClientZip = tasks.register('signDotNetClientZip', Sign) {
    sign configurations.dotNetClientZip
}


ospackage {
    license "ASL 2.0"
    packageName "ignite3-dotnet-client"
    packageGroup "Development/Libraries"
    url "https://ignite.apache.org"
    packageDescription "This package will install Apache Ignite 3 client library for .NET"
    os LINUX
    release getCommitNum()

    into(tokens.LIB_DIR) {
        from configurations.dotNetClient
    }
}

buildRpm {
    onlyIf {
        project.hasProperty('platforms.enable')
    }
}

buildDeb {
    onlyIf {
        project.hasProperty('platforms.enable')
    }
}


// --- release setup --- //
def createChecksums = tasks.register('createChecksums', Checksum) {
    onlyIf {
        project.hasProperty('platforms.enable')
    }

    inputFiles.from distZip
    checksumAlgorithm = Checksum.Algorithm.SHA512
}

distZip.finalizedBy(createChecksums)
