Skip to content

Commit

Permalink
refactor(utils): Move ORT directory properties to Environment
Browse files Browse the repository at this point in the history
These properties are tightly related to environment variables, so it
makes more sense to keep them there. Slightly improve their
documentation while at it.

Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Nov 21, 2023
1 parent b76ae85 commit bddecf4
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 34 deletions.
35 changes: 35 additions & 0 deletions utils/ort/src/main/kotlin/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

package org.ossreviewtoolkit.utils.ort

import java.io.File
import java.lang.Runtime

import org.ossreviewtoolkit.utils.common.Os
Expand Down Expand Up @@ -93,3 +94,37 @@ data class Environment(
)
}
}

/**
* The directory to store ORT (read-write) data in, like archives, caches, configuration, and tools. Defaults to the
* ".ort" directory below the current user's home directory.
*/
val ortDataDirectory by lazy {
Os.env[ORT_DATA_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: Os.userHomeDirectory.resolve(".ort")
}

/**
* The directory to store ORT (read-only) configuration in. Defaults to the "config" directory below the data directory.
*/
val ortConfigDirectory by lazy {
Os.env[ORT_CONFIG_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: ortDataDirectory.resolve("config")
}

/**
* The directory to store ORT (read-write) tools in. Defaults to the "tools" directory below the data directory.
*/
val ortToolsDirectory by lazy {
Os.env[ORT_TOOLS_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: ortDataDirectory.resolve("tools")
}
34 changes: 0 additions & 34 deletions utils/ort/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,11 @@ import java.net.Authenticator
import java.net.PasswordAuthentication
import java.net.URI

import org.ossreviewtoolkit.utils.common.Os
import org.ossreviewtoolkit.utils.common.toSafeUri
import org.ossreviewtoolkit.utils.common.toUri
import org.ossreviewtoolkit.utils.common.withoutPrefix
import org.ossreviewtoolkit.utils.common.withoutSuffix

/**
* The directory to store ORT (read-only) configuration in.
*/
val ortConfigDirectory by lazy {
Os.env[ORT_CONFIG_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: ortDataDirectory.resolve("config")
}

/**
* The directory to store ORT (read-write) tools in.
*/
val ortToolsDirectory by lazy {
Os.env[ORT_TOOLS_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: ortDataDirectory.resolve("tools")
}

/**
* The directory to store ORT (read-write) data in, like caches and archives.
*/
val ortDataDirectory by lazy {
Os.env[ORT_DATA_DIR_ENV_NAME]?.takeUnless {
it.isEmpty()
}?.let {
File(it)
} ?: Os.userHomeDirectory.resolve(".ort")
}

/**
* Global variable that gets toggled by a command line parameter parsed in the main entry points of the modules.
*/
Expand Down

0 comments on commit bddecf4

Please sign in to comment.