-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: log connector version and git revision
fixes #10
- Loading branch information
Showing
4 changed files
with
86 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
package io.questdb.kafka; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.util.Properties; | ||
|
||
final class VersionUtil { | ||
static String getVersion() { | ||
try { | ||
return VersionUtil.class.getPackage().getImplementationVersion(); | ||
} catch (Exception ex) { | ||
return "0.0.0.0"; | ||
private static final String VERSION; | ||
private static final String GIT_HASH; | ||
private static final String UNKNOWN = "unknown"; | ||
private static final String PROPERTIES_FILE = "questdb_connector_version.properties"; // keep in sync with pom.xml | ||
|
||
static { | ||
Properties properties = new Properties(); | ||
String version; | ||
String gitHash; | ||
try (InputStream is = VersionUtil.class.getClassLoader().getResourceAsStream(PROPERTIES_FILE)){ | ||
if (is == null) { | ||
version = UNKNOWN; | ||
gitHash = UNKNOWN; | ||
} else { | ||
properties.load(is); | ||
version = String.valueOf(properties.getOrDefault("git.build.version", UNKNOWN)); | ||
gitHash = String.valueOf(properties.getOrDefault("git.commit.id.abbrev", UNKNOWN)); | ||
} | ||
} catch (IOException e) { | ||
version = UNKNOWN; | ||
gitHash = UNKNOWN; | ||
} | ||
VERSION = version; | ||
GIT_HASH = gitHash; | ||
} | ||
|
||
static String getVersion() { | ||
return VERSION; | ||
} | ||
|
||
static String getGitHash() { | ||
return GIT_HASH; | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
connector/src/test/java/io/questdb/kafka/VersionUtilTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package io.questdb.kafka; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
class VersionUtilTest { | ||
// if these tests are failing then build the project with maven | ||
// maven build generates the questdb_connector_version.properties file | ||
|
||
@Test | ||
public void testGetVersion() { | ||
String version = VersionUtil.getVersion(); | ||
assertNotNull(version); | ||
assertNotEquals("unknown", version); | ||
assertFalse(version.isEmpty()); | ||
} | ||
|
||
@Test | ||
public void testGetGitHash() { | ||
String gitHash = VersionUtil.getGitHash(); | ||
assertNotNull(gitHash); | ||
assertNotEquals("unknown", gitHash); | ||
assertFalse(gitHash.isEmpty()); | ||
} | ||
} |