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

Fix IncludedFile bugs.

This commit is contained in:
Cedric Beust 2015-12-18 19:57:48 -08:00
parent e9bcad4735
commit f8a6439878
2 changed files with 14 additions and 9 deletions

View file

@ -7,6 +7,7 @@ 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
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
import java.util.zip.ZipException
import java.util.zip.ZipFile import java.util.zip.ZipFile
import java.util.zip.ZipOutputStream import java.util.zip.ZipOutputStream
@ -35,19 +36,23 @@ public class JarUtils {
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) {
val allFiles = file.allFromFiles(directory) val allFiles = file.allFromFiles(directory)
allFiles.forEach { source -> allFiles.forEach { relSource ->
val path = source.path val source =
if (relSource.isAbsolute) relSource
else File(KFiles.joinDir(directory, file.from, relSource.path))
if (source.isDirectory) { if (source.isDirectory) {
log(2, "Writing contents of directory $source") log(2, "Writing contents of directory $source")
// Directory // Directory
var name = path var name = source.name
if (!name.isEmpty()) { if (!name.isEmpty()) {
if (!name.endsWith("/")) name += "/" if (!name.endsWith("/")) name += "/"
val entry = JarEntry(name) val entry = JarEntry(name)
entry.time = source.lastModified() entry.time = source.lastModified()
try { try {
outputStream.putNextEntry(entry) outputStream.putNextEntry(entry)
} catch(ex: ZipException) {
log(2, "Can't add $name: ${ex.message}")
} finally { } finally {
outputStream.closeEntry() outputStream.closeEntry()
} }
@ -60,18 +65,17 @@ 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 && ! KFiles.isExcluded(entry.name, DEFAULT_JAR_EXCLUDES)) { 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)
} }
entry = stream.nextEntry entry = stream.nextEntry
} }
} else { } else {
val entry = JarEntry((file.to + source.path).replace("\\", "/")) val entry = JarEntry(file.to + relSource.path.replace("\\", "/"))
entry.time = source.lastModified() entry.time = source.lastModified()
val fromPath = source.path.replace("\\", "/")
val entryFile = source val entryFile = source
if (! entryFile.exists()) { if (!entryFile.exists()) {
throw AssertionError("File should exist: $entryFile") throw AssertionError("File should exist: $entryFile")
} }
addEntry(FileInputStream(entryFile), entry, outputStream, onError) addEntry(FileInputStream(entryFile), entry, outputStream, onError)
@ -158,7 +162,7 @@ class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<I
specs.forEach { spec -> specs.forEach { spec ->
val fullDir = KFiles.joinDir(directory, from) val fullDir = KFiles.joinDir(directory, from)
spec.toFiles(fullDir).forEach { source -> spec.toFiles(fullDir).forEach { source ->
result.add(if (source.isAbsolute) source else File(fullDir, source.path)) result.add(if (source.isAbsolute) source else File(source.path))
} }
} }
return result return result

View file

@ -261,7 +261,8 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val lastModified = output.lastModified() val lastModified = output.lastModified()
includedFiles.forEach { root -> includedFiles.forEach { root ->
val allFiles = root.allFromFiles(directory) val allFiles = root.allFromFiles(directory)
allFiles.forEach { file -> allFiles.forEach { relFile ->
val file = File(KFiles.joinDir(directory, root.from, relFile.path))
if (file.isFile) { if (file.isFile) {
if (file.lastModified() > lastModified) { if (file.lastModified() > lastModified) {
log(2, " Outdated $file and $output " log(2, " Outdated $file and $output "