bmsantos
12/29/2015, 4:08 AMprotected fun findTestClasses(project: Project, classpath: List<IClasspathDependency>): List<String> {
val path = KFiles.joinDir(project.directory, project.buildDirectory, KFiles.TEST_CLASSES_DIR)
val result = KFiles.findRecursively(File(path), arrayListOf(File(".")), {
file -> file.endsWith(".class")
}).map {
it.replace("/", ".").replace("\\", ".").replace(".class", "").substring(2)
}.filter {
try {
log(2, "*****************************************************")
// Only keep classes with a parameterless constructor
val urls = arrayOf(File(path).toURI().toURL()) + classpath.map { it.jarFile.get().toURI().toURL() }
val cl = URLClassLoader(urls, ClassLoader.getSystemClassLoader()).loadClass(it)
println("Found class: " + cl.canonicalName)
// val constructor = cl.getConstructor()
// If we get past this, we have a default constructor
log(2, "*****************************************************")
val input: InputStream = cl.getResourceAsStream(cl.simpleName + ".class")
val isTestable = JUnitClassVisitor.checkIfTestable(input)
log(2, "Is $it.canonicalName testable? $isTestable")
isTestable
} catch(ex: Exception) {
log(2, "Skipping non test class $it: ${ex.message}")
false
}
}
log(2, "Found ${result.size} test classes")
return result
}