Skip to content

Commit

Permalink
bugfix/Close streams at the function gitCommit and use lazy val inste…
Browse files Browse the repository at this point in the history
…ad of def
  • Loading branch information
constantine2nd committed Sep 15, 2023
1 parent e658e84 commit 616d423
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/main/scala/code/snippet/ApiExplorer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1908,13 +1908,18 @@ WIP to add comments on resource docs. This code copied from Sofit.
/*
Return the git commit. If we can't for some reason (not a git root etc) then log and return ""
*/
def gitCommit : String = {
lazy val gitCommit : String = {
val commit = try {
val properties = new java.util.Properties()
logger.debug("Before getResourceAsStream git.properties")
properties.load(getClass().getClassLoader().getResourceAsStream("git.properties"))
logger.debug("Before get Property git.commit.id")
properties.getProperty("git.commit.id", "")
val stream = getClass().getClassLoader().getResourceAsStream("git.properties")
try {
properties.load(stream)
logger.debug("Before get Property git.commit.id")
properties.getProperty("git.commit.id", "")
} finally {
stream.close()
}
} catch {
case e : Throwable => {
logger.warn("gitCommit says: Could not return git commit. Does resources/git.properties exist?")
Expand Down

0 comments on commit 616d423

Please sign in to comment.