|
| 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 | +} |
0 commit comments