Skip to content

Commit e46761c

Browse files
authored
Add bundle shading test (#5187)
* Add bundle shading test This test ensures that all classes in the SDK bundle artifact are correctly shaded. Unless it is necessary, such as for `org.reactivestreams classes`, all classes found in the bundle JAR should be under the `software.amazon.awssdk` package. * Update new module version * Dynamically load SDK class If the bundle the source of the class, this won't actually compile, becaus SDKClient will not compile. * Fixes * Update version
1 parent 7af4c50 commit e46761c

File tree

5 files changed

+178
-3
lines changed

5 files changed

+178
-3
lines changed

buildspecs/release-javadoc.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ phases:
1818
commands:
1919
- python ./scripts/doc_crosslinks/generate_cross_link_data.py --apiDefinitionsBasePath ./services/ --apiDefinitionsRelativeFilePath src/main/resources/codegen-resources/service-2.json --templateFilePath ./scripts/doc_crosslinks/crosslink_redirect.html --outputFilePath ./scripts/crosslink_redirect.html
2020
- mvn install -P quick -T1C
21-
- mvn clean install javadoc:aggregate -B -Ppublic-javadoc -Dcheckstyle.skip -Dspotbugs.skip -DskipTests -Ddoclint=none -pl '!:protocol-tests,!:protocol-tests-core,!:codegen-generated-classes-test,!:sdk-benchmarks,!:s3-benchmarks,!:module-path-tests,!:test-utils,!:http-client-tests,!:tests-coverage-reporting,!:sdk-native-image-test,!:ruleset-testing-core,!:old-client-version-compatibility-test,!:crt-unavailable-tests'
21+
- mvn clean install javadoc:aggregate -B -Ppublic-javadoc -Dcheckstyle.skip -Dspotbugs.skip -DskipTests -Ddoclint=none -pl '!:protocol-tests,!:protocol-tests-core,!:codegen-generated-classes-test,!:sdk-benchmarks,!:s3-benchmarks,!:module-path-tests,!:test-utils,!:http-client-tests,!:tests-coverage-reporting,!:sdk-native-image-test,!:ruleset-testing-core,!:old-client-version-compatibility-test,!:crt-unavailable-tests,!:bundle-shading-tests'
2222
- RELEASE_VERSION=`mvn -q -Dexec.executable=echo -Dexec.args='${project.version}' --non-recursive exec:exec`
2323
-
2424
- aws s3 sync target/site/apidocs/ $DOC_PATH/$RELEASE_VERSION/ --acl="public-read"
2525
- aws s3 cp ./scripts/crosslink_redirect.html $DOC_PATH/$RELEASE_VERSION/ --acl="public-read"
2626
- aws s3 sync $DOC_PATH/$RELEASE_VERSION/ $DOC_PATH/latest/ --acl=public-read --delete
2727
- jar cf aws-java-sdk-v2-docs.jar -C target/site/apidocs .
28-
- aws s3 cp aws-java-sdk-v2-docs.jar $DOC_PATH/ --acl="public-read"
28+
- aws s3 cp aws-java-sdk-v2-docs.jar $DOC_PATH/ --acl="public-read"

buildspecs/release-to-maven.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ phases:
3434
awk 'BEGIN { var=ENVIRON["SDK_SIGNING_GPG_KEYNAME"] } { gsub("\\$SDK_SIGNING_GPG_KEYNAME", var, $0); print }' > \
3535
$SETTINGS_XML
3636
37-
mvn clean deploy -B -s $SETTINGS_XML -Ppublishing -DperformRelease -Dspotbugs.skip -DskipTests -Dcheckstyle.skip -Djapicmp.skip -Ddoclint=none -pl !:protocol-tests,!:protocol-tests-core,!:codegen-generated-classes-test,!:sdk-benchmarks,!:module-path-tests,!:tests-coverage-reporting,!:stability-tests,!:sdk-native-image-test,!:auth-tests,!:s3-benchmarks,!:region-testing,!:old-client-version-compatibility-test,!:crt-unavailable-tests -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30 -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true
37+
mvn clean deploy -B -s $SETTINGS_XML -Ppublishing -DperformRelease -Dspotbugs.skip -DskipTests -Dcheckstyle.skip -Djapicmp.skip -Ddoclint=none -pl !:protocol-tests,!:protocol-tests-core,!:codegen-generated-classes-test,!:sdk-benchmarks,!:module-path-tests,!:tests-coverage-reporting,!:stability-tests,!:sdk-native-image-test,!:auth-tests,!:s3-benchmarks,!:region-testing,!:old-client-version-compatibility-test,!:crt-unavailable-tests,!:bundle-shading-tests -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30 -Dmaven.wagon.httpconnectionManager.ttlSeconds=120 -Dmaven.wagon.http.retryHandler.requestSentEnabled=true
3838
else
3939
echo "This version was already released."
4040
fi

pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
<module>test/ruleset-testing-core</module>
8989
<module>test/old-client-version-compatibility-test</module>
9090
<module>test/bundle-logging-bridge-binding-test</module>
91+
<module>test/bundle-shading-tests</module>
9192
<module>test/crt-unavailable-tests</module>
9293
</modules>
9394
<scm>

test/bundle-shading-tests/pom.xml

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
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+
<parent>
21+
<artifactId>aws-sdk-java-pom</artifactId>
22+
<groupId>software.amazon.awssdk</groupId>
23+
<version>2.25.49-SNAPSHOT</version>
24+
<relativePath>../../pom.xml</relativePath>
25+
</parent>
26+
<modelVersion>4.0.0</modelVersion>
27+
28+
<artifactId>bundle-shading-tests</artifactId>
29+
<name>AWS Java SDK :: Test :: Bundle Shading Tests</name>
30+
<description>Test package for testing that the SDK Bundle has been shaded correctly.</description>
31+
<dependencyManagement>
32+
<dependencies>
33+
<dependency>
34+
<groupId>software.amazon.awssdk</groupId>
35+
<artifactId>bom-internal</artifactId>
36+
<version>${project.version}</version>
37+
<type>pom</type>
38+
<scope>import</scope>
39+
</dependency>
40+
</dependencies>
41+
</dependencyManagement>
42+
43+
<dependencies>
44+
<dependency>
45+
<groupId>software.amazon.awssdk</groupId>
46+
<artifactId>bundle</artifactId>
47+
<version>${awsjavasdk.version}</version>
48+
<scope>test</scope>
49+
</dependency>
50+
<dependency>
51+
<groupId>org.junit.jupiter</groupId>
52+
<artifactId>junit-jupiter</artifactId>
53+
<scope>test</scope>
54+
</dependency>
55+
<dependency>
56+
<groupId>org.junit.jupiter</groupId>
57+
<artifactId>junit-jupiter-engine</artifactId>
58+
<scope>test</scope>
59+
</dependency>
60+
</dependencies>
61+
62+
<build>
63+
<plugins>
64+
<plugin>
65+
<groupId>org.apache.maven.plugins</groupId>
66+
<artifactId>maven-dependency-plugin</artifactId>
67+
<version>${maven-dependency-plugin.version}</version>
68+
<configuration>
69+
<failOnWarning>false</failOnWarning>
70+
<ignoreNonCompile>false</ignoreNonCompile>
71+
</configuration>
72+
</plugin>
73+
</plugins>
74+
</build>
75+
76+
</project>
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
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.bundle;
17+
18+
import static org.junit.jupiter.api.Assertions.fail;
19+
20+
import java.io.IOException;
21+
import java.net.URL;
22+
import java.nio.file.Files;
23+
import java.nio.file.Path;
24+
import java.nio.file.Paths;
25+
import java.nio.file.StandardOpenOption;
26+
import java.util.HashSet;
27+
import java.util.Set;
28+
import java.util.regex.Pattern;
29+
import java.util.zip.ZipEntry;
30+
import java.util.zip.ZipInputStream;
31+
import org.junit.jupiter.api.Assumptions;
32+
import org.junit.jupiter.api.BeforeAll;
33+
import org.junit.jupiter.api.Test;
34+
35+
public class BundleShadedCorrectlyTest {
36+
private static final Set<String> ALLOWED_FILES;
37+
38+
static {
39+
Set<String> allowedFiles = new HashSet<>();
40+
allowedFiles.add("mime.types");
41+
allowedFiles.add("VersionInfo.java");
42+
allowedFiles.add("mozilla/public-suffix-list.txt");
43+
ALLOWED_FILES = allowedFiles;
44+
}
45+
private static final Pattern ALLOWED_PREFIXES = Pattern.compile("^META-INF/.*|"
46+
+ "^software/amazon/awssdk/.*|"
47+
+ "^software/amazon/eventstream/.*|"
48+
+ "^org/reactivestreams/.*|");
49+
private static Path bundlePath;
50+
51+
@BeforeAll
52+
public static void setup() {
53+
try {
54+
Class<?> sdkClientClss = Class.forName("software.amazon.awssdk.core.SdkClient");
55+
URL jarLocation = sdkClientClss.getProtectionDomain().getCodeSource().getLocation();
56+
Path sdkClientJar = Paths.get(jarLocation.getFile());
57+
if (isBundleJar(sdkClientJar.getFileName().toString())) {
58+
bundlePath = sdkClientJar;
59+
}
60+
} catch (ClassNotFoundException ignored) {
61+
}
62+
}
63+
64+
@Test
65+
public void testBundlePathsAreShaded() throws IOException {
66+
Assumptions.assumeTrue(bundlePath != null, "SDK classes are not loaded from the bundle.");
67+
68+
try (ZipInputStream jarZipIs = new ZipInputStream(Files.newInputStream(bundlePath, StandardOpenOption.READ))) {
69+
while (true) {
70+
ZipEntry e = jarZipIs.getNextEntry();
71+
72+
if (e == null) {
73+
break;
74+
}
75+
76+
if (e.isDirectory()) {
77+
continue;
78+
}
79+
80+
String fileName = e.getName();
81+
82+
if (ALLOWED_FILES.contains(fileName)) {
83+
continue;
84+
}
85+
86+
if (!ALLOWED_PREFIXES.matcher(fileName).matches()) {
87+
fail(() -> String.format("%s is not correctly shaded", fileName));
88+
}
89+
}
90+
}
91+
}
92+
93+
private static boolean isBundleJar(String fileName) {
94+
return fileName != null &&
95+
(fileName.startsWith("bundle-") ||
96+
fileName.startsWith("aws-sdk-java-bundle-"));
97+
}
98+
}

0 commit comments

Comments
 (0)