mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 16:28:12 -07:00
Exclude certificate files from META-INF.
This commit is contained in:
parent
cd4363640e
commit
ec5a8bf69d
3 changed files with 37 additions and 29 deletions
|
@ -1,5 +1,6 @@
|
||||||
package com.beust.kobalt.misc
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.IFileSpec
|
||||||
import com.beust.kobalt.SystemProperties
|
import com.beust.kobalt.SystemProperties
|
||||||
import com.beust.kobalt.api.Kobalt
|
import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
|
@ -7,10 +8,10 @@ import com.beust.kobalt.homeDir
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.Files
|
import java.nio.file.*
|
||||||
import java.nio.file.Path
|
import kotlin.io.FileAlreadyExistsException
|
||||||
import java.nio.file.Paths
|
import kotlin.io.FileSystemException
|
||||||
import java.nio.file.StandardCopyOption
|
import kotlin.io.NoSuchFileException
|
||||||
|
|
||||||
class KFiles {
|
class KFiles {
|
||||||
val kobaltJar : String
|
val kobaltJar : String
|
||||||
|
@ -102,7 +103,7 @@ class KFiles {
|
||||||
allDirs.addAll(directories.map { File(rootDir, it.path) })
|
allDirs.addAll(directories.map { File(rootDir, it.path) })
|
||||||
}
|
}
|
||||||
|
|
||||||
val seen = hashSetOf<Path>()
|
val seen = hashSetOf<java.nio.file.Path>()
|
||||||
allDirs.forEach { dir ->
|
allDirs.forEach { dir ->
|
||||||
if (! dir.exists()) {
|
if (! dir.exists()) {
|
||||||
log(2, "Couldn't find directory $dir")
|
log(2, "Couldn't find directory $dir")
|
||||||
|
@ -248,6 +249,27 @@ class KFiles {
|
||||||
fun makeOutputDir(project: Project) : File = makeDir(project, KFiles.CLASSES_DIR)
|
fun makeOutputDir(project: Project) : File = makeDir(project, KFiles.CLASSES_DIR)
|
||||||
|
|
||||||
fun makeOutputTestDir(project: Project) : File = makeDir(project, KFiles.TEST_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> {
|
fun findRecursively(directory: File, function: Function1<String, Boolean>): List<String> {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package com.beust.kobalt.plugin.packaging
|
package com.beust.kobalt.plugin.packaging
|
||||||
|
|
||||||
import com.beust.kobalt.IFileSpec
|
import com.beust.kobalt.IFileSpec
|
||||||
|
import com.beust.kobalt.misc.KFiles
|
||||||
import com.beust.kobalt.misc.log
|
import com.beust.kobalt.misc.log
|
||||||
import com.google.common.io.CharStreams
|
import com.google.common.io.CharStreams
|
||||||
import java.io.*
|
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,
|
public fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
|
||||||
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
|
||||||
file.specs.forEach { spec ->
|
file.specs.forEach { spec ->
|
||||||
|
@ -56,7 +62,7 @@ public class JarUtils {
|
||||||
val stream = JarInputStream(FileInputStream(source))
|
val stream = JarInputStream(FileInputStream(source))
|
||||||
var entry = stream.nextEntry
|
var entry = stream.nextEntry
|
||||||
while (entry != null) {
|
while (entry != null) {
|
||||||
if (!entry.isDirectory) {
|
if (! entry.isDirectory && ! KFiles.isExcluded(entry.name, DEFAULT_JAR_EXCLUDES)) {
|
||||||
val ins = JarFile(source).getInputStream(entry)
|
val ins = JarFile(source).getInputStream(entry)
|
||||||
addEntry(ins, JarEntry(entry), outputStream, onError)
|
addEntry(ins, JarEntry(entry), outputStream, onError)
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,8 +20,6 @@ import com.beust.kobalt.plugin.java.JavaPlugin
|
||||||
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.FileSystems
|
|
||||||
import java.nio.file.PathMatcher
|
|
||||||
import java.nio.file.Paths
|
import java.nio.file.Paths
|
||||||
import java.util.jar.JarOutputStream
|
import java.util.jar.JarOutputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
|
@ -72,24 +70,6 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
return TaskResult()
|
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 {
|
private fun generateWar(project: Project, war: War) : File {
|
||||||
//
|
//
|
||||||
// src/main/web app and classes
|
// src/main/web app and classes
|
||||||
|
@ -153,7 +133,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
|
|
||||||
// Class files
|
// Class files
|
||||||
val files = KFiles.findRecursively(classesDir).map { File(relClassesDir.toFile(), it) }
|
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>()
|
val fileSpecs = arrayListOf<IFileSpec>()
|
||||||
filesNotExcluded.forEach {
|
filesNotExcluded.forEach {
|
||||||
fileSpecs.add(FileSpec(it.path.toString().substring(prefixPath.toString().length + 1)))
|
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 ->
|
}.forEach { file : File ->
|
||||||
if (! seen.contains(file.name)) {
|
if (! seen.contains(file.name)) {
|
||||||
seen.add(file.name)
|
seen.add(file.name)
|
||||||
if (!isExcluded(file, jar.excludes)) {
|
if (! KFiles.isExcluded(file, jar.excludes)) {
|
||||||
allFiles.add(IncludedFile(arrayListOf(FileSpec(file.path))))
|
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))
|
includedSpecs.add(FileSpec(file.path))
|
||||||
} 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")
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue