Skip to content

Commit b3558fc

Browse files
committed
Hacing
1 parent 021a962 commit b3558fc

File tree

2 files changed

+99
-50
lines changed

2 files changed

+99
-50
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*
2+
* Copyright 2017-2019 the original author or authors.
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+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.spring.javaformat.checkstyle.check;
18+
19+
import java.util.Arrays;
20+
import java.util.Collections;
21+
import java.util.LinkedHashSet;
22+
import java.util.Set;
23+
24+
import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck;
25+
import com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck;
26+
27+
/**
28+
* Spring variant of {@link AvoidStarImportCheck}.
29+
*/
30+
public class SpringAvoidStaticImportCheck extends AvoidStaticImportCheck {
31+
32+
private static final Set<String> ALWAYS_EXCLUDED;
33+
static {
34+
Set<String> excludes = new LinkedHashSet<>();
35+
excludes.add("io.restassured.RestAssured.*");
36+
excludes.add("org.assertj.core.api.Assertions.*");
37+
excludes.add("org.assertj.core.api.Assumptions.*");
38+
excludes.add("org.assertj.core.api.HamcrestCondition.*");
39+
excludes.add("org.awaitility.Awaitility.*");
40+
excludes.add("org.hamcrest.CoreMatchers.*");
41+
excludes.add("org.hamcrest.Matchers.*");
42+
excludes.add("org.junit.Assert.*");
43+
excludes.add("org.junit.Assume.*");
44+
excludes.add("org.junit.internal.matchers.ThrowableMessageMatcher.*");
45+
excludes.add("org.junit.jupiter.api.Assertions.*");
46+
excludes.add("org.junit.jupiter.api.Assumptions.*");
47+
excludes.add("org.junit.jupiter.api.Assertions.*");
48+
excludes.add("org.mockito.ArgumentMatchers.*");
49+
excludes.add("org.mockito.BDDMockito.*");
50+
excludes.add("org.mockito.Matchers.*");
51+
excludes.add("org.mockito.Mockito.*");
52+
excludes.add("org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*");
53+
excludes.add("org.springframework.boot.configurationprocessor.TestCompiler.*");
54+
excludes.add("org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*");
55+
excludes.add("org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo");
56+
excludes.add("org.springframework.restdocs.headers.HeaderDocumentation.*");
57+
excludes.add("org.springframework.restdocs.hypermedia.HypermediaDocumentation.*");
58+
excludes.add("org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*");
59+
excludes.add("org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*");
60+
excludes.add("org.springframework.restdocs.operation.preprocess.Preprocessors.*");
61+
excludes.add("org.springframework.restdocs.payload.PayloadDocumentation.*");
62+
excludes.add("org.springframework.restdocs.request.RequestDocumentation.*");
63+
excludes.add("org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*");
64+
excludes.add("org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*");
65+
excludes.add("org.springframework.restdocs.snippet.Attributes.*");
66+
excludes.add("org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*");
67+
excludes.add("org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*");
68+
excludes.add("org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*");
69+
excludes.add("org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*");
70+
excludes.add("org.springframework.test.web.client.ExpectedCount.*");
71+
excludes.add("org.springframework.test.web.client.match.MockRestRequestMatchers.*");
72+
excludes.add("org.springframework.test.web.client.response.MockRestResponseCreators.*");
73+
excludes.add("org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*");
74+
excludes.add("org.springframework.test.web.servlet.result.MockMvcResultHandlers.*");
75+
excludes.add("org.springframework.test.web.servlet.result.MockMvcResultMatchers.*");
76+
excludes.add("org.springframework.test.web.servlet.setup.MockMvcBuilders.*");
77+
excludes.add("org.springframework.web.reactive.function.BodyInserters.*");
78+
excludes.add("org.springframework.web.reactive.function.server.RequestPredicates.*");
79+
excludes.add("org.springframework.web.reactive.function.server.RouterFunctions.*");
80+
excludes.add("org.springframework.ws.test.client.RequestMatchers.*");
81+
excludes.add("org.springframework.ws.test.client.ResponseCreators.*");
82+
ALWAYS_EXCLUDED = Collections.unmodifiableSet(excludes);
83+
}
84+
85+
public SpringAvoidStaticImportCheck() {
86+
setExcludes(ALWAYS_EXCLUDED.toArray(new String[0]));
87+
}
88+
89+
@Override
90+
public void setExcludes(String... excludes) {
91+
Set<String> merged = new LinkedHashSet<>(ALWAYS_EXCLUDED);
92+
merged.addAll(Arrays.asList(excludes));
93+
super.setExcludes(merged.toArray(new String[0]));
94+
}
95+
96+
}

spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -73,56 +73,6 @@
7373

7474
<!-- Imports -->
7575
<module name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStarImportCheck" />
76-
<module name="com.puppycrawl.tools.checkstyle.checks.imports.AvoidStaticImportCheck">
77-
<property name="excludes" value="
78-
io.restassured.RestAssured.*,
79-
org.assertj.core.api.Assertions.*,
80-
org.assertj.core.api.Assumptions.*,
81-
org.assertj.core.api.HamcrestCondition.*,
82-
org.awaitility.Awaitility.*,
83-
org.hamcrest.CoreMatchers.*,
84-
org.hamcrest.Matchers.*,
85-
org.junit.Assert.*,
86-
org.junit.Assume.*,
87-
org.junit.internal.matchers.ThrowableMessageMatcher.*,
88-
org.junit.jupiter.api.Assertions.*,
89-
org.junit.jupiter.api.Assumptions.*,
90-
org.junit.jupiter.api.Assertions.*,
91-
org.mockito.ArgumentMatchers.*,
92-
org.mockito.BDDMockito.*,
93-
org.mockito.Matchers.*,
94-
org.mockito.Mockito.*,
95-
org.springframework.boot.configurationprocessor.ConfigurationMetadataMatchers.*,
96-
org.springframework.boot.configurationprocessor.TestCompiler.*,
97-
org.springframework.boot.test.autoconfigure.AutoConfigurationImportedCondition.*,
98-
org.springframework.hateoas.mvc.ControllerLinkBuilder.linkTo,
99-
org.springframework.restdocs.headers.HeaderDocumentation.*,
100-
org.springframework.restdocs.hypermedia.HypermediaDocumentation.*,
101-
org.springframework.restdocs.mockmvc.MockMvcRestDocumentation.*,
102-
org.springframework.restdocs.mockmvc.RestDocumentationRequestBuilders.*,
103-
org.springframework.restdocs.operation.preprocess.Preprocessors.*,
104-
org.springframework.restdocs.payload.PayloadDocumentation.*,
105-
org.springframework.restdocs.request.RequestDocumentation.*,
106-
org.springframework.restdocs.restassured3.operation.preprocess.RestAssuredPreprocessors.*,
107-
org.springframework.restdocs.restassured3.RestAssuredRestDocumentation.*,
108-
org.springframework.restdocs.snippet.Attributes.*,
109-
org.springframework.restdocs.webtestclient.WebTestClientRestDocumentation.*,
110-
org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestBuilders.*,
111-
org.springframework.security.test.web.servlet.request.SecurityMockMvcRequestPostProcessors.*,
112-
org.springframework.security.test.web.servlet.setup.SecurityMockMvcConfigurers.*,
113-
org.springframework.test.web.client.ExpectedCount.*,
114-
org.springframework.test.web.client.match.MockRestRequestMatchers.*,
115-
org.springframework.test.web.client.response.MockRestResponseCreators.*,
116-
org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*,
117-
org.springframework.test.web.servlet.result.MockMvcResultHandlers.*,
118-
org.springframework.test.web.servlet.result.MockMvcResultMatchers.*,
119-
org.springframework.test.web.servlet.setup.MockMvcBuilders.*,
120-
org.springframework.web.reactive.function.BodyInserters.*,
121-
org.springframework.web.reactive.function.server.RequestPredicates.*,
122-
org.springframework.web.reactive.function.server.RouterFunctions.*,
123-
org.springframework.ws.test.client.RequestMatchers.*,
124-
org.springframework.ws.test.client.ResponseCreators.*" />
125-
</module>
12676
<module name="com.puppycrawl.tools.checkstyle.checks.imports.RedundantImportCheck" />
12777
<module name="com.puppycrawl.tools.checkstyle.checks.imports.UnusedImportsCheck">
12878
<property name="processJavadoc" value="true" />
@@ -208,6 +158,9 @@
208158
<module name="com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck" />
209159

210160
<!-- Spring Conventions -->
161+
<module name="io.spring.javaformat.checkstyle.check.SpringAvoidStaticImportCheck" >
162+
<property name="excludes" value="${avoidStaticImportExcludes}"/>
163+
</module>
211164
<module name="io.spring.javaformat.checkstyle.check.SpringLambdaCheck" />
212165
<module name="io.spring.javaformat.checkstyle.check.SpringTernaryCheck" />
213166
<module name="io.spring.javaformat.checkstyle.check.SpringCatchCheck" />

0 commit comments

Comments
 (0)