diff --git a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts index 4c38cd487029f..8cea28a21f0f1 100644 --- a/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts +++ b/buildSrc/src/main/kotlin/ort-kotlin-conventions.gradle.kts @@ -113,6 +113,12 @@ java { } } +tasks.withType().configureEach { + manifest { + attributes["Build-Jdk"] = javaToolchains.compilerFor(java.toolchain).map { it.metadata.jvmVersion } + } +} + val maxKotlinJvmTarget = runCatching { JvmTarget.fromTarget(javaLanguageVersion) } .getOrDefault(enumValues().max()) diff --git a/cli/src/funTest/assets/git-repo-expected-output.yml b/cli/src/funTest/assets/git-repo-expected-output.yml index ef77cbebb5026..3b6f280282408 100644 --- a/cli/src/funTest/assets/git-repo-expected-output.yml +++ b/cli/src/funTest/assets/git-repo-expected-output.yml @@ -47,6 +47,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml b/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml index af9d29dd2a511..5ead4c4f0d4e3 100644 --- a/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml +++ b/cli/src/funTest/assets/gradle-all-dependencies-expected-result-with-curations.yml @@ -40,6 +40,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/cli/src/main/kotlin/OrtMain.kt b/cli/src/main/kotlin/OrtMain.kt index 8afa8bd33a55a..84d0ea0292913 100644 --- a/cli/src/main/kotlin/OrtMain.kt +++ b/cli/src/main/kotlin/OrtMain.kt @@ -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() ) diff --git a/model/src/test/assets/result-with-issues-graph-old.yml b/model/src/test/assets/result-with-issues-graph-old.yml index 6460cfe9bff0c..813f1a184b827 100644 --- a/model/src/test/assets/result-with-issues-graph-old.yml +++ b/model/src/test/assets/result-with-issues-graph-old.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: 4 diff --git a/model/src/test/assets/result-with-issues-graph.yml b/model/src/test/assets/result-with-issues-graph.yml index cf2a9da9839e4..30b98b128a789 100644 --- a/model/src/test/assets/result-with-issues-graph.yml +++ b/model/src/test/assets/result-with-issues-graph.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: 4 diff --git a/model/src/test/assets/result-with-issues-scopes.yml b/model/src/test/assets/result-with-issues-scopes.yml index 5357088ec6ecc..e48882fd41e74 100644 --- a/model/src/test/assets/result-with-issues-scopes.yml +++ b/model/src/test/assets/result-with-issues-scopes.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: 4 diff --git a/model/src/test/assets/sbt-multi-project-example-expected-output.yml b/model/src/test/assets/sbt-multi-project-example-expected-output.yml index ae1862c8d8a67..61689dfc575bd 100644 --- a/model/src/test/assets/sbt-multi-project-example-expected-output.yml +++ b/model/src/test/assets/sbt-multi-project-example-expected-output.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/model/src/test/assets/sbt-multi-project-example-graph-old.yml b/model/src/test/assets/sbt-multi-project-example-graph-old.yml index 69f775974c037..75faa6da133a5 100644 --- a/model/src/test/assets/sbt-multi-project-example-graph-old.yml +++ b/model/src/test/assets/sbt-multi-project-example-graph-old.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/model/src/test/assets/sbt-multi-project-example-graph.yml b/model/src/test/assets/sbt-multi-project-example-graph.yml index 0d75737b403dc..4349d7f016361 100644 --- a/model/src/test/assets/sbt-multi-project-example-graph.yml +++ b/model/src/test/assets/sbt-multi-project-example-graph.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml index a437ece9332bd..59ffd4138f563 100644 --- a/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml +++ b/plugins/package-managers/node/src/funTest/assets/projects/synthetic/pnpm-workspaces-expected-output.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml b/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml index ae1862c8d8a67..61689dfc575bd 100644 --- a/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml +++ b/plugins/package-managers/sbt/src/funTest/assets/projects/external/sbt-multi-project-example-expected-output.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml b/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml index 96addfafd0e71..e024c4d9dbada 100644 --- a/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml +++ b/plugins/package-managers/sbt/src/funTest/assets/projects/synthetic/sbt-http4s-template-expected-output.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml b/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml index 7b6d47ae8f313..282034b52a401 100644 --- a/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml +++ b/plugins/reporters/web-app/src/funTest/assets/scan-result-for-synthetic-gradle-lib.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" @@ -188,6 +189,7 @@ scanner: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml b/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml index b677cab0abe06..5aab6ad8bdfc5 100644 --- a/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/assets/scanner-integration-all-pkgs-expected-ort-result.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" @@ -186,6 +187,7 @@ scanner: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml b/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml index fd739c4ab3f28..4ff01026e6357 100644 --- a/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml +++ b/scanner/src/funTest/assets/scanner-integration-subset-pkgs-expected-ort-result.yml @@ -16,6 +16,7 @@ analyzer: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" @@ -105,6 +106,7 @@ scanner: end_time: "1970-01-01T00:00:00Z" environment: ort_version: "HEAD" + build_jdk: "" java_version: "" os: "" processors: "" diff --git a/utils/ort/src/main/kotlin/Environment.kt b/utils/ort/src/main/kotlin/Environment.kt index da8324526b996..a6f51acd409c0 100644 --- a/utils/ort/src/main/kotlin/Environment.kt +++ b/utils/ort/src/main/kotlin/Environment.kt @@ -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 @@ -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. */ @@ -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. */ diff --git a/utils/test/src/main/kotlin/Utils.kt b/utils/test/src/main/kotlin/Utils.kt index bd5d027d81a16..7c2cfa7ef40d6 100644 --- a/utils/test/src/main/kotlin/Utils.kt +++ b/utils/test/src/main/kotlin/Utils.kt @@ -92,6 +92,7 @@ fun patchExpectedResult( val env = Environment() val replacements = buildMap { + put("", env.buildJdk) put("", env.javaVersion) put("", env.os) put("\"\"", env.processors.toString())