Skip to content

Commit 262251c

Browse files
committed
removed duplication and stdout
1 parent b0a8934 commit 262251c

File tree

5 files changed

+24
-52
lines changed

5 files changed

+24
-52
lines changed

clickhouse-client/src/main/java/com/clickhouse/client/config/ClickHouseClientOption.java

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -493,21 +493,7 @@ public enum ClickHouseClientOption implements ClickHouseOption {
493493
}
494494
options = Collections.unmodifiableMap(map);
495495

496-
// <artifact-id> <version> (revision: <revision>)
497-
String tmpVersion = "unknown";
498-
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("clickhouse-client-version.properties")) {
499-
Properties p = new Properties();
500-
p.load(in);
501-
502-
String tmp = p.getProperty("version");
503-
if (tmp != null && !tmp.isEmpty() && !tmp.equals("${revision}")) {
504-
tmpVersion = tmp;
505-
}
506-
} catch (Exception e) {
507-
// ignore
508-
}
509-
510-
PRODUCT_VERSION = tmpVersion;
496+
PRODUCT_VERSION = readVersionFromResource("clickhouse-client-version.properties");
511497
PRODUCT_REVISION = UNKNOWN;
512498

513499
CLIENT_OS_INFO = new StringBuilder().append(getSystemConfig("os.name", "O/S")).append('/')
@@ -529,6 +515,23 @@ public enum ClickHouseClientOption implements ClickHouseOption {
529515
CLIENT_HOST = host == null || host.isEmpty() ? UNKNOWN : host;
530516
}
531517

518+
public static String readVersionFromResource(String resourceFilePath) {
519+
// TODO: move to client-v2 when client-v1 is deprecated completely
520+
String tmpVersion = "unknown";
521+
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(resourceFilePath)) {
522+
Properties p = new Properties();
523+
p.load(in);
524+
525+
String tmp = p.getProperty("version");
526+
if (tmp != null && !tmp.isEmpty() && !tmp.equals("${revision}")) {
527+
tmpVersion = tmp;
528+
}
529+
} catch (Exception e) {
530+
// ignore
531+
}
532+
return tmpVersion;
533+
}
534+
532535
/**
533536
* Builds user-agent based on given product name. The user-agent will be
534537
* something look like

clickhouse-http-client/src/test/java/com/clickhouse/client/http/ClickHouseHttpClientTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,6 @@ private void testUserAgent(ClickHouseOption option, String optionValue) throws E
174174
.executeAndWait()) {
175175
if (response.records().iterator().hasNext()) {
176176
String result = response.firstRecord().getValue(0).asString();
177-
System.out.println(result);
178177
Assert.assertTrue(result.startsWith(optionValue + " ClickHouse-JavaClient/"));
179178
Assert.assertTrue(result.indexOf("Http") > 0);
180179
break;

client-v2/src/main/java/com/clickhouse/client/api/Client.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2160,28 +2160,12 @@ public void updateClientName(String name) {
21602160
this.configuration.put(ClientConfigProperties.CLIENT_NAME.getKey(), name);
21612161
}
21622162

2163-
public static final String clientVersion = getPackageVersion();
2163+
public static final String clientVersion =
2164+
ClickHouseClientOption.readVersionFromResource("client-v2-version.properties");
21642165
public static final String CLIENT_USER_AGENT = "clickhouse-java-v2/";
21652166

21662167
private Collection<String> unmodifiableDbRolesView = Collections.emptyList();
21672168

2168-
private static String getPackageVersion() {
2169-
String version = "unknown";
2170-
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("client-v2-version.properties")) {
2171-
Properties p = new Properties();
2172-
p.load(in);
2173-
2174-
String tmp = p.getProperty("version");
2175-
if (tmp != null && !tmp.isEmpty() && !tmp.equals("${revision}")) {
2176-
version = tmp;
2177-
}
2178-
} catch (Exception e) {
2179-
LOG.error("Failed to load version file", e);
2180-
}
2181-
2182-
return version;
2183-
}
2184-
21852169
/**
21862170
* Returns list of DB roles that should be applied to each query.
21872171
*

client-v2/src/main/java/com/clickhouse/client/api/internal/HttpAPIClientHelper.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -646,6 +646,7 @@ public static Map<String, String> parseUrlParameters(URL url) {
646646

647647

648648
private void correctUserAgentHeader(HttpRequest request, Map<String, Object> requestConfig) {
649+
//TODO: implement cache for user-agent
649650
Header userAgentHeader = request.getLastHeader(HttpHeaders.USER_AGENT);
650651
request.removeHeaders(HttpHeaders.USER_AGENT);
651652

@@ -670,10 +671,7 @@ private String buildDefaultUserAgent() {
670671
StringBuilder userAgent = new StringBuilder();
671672
userAgent.append(Client.CLIENT_USER_AGENT);
672673

673-
String clientVersion = Client.class.getPackage().getImplementationVersion();
674-
if (clientVersion == null) {
675-
clientVersion = Client.clientVersion;
676-
}
674+
String clientVersion = Client.clientVersion;
677675

678676
userAgent.append(clientVersion);
679677

jdbc-v2/src/main/java/com/clickhouse/jdbc/Driver.java

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33

44
import com.clickhouse.client.api.ClientConfigProperties;
5+
import com.clickhouse.client.config.ClickHouseClientOption;
56
import com.clickhouse.jdbc.internal.JdbcConfiguration;
67
import com.clickhouse.jdbc.internal.ExceptionUtils;
78
import org.slf4j.Logger;
@@ -60,20 +61,7 @@ public static String getFrameworksDetected() {
6061
static {
6162
log.debug("Initializing ClickHouse JDBC driver V2");
6263

63-
String tmpDriverVersion = "unknown";
64-
try (InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream("jdbc-v2-version.properties")) {
65-
Properties p = new Properties();
66-
p.load(in);
67-
68-
String tmp = p.getProperty("version");
69-
if (tmp != null && !tmp.isEmpty() && !tmp.equals("${revision}")) {
70-
tmpDriverVersion = tmp;
71-
}
72-
} catch (Exception e) {
73-
log.error("Failed to load version file", e);
74-
}
75-
76-
driverVersion = tmpDriverVersion;
64+
driverVersion = ClickHouseClientOption.readVersionFromResource("jdbc-v2-version.properties");
7765
log.info("ClickHouse JDBC driver version: {}", driverVersion);
7866

7967
int tmpMajorVersion;

0 commit comments

Comments
 (0)