1
0
Fork 0
mirror of https://github.com/ethauvin/kobalt.git synced 2025-04-26 16:28:12 -07:00

Fix the source includes.

This commit is contained in:
Cedric Beust 2016-02-17 06:51:52 -08:00
parent e824d7dbbf
commit 14cb546dd7
3 changed files with 49 additions and 22 deletions

View file

@ -22,37 +22,32 @@ sealed class IFileSpec {
constructor(spec: String) : this(arrayListOf(spec)) constructor(spec: String) : this(arrayListOf(spec))
private fun isIncluded(includeMatchers: Glob, excludes: List<Glob>, rel: Path) : Boolean { private fun isIncluded(excludes: List<Glob>, rel: Path) : Boolean {
excludes.forEach { excludes.forEach {
if (it.matches(rel)) { if (it.matches(rel)) {
log(2, "Excluding ${rel.toFile()}") log(2, "Excluding ${rel.toFile()}")
return false return false
} }
} }
if (includeMatchers.matches(rel)) { log(2, "Including ${rel.toFile().absolutePath}")
log(2, "Including ${rel.toFile().absolutePath}") return true
return true
}
log(2, "Excluding ${rel.toFile()} (not matching any include pattern")
return false
} }
override fun toFiles(filePath: String, excludes: List<Glob>): List<File> { override fun toFiles(filePath: String, excludes: List<Glob>): List<File> {
val result = arrayListOf<File>() val result = arrayListOf<File>()
val includes = Glob(*spec.toTypedArray())
if (File(filePath).isDirectory) { if (File(filePath).isDirectory) {
Files.walkFileTree(Paths.get(filePath), object : SimpleFileVisitor<Path>() { Files.walkFileTree(Paths.get(filePath), object : SimpleFileVisitor<Path>() {
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult { override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
val rel = Paths.get(filePath).relativize(path) val rel = Paths.get(filePath).relativize(path)
if (isIncluded(includes, excludes, rel)) { if (isIncluded(excludes, rel)) {
result.add(rel.toFile()) result.add(rel.toFile())
} }
return FileVisitResult.CONTINUE return FileVisitResult.CONTINUE
} }
}) })
} else { } else {
if (isIncluded(includes, excludes, Paths.get(filePath))) { if (isIncluded(excludes, Paths.get(filePath))) {
result.add(File(filePath)) result.add(File(filePath))
} }
} }

View file

@ -259,7 +259,7 @@ open class JvmCompilerPlugin @Inject constructor(
buildDirectory.mkdirs() buildDirectory.mkdirs()
val initialSourceDirectories = ArrayList<File>(sourceDirectories) val initialSourceDirectories = ArrayList<File>()
// Source directories from the contributors // Source directories from the contributors
initialSourceDirectories.addAll( initialSourceDirectories.addAll(
if (isTest) { if (isTest) {
@ -279,9 +279,13 @@ open class JvmCompilerPlugin @Inject constructor(
} }
// Now that we have all the source directories, find all the source files in them // Now that we have all the source directories, find all the source files in them
val sourceFiles = files.findRecursively(projectDirectory, allSourceDirectories, val sourceFiles = if (allSourceDirectories.size > 0) {
{ file -> sourceSuffixes.any { file.endsWith(it) }}) files.findRecursively(projectDirectory, allSourceDirectories,
.map { File(projectDirectory, it).path } { file -> sourceSuffixes.any { file.endsWith(it) } })
.map { File(projectDirectory, it).path }
} else {
emptyList()
}
// Special treatment if we are compiling Kotlin files and the project also has a java source // 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 // directory. In this case, also pass that java source directory to the Kotlin compiler as is

View file

@ -4,19 +4,42 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.misc.KFiles import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log import com.beust.kobalt.misc.log
import org.testng.annotations.Test import org.testng.annotations.Test
import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream
import java.util.jar.JarFile import java.util.jar.JarFile
import java.util.jar.JarInputStream import java.util.jar.JarInputStream
@Test
class VerifyKobaltZipTest : KobaltTest() { class VerifyKobaltZipTest : KobaltTest() {
@Test 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")
}
fun verifyZipFile() { fun verifyZipFile() {
var success = true var success = true
var foundKobaltw = false var foundKobaltw = false
var foundJar = false var foundJar = false
var foundWrapperJar = false var foundWrapperJar = false
val jarFilePath = "kobalt-" + Kobalt.version + ".jar" val mainJarFilePath = "kobalt-" + Kobalt.version + ".jar"
val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip") val zipFilePath = KFiles.joinDir("kobaltBuild", "libs", "kobalt-" + Kobalt.version + ".zip")
val zipFile = JarFile(zipFilePath) val zipFile = JarFile(zipFilePath)
val stream = JarInputStream(FileInputStream(zipFilePath)) val stream = JarInputStream(FileInputStream(zipFilePath))
@ -24,11 +47,12 @@ class VerifyKobaltZipTest : KobaltTest() {
while (entry != null) { while (entry != null) {
if (entry.name == "kobaltw") { if (entry.name == "kobaltw") {
foundKobaltw = true foundKobaltw = true
} else if (entry.name.endsWith(jarFilePath)) { } else if (entry.name.endsWith(mainJarFilePath)) {
val ins = zipFile.getInputStream(entry) val ins = zipFile.getInputStream(entry)
if (ins.available() < 20000000) { if (ins.available() < 20000000) {
throw KobaltException(jarFilePath + " is too small: " + jarFilePath) throw AssertionError(mainJarFilePath + " is too small: " + mainJarFilePath)
} }
verifyMainJarFile(ins)
foundJar = true foundJar = true
} else if (entry.name.endsWith("kobalt-wrapper.jar")) { } else if (entry.name.endsWith("kobalt-wrapper.jar")) {
foundWrapperJar = true foundWrapperJar = true
@ -38,17 +62,21 @@ class VerifyKobaltZipTest : KobaltTest() {
entry = stream.nextEntry entry = stream.nextEntry
} }
if (! success) { if (! success) {
throw KobaltException("Found unexpected file in $zipFilePath") throw AssertionError("Found unexpected file in $zipFilePath")
} }
if (! foundKobaltw) { if (! foundKobaltw) {
throw KobaltException("Couldn't find kobaltw in $zipFilePath") throw AssertionError("Couldn't find kobaltw in $zipFilePath")
} }
if (! foundJar) { if (! foundJar) {
throw KobaltException("Couldn't find jar in $zipFilePath") throw AssertionError("Couldn't find jar in $zipFilePath")
} }
if (! foundWrapperJar) { if (! foundWrapperJar) {
throw KobaltException("Couldn't find wrapper jar in $zipFilePath") throw AssertionError("Couldn't find wrapper jar in $zipFilePath")
} }
log(1, "$zipFilePath looks correct") log(1, "$zipFilePath looks correct")
} }
private fun verifyMainJarFile(ins: InputStream) {
assertExistsInJar(JarInputStream(ins), "com/beust/kobalt/MainKt.class")
}
} }