builder: use FastClasspathScanner for Java 8 too
This commit is contained in:
parent
7ba2b557e3
commit
d59cb7b879
3 changed files with 5 additions and 43 deletions
|
@ -31,7 +31,6 @@
|
||||||
<map-builder.version>1.0.0</map-builder.version>
|
<map-builder.version>1.0.0</map-builder.version>
|
||||||
<mockito.version>2.13.0</mockito.version>
|
<mockito.version>2.13.0</mockito.version>
|
||||||
<assertj.version>3.9.0</assertj.version>
|
<assertj.version>3.9.0</assertj.version>
|
||||||
<conditional.version>0.3.0</conditional.version>
|
|
||||||
<fast-classpath-scanner.version>2.18.1</fast-classpath-scanner.version>
|
<fast-classpath-scanner.version>2.18.1</fast-classpath-scanner.version>
|
||||||
|
|
||||||
<maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
|
<maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
|
||||||
|
@ -60,11 +59,6 @@
|
||||||
<version>${lombok.version}</version>
|
<version>${lombok.version}</version>
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
|
||||||
<groupId>net.kemitix</groupId>
|
|
||||||
<artifactId>conditional</artifactId>
|
|
||||||
<version>${conditional.version}</version>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>io.github.lukehutch</groupId>
|
<groupId>io.github.lukehutch</groupId>
|
||||||
<artifactId>fast-classpath-scanner</artifactId>
|
<artifactId>fast-classpath-scanner</artifactId>
|
||||||
|
|
|
@ -21,14 +21,9 @@
|
||||||
|
|
||||||
package net.kemitix.checkstyle.ruleset.builder;
|
package net.kemitix.checkstyle.ruleset.builder;
|
||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
|
||||||
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
|
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import net.kemitix.conditional.Value;
|
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
import java.net.URLClassLoader;
|
|
||||||
import java.util.function.Supplier;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,30 +32,12 @@ import java.util.stream.Stream;
|
||||||
* @author Paul Campbell (pcampbell@kemitix.net).
|
* @author Paul Campbell (pcampbell@kemitix.net).
|
||||||
*/
|
*/
|
||||||
@Service
|
@Service
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class DefaultPackageScanner implements PackageScanner {
|
public class DefaultPackageScanner implements PackageScanner {
|
||||||
|
|
||||||
private final ClassPath classPath;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final Stream<String> apply(final RuleSource ruleSource) {
|
public final Stream<String> apply(final RuleSource ruleSource) {
|
||||||
return Value.<Stream<String>>where(isJava8())
|
final String basePackage = ruleSource.getBasePackage();
|
||||||
.then(scanPackageByClassPath(ruleSource.getBasePackage()))
|
return new FastClasspathScanner(basePackage)
|
||||||
.otherwise(scanPackageByModulePath(ruleSource.getBasePackage()));
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isJava8() {
|
|
||||||
return getClass().getClassLoader() instanceof URLClassLoader;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Supplier<Stream<String>> scanPackageByClassPath(final String basePackage) {
|
|
||||||
return () -> classPath.getTopLevelClassesRecursive(basePackage)
|
|
||||||
.stream()
|
|
||||||
.map(ClassPath.ClassInfo::getName);
|
|
||||||
}
|
|
||||||
|
|
||||||
private Supplier<Stream<String>> scanPackageByModulePath(final String basePackage) {
|
|
||||||
return () -> new FastClasspathScanner(basePackage)
|
|
||||||
.scan()
|
.scan()
|
||||||
.getNamesOfAllStandardClasses()
|
.getNamesOfAllStandardClasses()
|
||||||
.stream()
|
.stream()
|
||||||
|
|
|
@ -1,10 +1,7 @@
|
||||||
package net.kemitix.checkstyle.ruleset.builder;
|
package net.kemitix.checkstyle.ruleset.builder;
|
||||||
|
|
||||||
import com.google.common.reflect.ClassPath;
|
|
||||||
import org.junit.Before;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.stream.Stream;
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
@ -16,16 +13,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||||
*/
|
*/
|
||||||
public class DefaultPackageScannerTest {
|
public class DefaultPackageScannerTest {
|
||||||
|
|
||||||
private PackageScanner scanner;
|
private PackageScanner scanner = new DefaultPackageScanner();
|
||||||
|
|
||||||
@Before
|
|
||||||
public void setUp() throws Exception {
|
|
||||||
final ClassPath classPath = ClassPath.from(getClass().getClassLoader());
|
|
||||||
scanner = new DefaultPackageScanner(classPath);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canScanCheckstylePackage() throws IOException {
|
public void canScanCheckstylePackage() {
|
||||||
//when
|
//when
|
||||||
final Stream<String> result = scanner.apply(RuleSource.CHECKSTYLE);
|
final Stream<String> result = scanner.apply(RuleSource.CHECKSTYLE);
|
||||||
//then
|
//then
|
||||||
|
@ -34,7 +25,7 @@ public class DefaultPackageScannerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void canScanSevntuPackage() throws IOException {
|
public void canScanSevntuPackage() {
|
||||||
//when
|
//when
|
||||||
final Stream<String> result = scanner.apply(RuleSource.SEVNTU);
|
final Stream<String> result = scanner.apply(RuleSource.SEVNTU);
|
||||||
//then
|
//then
|
||||||
|
|
Loading…
Reference in a new issue