Skip to content

Commit

Permalink
Make comet-git-info.properties optional
Browse files Browse the repository at this point in the history
  • Loading branch information
andygrove committed Oct 21, 2024
1 parent 4033687 commit 6979696
Showing 1 changed file with 31 additions and 44 deletions.
75 changes: 31 additions & 44 deletions common/src/main/scala/org/apache/comet/package.scala
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ package org.apache
import java.util.Properties

import org.apache.arrow.memory.RootAllocator
import org.apache.spark.internal.Logging

package object comet {

Expand All @@ -39,60 +40,46 @@ package object comet {
* benchmarking software to provide the source revision and repository. In addition, the build
* information is included to aid in future debugging efforts for releases.
*/
private object CometBuildInfo {
private object CometBuildInfo extends Logging {

val (
cometVersion: String,
cometBranch: String,
cometRevision: String,
cometBuildUserName: String,
cometBuildUserEmail: String,
cometRepoUrl: String,
cometBuildTimestamp: String) = {
val props: Properties = {
val props = new Properties()
val resourceStream = Thread
.currentThread()
.getContextClassLoader
.getResourceAsStream("comet-git-info.properties")
if (resourceStream == null) {
throw new CometRuntimeException("Could not find comet-git-info.properties")
}

try {
val unknownProp = "<unknown>"
val props = new Properties()
props.load(resourceStream)
(
props.getProperty("git.build.version", unknownProp),
props.getProperty("git.branch", unknownProp),
props.getProperty("git.commit.id.full", unknownProp),
props.getProperty("git.build.user.name", unknownProp),
props.getProperty("git.build.user.email", unknownProp),
props.getProperty("git.remote.origin.url", unknownProp),
props.getProperty("git.build.time", unknownProp))
} catch {
case e: Exception =>
throw new CometRuntimeException(
"Error loading properties from comet-git-info.properties",
e)
} finally {
if (resourceStream != null) {
try {
resourceStream.close()
} catch {
case e: Exception =>
throw new CometRuntimeException("Error closing Comet build info resource stream", e)
if (resourceStream != null) {
try {
props.load(resourceStream)
} catch {
case e: Exception =>
logError("Error loading properties from comet-git-info.properties", e)
} finally {
if (resourceStream != null) {
try {
resourceStream.close()
} catch {
case e: Exception =>
logError("Error closing Comet build info resource stream", e)
}
}
}
} else {
logWarning("Could not find comet-git-info.properties")
}
props
}
}

val COMET_VERSION = CometBuildInfo.cometVersion
val COMET_BRANCH = CometBuildInfo.cometBranch
val COMET_REVISION = CometBuildInfo.cometRevision
val COMET_BUILD_USER_EMAIL = CometBuildInfo.cometBuildUserEmail
val COMET_BUILD_USER_NAME = CometBuildInfo.cometBuildUserName
val COMET_REPO_URL = CometBuildInfo.cometRepoUrl
val COMET_BUILD_TIMESTAMP = CometBuildInfo.cometBuildTimestamp
private def getProp(name: String): String = {
CometBuildInfo.props.getProperty(name, "<unknown>")
}

val COMET_VERSION: String = getProp("git.build.version")
val COMET_BRANCH: String = getProp("git.branch")
val COMET_REVISION: String = getProp("git.commit.id.full")
val COMET_BUILD_USER_EMAIL: String = getProp("git.build.user.name")
val COMET_BUILD_USER_NAME: String = getProp("git.build.user.email")
val COMET_REPO_URL: String = getProp("git.remote.origin.url")
val COMET_BUILD_TIMESTAMP: String = getProp("git.build.time")
}

0 comments on commit 6979696

Please sign in to comment.