Skip to content

Commit

Permalink
feat(cli): Print the JDK version ORT was built with
Browse files Browse the repository at this point in the history
Signed-off-by: Sebastian Schuberth <[email protected]>
  • Loading branch information
sschuberth committed Mar 14, 2024
1 parent 3112df6 commit fad4d5e
Show file tree
Hide file tree
Showing 18 changed files with 45 additions and 3 deletions.
6 changes: 6 additions & 0 deletions buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ java {
}
}

tasks.withType<Jar>().configureEach {
manifest {
attributes["Build-Jdk"] = javaToolchains.compilerFor(java.toolchain).map { it.metadata.jvmVersion }
}
}

val maxKotlinJvmTarget = runCatching { JvmTarget.fromTarget(javaLanguageVersion) }
.getOrDefault(enumValues<JvmTarget>().max())

Expand Down
1 change: 1 addition & 0 deletions cli/src/funTest/assets/git-repo-expected-output.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
6 changes: 3 additions & 3 deletions cli/src/main/kotlin/OrtMain.kt
Original file line number Diff line number Diff line change
Expand Up @@ -190,9 +190,9 @@ class OrtMain : CliktCommand(

cell(
"""
The OSS Review Toolkit, version ${Theme.Default.info(version)}.
Running$command$user under Java ${env.javaVersion} on ${env.os}
The OSS Review Toolkit, version ${Theme.Default.info(version)},
built with JDK ${env.buildJdk}, running under Java ${env.javaVersion}.
Executing$command$user on ${env.os}
with ${env.processors} CPUs and a maximum of $maxMemInMib MiB of memory.
""".trimIndent()
)
Expand Down
1 change: 1 addition & 0 deletions model/src/test/assets/result-with-issues-graph-old.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: 4
Expand Down
1 change: 1 addition & 0 deletions model/src/test/assets/result-with-issues-graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: 4
Expand Down
1 change: 1 addition & 0 deletions model/src/test/assets/result-with-issues-scopes.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: 4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
1 change: 1 addition & 0 deletions model/src/test/assets/sbt-multi-project-example-graph.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down Expand Up @@ -188,6 +189,7 @@ scanner:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down Expand Up @@ -186,6 +187,7 @@ scanner:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ analyzer:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down Expand Up @@ -105,6 +106,7 @@ scanner:
end_time: "1970-01-01T00:00:00Z"
environment:
ort_version: "HEAD"
build_jdk: "<REPLACE_JDK>"
java_version: "<REPLACE_JAVA>"
os: "<REPLACE_OS>"
processors: "<REPLACE_PROCESSORS>"
Expand Down
18 changes: 18 additions & 0 deletions utils/ort/src/main/kotlin/Environment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ package org.ossreviewtoolkit.utils.ort

import java.io.File
import java.lang.Runtime
import java.util.jar.JarFile

import org.ossreviewtoolkit.utils.common.Os

Expand All @@ -33,6 +34,11 @@ data class Environment(
*/
val ortVersion: String = ORT_VERSION,

/**
* The JDK version ORT was built with.
*/
val buildJdk: String = BUILD_JDK,

/**
* The version of Java used.
*/
Expand Down Expand Up @@ -71,6 +77,18 @@ data class Environment(
*/
val ORT_VERSION by lazy { this::class.java.`package`.implementationVersion ?: "IDE-SNAPSHOT" }

/**
* The version of the OSS Review Toolkit as a string.
*/
val BUILD_JDK: String by lazy {
runCatching {
val codeSource = this::class.java.protectionDomain.codeSource
JarFile(codeSource?.location?.file).use {
it.manifest.mainAttributes.getValue("Build-Jdk")
}
}.getOrDefault(System.getProperty("java.version"))
}

/**
* A string that is supposed to be used as the User Agent when using ORT as an HTTP client.
*/
Expand Down
1 change: 1 addition & 0 deletions utils/test/src/main/kotlin/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ fun patchExpectedResult(
val env = Environment()

val replacements = buildMap {
put("<REPLACE_JDK>", env.buildJdk)
put("<REPLACE_JAVA>", env.javaVersion)
put("<REPLACE_OS>", env.os)
put("\"<REPLACE_PROCESSORS>\"", env.processors.toString())
Expand Down

0 comments on commit fad4d5e

Please sign in to comment.