diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt index af798ac6..480a8553 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/FileSpec.kt @@ -22,32 +22,37 @@ sealed class IFileSpec { constructor(spec: String) : this(arrayListOf(spec)) - private fun isIncluded(excludes: List, rel: Path) : Boolean { + private fun isIncluded(includeMatchers: Glob, excludes: List, rel: Path) : Boolean { excludes.forEach { if (it.matches(rel)) { log(2, "Excluding ${rel.toFile()}") return false } } - log(2, "Including ${rel.toFile().absolutePath}") - return true + if (includeMatchers.matches(rel)) { + log(2, "Including ${rel.toFile().absolutePath}") + return true + } + log(2, "Excluding ${rel.toFile()} (not matching any include pattern") + return false } override fun toFiles(filePath: String, excludes: List): List { val result = arrayListOf() + val includes = Glob(*spec.toTypedArray()) if (File(filePath).isDirectory) { Files.walkFileTree(Paths.get(filePath), object : SimpleFileVisitor() { override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { val rel = Paths.get(filePath).relativize(path) - if (isIncluded(excludes, rel)) { + if (isIncluded(includes, excludes, rel)) { result.add(rel.toFile()) } return FileVisitResult.CONTINUE } }) } else { - if (isIncluded(excludes, Paths.get(filePath))) { + if (isIncluded(includes, excludes, Paths.get(filePath))) { result.add(File(filePath)) } } diff --git a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt index 2f829311..cfb4f637 100644 --- a/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt +++ b/modules/kobalt-plugin-api/src/main/kotlin/com/beust/kobalt/internal/JvmCompilerPlugin.kt @@ -259,7 +259,7 @@ open class JvmCompilerPlugin @Inject constructor( buildDirectory.mkdirs() - val initialSourceDirectories = ArrayList() + val initialSourceDirectories = ArrayList(sourceDirectories) // Source directories from the contributors initialSourceDirectories.addAll( if (isTest) { @@ -279,13 +279,9 @@ open class JvmCompilerPlugin @Inject constructor( } // Now that we have all the source directories, find all the source files in them - val sourceFiles = if (allSourceDirectories.size > 0) { - files.findRecursively(projectDirectory, allSourceDirectories, - { file -> sourceSuffixes.any { file.endsWith(it) } }) - .map { File(projectDirectory, it).path } - } else { - emptyList() - } + val sourceFiles = files.findRecursively(projectDirectory, allSourceDirectories, + { file -> sourceSuffixes.any { file.endsWith(it) }}) + .map { File(projectDirectory, it).path } // Special treatment if we are compiling Kotlin files and the project also has a java source // directory. In this case, also pass that java source directory to the Kotlin compiler as is diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZip.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZip.kt index 6d6d1bb2..fa209399 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZip.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZip.kt @@ -4,42 +4,19 @@ import com.beust.kobalt.api.Kobalt import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.log import org.testng.annotations.Test -import java.io.File import java.io.FileInputStream -import java.io.InputStream import java.util.jar.JarFile import java.util.jar.JarInputStream -@Test class VerifyKobaltZipTest : KobaltTest() { - private fun assertExistsInJar(jarName: String, fileName: String) { - val sourceJarPath = KFiles.joinDir("kobaltBuild", "libs", jarName) - assertExistsInJar(JarInputStream(FileInputStream(File(sourceJarPath))), fileName) - } - - fun assertExistsInJar(stream: JarInputStream, fileName: String) { - var entry = stream.nextEntry - var found = false - while (entry != null) { - if (entry.name == fileName) found = true - entry = stream.nextEntry - } - if (! found) { - throw AssertionError("Couldn't find Main.kt in $fileName") - } - } - - fun verifySourceFile() { - assertExistsInJar("kobalt-" + Kobalt.version + "-sources.jar", "com/beust/kobalt/Main.kt") - } - + @Test fun verifyZipFile() { var success = true var foundKobaltw = false var foundJar = false var foundWrapperJar = false - val mainJarFilePath = "kobalt-" + Kobalt.version + ".jar" + val jarFilePath = "kobalt-" + Kobalt.version + ".jar" val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip") val zipFile = JarFile(zipFilePath) val stream = JarInputStream(FileInputStream(zipFilePath)) @@ -47,12 +24,11 @@ class VerifyKobaltZipTest : KobaltTest() { while (entry != null) { if (entry.name == "kobaltw") { foundKobaltw = true - } else if (entry.name.endsWith(mainJarFilePath)) { + } else if (entry.name.endsWith(jarFilePath)) { val ins = zipFile.getInputStream(entry) if (ins.available() < 20000000) { - throw AssertionError(mainJarFilePath + " is too small: " + mainJarFilePath) + throw KobaltException(jarFilePath + " is too small: " + jarFilePath) } - verifyMainJarFile(ins) foundJar = true } else if (entry.name.endsWith("kobalt-wrapper.jar")) { foundWrapperJar = true @@ -62,21 +38,17 @@ class VerifyKobaltZipTest : KobaltTest() { entry = stream.nextEntry } if (! success) { - throw AssertionError("Found unexpected file in $zipFilePath") + throw KobaltException("Found unexpected file in $zipFilePath") } if (! foundKobaltw) { - throw AssertionError("Couldn't find kobaltw in $zipFilePath") + throw KobaltException("Couldn't find kobaltw in $zipFilePath") } if (! foundJar) { - throw AssertionError("Couldn't find jar in $zipFilePath") + throw KobaltException("Couldn't find jar in $zipFilePath") } if (! foundWrapperJar) { - throw AssertionError("Couldn't find wrapper jar in $zipFilePath") + throw KobaltException("Couldn't find wrapper jar in $zipFilePath") } log(1, "$zipFilePath looks correct") } - - private fun verifyMainJarFile(ins: InputStream) { - assertExistsInJar(JarInputStream(ins), "com/beust/kobalt/MainKt.class") - } }