diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringIllegalImportCheck.java b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringIllegalImportCheck.java new file mode 100644 index 00000000..3cb064e7 --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/java/io/spring/javaformat/checkstyle/check/SpringIllegalImportCheck.java @@ -0,0 +1,43 @@ +/* + * Copyright 2017-2021 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * https://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package io.spring.javaformat.checkstyle.check; + +import com.puppycrawl.tools.checkstyle.checks.imports.IllegalImportCheck; + +/** + * Checks for illegal import packages and classes. + * + * @author Sushant Kumar Singh + * + */ +public class SpringIllegalImportCheck extends IllegalImportCheck { + + /** + * Illegal packages. + */ + private static final String[] ILLEGAL_PKGS = {"sun", "lombok"}; + + /** + * Illegal classes. + */ + private static final String[] ILLEGAL_CLASSES = {}; + + public SpringIllegalImportCheck() { + setIllegalPkgs(ILLEGAL_PKGS); + setIllegalClasses(ILLEGAL_CLASSES); + } +} diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml index 41eb9ebf..3b169e80 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml +++ b/spring-javaformat/spring-javaformat-checkstyle/src/main/resources/io/spring/javaformat/checkstyle/spring-checkstyle.xml @@ -162,5 +162,6 @@ + diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java index 82e63f1e..58bc2ee7 100644 --- a/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/java/io/spring/javaformat/checkstyle/SpringConfigurationLoaderTests.java @@ -48,7 +48,7 @@ public void loadShouldLoadChecks() { assertThat(checks).hasSize(5); TreeWalker treeWalker = (TreeWalker) checks.toArray()[4]; Set ordinaryChecks = (Set) Extractors.byName("ordinaryChecks").extract(treeWalker); - assertThat(ordinaryChecks).hasSize(60); + assertThat(ordinaryChecks).hasSize(61); } @Test @@ -59,7 +59,7 @@ public void loadWithExcludeShouldExcludeChecks() { assertThat(checks).hasSize(5); TreeWalker treeWalker = (TreeWalker) checks.toArray()[4]; Set ordinaryChecks = (Set) Extractors.byName("ordinaryChecks").extract(treeWalker); - assertThat(ordinaryChecks).hasSize(59); + assertThat(ordinaryChecks).hasSize(60); } @Test diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/LombokImport.txt b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/LombokImport.txt new file mode 100644 index 00000000..d0c0e151 --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/check/LombokImport.txt @@ -0,0 +1 @@ ++LombokImport.java:6:1: import.illegal \ No newline at end of file diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/config/LombokImport.xml b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/config/LombokImport.xml new file mode 100644 index 00000000..35f66a24 --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/config/LombokImport.xml @@ -0,0 +1,10 @@ + + + + + + + + \ No newline at end of file diff --git a/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/LombokImport.java b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/LombokImport.java new file mode 100644 index 00000000..c8bdc63b --- /dev/null +++ b/spring-javaformat/spring-javaformat-checkstyle/src/test/resources/source/LombokImport.java @@ -0,0 +1,10 @@ + +/** + * @author Sushant Kumar Singh + * + */ +import lombok.*; + +public class LombokImport { + +}