Skip to content

Commit

Permalink
Cherry-picked Java 9 implementationVersion fallback from develop (#155)
Browse files Browse the repository at this point in the history
  • Loading branch information
shyiko committed Feb 27, 2018
1 parent e101a66 commit 5bb8846
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion ktlint/src/main/kotlin/com/github/shyiko/ktlint/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ import java.util.concurrent.Future
import java.util.concurrent.TimeUnit
import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger
import java.util.jar.Manifest
import kotlin.system.exitProcess

object Main {
Expand Down Expand Up @@ -220,7 +221,7 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s
fun main(args: Array<String>) {
parseCmdLine(args)
if (version) {
println(javaClass.`package`.implementationVersion)
println(getImplementationVersion())
exitProcess(0)
}
if (installGitPreCommitHook) {
Expand Down Expand Up @@ -334,6 +335,15 @@ ${ByteArrayOutputStream().let { this.printUsage(it); it }.toString().trimEnd().s
}
}

private fun getImplementationVersion() = javaClass.`package`.implementationVersion
// 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))
?: javaClass.getResourceAsStream("/META-INF/MANIFEST.MF")
?.let { stream ->
Manifest(stream).mainAttributes.getValue("Implementation-Version")
}

private fun loadReporter(dependencyResolver: Lazy<MavenDependencyResolver>): Reporter {
data class ReporterTemplate(val id: String, val config: Map<String, String>, var output: String?)
val tpls = (if (reporters.isEmpty()) listOf("plain") else reporters)
Expand Down

0 comments on commit 5bb8846

Please sign in to comment.