Skip to content

Commit

Permalink
Rename file "KtlintVersionProvider.kt" containing method "getKtlintVe…
Browse files Browse the repository at this point in the history
…rsion" to "KtlintVersion.kt" with method "ktlintVersion" so that file adheres to PascalNaming convention in the modified FilenameRule.
  • Loading branch information
paul-dingemans authored and bedla committed Mar 19, 2022
1 parent 4c24a76 commit ffe22c6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import java.util.jar.Manifest
* (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))
*/
public fun <T> getKtlintVersion(javaClass: Class<T>): String? = javaClass.`package`.implementationVersion
?: javaClass.getResourceAsStream("/META-INF/MANIFEST.MF")?.run {
Manifest(this).mainAttributes.getValue("Implementation-Version")
}
public fun <T> ktlintVersion(javaClass: Class<T>): String? =
javaClass.`package`.implementationVersion ?: getManifestVersion(javaClass)

private fun <T> getManifestVersion(javaClass: Class<T>) =
javaClass.getResourceAsStream("/META-INF/MANIFEST.MF")
?.run {
Manifest(this).mainAttributes.getValue("Implementation-Version")
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package com.pinterest.ktlint.reporter.sarif

import com.pinterest.ktlint.core.LintError
import com.pinterest.ktlint.core.Reporter
import com.pinterest.ktlint.core.getKtlintVersion
import com.pinterest.ktlint.core.ktlintVersion
import io.github.detekt.sarif4k.ArtifactLocation
import io.github.detekt.sarif4k.Level
import io.github.detekt.sarif4k.Location
Expand Down Expand Up @@ -64,7 +64,7 @@ public class SarifReporter(private val out: PrintStream) : Reporter {
}

override fun afterAll() {
val version = getKtlintVersion(SarifReporter::class.java)
val version = ktlintVersion(SarifReporter::class.java)
val sarifSchema210 = SarifSchema210(
schema = "https://raw.githubusercontent.com/oasis-tcs/sarif-spec/master/Schemata/sarif-schema-2.1.0.json",
version = Version.The210,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.pinterest.ktlint.internal

import com.pinterest.ktlint.core.getKtlintVersion
import com.pinterest.ktlint.core.ktlintVersion
import picocli.CommandLine

/**
* Dynamically provides current ktlint version as [CommandLine.IVersionProvider]
*/
internal class KtlintVersionProvider : CommandLine.IVersionProvider {
override fun getVersion(): Array<String> {
val version = getKtlintVersion(KtlintVersionProvider::class.java)
return version?.let { arrayOf(version) } ?: error("Failed to determine ktlint version")
}
override fun getVersion(): Array<String> =
ktlintVersion(KtlintVersionProvider::class.java)
?.let { version -> arrayOf(version) }
?: error("Failed to determine ktlint version")
}

0 comments on commit ffe22c6

Please sign in to comment.