Skip to content

Commit 4979786

Browse files
committed
OrtMain: Fixup the "user.home" property before running ORT
Signed-off-by: Sebastian Schuberth <[email protected]>
1 parent d2b51fd commit 4979786

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

cli/src/main/kotlin/OrtMain.kt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ import org.apache.logging.log4j.core.config.Configurator
4444

4545
const val TOOL_NAME = "ort"
4646

47+
/**
48+
* The name of the environment variable to customize the ORT user home.
49+
*/
50+
const val ORT_USER_HOME_ENV = "ORT_USER_HOME"
51+
4752
/**
4853
* The main entry point of the application.
4954
*/
@@ -96,9 +101,30 @@ object OrtMain : CommandWithHelp() {
96101
*/
97102
@JvmStatic
98103
fun main(args: Array<String>) {
104+
fixupUserHomeProperty()
99105
exitProcess(run(args))
100106
}
101107

108+
/**
109+
* Check if the "user.home" property is set to a sane value and otherwise set it to the value of the ORT_USER_HOME
110+
* environment variable, if set, or to the value of an (OS-specific) environment variable for the user home
111+
* directory. This works around the issue that esp. in certain Docker scenarios "user.home" is set to "?", see
112+
* https://bugs.openjdk.java.net/browse/JDK-8193433 for some background information.
113+
*/
114+
fun fixupUserHomeProperty() {
115+
val userHome = System.getProperty("user.home")
116+
val checkedUserHome = sequenceOf(
117+
userHome,
118+
System.getenv(ORT_USER_HOME_ENV),
119+
System.getenv("HOME"),
120+
System.getenv("USERPROFILE")
121+
).first {
122+
it != null && it.isNotBlank() && it != "?"
123+
}
124+
125+
if (checkedUserHome != userHome) System.setProperty("user.home", checkedUserHome)
126+
}
127+
102128
/**
103129
* Run the ORT CLI with the provided [args] and return the exit code of [CommandWithHelp.run].
104130
*/

0 commit comments

Comments
 (0)