Skip to content

Commit

Permalink
fix: properly load connector version
Browse files Browse the repository at this point in the history
  • Loading branch information
jeqo committed Mar 8, 2024
1 parent a37919c commit dfcc855
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 19 deletions.
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,6 @@ jar {


test {
useJUnitPlatform()

//we do not need to check classpath hell for testing
systemProperty "tests.jarhell.check", "false"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class ElasticsearchSinkConnector extends SinkConnector {

@Override
public String version() {
return Version.getVersion();
return Version.VERSION;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public class ElasticsearchSinkTask extends SinkTask {

@Override
public String version() {
return Version.getVersion();
return Version.VERSION;
}

@Override
Expand Down
21 changes: 8 additions & 13 deletions src/main/java/io/aiven/connect/elasticsearch/Version.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,18 @@

public class Version {
private static final Logger log = LoggerFactory.getLogger(Version.class);
private static String version = "unknown";
private static final String PROPERTIES_FILENAME = "elasticsearch-connector-for-apache-kafka-version.properties";

private static final String VERSION_FILE = "/aiven-kafka-connect-elasticsearch-version.properties";
static final String VERSION;

static {
try {
final Properties props = new Properties();
try (InputStream versionFileStream = Version.class.getResourceAsStream(VERSION_FILE)) {
props.load(versionFileStream);
version = props.getProperty("version", version).trim();
}
final Properties props = new Properties();
try (final InputStream resourceStream =
Version.class.getClassLoader().getResourceAsStream(PROPERTIES_FILENAME)) {
props.load(resourceStream);
} catch (final Exception e) {
log.warn("Error while loading version:", e);
log.warn("Error while loading {}: {}", PROPERTIES_FILENAME, e.getMessage());
}
}

public static String getVersion() {
return version;
VERSION = props.getProperty("version", "unknown").trim();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
##
# Copyright 2019 Aiven Oy
# Copyright 2016 Confluent Inc.
# Copyright 2020 Aiven Oy
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -14,4 +13,4 @@
# See the License for the specific language governing permissions and
# limitations under the License.
##
version=${version ?: 'unknown'}
version=${version ?: 'unknown'}

0 comments on commit dfcc855

Please sign in to comment.