From 023d8a5e04438582cf0665b380d1ed7cb870814e Mon Sep 17 00:00:00 2001 From: Cedric Beust Date: Thu, 5 Nov 2015 01:44:24 -0800 Subject: [PATCH] Don't require $JAVA_HOME any more. --- TODO.md | 2 +- src/main/kotlin/com/beust/kobalt/Jvm.kt | 17 ++++++++++------- .../kotlin/com/beust/kobalt/SystemProperties.kt | 6 ++---- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/TODO.md b/TODO.md index b9588c5d..eaebb89f 100644 --- a/TODO.md +++ b/TODO.md @@ -1,6 +1,5 @@ To do: -- [ ] Get rid of the $JAVA_HOME requirement - [ ] Add a "Auto complete Build.kt" menu in the plug-in - [ ] "All artifacts successfully uploaded" is shown before the upload is actually done - [ ] use groupId/artifactId @@ -33,6 +32,7 @@ To do: Done: +- [x] Get rid of the $JAVA_HOME requirement - [x] getDependencies() should return the transitive dependencies - [x] Project ordering: kotlinProject(wrapper) {} - [x] Make files appear in download list automatically on bintray (undocumented API) diff --git a/src/main/kotlin/com/beust/kobalt/Jvm.kt b/src/main/kotlin/com/beust/kobalt/Jvm.kt index e7cd1fe7..1902c618 100644 --- a/src/main/kotlin/com/beust/kobalt/Jvm.kt +++ b/src/main/kotlin/com/beust/kobalt/Jvm.kt @@ -95,10 +95,13 @@ public open class Jvm constructor( // } override public fun findExecutable(command: String): File { - val exec = File(javaHome, "bin/" + command) - val executable = java.io.File(os.getExecutableName(exec.getAbsolutePath())) - if (executable.isFile()) { - return executable + if (javaHome != null) { + val jdkHome = if (javaHome!!.endsWith("jre")) javaHome!!.parentFile else javaHome + val exec = File(jdkHome, "bin/" + command) + var executable = File(os.getExecutableName(exec.absolutePath)) + if (executable.isFile) { + return executable + } } // if (userSupplied) { @@ -108,12 +111,12 @@ public open class Jvm constructor( val pathExecutable = os.findInPath(command) if (pathExecutable != null) { - log(1, "Unable to find the ${command} executable using home: " + - "%{javaHome}. We found it on the PATH: ${pathExecutable}.") + log(1, "Unable to find the $command executable using home: " + + "%{javaHome}. We found it on the PATH: $pathExecutable.") return pathExecutable } - warn("Unable to find the ${command} executable. Tried the java home: ${javaHome}" + + warn("Unable to find the $command executable. Tried the java home: $javaHome" + " and the PATH. We will assume the executable can be ran in the current " + "working folder.") return java.io.File(os.getExecutableName(command)) diff --git a/src/main/kotlin/com/beust/kobalt/SystemProperties.kt b/src/main/kotlin/com/beust/kobalt/SystemProperties.kt index eb223589..b7877264 100644 --- a/src/main/kotlin/com/beust/kobalt/SystemProperties.kt +++ b/src/main/kotlin/com/beust/kobalt/SystemProperties.kt @@ -1,11 +1,9 @@ package com.beust.kobalt -import java.util.concurrent.locks.ReentrantLock -import javax.inject.Inject - public class SystemProperties { companion object { - val javaBase = System.getenv("JAVA_HOME") ?: throw IllegalArgumentException("JAVA_HOME not defined") + val javaBase = System.getProperty("java.home") ?: + (System.getenv("JAVA_HOME") ?: throw IllegalArgumentException("JAVA_HOME not defined")) val javaVersion = System.getProperty("java.version") val homeDir = System.getProperty("user.home") val tmpDir = System.getProperty("java.io.tmpdir")