Skip to content

Commit

Permalink
Bump the version from 1.12.1 to 1.12.2 (#202)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
sirknightj authored Oct 14, 2024
1 parent bad77af commit eac8b8d
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 2 deletions.
11 changes: 10 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<groupId>com.amazonaws</groupId>
<artifactId>amazon-kinesis-video-streams-producer-sdk-java</artifactId>
<name>Amazon Kinesis Video Streams Producer SDK Java</name>
<version>1.12.1</version>
<version>1.12.2</version>
<description>The Amazon Kinesis Video Streams Producer SDK for Java enables Java developers to ingest data into
Amazon Kinesis Video.
</description>
Expand Down Expand Up @@ -220,6 +220,15 @@
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/pom.properties</include>
</includes>
</resource>
</resources>
</build>
</project>

16 changes: 15 additions & 1 deletion src/main/java/com/amazonaws/kinesisvideo/util/VersionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -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";

Expand Down
1 change: 1 addition & 0 deletions src/main/resources/pom.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
version=${project.version}
60 changes: 60 additions & 0 deletions src/test/java/com/amazonaws/kinesisvideo/util/VersionUtilTest.java
Original file line number Diff line number Diff line change
@@ -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("<version>"))
.map(line -> line.replace("<version>", "")
.replace("</version>", "").trim())
.findFirst()
.orElseThrow(() -> new IllegalStateException("'<version>projectVersion</version>' is not found in " + POM_XML_LOCATION));
}
}
}

0 comments on commit eac8b8d

Please sign in to comment.