From 697969668467120fcf61ba1a52a8d980f5b9bc92 Mon Sep 17 00:00:00 2001 From: Andy Grove Date: Mon, 21 Oct 2024 08:53:11 -0600 Subject: [PATCH] Make comet-git-info.properties optional --- .../main/scala/org/apache/comet/package.scala | 75 ++++++++----------- 1 file changed, 31 insertions(+), 44 deletions(-) diff --git a/common/src/main/scala/org/apache/comet/package.scala b/common/src/main/scala/org/apache/comet/package.scala index f44139ba6..552022f59 100644 --- a/common/src/main/scala/org/apache/comet/package.scala +++ b/common/src/main/scala/org/apache/comet/package.scala @@ -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 { @@ -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 = "" - 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, "") + } + 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") }