Skip to content

Commit a8d55fc

Browse files
authored
Added sdk version to exception messages
The version is extracted from the pom file and put into SDKVersion.java. The old method that looked in the manifest now uses SDKVersion.
1 parent 8d32e5e commit a8d55fc

File tree

6 files changed

+90
-3
lines changed

6 files changed

+90
-3
lines changed

driver/pom.xml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -428,6 +428,16 @@
428428
<artifactId>exec-maven-plugin</artifactId>
429429
<version>3.1.0</version>
430430
<executions>
431+
<execution>
432+
<id>Generate SDK Version strings</id>
433+
<phase>generate-sources</phase>
434+
<configuration>
435+
<executable>${basedir}/scripts/generate_version_strings.sh</executable>
436+
</configuration>
437+
<goals>
438+
<goal>exec</goal>
439+
</goals>
440+
</execution>
431441
<execution>
432442
<id>human-readable NSON string generation</id>
433443
<phase>generate-sources</phase>
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright (C) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
4+
#
5+
# This file was distributed by Oracle as part of a version of Oracle NoSQL
6+
# Database made available at:
7+
#
8+
# http://www.oracle.com/technetwork/database/database-technologies/nosqldb/downloads/index.html
9+
#
10+
# Please see the LICENSE file included in the top-level directory of the
11+
# appropriate version of Oracle NoSQL Database for a copy of the license and
12+
# additional information.
13+
14+
# this script creates java code to enable using human-readable strings for field
15+
# names in nson debug/logging/verbose output. It modifies NsonProtocol.java to
16+
# add a map of field names to human readable field names.
17+
18+
SDK_VERSION_FILE=src/main/java/oracle/nosql/driver/SDKVersion.java
19+
20+
# get the version string from pom file
21+
sdk_version=$(mvn org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=project.version -q -DforceStdout)
22+
if [ "$sdk_version" = "" ] ; then
23+
echo "Error getting version from pom file"
24+
exit 1
25+
fi
26+
27+
# delete everything after the package declaration
28+
lastline=$(grep -n 'package oracle.nosql.driver' $SDK_VERSION_FILE | tail -1 | sed -e 's/:.*$//')
29+
head -$lastline $SDK_VERSION_FILE > /tmp/sdkversion.$$
30+
31+
# add SDKVersion class
32+
cat << EOT >> /tmp/sdkversion.$$
33+
/**
34+
* Public class to manage SDK version information
35+
*/
36+
public class SDKVersion {
37+
/**
38+
* The full X.Y.Z version of the current SDK
39+
*/
40+
public static final String VERSION = "$sdk_version";
41+
}
42+
EOT
43+
44+
# replace file
45+
mv /tmp/sdkversion.$$ $SDK_VERSION_FILE
46+
echo "Set SDKVersion.VERSION to $sdk_version"
47+
exit 0
48+

driver/src/main/java/oracle/nosql/driver/DriverMain.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ private static void usageExit() {
7272
* by maven.
7373
*/
7474
private static String findVersion() {
75-
return NoSQLHandleConfig.class.getPackage().getImplementationVersion();
75+
return SDKVersion.VERSION;
7676
}
7777

7878
/**

driver/src/main/java/oracle/nosql/driver/NoSQLException.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class NoSQLException extends RuntimeException {
2121
* @param msg the message
2222
*/
2323
public /*protected*/ NoSQLException(String msg) {
24-
super(msg);
24+
super(msg + " (" + SDKVersion.VERSION + ")");
2525
}
2626

2727
/**
@@ -31,7 +31,7 @@ public class NoSQLException extends RuntimeException {
3131
* @param cause the cause
3232
*/
3333
public /*protected*/ NoSQLException(String msg, Throwable cause) {
34-
super(msg, cause);
34+
super(msg + " (" + SDKVersion.VERSION + ")", cause);
3535
}
3636

3737
/**
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/*-
2+
* Copyright (c) 2011, 2023 Oracle and/or its affiliates. All rights reserved.
3+
*
4+
* Licensed under the Universal Permissive License v 1.0 as shown at
5+
* https://oss.oracle.com/licenses/upl/
6+
*/
7+
package oracle.nosql.driver;
8+
/**
9+
* Public class to manage SDK version information
10+
*/
11+
public class SDKVersion {
12+
/**
13+
* The full X.Y.Z version of the current SDK
14+
*/
15+
public static final String VERSION = "5.4.13";
16+
}

driver/src/test/java/oracle/nosql/driver/HandleConfigTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
package oracle.nosql.driver;
99

1010
import static org.junit.Assert.assertEquals;
11+
import static org.junit.Assert.assertNotNull;
12+
import static org.junit.Assert.assertTrue;
1113
import static org.junit.Assert.fail;
1214

1315
import java.net.URL;
@@ -94,6 +96,17 @@ public void testSslProtocols() {
9496
}
9597
}
9698

99+
@Test
100+
public void testSdkVersion() {
101+
final String version = NoSQLHandleConfig.getLibraryVersion();
102+
assertNotNull("SDK version should be non-null", version);
103+
/* check that version string has three dot-separated parts */
104+
String[] arr = version.split("\\.", -1);
105+
assertTrue("SDK version \"" + version +
106+
"\" should have at least three dot-separated parts",
107+
arr.length > 2);
108+
}
109+
97110
private void expectIllegalArg(String endpoint) {
98111
try {
99112
new NoSQLHandleConfig(endpoint);

0 commit comments

Comments
 (0)