Skip to content

Commit

Permalink
fix: Make comet-git-info.properties optional (#1027)
Browse files Browse the repository at this point in the history
* Make comet-git-info.properties optional

* use constant
  • Loading branch information
andygrove authored Oct 21, 2024
1 parent 4033687 commit 3df9d5c
Showing 1 changed file with 33 additions and 45 deletions.
78 changes: 33 additions & 45 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,47 @@ 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 {
private val GIT_INFO_PROPS_FILENAME = "comet-git-info.properties"

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)
.getResourceAsStream(GIT_INFO_PROPS_FILENAME)
if (resourceStream != null) {
try {
props.load(resourceStream)
} catch {
case e: Exception =>
logError(s"Error loading properties from $GIT_INFO_PROPS_FILENAME", e)
} finally {
if (resourceStream != null) {
try {
resourceStream.close()
} catch {
case e: Exception =>
logError("Error closing Comet build info resource stream", e)
}
}
}
} else {
logWarning(s"Could not find $GIT_INFO_PROPS_FILENAME")
}
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 3df9d5c

Please sign in to comment.