From eac8b8d95cdce4fbe8ef4694b0e589f98fa54d4e Mon Sep 17 00:00:00 2001 From: sirknightj Date: Mon, 14 Oct 2024 14:07:53 -0700 Subject: [PATCH] Bump the version from 1.12.1 to 1.12.2 (#202) * Bump the version from 1.12.1 to 1.12.2 * Bump the version for the user agent, make it dynamic, add test to check it matches the value from pom * Adjust variable name and cleanup test * Extract constants --- pom.xml | 11 +++- .../kinesisvideo/util/VersionUtil.java | 16 ++++- src/main/resources/pom.properties | 1 + .../kinesisvideo/util/VersionUtilTest.java | 60 +++++++++++++++++++ 4 files changed, 86 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/pom.properties create mode 100644 src/test/java/com/amazonaws/kinesisvideo/util/VersionUtilTest.java diff --git a/pom.xml b/pom.xml index 9a1fcbdf..6d723409 100644 --- a/pom.xml +++ b/pom.xml @@ -15,7 +15,7 @@ com.amazonaws amazon-kinesis-video-streams-producer-sdk-java Amazon Kinesis Video Streams Producer SDK Java - 1.12.1 + 1.12.2 The Amazon Kinesis Video Streams Producer SDK for Java enables Java developers to ingest data into Amazon Kinesis Video. @@ -220,6 +220,15 @@ + + + src/main/resources + true + + **/pom.properties + + + diff --git a/src/main/java/com/amazonaws/kinesisvideo/util/VersionUtil.java b/src/main/java/com/amazonaws/kinesisvideo/util/VersionUtil.java index ab692f65..9be6385f 100644 --- a/src/main/java/com/amazonaws/kinesisvideo/util/VersionUtil.java +++ b/src/main/java/com/amazonaws/kinesisvideo/util/VersionUtil.java @@ -3,10 +3,24 @@ import com.amazonaws.kinesisvideo.common.preconditions.Preconditions; import javax.annotation.Nonnull; +import java.io.IOException; +import java.util.Properties; public final class VersionUtil { - public static final String AWS_SDK_KVS_PRODUCER_VERSION_STRING = "1.9.5"; + private static final String POM_PROPERTIES_FILE = "pom.properties"; + private static final String POM_PROPERTIES_VERSION_KEY = "version"; + public static final String AWS_SDK_KVS_PRODUCER_VERSION_STRING; + + static { + try { + final Properties properties = new Properties(); + properties.load(VersionUtil.class.getClassLoader().getResourceAsStream(POM_PROPERTIES_FILE)); + AWS_SDK_KVS_PRODUCER_VERSION_STRING = properties.getProperty(POM_PROPERTIES_VERSION_KEY); + } catch (IOException e) { + throw new ExceptionInInitializerError("Unable to get project version from pom.xml: " + e); + } + } private static final String DEFAULT_USER_AGENT_NAME = "AWS-SDK-KVS"; diff --git a/src/main/resources/pom.properties b/src/main/resources/pom.properties new file mode 100644 index 00000000..defbd482 --- /dev/null +++ b/src/main/resources/pom.properties @@ -0,0 +1 @@ +version=${project.version} diff --git a/src/test/java/com/amazonaws/kinesisvideo/util/VersionUtilTest.java b/src/test/java/com/amazonaws/kinesisvideo/util/VersionUtilTest.java new file mode 100644 index 00000000..2f8433a9 --- /dev/null +++ b/src/test/java/com/amazonaws/kinesisvideo/util/VersionUtilTest.java @@ -0,0 +1,60 @@ +package com.amazonaws.kinesisvideo.util; + +import org.junit.Test; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; + +import static com.amazonaws.kinesisvideo.util.VersionUtil.AWS_SDK_KVS_PRODUCER_VERSION_STRING; +import static com.amazonaws.kinesisvideo.util.VersionUtil.getUserAgent; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +public class VersionUtilTest { + + private static final String POM_XML_LOCATION = "pom.xml"; + + @Test + public void test_versionString_isNotNullOrEmpty() { + final String producerVersionString = AWS_SDK_KVS_PRODUCER_VERSION_STRING; + assertNotNull(producerVersionString); + assertNotEquals("", producerVersionString); + } + + @Test + public void test_versionString_isEqualToDeclaredInPomXML() throws IOException { + final String producerVersionString = extractVersionFromPomXML(); + + assertNotNull("project.version was not found in pom.xml!", producerVersionString); + assertNotEquals("", producerVersionString); + assertEquals(producerVersionString, AWS_SDK_KVS_PRODUCER_VERSION_STRING); + } + + @Test + public void test_userAgent_containsProjectVersion() throws IOException { + final String userAgent = getUserAgent(); + final String pomDefinedProjectVersion = extractVersionFromPomXML(); + + assertNotNull(userAgent); + assertNotEquals("", userAgent); + + assertNotNull(pomDefinedProjectVersion); + assertNotEquals("", pomDefinedProjectVersion); + + assertTrue(userAgent.contains(pomDefinedProjectVersion)); + } + + private String extractVersionFromPomXML() throws IOException { + try (final BufferedReader reader = new BufferedReader(new FileReader(POM_XML_LOCATION))) { + return reader.lines() + .filter(line -> line.contains("")) + .map(line -> line.replace("", "") + .replace("", "").trim()) + .findFirst() + .orElseThrow(() -> new IllegalStateException("'projectVersion' is not found in " + POM_XML_LOCATION)); + } + } +}