All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.pinterest.ktlint.internal.KtlintVersionProvider.kt Maven / Gradle / Ivy

There is a newer version: 0.51.0-FINAL
Show newest version
package com.pinterest.ktlint.internal

import java.util.jar.Manifest
import picocli.CommandLine

/**
 * Dynamically provides current ktlint version.
 */
internal class KtlintVersionProvider : CommandLine.IVersionProvider {
    override fun getVersion(): Array {
        var version: String? = javaClass.`package`.implementationVersion
        if (version == null) {
            // JDK 9 regression workaround (https://bugs.openjdk.java.net/browse/JDK-8190987, fixed in JDK 10)
            // (note that version reported by the fallback might not be null if META-INF/MANIFEST.MF is
            // loaded from another JAR on the classpath (e.g. if META-INF/MANIFEST.MF wasn't created as part of the build))
            version = javaClass.getResourceAsStream("/META-INF/MANIFEST.MF")?.run {
                Manifest(this).mainAttributes.getValue("Implementation-Version")
            }
        }

        return version?.let { arrayOf(version) } ?: error("Failed to determine ktlint version")
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy