Skip to content

Commit

Permalink
jvm util functions
Browse files Browse the repository at this point in the history
  • Loading branch information
AbdullinAM committed Apr 29, 2024
1 parent 4e49707 commit 2b80729
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<artifactId>kt-helper</artifactId>
<groupId>org.vorpal.research</groupId>
<packaging>jar</packaging>
<version>0.1.17</version>
<version>0.1.18</version>

<properties>
<jvm.version>1.8</jvm.version>
Expand Down
21 changes: 21 additions & 0 deletions src/main/kotlin/org/vorpal/research/kthelper/jvm.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.vorpal.research.kthelper

import org.vorpal.research.kthelper.assert.unreachable
import java.nio.file.Path
import java.nio.file.Paths


fun getJDKPath(): Path {
return Paths.get(System.getProperty("java.home")).parent.toAbsolutePath()
}

fun getJavaPath(): Path = Paths.get(System.getProperty("java.home"), "bin", "java").toAbsolutePath()

fun getJavacPath(): Path = Paths.get(System.getProperty("java.home"), "bin", "javac").toAbsolutePath()

fun getJvmVersion(): Int {
val versionStr = System.getProperty("java.version")
return """(1.)?(\d+)""".toRegex().find(versionStr)?.let {
it.groupValues[2].toInt()
} ?: unreachable("Could not detect JVM version: \"$versionStr\"")
}

0 comments on commit 2b80729

Please sign in to comment.