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

Timestamp work.

This commit is contained in:
Cedric Beust 2015-12-19 02:26:10 +04:00
parent 0d75f9ad5f
commit d9a287f710
5 changed files with 80 additions and 25 deletions

View file

@ -112,7 +112,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
it.exists()
} .forEach {
log(2, "Copying from $sourceDirs to $absOutputDir")
KFiles.copyRecursively(it, absOutputDir, deleteFirst = true)
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
}
} else {
lp(project, "No resources to copy for $sourceSet")
@ -133,7 +133,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
project.projectProperties.put(COMPILER_ARGS, arrayListOf(*args))
}
fun isOutOfDate(project: Project, context: KobaltContext, actionInfo: CompilerActionInfo) : Boolean {
fun isOutdated(project: Project, context: KobaltContext, actionInfo: CompilerActionInfo) : Boolean {
fun stripSourceDir(sourceFile: String) : String {
project.sourceDirectories.forEach {
val d = KFiles.joinDir(project.directory, it)
@ -150,10 +150,10 @@ abstract class JvmCompilerPlugin @Inject constructor(
fun toClassFile(sourceFile: String) = stripSuffix(sourceFile) + ".class"
val sourceFiles = actionInfo.sourceFiles.map { stripSourceDir(it) }
sourceFiles.forEach { sourceFile ->
val classFile = KFiles.joinDir(project.directory, project.classesDir(context), toClassFile(sourceFile))
if (classFile == null || File(sourceFile).lastModified() > File(classFile).lastModified()) {
actionInfo.sourceFiles.forEach { sourceFile ->
val stripped = stripSourceDir(sourceFile)
val classFile = File(KFiles.joinDir(project.directory, project.classesDir(context), toClassFile(stripped)))
if (! classFile.exists() || File(sourceFile).lastModified() > classFile.lastModified()) {
return true
}
}
@ -170,7 +170,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
sourceDirectories.add(sourceDirectory)
}
val info = createCompilerActionInfo(project, context, isTest = false)
if (isOutOfDate(project, context, info)) {
if (isOutdated(project, context, info)) {
val compiler = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.compilerContributors)
if (compiler != null) {
return compiler.compile(project, context, info)

View file

@ -34,7 +34,8 @@ public class JarUtils {
public fun addSingleFile(directory: String, file: IncludedFile, outputStream: ZipOutputStream,
expandJarFiles: Boolean, onError: (Exception) -> Unit = DEFAULT_HANDLER) {
file.allFromFiles(directory).forEach { source ->
val allFiles = file.allFromFiles(directory)
allFiles.forEach { source ->
val path = source.path
if (source.isDirectory) {
log(2, "Writing contents of directory $source")
@ -68,8 +69,8 @@ public class JarUtils {
} else {
val entry = JarEntry((file.to + source.path).replace("\\", "/"))
entry.time = source.lastModified()
val fromPath = (file.from + "/" + source.path).replace("\\", "/")
val entryFile = File(directory, fromPath)
val fromPath = source.path.replace("\\", "/")
val entryFile = source
if (! entryFile.exists()) {
throw AssertionError("File should exist: $entryFile")
}
@ -155,9 +156,9 @@ class IncludedFile(val fromOriginal: From, val toOriginal: To, val specs: List<I
fun allFromFiles(directory: String): List<File> {
val result = arrayListOf<File>()
specs.forEach { spec ->
val path = spec.toString()
spec.toFiles(directory + "/" + from).forEach { source ->
result.add(source)
val fullDir = KFiles.joinDir(directory, from)
spec.toFiles(fullDir).forEach { source ->
result.add(if (source.isAbsolute) source else File(fullDir, source.path))
}
}
return result

View file

@ -7,6 +7,7 @@ import com.beust.kobalt.api.Kobalt
import com.beust.kobalt.api.Project
import com.beust.kobalt.homeDir
import com.beust.kobalt.internal.build.BuildFile
import com.beust.kobalt.maven.Md5
import java.io.File
import java.io.IOException
import java.nio.file.*
@ -160,7 +161,7 @@ class KFiles {
// Until then, wipe everything first
if (deleteFirst) to.deleteRecursively()
// to.mkdirs()
hackCopyRecursively(from, to, replaceExisting, onError)
hackCopyRecursively(from, to, replaceExisting = replaceExisting, onError = onError)
}
/** Private exception class, used to terminate recursive copying */
@ -171,6 +172,7 @@ class KFiles {
*/
private fun hackCopyRecursively(from: File, dst: File,
replaceExisting: Boolean,
checkTimestamp: Boolean = false,
onError: (File, IOException) -> OnErrorAction =
{ file, exception -> throw exception }
): Boolean {
@ -196,9 +198,13 @@ class KFiles {
} else if (src.isDirectory) {
dstFile.mkdirs()
} else {
if (src.copyTo(dstFile, true) != src.length()) {
if (onError(src, IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE)
return false
if (dstFile.exists() && Md5.toMd5(src) == Md5.toMd5(dstFile)) {
log(2, " Identical files, not copying $src to $dstFile")
} else {
if (src.copyTo(dstFile, true) != src.length()) {
if (onError(src, IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE)
return false
}
}
}
}
@ -242,8 +248,14 @@ class KFiles {
log(2, "Windows detected, not overwriting $to")
} else {
try {
log(2, "Copy from $from to ${to!!}")
Files.copy(from, to, option)
if (from != null && to != null) {
if (!Files.exists(to) || Md5.toMd5(from.toFile()) != Md5.toMd5(to.toFile())) {
log(2, "Copy from $from to ${to}")
Files.copy(from, to, option)
} else {
log(2, " Not copying, indentical files: $from $to")
}
}
} catch(ex: IOException) {
// Windows is anal about this
log(1, "Couldn't copy $from to $to: ${ex.message}")