Skip to content

Commit c7f7e42

Browse files
authored
Add utils-lite package (#6395)
Add utils-lite package
1 parent 3addb7d commit c7f7e42

File tree

11 files changed

+267
-2
lines changed

11 files changed

+267
-2
lines changed

.brazil.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"s3-transfer-manager": { "packageName": "AwsJavaSdk-S3-TransferManager" },
3333
"s3-event-notifications": { "packageName": "AwsJavaSdk-S3-EventNotifications" },
3434
"sdk-core": { "packageName": "AwsJavaSdk-Core" },
35+
"utils-lite": { "packageName": "AwsJavaSdk-UtilsLite" },
3536
"url-connection-client": { "packageName": "AwsJavaSdk-HttpClient-UrlConnectionClient" },
3637
"utils": { "packageName": "AwsJavaSdk-Core-Utils" },
3738
"imds": { "packageName": "AwsJavaSdk-Imds" },

bom/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,11 @@
212212
<artifactId>utils</artifactId>
213213
<version>${awsjavasdk.version}</version>
214214
</dependency>
215+
<dependency>
216+
<groupId>software.amazon.awssdk</groupId>
217+
<artifactId>utils-lite</artifactId>
218+
<version>${awsjavasdk.version}</version>
219+
</dependency>
215220
<dependency>
216221
<groupId>software.amazon.awssdk</groupId>
217222
<artifactId>cloudwatch-metric-publisher</artifactId>

pom.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@
6767
<module>metric-publishers</module>
6868
<module>release-scripts</module>
6969
<module>utils</module>
70+
<module>utils-lite</module>
7071
<module>codegen-lite</module>
7172
<module>codegen-lite-maven-plugin</module>
7273
<module>archetypes</module>
@@ -665,6 +666,7 @@
665666
<includeModule>cloudwatch-metric-publisher</includeModule>
666667
<includeModule>emf-metric-logging-publisher</includeModule>
667668
<includeModule>utils</includeModule>
669+
<includeModule>utils-lite</includeModule>
668670
<includeModule>imds</includeModule>
669671
<includeModule>retries</includeModule>
670672
<includeModule>retries-spi</includeModule>

test/architecture-tests/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,11 @@
6161
<groupId>software.amazon.awssdk</groupId>
6262
<version>${awsjavasdk.version}</version>
6363
</dependency>
64+
<dependency>
65+
<artifactId>utils-lite</artifactId>
66+
<groupId>software.amazon.awssdk</groupId>
67+
<version>${awsjavasdk.version}</version>
68+
</dependency>
6469
<dependency>
6570
<artifactId>s3</artifactId>
6671
<groupId>software.amazon.awssdk</groupId>
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
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.archtests;
17+
18+
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes;
19+
20+
import com.tngtech.archunit.core.domain.JavaClasses;
21+
import com.tngtech.archunit.core.importer.ClassFileImporter;
22+
import com.tngtech.archunit.lang.ArchRule;
23+
import org.junit.jupiter.api.Test;
24+
25+
/**
26+
* Architecture tests for the utils-lite package to ensure it only contains allowed classes.
27+
*/
28+
public class UtilsLitePackageTest {
29+
30+
private static final JavaClasses CLASSES = new ClassFileImporter()
31+
.importPackages("software.amazon.awssdk.utilslite");
32+
33+
@Test
34+
public void utilsLitePackage_shouldOnlyContainAllowedClasses() {
35+
ArchRule rule = classes()
36+
.that().resideInAPackage("software.amazon.awssdk.utilslite")
37+
.should().haveNameMatching(".*\\.(SdkInternalThreadLocal|SdkInternalThreadLocalTest)")
38+
.allowEmptyShould(true)
39+
.because("utils-lite package should only contain SdkInternalThreadLocal and its test");
40+
41+
rule.check(CLASSES);
42+
}
43+
}

test/http-client-benchmarks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@
175175
<plugin>
176176
<groupId>org.apache.maven.plugins</groupId>
177177
<artifactId>maven-shade-plugin</artifactId>
178-
<version>2.2</version>
178+
<version>3.5.0</version>
179179
<executions>
180180
<execution>
181181
<phase>package</phase>

test/sdk-benchmarks/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@
340340
<plugin>
341341
<groupId>org.apache.maven.plugins</groupId>
342342
<artifactId>maven-shade-plugin</artifactId>
343-
<version>2.2</version>
343+
<version>3.5.0</version>
344344
<executions>
345345
<execution>
346346
<phase>package</phase>

test/tests-coverage-reporting/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,11 @@
326326
<artifactId>http-client-spi</artifactId>
327327
<version>${awsjavasdk.version}</version>
328328
</dependency>
329+
<dependency>
330+
<groupId>software.amazon.awssdk</groupId>
331+
<artifactId>utils-lite</artifactId>
332+
<version>${awsjavasdk.version}</version>
333+
</dependency>
329334
</dependencies>
330335

331336
<build>

utils-lite/pom.xml

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
~ Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
4+
~
5+
~ Licensed under the Apache License, Version 2.0 (the "License").
6+
~ You may not use this file except in compliance with the License.
7+
~ A copy of the License is located at
8+
~
9+
~ http://aws.amazon.com/apache2.0
10+
~
11+
~ or in the "license" file accompanying this file. This file is distributed
12+
~ on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
13+
~ express or implied. See the License for the specific language governing
14+
~ permissions and limitations under the License.
15+
-->
16+
17+
<project xmlns="http://maven.apache.org/POM/4.0.0"
18+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
19+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
20+
<modelVersion>4.0.0</modelVersion>
21+
<parent>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<artifactId>aws-sdk-java-pom</artifactId>
24+
<version>2.33.3-SNAPSHOT</version>
25+
</parent>
26+
<artifactId>utils-lite</artifactId>
27+
<name>AWS Java SDK :: Utils Lite</name>
28+
<description>
29+
A package providing minimal external utils.
30+
</description>
31+
<url>https://aws.amazon.com/sdkforjava</url>
32+
33+
<dependencyManagement>
34+
<dependencies>
35+
<dependency>
36+
<groupId>software.amazon.awssdk</groupId>
37+
<artifactId>bom-internal</artifactId>
38+
<version>${project.version}</version>
39+
<type>pom</type>
40+
<scope>import</scope>
41+
</dependency>
42+
</dependencies>
43+
</dependencyManagement>
44+
45+
<dependencies>
46+
<dependency>
47+
<groupId>software.amazon.awssdk</groupId>
48+
<artifactId>annotations</artifactId>
49+
<version>${awsjavasdk.version}</version>
50+
</dependency>
51+
<dependency>
52+
<groupId>org.junit.jupiter</groupId>
53+
<artifactId>junit-jupiter</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
<dependency>
57+
<groupId>org.assertj</groupId>
58+
<artifactId>assertj-core</artifactId>
59+
<scope>test</scope>
60+
</dependency>
61+
</dependencies>
62+
63+
<build>
64+
<plugins>
65+
<plugin>
66+
<groupId>org.apache.maven.plugins</groupId>
67+
<artifactId>maven-jar-plugin</artifactId>
68+
<configuration>
69+
<archive>
70+
<manifestEntries>
71+
<Automatic-Module-Name>software.amazon.awssdk.utilslite</Automatic-Module-Name>
72+
</manifestEntries>
73+
</archive>
74+
</configuration>
75+
</plugin>
76+
</plugins>
77+
</build>
78+
79+
</project>
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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.utilslite;
17+
18+
import java.util.HashMap;
19+
import java.util.Map;
20+
import software.amazon.awssdk.annotations.SdkProtectedApi;
21+
22+
/**
23+
* Utility for thread-local context storage.
24+
*/
25+
@SdkProtectedApi
26+
public final class SdkInternalThreadLocal {
27+
private static final ThreadLocal<Map<String, String>> STORAGE = ThreadLocal.withInitial(HashMap::new);
28+
29+
private SdkInternalThreadLocal() {
30+
}
31+
32+
public static void put(String key, String value) {
33+
if (value == null) {
34+
STORAGE.get().remove(key);
35+
} else {
36+
STORAGE.get().put(key, value);
37+
}
38+
}
39+
40+
public static String get(String key) {
41+
return STORAGE.get().get(key);
42+
}
43+
44+
public static String remove(String key) {
45+
return STORAGE.get().remove(key);
46+
}
47+
48+
public static void clear() {
49+
STORAGE.get().clear();
50+
}
51+
52+
public static boolean containsKey(String key) {
53+
return STORAGE.get().containsKey(key);
54+
}
55+
}

0 commit comments

Comments
 (0)