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

Exclude certificate files from META-INF.

This commit is contained in:
Cedric Beust 2015-12-01 14:49:32 -08:00
parent cd4363640e
commit ec5a8bf69d
3 changed files with 37 additions and 29 deletions

View file

@ -1,5 +1,6 @@
package com.beust.kobalt.misc
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.SystemProperties
import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
@ -7,10 +8,10 @@ import com.beust.kobalt.homeDir
import com.beust.kobalt.internal.build.BuildFile
import java.io.File
import java.io.IOException
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.Paths
import java.nio.file.StandardCopyOption
import java.nio.file.*
import kotlin.io.FileAlreadyExistsException
import kotlin.io.FileSystemException
import kotlin.io.NoSuchFileException
class KFiles {
val kobaltJar : String
@ -102,7 +103,7 @@ class KFiles {
allDirs.addAll(directories.map { File(rootDir, it.path) })
}
val seen = hashSetOf<Path>()
val seen = hashSetOf<java.nio.file.Path>()
allDirs.forEach { dir ->
if (! dir.exists()) {
log(2, "Couldn't find directory $dir")
@ -248,6 +249,27 @@ class KFiles {
fun makeOutputDir(project: Project) : File = makeDir(project, KFiles.CLASSES_DIR)
fun makeOutputTestDir(project: Project) : File = makeDir(project, KFiles.TEST_CLASSES_DIR)
fun isExcluded(file: File, excludes: List<IFileSpec.Glob>) = isExcluded(file.path, excludes)
fun isExcluded(file: String, excludes: List<IFileSpec.Glob>) : Boolean {
if (excludes.isEmpty()) {
return false
} else {
val ex = arrayListOf<PathMatcher>()
excludes.forEach {
ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}"))
}
ex.forEach {
if (it.matches(Paths.get(file))) {
log(2, "Excluding $file")
return true
}
}
}
return false
}
}
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {

View file

@ -1,6 +1,7 @@
package com.beust.kobalt.plugin.packaging
import com.beust.kobalt.IFileSpec
import com.beust.kobalt.misc.KFiles
import com.beust.kobalt.misc.log
import com.google.common.io.CharStreams
import java.io.*
@ -28,6 +29,11 @@ public class JarUtils {
}
}
private val DEFAULT_JAR_EXCLUDES = arrayListOf(
IFileSpec.Glob("META-INF/*.SF"),
IFileSpec.Glob("META-INF/*.DSA"),
IFileSpec.Glob("META-INF/*.RSA"))
public fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
file.specs.forEach { spec ->
@ -56,7 +62,7 @@ public class JarUtils {
val stream = JarInputStream(FileInputStream(source))
var entry = stream.nextEntry
while (entry != null) {
if (!entry.isDirectory) {
if (! entry.isDirectory && ! KFiles.isExcluded(entry.name, DEFAULT_JAR_EXCLUDES)) {
val ins = JarFile(source).getInputStream(entry)
addEntry(ins, JarEntry(entry), outputStream, onError)
}

View file

@ -20,8 +20,6 @@ import com.beust.kobalt.plugin.java.JavaPlugin
import java.io.File
import java.io.FileOutputStream
import java.io.OutputStream
import java.nio.file.FileSystems
import java.nio.file.PathMatcher
import java.nio.file.Paths
import java.util.jar.JarOutputStream
import java.util.zip.ZipOutputStream
@ -72,24 +70,6 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
return TaskResult()
}
private fun isExcluded(file: File, excludes: List<Glob>) : Boolean {
if (excludes.isEmpty()) {
return false
} else {
val ex = arrayListOf<PathMatcher>()
excludes.forEach {
ex.add(FileSystems.getDefault().getPathMatcher("glob:${it.spec}"))
}
ex.forEach {
if (it.matches(Paths.get(file.name))) {
log(2, "Excluding $file")
return true
}
}
}
return false
}
private fun generateWar(project: Project, war: War) : File {
//
// src/main/web app and classes
@ -153,7 +133,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
// Class files
val files = KFiles.findRecursively(classesDir).map { File(relClassesDir.toFile(), it) }
val filesNotExcluded : List<File> = files.filter { ! isExcluded(it, jar.excludes) }
val filesNotExcluded : List<File> = files.filter { ! KFiles.isExcluded(it, jar.excludes) }
val fileSpecs = arrayListOf<IFileSpec>()
filesNotExcluded.forEach {
fileSpecs.add(FileSpec(it.path.toString().substring(prefixPath.toString().length + 1)))
@ -183,7 +163,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
}.forEach { file : File ->
if (! seen.contains(file.name)) {
seen.add(file.name)
if (!isExcluded(file, jar.excludes)) {
if (! KFiles.isExcluded(file, jar.excludes)) {
allFiles.add(IncludedFile(arrayListOf(FileSpec(file.path))))
}
}
@ -221,7 +201,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
}
}
if (!isExcluded(file, excludes)) {
if (! KFiles.isExcluded(file, excludes)) {
includedSpecs.add(FileSpec(file.path))
} else {
log(2, "Not adding ${file.path} to jar file because it's excluded")