Skip to content

Commit 6b985d4

Browse files
authored
Enabling checkstyle for test and integration test folders and adds a check to prohibit the @ignore annotation (#3631)
1 parent 7052ba6 commit 6b985d4

File tree

7 files changed

+74
-14
lines changed

7 files changed

+74
-14
lines changed
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
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.buildtools.checkstyle;
17+
18+
import com.puppycrawl.tools.checkstyle.api.AbstractCheck;
19+
import com.puppycrawl.tools.checkstyle.api.DetailAST;
20+
import com.puppycrawl.tools.checkstyle.api.TokenTypes;
21+
import com.puppycrawl.tools.checkstyle.utils.AnnotationUtil;
22+
23+
/**
24+
* Checks if a class uses the @Ignore annotation. Avoid disabling tests and work to
25+
* resolve issues with the test instead.
26+
*
27+
* For manual tests and exceptional circumstances, use the commentation feature CHECKSTYLE: OFF
28+
* to mark a test as ignored.
29+
*/
30+
public class NoIgnoreAnnotationsCheck extends AbstractCheck {
31+
32+
private static final String IGNORE_ANNOTATION = "Ignore";
33+
34+
@Override
35+
public int[] getDefaultTokens() {
36+
return getRequiredTokens();
37+
}
38+
39+
@Override
40+
public int[] getAcceptableTokens() {
41+
return getRequiredTokens();
42+
}
43+
44+
@Override
45+
public int[] getRequiredTokens() {
46+
return new int[] {TokenTypes.CLASS_DEF, TokenTypes.METHOD_DEF};
47+
}
48+
49+
@Override
50+
public void visitToken(DetailAST ast) {
51+
if (!AnnotationUtil.containsAnnotation(ast, IGNORE_ANNOTATION)) {
52+
return;
53+
}
54+
55+
log(ast, "@Ignore annotation is not allowed");
56+
}
57+
}

build-tools/src/main/resources/software/amazon/awssdk/checkstyle-suppressions.xml

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,13 @@
1616
-->
1717

1818
<!DOCTYPE suppressions PUBLIC
19-
"-//Puppy Crawl//DTD Suppressions 1.1//EN"
20-
"http://www.puppycrawl.com/dtds/suppressions_1_1.dtd">
19+
"-//Puppy Crawl//DTD Suppressions 1.2//EN"
20+
"http://www.puppycrawl.com/dtds/suppressions_1_2.dtd">
2121
<suppressions>
22-
<!-- TODO: Disable these suppressions. -->
23-
<suppress checks=".*"
22+
<!-- ignore all checks for test classes except for the NoIgnoreAnnotationsCheck -->
23+
<suppress checks="^((?!NoIgnoreAnnotationsCheck).)*$"
2424
files=".*[\\/](test|it)[\\/]java[\\/].+\.java$"/>
2525

26-
<!-- TODO: Disable these suppressions. -->
27-
<suppress checks=".*"
28-
files=".(flow)[\\/].+\.java$"/>
29-
3026
<!-- ignore missing annotation checks under test/codegen directory -->
3127
<suppress checks="MissingSdkAnnotationCheck"
3228
files=".(codegen|test|release)[\\/].+\.java$"/>

build-tools/src/main/resources/software/amazon/awssdk/checkstyle.xml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,6 @@
384384
<property name="ignoreComments" value="true"/>
385385
</module>
386386

387-
388387
<!-- Checks that we don't use AttributeKey.newInstance directly -->
389388
<module name="Regexp">
390389
<property name="format" value="AttributeKey\.newInstance"/>
@@ -401,6 +400,10 @@
401400
<property name="ignoreComments" value="true"/>
402401
</module>
403402

403+
<!-- Checks that we don't use the @Ignore annotation on tests -->
404+
<module name="software.amazon.awssdk.buildtools.checkstyle.NoIgnoreAnnotationsCheck">
405+
</module>
406+
404407
<!-- Checks that we don't use plural enum names -->
405408
<module name="software.amazon.awssdk.buildtools.checkstyle.PluralEnumNames"/>
406409

core/sdk-core/src/main/java/software/amazon/awssdk/core/interceptor/ExecutionInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
import software.amazon.awssdk.core.SdkRequest;
2424
import software.amazon.awssdk.core.SdkResponse;
2525
import software.amazon.awssdk.core.async.AsyncRequestBody;
26-
// Disable CS to avoid "Unused Import" error. If we use the FQCN in the Javadoc, we'll run into line length issues instead.
27-
// CHECKSTYLE:OFF
26+
27+
// CHECKSTYLE:OFF - Avoid "Unused Import" error. If we use the FQCN in the Javadoc, we'll run into line length issues instead.
2828
import software.amazon.awssdk.core.client.config.ClientOverrideConfiguration;
2929
// CHECKSTYLE:ON
3030
import software.amazon.awssdk.core.retry.RetryPolicy;

pom.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@
170170
<reactive-streams.version>1.0.3</reactive-streams.version>
171171

172172
<skip.unit.tests>${skipTests}</skip.unit.tests>
173+
<integTestSourceDirectory>${project.basedir}/src/it/java</integTestSourceDirectory>
173174
</properties>
174175

175176
<dependencyManagement>
@@ -422,6 +423,8 @@
422423
<consoleOutput>true</consoleOutput>
423424
<failsOnError>true</failsOnError>
424425
<logViolationsToConsole>true</logViolationsToConsole>
426+
<testSourceDirectories>${project.build.testSourceDirectory},${integTestSourceDirectory}</testSourceDirectories>
427+
<includeTestSourceDirectory>true</includeTestSourceDirectory>
425428
<failOnViolation>true</failOnViolation>
426429
<excludes>**/module-info.java</excludes>
427430
</configuration>

services/sqs/src/it/java/software/amazon/awssdk/services/sqs/SqsConcurrentPerformanceIntegrationTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,10 @@ public class SqsConcurrentPerformanceIntegrationTest extends IntegrationTestBase
4545
* You can use the netstat command to look at the current sockets connected to SQS and verify
4646
* that they don't sit around in CLOSE_WAIT, and are correctly being reaped.
4747
*/
48+
// CHECKSTYLE:OFF - Allowing @Ignore for this manual test
4849
@Test
4950
@Ignore
51+
// CHECKSTYLE:ON
5052
public void testIdleConnectionReaping() throws Exception {
5153
sqs = SqsAsyncClient.builder().credentialsProvider(getCredentialsProvider()).build();
5254
sqs = SqsAsyncClient.builder().credentialsProvider(getCredentialsProvider()).build();
@@ -79,4 +81,4 @@ public void run() {
7981
private void waitForUserInput() throws IOException {
8082
new BufferedReader(new InputStreamReader(System.in)).readLine();
8183
}
82-
}
84+
}

utils/src/main/java/software/amazon/awssdk/utils/UserHomeDirectoryUtils.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,7 @@ private UserHomeDirectoryUtils() {
3030
}
3131

3232
public static String userHomeDirectory() {
33-
// To match the logic of the CLI we have to consult environment variables directly.
34-
// CHECKSTYLE:OFF
33+
// CHECKSTYLE:OFF - To match the logic of the CLI we have to consult environment variables directly.
3534
Optional<String> home = SystemSetting.getStringValueFromEnvironmentVariable("HOME");
3635

3736
if (home.isPresent()) {

0 commit comments

Comments
 (0)