Skip to content

Commit 73d8377

Browse files
committed
Make ServiceVersionInfo conform to major.minor.x
1 parent f6bd9ba commit 73d8377

File tree

5 files changed

+63
-10
lines changed

5 files changed

+63
-10
lines changed

codegen/src/main/java/software/amazon/awssdk/codegen/poet/client/specs/ServiceVersionInfoSpec.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,14 @@
2222
import com.squareup.javapoet.MethodSpec;
2323
import com.squareup.javapoet.TypeSpec;
2424
import javax.lang.model.element.Modifier;
25+
import java.util.regex.Matcher;
26+
import java.util.regex.Pattern;
2527
import software.amazon.awssdk.annotations.SdkInternalApi;
2628
import software.amazon.awssdk.codegen.model.intermediate.IntermediateModel;
2729
import software.amazon.awssdk.codegen.poet.ClassSpec;
2830
import software.amazon.awssdk.codegen.poet.PoetExtension;
2931
import software.amazon.awssdk.codegen.poet.PoetUtils;
32+
import software.amazon.awssdk.codegen.utils.VersionUtils;
3033

3134
public class ServiceVersionInfoSpec implements ClassSpec {
3235
private final PoetExtension poetExtension;
@@ -37,14 +40,16 @@ public ServiceVersionInfoSpec(IntermediateModel model) {
3740

3841
@Override
3942
public TypeSpec poetSpec() {
43+
String majorMinorVersion = VersionUtils.convertToMajorMinorX(SDK_VERSION);
44+
4045
TypeSpec.Builder builder = TypeSpec.classBuilder("ServiceVersionInfo")
4146
.addModifiers(Modifier.PUBLIC, Modifier.FINAL)
4247
.addAnnotation(PoetUtils.generatedAnnotation())
4348
.addAnnotation(SdkInternalApi.class)
4449
.addField(FieldSpec.builder(
4550
String.class, "VERSION", Modifier.PUBLIC, Modifier.STATIC, Modifier.FINAL)
46-
.initializer("$S", SDK_VERSION)
47-
.addJavadoc("Returns the current version for the AWS SDK in which"
51+
.initializer("$S", majorMinorVersion)
52+
.addJavadoc("Returns the current major.minor.x version for the AWS SDK in which"
4853
+ " this class is running.")
4954
.build())
5055
.addMethod(privateConstructor());
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License").
5+
* You may not use this file except in compliance with the License.
6+
* A copy of the License is located at
7+
*
8+
* http://aws.amazon.com/apache2.0
9+
*
10+
* or in the "license" file accompanying this file. This file is distributed
11+
* on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
12+
* express or implied. See the License for the specific language governing
13+
* permissions and limitations under the License.
14+
*/
15+
16+
package software.amazon.awssdk.codegen.utils;
17+
18+
import java.util.regex.Matcher;
19+
import java.util.regex.Pattern;
20+
import software.amazon.awssdk.annotations.SdkInternalApi;
21+
22+
@SdkInternalApi
23+
public class VersionUtils {
24+
25+
private VersionUtils() {}
26+
27+
/**
28+
* Converts a full version string to a major.minor.x format.
29+
*
30+
* @param version The full version string to convert (e.g., "2.32.1")
31+
* @return The version string in major.minor.x format (e.g., "2.32.x"),
32+
* or the original string if it doesn't match the expected version pattern
33+
*/
34+
public static String convertToMajorMinorX(String version) {
35+
Pattern pattern = Pattern.compile("(\\d+)\\.(\\d+)\\.(\\d+)(.*)");
36+
Matcher matcher = pattern.matcher(version);
37+
38+
if (matcher.matches()) {
39+
String major = matcher.group(1);
40+
String minor = matcher.group(2);
41+
String suffix = matcher.group(4);
42+
43+
return major + "." + minor + ".x" + suffix;
44+
}
45+
46+
return version;
47+
}
48+
}

codegen/src/test/java/software/amazon/awssdk/codegen/poet/client/ServiceVersionInfoSpecTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
package software.amazon.awssdk.codegen.poet.client;
1717

1818
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
19-
import static org.hamcrest.Matchers.equalToIgnoringWhiteSpace;
19+
import static software.amazon.awssdk.core.util.VersionInfo.SDK_VERSION;
2020

2121
import com.squareup.javapoet.JavaFile;
2222
import com.squareup.javapoet.TypeSpec;
@@ -26,7 +26,7 @@
2626
import software.amazon.awssdk.codegen.poet.ClassSpec;
2727
import software.amazon.awssdk.codegen.poet.ClientTestModels;
2828
import software.amazon.awssdk.codegen.poet.client.specs.ServiceVersionInfoSpec;
29-
import software.amazon.awssdk.core.util.VersionInfo;
29+
import software.amazon.awssdk.codegen.utils.VersionUtils;
3030

3131
public class ServiceVersionInfoSpecTest {
3232

@@ -36,7 +36,7 @@ public class ServiceVersionInfoSpecTest {
3636
// version at build time.
3737
@Test
3838
void testServiceVersionInfoClass() {
39-
String currVersion = VersionInfo.SDK_VERSION;
39+
String currVersion = VersionUtils.convertToMajorMinorX(SDK_VERSION);
4040
ClassSpec serviceVersionInfoSpec = new ServiceVersionInfoSpec(ClientTestModels.restJsonServiceModels());
4141

4242
String expectedContent = loadFixtureFile("test-service-version-info-class.java");

codegen/src/test/resources/software/amazon/awssdk/codegen/poet/client/specs/test-service-version-info-class.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
@SdkInternalApi
99
public final class ServiceVersionInfo {
1010
/**
11-
* Returns the current version for the AWS SDK in which this class is running.
11+
* Returns the current major.minor.x version for the AWS SDK in which this class is running.
1212
*/
1313
public static final String VERSION = "{{VERSION}}";
1414

core/sdk-core/src/test/java/software/amazon/awssdk/core/internal/useragent/SdkUserAgentBuilderTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private static Stream<Arguments> inputValues() {
5252
Arrays.asList("Kotlin", "Scala"));
5353

5454
SdkClientUserAgentProperties minimalProperties = sdkProperties(null, null, null, null, null);
55-
SdkClientUserAgentProperties maximalProperties = sdkProperties("arbitrary", "async", "Netty", "someAppId", "DynamoDB#2.26.22-SNAPSHOT");
55+
SdkClientUserAgentProperties maximalProperties = sdkProperties("arbitrary", "async", "Netty", "someAppId", "DynamoDB#2.26.x-SNAPSHOT");
5656

5757

5858
return Stream.of(
@@ -88,11 +88,11 @@ private static Stream<Arguments> inputValues() {
8888
sdkProperties( null, null, null, "someAppId", null),
8989
maximalSysAgent),
9090
Arguments.of("standard sysagent, request values - apiMetadata",
91-
"aws-sdk-java/2.26.22-SNAPSHOT ua/2.1 api/DynamoDB#2.26.22-SNAPSHOT os/Mac_OS_X#14.6.1 lang/java#21.0.2 md/OpenJDK_64-Bit_Server_VM#21.0.2+13-LTS md/en_US",
92-
sdkProperties(null, null, null, null, "DynamoDB#2.26.22-SNAPSHOT"),
91+
"aws-sdk-java/2.26.22-SNAPSHOT ua/2.1 api/DynamoDB#2.26.x-SNAPSHOT os/Mac_OS_X#14.6.1 lang/java#21.0.2 md/OpenJDK_64-Bit_Server_VM#21.0.2+13-LTS md/en_US",
92+
sdkProperties(null, null, null, null, "DynamoDB#2.26.x-SNAPSHOT"),
9393
standardValuesSysAgent),
9494
Arguments.of("standard sysagent, request values - maximal",
95-
"aws-sdk-java/2.26.22-SNAPSHOT md/io#async md/http#Netty md/internal ua/2.1 api/DynamoDB#2.26.22-SNAPSHOT"
95+
"aws-sdk-java/2.26.22-SNAPSHOT md/io#async md/http#Netty md/internal ua/2.1 api/DynamoDB#2.26.x-SNAPSHOT"
9696
+ " os/Mac_OS_X#14.6.1 lang/java#21.0.2 "
9797
+ "md/OpenJDK_64-Bit_Server_VM#21.0.2+13-LTS md/vendor#Amazon.com_Inc. md/en_US md/Kotlin md/Scala "
9898
+ "exec-env/lambda app/someAppId",

0 commit comments

Comments
 (0)