From 5692b0f2af6b5fa957331744955b54d07d9f872a Mon Sep 17 00:00:00 2001 From: Jon Schneider Date: Tue, 23 Aug 2016 11:23:36 -0700 Subject: [PATCH] Validate and filter inputs to SourceSet --- .../kotlin/com/netflix/java/refactor/SourceSet.kt | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/main/kotlin/com/netflix/java/refactor/SourceSet.kt b/src/main/kotlin/com/netflix/java/refactor/SourceSet.kt index fbae13d..84d08c3 100644 --- a/src/main/kotlin/com/netflix/java/refactor/SourceSet.kt +++ b/src/main/kotlin/com/netflix/java/refactor/SourceSet.kt @@ -10,10 +10,14 @@ import java.util.* data class SourceSet(val allSourceFiles: Iterable, val classpath: Iterable) { val logger: Logger = LoggerFactory.getLogger(SourceSet::class.java) + val filteredClasspath = classpath.filter { + val fn = it.fileName.toString() + fn.endsWith(".jar") && !fn.endsWith("-javadoc.jar") && !fn.endsWith("-sources.jar") + } - private val parser = AstParser(classpath) + private val parser = AstParser(filteredClasspath) private val compilationUnits by lazy { - parser.parseFiles(allSourceFiles.toList()).map { CompilationUnit(it, parser) } + parser.parseFiles(allSourceFiles.filter { it.fileName.toString().endsWith(".java") }.toList()).map { CompilationUnit(it, parser) } } fun allJava() = compilationUnits.map { cu -> JavaSource(cu) } @@ -24,7 +28,7 @@ data class SourceSet(val allSourceFiles: Iterable, val classpath: Iterable */ fun allAutoRefactorsOnClasspath(): Map> { val scanners = HashMap>() - val classLoader = URLClassLoader(classpath.map { it.toFile().toURI().toURL() }.toTypedArray(), javaClass.classLoader) + val classLoader = URLClassLoader(filteredClasspath.map { it.toFile().toURI().toURL() }.toTypedArray(), javaClass.classLoader) val reporter = object: AnnotationDetector.TypeReporter { override fun annotations() = arrayOf(AutoRefactor::class.java) @@ -47,7 +51,7 @@ data class SourceSet(val allSourceFiles: Iterable, val classpath: Iterable } } - AnnotationDetector(reporter).detect(*classpath.map { it.toFile() }.toTypedArray()) + AnnotationDetector(reporter).detect(*filteredClasspath.map { it.toFile() }.toTypedArray()) return scanners }