Repository: Unleash/unleash-client-java (java)

Issue:
Add sdkVersion in client-register call
As specified in https://github.com/Unleash/unleash/blob/master/docs/api/client/register-api.md clients should now include sdk type and version identifier. 

The value of the of this field should be picked up from pom.xml and look like:
`sdkVersion: unleash-client-java:3.x.z`

Pull request description:
Add sdkVersion to client registration
closes #39

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 6ea79226..f9a02c94 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,5 +1,8 @@
 # Changelog
 
+## [unreleased]
+- Add sdkVersion in client-register call
+
 ## 2.1.3 Expose Feature Toggle Definition
 - Exposing the Feature Toggle Definition via the `getFeatureToggleDefinition` method on DefaultUnleash to make it easier to extend it with new functionality. 
 
diff --git a/pom.xml b/pom.xml
index 86207b6f..3f688207 100644
--- a/pom.xml
+++ b/pom.xml
@@ -93,6 +93,18 @@
                     <target>1.8</target>
                 </configuration>
             </plugin>
+            <plugin>
+                <groupId>org.apache.maven.plugins</groupId>
+                <artifactId>maven-jar-plugin</artifactId>
+                <configuration>
+                    <archive>
+                        <manifest>
+                            <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
+                            <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries>
+                        </manifest>
+                    </archive>
+                </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.sonatype.plugins</groupId>
                 <artifactId>nexus-staging-maven-plugin</artifactId>
@@ -121,7 +133,6 @@
                     <maxmem>256m</maxmem>
                     <!-- aggregated reports for multi-module projects -->
                     <aggregate>true</aggregate>
-                    <check/>
                 </configuration>
             </plugin>
         </plugins>
diff --git a/src/main/java/no/finn/unleash/metric/ClientRegistration.java b/src/main/java/no/finn/unleash/metric/ClientRegistration.java
index 5c4400ad..99bee592 100644
--- a/src/main/java/no/finn/unleash/metric/ClientRegistration.java
+++ b/src/main/java/no/finn/unleash/metric/ClientRegistration.java
@@ -8,6 +8,7 @@
 class ClientRegistration {
     private final String appName;
     private final String instanceId;
+    private final String sdkVersion;
     private final Set<String> strategies;
     private final LocalDateTime started;
     private final long interval;
@@ -15,6 +16,7 @@ class ClientRegistration {
     ClientRegistration(UnleashConfig config, LocalDateTime started, Set<String> strategies) {
         this.appName = config.getAppName();
         this.instanceId = config.getInstanceId();
+        this.sdkVersion = config.getSdkVersion();
         this.started = started;
         this.strategies = strategies;
         this.interval = config.getSendMetricsInterval();
@@ -28,6 +30,10 @@ class ClientRegistration {
         return instanceId;
     }
 
+    public String getSdkVersion() {
+        return sdkVersion;
+    }
+
     public Set<String> getStrategies() {
         return strategies;
     }
diff --git a/src/main/java/no/finn/unleash/repository/ToggleBackupHandlerFile.java b/src/main/java/no/finn/unleash/repository/ToggleBackupHandlerFile.java
index ba078434..8fb608ad 100644
--- a/src/main/java/no/finn/unleash/repository/ToggleBackupHandlerFile.java
+++ b/src/main/java/no/finn/unleash/repository/ToggleBackupHandlerFile.java
@@ -28,7 +28,7 @@ public class ToggleBackupHandlerFile implements ToggleBackupHandler {
             LOG.warn(" Unleash could not find the backup-file '" + backupFile + "'. \n" +
                     "This is expected behavior the first time unleash runs in a new environment.");
         } catch (IOException | IllegalStateException | JsonParseException e) {
-            LOG.warn("Failed to read backup file:'{}'", backupFile, e);
+            LOG.error("Failed to read backup file:'{}'", backupFile, e);
         }
         List<FeatureToggle> emptyList = Collections.emptyList();
         return new ToggleCollection(emptyList);
diff --git a/src/main/java/no/finn/unleash/util/UnleashConfig.java b/src/main/java/no/finn/unleash/util/UnleashConfig.java
index dbe71e90..c15c712f 100644
--- a/src/main/java/no/finn/unleash/util/UnleashConfig.java
+++ b/src/main/java/no/finn/unleash/util/UnleashConfig.java
@@ -7,6 +7,7 @@ import java.net.URI;
 import java.net.UnknownHostException;
 import java.util.HashMap;
 import java.util.Map;
+import java.util.Optional;
 
 import no.finn.unleash.UnleashContextProvider;
 
@@ -19,6 +20,7 @@ public class UnleashConfig {
     private final Map<String, String> customHttpHeaders;
     private final String appName;
     private final String instanceId;
+    private final String sdkVersion;
     private final String backupFile;
     private final long fetchTogglesInterval;
     private final long sendMetricsInterval;
@@ -30,6 +32,7 @@ public class UnleashConfig {
             Map<String, String> customHttpHeaders,
             String appName,
             String instanceId,
+            String sdkVersion,
             String backupFile,
             long fetchTogglesInterval,
             long sendMetricsInterval,
@@ -50,6 +53,7 @@ public class UnleashConfig {
         this.unleashURLs = new UnleashURLs(unleashAPI);
         this.appName = appName;
         this.instanceId = instanceId;
+        this.sdkVersion = sdkVersion;
         this.backupFile = backupFile;
         this.fetchTogglesInterval = fetchTogglesInterval;
         this.sendMetricsInterval = sendMetricsInterval;
@@ -73,6 +77,10 @@ public class UnleashConfig {
         return instanceId;
     }
 
+    public String getSdkVersion() {
+        return sdkVersion;
+    }
+
     public long getFetchTogglesInterval() {
         return fetchTogglesInterval;
     }
@@ -113,6 +121,7 @@ public class UnleashConfig {
         private Map<String, String> customHttpHeaders = new HashMap<>();
         private String appName;
         private String instanceId = getDefaultInstanceId();
+        private String sdkVersion = getDefaultSdkVersion();
         private String backupFile;
         private long fetchTogglesInterval = 10;
         private long sendMetricsInterval = 60;
@@ -194,11 +203,18 @@ public class UnleashConfig {
                     customHttpHeaders,
                     appName,
                     instanceId,
+                    sdkVersion,
                     getBackupFile(),
                     fetchTogglesInterval,
                     sendMetricsInterval,
                     disableMetrics,
                     contextProvider);
         }
+
+        public String getDefaultSdkVersion() {
+            String version = Optional.ofNullable(getClass().getPackage().getImplementationVersion())
+                    .orElse("development");
+            return "unleash-client-java:" + version;
+        }
     }
 }


Test patch:
diff --git a/src/test/java/no/finn/unleash/util/UnleashConfigTest.java b/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
index 8bb41361..e5e24000 100644
--- a/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
+++ b/src/test/java/no/finn/unleash/util/UnleashConfigTest.java
@@ -64,6 +64,16 @@ public class UnleashConfigTest {
         assertThat(config.getBackupFile(), is("/test/unleash-backup.json"));
     }
 
+    @Test
+    public void should_set_sdk_version() {
+        UnleashConfig config = UnleashConfig.builder()
+                .appName("my-app")
+                .unleashAPI("http://unleash.org")
+                .build();
+
+        assertThat(config.getSdkVersion(), is("unleash-client-java:development"));
+    }
+
     @Test
     public void should_add_app_name_and_instance_id_and_user_agent_to_connection() throws IOException {
         String appName = "my-app";