Skip to content

Commit 307daf5

Browse files
committed
Add an API for accessing Cobrix version and build info.
1 parent 4211a3d commit 307daf5

2 files changed

Lines changed: 52 additions & 2 deletions

File tree

spark-cobol/src/main/scala/za/co/absa/cobrix/spark/cobol/utils/BuildProperties.scala

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,26 @@ import java.util.Properties
2020

2121
object BuildProperties {
2222
private val properties = new Properties()
23-
private val buildVersionKey = "build.version"
24-
private val buildTimestampKey = "build.timestamp"
23+
val buildVersionKey = "build.version"
24+
val buildTimestampKey = "build.timestamp"
2525

2626
/** Returns the version of the build. */
2727
lazy val buildVersion: String = properties.getProperty(buildVersionKey)
2828

2929
/** Returns the version of the build. */
3030
lazy val buildTimestamp: String = properties.getProperty(buildTimestampKey)
3131

32+
/** Returns full version to refer to in the user interface. */
33+
def getFullVersion: String = {
34+
val version = buildVersion
35+
if (version.contains("SNAPSHOT")) {
36+
val builtAt = buildTimestamp
37+
s"$version built $builtAt"
38+
} else {
39+
version
40+
}
41+
}
42+
3243
loadConfig()
3344

3445
private def loadConfig(): Unit = {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright 2018 ABSA Group Limited
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package za.co.absa.cobrix.spark.cobol.utils
18+
19+
import org.scalatest.wordspec.AnyWordSpec
20+
21+
class BuildPropertiesSuite extends AnyWordSpec {
22+
"BuildProperties" should {
23+
"return non-empty build version" in {
24+
assert(BuildProperties.buildVersion.nonEmpty)
25+
}
26+
27+
"return non-empty build timestamp" in {
28+
assert(BuildProperties.buildTimestamp.nonEmpty)
29+
}
30+
31+
"return full version containing build version and timestamp for SNAPSHOT versions" in {
32+
val fullVersion = BuildProperties.getFullVersion
33+
assert(fullVersion.contains(BuildProperties.buildVersion))
34+
if (BuildProperties.buildVersion.contains("SNAPSHOT")) {
35+
assert(fullVersion.contains(BuildProperties.buildTimestamp))
36+
}
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)