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>
|
||||
<mockito.version>2.13.0</mockito.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>
|
||||
|
||||
<maven-checkstyle-plugin.version>3.0.0</maven-checkstyle-plugin.version>
|
||||
|
@ -60,11 +59,6 @@
|
|||
<version>${lombok.version}</version>
|
||||
<scope>provided</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>net.kemitix</groupId>
|
||||
<artifactId>conditional</artifactId>
|
||||
<version>${conditional.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>io.github.lukehutch</groupId>
|
||||
<artifactId>fast-classpath-scanner</artifactId>
|
||||
|
|
|
@ -21,14 +21,9 @@
|
|||
|
||||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import io.github.lukehutch.fastclasspathscanner.FastClasspathScanner;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import net.kemitix.conditional.Value;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLClassLoader;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
|
@ -37,30 +32,12 @@ import java.util.stream.Stream;
|
|||
* @author Paul Campbell (pcampbell@kemitix.net).
|
||||
*/
|
||||
@Service
|
||||
@RequiredArgsConstructor
|
||||
public class DefaultPackageScanner implements PackageScanner {
|
||||
|
||||
private final ClassPath classPath;
|
||||
|
||||
@Override
|
||||
public final Stream<String> apply(final RuleSource ruleSource) {
|
||||
return Value.<Stream<String>>where(isJava8())
|
||||
.then(scanPackageByClassPath(ruleSource.getBasePackage()))
|
||||
.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)
|
||||
final String basePackage = ruleSource.getBasePackage();
|
||||
return new FastClasspathScanner(basePackage)
|
||||
.scan()
|
||||
.getNamesOfAllStandardClasses()
|
||||
.stream()
|
||||
|
|
|
@ -1,10 +1,7 @@
|
|||
package net.kemitix.checkstyle.ruleset.builder;
|
||||
|
||||
import com.google.common.reflect.ClassPath;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
@ -16,16 +13,10 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
*/
|
||||
public class DefaultPackageScannerTest {
|
||||
|
||||
private PackageScanner scanner;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
final ClassPath classPath = ClassPath.from(getClass().getClassLoader());
|
||||
scanner = new DefaultPackageScanner(classPath);
|
||||
}
|
||||
private PackageScanner scanner = new DefaultPackageScanner();
|
||||
|
||||
@Test
|
||||
public void canScanCheckstylePackage() throws IOException {
|
||||
public void canScanCheckstylePackage() {
|
||||
//when
|
||||
final Stream<String> result = scanner.apply(RuleSource.CHECKSTYLE);
|
||||
//then
|
||||
|
@ -34,7 +25,7 @@ public class DefaultPackageScannerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void canScanSevntuPackage() throws IOException {
|
||||
public void canScanSevntuPackage() {
|
||||
//when
|
||||
final Stream<String> result = scanner.apply(RuleSource.SEVNTU);
|
||||
//then
|
||||
|
|
Loading…
Reference in a new issue