mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Fix inclusion bug.
This commit is contained in:
parent
a574bc1adf
commit
2f386a622d
6 changed files with 44 additions and 17 deletions
|
@ -42,9 +42,13 @@ sealed class IFileSpec {
|
||||||
val includes = Glob(*spec.toTypedArray())
|
val includes = Glob(*spec.toTypedArray())
|
||||||
|
|
||||||
if (File(filePath).isDirectory) {
|
if (File(filePath).isDirectory) {
|
||||||
Files.walkFileTree(Paths.get(filePath), object : SimpleFileVisitor<Path>() {
|
val rootDir = if (File(filePath).isAbsolute) Paths.get(filePath)
|
||||||
override public fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
|
else if (baseDir != null) Paths.get(baseDir, filePath)
|
||||||
val rel = Paths.get(filePath).relativize(path)
|
else Paths.get(filePath)
|
||||||
|
Files.walkFileTree(rootDir, object : SimpleFileVisitor<Path>() {
|
||||||
|
override fun visitFile(path: Path, attrs: BasicFileAttributes): FileVisitResult {
|
||||||
|
val rel = if (baseDir != null && !baseDir.isEmpty()) Paths.get(baseDir).relativize(path)
|
||||||
|
else path
|
||||||
if (isIncluded(includes, excludes, path)) {
|
if (isIncluded(includes, excludes, path)) {
|
||||||
result.add(rel.toFile())
|
result.add(rel.toFile())
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ import com.beust.kobalt.Glob
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
import com.google.common.io.CharStreams
|
import com.google.common.io.CharStreams
|
||||||
import java.io.*
|
import java.io.*
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.jar.JarEntry
|
import java.util.jar.JarEntry
|
||||||
import java.util.jar.JarFile
|
import java.util.jar.JarFile
|
||||||
import java.util.jar.JarInputStream
|
import java.util.jar.JarInputStream
|
||||||
|
@ -39,7 +40,7 @@ public class JarUtils {
|
||||||
|
|
||||||
// Turn the found file into the local physical file that will be put in the jar file
|
// Turn the found file into the local physical file that will be put in the jar file
|
||||||
val localFile = if (File(foundFile.path).isAbsolute) File(foundFile.path)
|
val localFile = if (File(foundFile.path).isAbsolute) File(foundFile.path)
|
||||||
else file.from(foundFile.path)
|
else File(directory, file.from(foundFile.path).path)
|
||||||
|
|
||||||
if (!localFile.exists()) {
|
if (!localFile.exists()) {
|
||||||
throw AssertionError("File should exist: $localFile")
|
throw AssertionError("File should exist: $localFile")
|
||||||
|
@ -174,7 +175,7 @@ class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<I
|
||||||
result.add(if (source.isAbsolute) source else File(source.path))
|
result.add(if (source.isAbsolute) source else File(source.path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result.map { Paths.get(it.path).normalize().toFile()}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -38,7 +38,7 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
filesNotExcluded.forEach {
|
filesNotExcluded.forEach {
|
||||||
fileSpecs.add(IFileSpec.FileSpec(it.path.toString().substring(prefixPath.toString().length + 1)))
|
fileSpecs.add(IFileSpec.FileSpec(it.path.toString().substring(prefixPath.toString().length + 1)))
|
||||||
}
|
}
|
||||||
result.add(IncludedFile(From(project.directory + "/" + prefixPath.toString() + "/"), To(""), fileSpecs))
|
result.add(IncludedFile(From(prefixPath.toString()), To(""), fileSpecs))
|
||||||
|
|
||||||
// Resources, if applicable
|
// Resources, if applicable
|
||||||
context.variant.resourceDirectories(project).forEach {
|
context.variant.resourceDirectories(project).forEach {
|
||||||
|
@ -48,7 +48,8 @@ class JarGenerator @Inject constructor(val dependencyManager: DependencyManager)
|
||||||
//
|
//
|
||||||
// The user specified an include, just use it verbatim
|
// The user specified an include, just use it verbatim
|
||||||
//
|
//
|
||||||
result.addAll(PackagingPlugin.findIncludedFiles(project.directory, jar.includedFiles, jar.excludes))
|
val includedFiles = PackagingPlugin.findIncludedFiles(project.directory, jar.includedFiles, jar.excludes)
|
||||||
|
result.addAll(includedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
|
@ -14,6 +14,7 @@ import com.beust.kobalt.misc.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.FileOutputStream
|
import java.io.FileOutputStream
|
||||||
import java.io.OutputStream
|
import java.io.OutputStream
|
||||||
|
import java.nio.file.Paths
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -51,13 +52,14 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
val fromPath = includedFile.from
|
val fromPath = includedFile.from
|
||||||
if (File(fromPath).exists()) {
|
if (File(fromPath).exists()) {
|
||||||
spec.toFiles(directory, fromPath).forEach { file ->
|
spec.toFiles(directory, fromPath).forEach { file ->
|
||||||
val fullFile = File(fromPath, file.path)
|
val fullFile = File(KFiles.joinDir(directory, fromPath, file.path))
|
||||||
if (! fullFile.exists()) {
|
if (! fullFile.exists()) {
|
||||||
throw AssertionError("File should exist: $fullFile")
|
throw AssertionError("File should exist: $fullFile")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!KFiles.isExcluded(fullFile, excludes)) {
|
if (!KFiles.isExcluded(fullFile, excludes)) {
|
||||||
includedSpecs.add(FileSpec(file.path))
|
val normalized = Paths.get(file.path).normalize().toFile().path
|
||||||
|
includedSpecs.add(FileSpec(normalized))
|
||||||
} else {
|
} else {
|
||||||
log(2, "Not adding ${file.path} to jar file because it's excluded")
|
log(2, "Not adding ${file.path} to jar file because it's excluded")
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,6 +13,7 @@ import java.nio.file.Files
|
||||||
class IncludeExcludeTest : KobaltTest() {
|
class IncludeExcludeTest : KobaltTest() {
|
||||||
private lateinit var topDirectory: File
|
private lateinit var topDirectory: File
|
||||||
private lateinit var directory: File
|
private lateinit var directory: File
|
||||||
|
private lateinit var htmlDir: File
|
||||||
|
|
||||||
val A1 = "A1.class"
|
val A1 = "A1.class"
|
||||||
val B1 = "B1.class"
|
val B1 = "B1.class"
|
||||||
|
@ -20,6 +21,7 @@ class IncludeExcludeTest : KobaltTest() {
|
||||||
val C1 = "C1.class"
|
val C1 = "C1.class"
|
||||||
val C2 = "C2.class"
|
val C2 = "C2.class"
|
||||||
val C3 = "C3.class"
|
val C3 = "C3.class"
|
||||||
|
val A_HTML = "a.html"
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
fun bc() {
|
fun bc() {
|
||||||
|
@ -29,26 +31,43 @@ class IncludeExcludeTest : KobaltTest() {
|
||||||
listOf(A1, B1, B2, C1, C2, C3).forEach {
|
listOf(A1, B1, B2, C1, C2, C3).forEach {
|
||||||
File(directory, it).createNewFile()
|
File(directory, it).createNewFile()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
htmlDir = Files.createTempDirectory("kobaltTest-").toFile()
|
||||||
|
htmlDir.mkdirs()
|
||||||
|
File(htmlDir, A_HTML).createNewFile()
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun html() {
|
||||||
|
val inc = IncludedFile(From(""), To(""), listOf(IFileSpec.GlobSpec("**html")))
|
||||||
|
val files = inc.allFromFiles(htmlDir.path)
|
||||||
|
println("Files " + files)
|
||||||
|
Assert.assertEquals(files.size, 1)
|
||||||
|
Assert.assertEquals(files[0].path, A_HTML)
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider
|
@DataProvider
|
||||||
fun dp() : Array<Array<out Any?>> = arrayOf(
|
fun dp() : Array<Array<out Any?>> = arrayOf(
|
||||||
arrayOf(directory, listOf("A**class", "B**class"), listOf<String>(), listOf(A1, B1, B2)),
|
arrayOf(directory, listOf("**A**class", "**B**class"), listOf<String>(), listOf(A1, B1, B2)),
|
||||||
arrayOf(directory, listOf("A**class", "B**class"), listOf("B*class"), listOf(A1)),
|
arrayOf(directory, listOf("**A**class", "**B**class"), listOf("**B*class"), listOf(A1)),
|
||||||
arrayOf(directory, listOf("*class"), listOf("B*class"), listOf(A1, C1, C2, C3)),
|
arrayOf(directory, listOf("**class"), listOf("**B*class"), listOf(A1, C1, C2, C3)),
|
||||||
arrayOf(topDirectory, listOf("**/*class"), listOf<String>(), listOf(A1, B1, B2, C1, C2, C3)),
|
arrayOf(topDirectory, listOf("**/*class"), listOf<String>(), listOf(A1, B1, B2, C1, C2, C3)),
|
||||||
arrayOf(topDirectory, listOf("*class"), listOf<String>(), listOf<String>()),
|
arrayOf(topDirectory, listOf("*class"), listOf<String>(), listOf<String>()),
|
||||||
arrayOf(topDirectory, listOf("**/B*class"), listOf<String>(), listOf(B1, B2)),
|
arrayOf(topDirectory, listOf("**/B*class"), listOf<String>(), listOf(B1, B2)),
|
||||||
arrayOf(topDirectory, listOf("**/A*class", "**/B*class"), listOf("B*class"),
|
arrayOf(topDirectory, listOf("**A*class", "**B*class"), listOf("**C*class"),
|
||||||
listOf(A1, B1, B2)),
|
listOf(A1, B1, B2)),
|
||||||
arrayOf(topDirectory, listOf("**/A*class", "**/B*class"), listOf("**/B*class"),
|
arrayOf(topDirectory, listOf("**A*class", "**B*class"), listOf("**B*class"),
|
||||||
listOf(A1))
|
listOf(A1))
|
||||||
)
|
)
|
||||||
|
|
||||||
@Test(dataProvider = "dp")
|
@Test(dataProvider = "dp")
|
||||||
fun shouldInclude(root: File, includedSpec: List<String>, excludedSpec: List<String>, expectedFiles: List<String>) {
|
fun shouldInclude(root: File, includedSpec: List<String>, excludedSpec: List<String>, expectedFiles:
|
||||||
|
List<String>) {
|
||||||
val g = IFileSpec.GlobSpec(includedSpec)
|
val g = IFileSpec.GlobSpec(includedSpec)
|
||||||
val files = g.toFiles("", root.path, excludedSpec.map { Glob(it) })
|
val files = g.toFiles(null, root.path, excludedSpec.map { Glob(it) })
|
||||||
|
// if (files.map { it.name } != expectedFiles) {
|
||||||
|
// println("FAILURE")
|
||||||
|
// }
|
||||||
Assert.assertEquals(files.map { it.name }, expectedFiles)
|
Assert.assertEquals(files.map { it.name }, expectedFiles)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ import java.util.jar.JarInputStream
|
||||||
|
|
||||||
class VerifyKobaltZipTest : KobaltTest() {
|
class VerifyKobaltZipTest : KobaltTest() {
|
||||||
private fun verifyMainJarFile(ins: InputStream) {
|
private fun verifyMainJarFile(ins: InputStream) {
|
||||||
assertExistsInJarInputStream(JarInputStream(ins), "com/beust/kobalt/MainKt.class", "templates/plugin.jar")
|
assertExistsInJarInputStream(JarInputStream(ins), "com/beust/kobalt/MainKt.class", "templates/kobaltPlugin.jar")
|
||||||
}
|
}
|
||||||
@Test
|
@Test
|
||||||
fun verifySourceJarFile() {
|
fun verifySourceJarFile() {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue