mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Timestamp work.
This commit is contained in:
parent
0d75f9ad5f
commit
d9a287f710
5 changed files with 80 additions and 25 deletions
|
@ -112,7 +112,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
||||||
it.exists()
|
it.exists()
|
||||||
} .forEach {
|
} .forEach {
|
||||||
log(2, "Copying from $sourceDirs to $absOutputDir")
|
log(2, "Copying from $sourceDirs to $absOutputDir")
|
||||||
KFiles.copyRecursively(it, absOutputDir, deleteFirst = true)
|
KFiles.copyRecursively(it, absOutputDir, deleteFirst = false)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
lp(project, "No resources to copy for $sourceSet")
|
lp(project, "No resources to copy for $sourceSet")
|
||||||
|
@ -133,7 +133,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
||||||
project.projectProperties.put(COMPILER_ARGS, arrayListOf(*args))
|
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 {
|
fun stripSourceDir(sourceFile: String) : String {
|
||||||
project.sourceDirectories.forEach {
|
project.sourceDirectories.forEach {
|
||||||
val d = KFiles.joinDir(project.directory, it)
|
val d = KFiles.joinDir(project.directory, it)
|
||||||
|
@ -150,10 +150,10 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
||||||
|
|
||||||
fun toClassFile(sourceFile: String) = stripSuffix(sourceFile) + ".class"
|
fun toClassFile(sourceFile: String) = stripSuffix(sourceFile) + ".class"
|
||||||
|
|
||||||
val sourceFiles = actionInfo.sourceFiles.map { stripSourceDir(it) }
|
actionInfo.sourceFiles.forEach { sourceFile ->
|
||||||
sourceFiles.forEach { sourceFile ->
|
val stripped = stripSourceDir(sourceFile)
|
||||||
val classFile = KFiles.joinDir(project.directory, project.classesDir(context), toClassFile(sourceFile))
|
val classFile = File(KFiles.joinDir(project.directory, project.classesDir(context), toClassFile(stripped)))
|
||||||
if (classFile == null || File(sourceFile).lastModified() > File(classFile).lastModified()) {
|
if (! classFile.exists() || File(sourceFile).lastModified() > classFile.lastModified()) {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -170,7 +170,7 @@ abstract class JvmCompilerPlugin @Inject constructor(
|
||||||
sourceDirectories.add(sourceDirectory)
|
sourceDirectories.add(sourceDirectory)
|
||||||
}
|
}
|
||||||
val info = createCompilerActionInfo(project, context, isTest = false)
|
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)
|
val compiler = ActorUtils.selectAffinityActor(project, context, context.pluginInfo.compilerContributors)
|
||||||
if (compiler != null) {
|
if (compiler != null) {
|
||||||
return compiler.compile(project, context, info)
|
return compiler.compile(project, context, info)
|
||||||
|
|
|
@ -34,7 +34,8 @@ 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) {
|
||||||
file.allFromFiles(directory).forEach { source ->
|
val allFiles = file.allFromFiles(directory)
|
||||||
|
allFiles.forEach { source ->
|
||||||
val path = source.path
|
val path = source.path
|
||||||
if (source.isDirectory) {
|
if (source.isDirectory) {
|
||||||
log(2, "Writing contents of directory $source")
|
log(2, "Writing contents of directory $source")
|
||||||
|
@ -68,8 +69,8 @@ public class JarUtils {
|
||||||
} else {
|
} else {
|
||||||
val entry = JarEntry((file.to + source.path).replace("\\", "/"))
|
val entry = JarEntry((file.to + source.path).replace("\\", "/"))
|
||||||
entry.time = source.lastModified()
|
entry.time = source.lastModified()
|
||||||
val fromPath = (file.from + "/" + source.path).replace("\\", "/")
|
val fromPath = source.path.replace("\\", "/")
|
||||||
val entryFile = File(directory, fromPath)
|
val entryFile = source
|
||||||
if (! entryFile.exists()) {
|
if (! entryFile.exists()) {
|
||||||
throw AssertionError("File should exist: $entryFile")
|
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> {
|
fun allFromFiles(directory: String): List<File> {
|
||||||
val result = arrayListOf<File>()
|
val result = arrayListOf<File>()
|
||||||
specs.forEach { spec ->
|
specs.forEach { spec ->
|
||||||
val path = spec.toString()
|
val fullDir = KFiles.joinDir(directory, from)
|
||||||
spec.toFiles(directory + "/" + from).forEach { source ->
|
spec.toFiles(fullDir).forEach { source ->
|
||||||
result.add(source)
|
result.add(if (source.isAbsolute) source else File(fullDir, source.path))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result
|
return result
|
||||||
|
|
|
@ -7,6 +7,7 @@ import com.beust.kobalt.api.Kobalt
|
||||||
import com.beust.kobalt.api.Project
|
import com.beust.kobalt.api.Project
|
||||||
import com.beust.kobalt.homeDir
|
import com.beust.kobalt.homeDir
|
||||||
import com.beust.kobalt.internal.build.BuildFile
|
import com.beust.kobalt.internal.build.BuildFile
|
||||||
|
import com.beust.kobalt.maven.Md5
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.io.IOException
|
import java.io.IOException
|
||||||
import java.nio.file.*
|
import java.nio.file.*
|
||||||
|
@ -160,7 +161,7 @@ class KFiles {
|
||||||
// Until then, wipe everything first
|
// Until then, wipe everything first
|
||||||
if (deleteFirst) to.deleteRecursively()
|
if (deleteFirst) to.deleteRecursively()
|
||||||
// to.mkdirs()
|
// to.mkdirs()
|
||||||
hackCopyRecursively(from, to, replaceExisting, onError)
|
hackCopyRecursively(from, to, replaceExisting = replaceExisting, onError = onError)
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Private exception class, used to terminate recursive copying */
|
/** Private exception class, used to terminate recursive copying */
|
||||||
|
@ -171,6 +172,7 @@ class KFiles {
|
||||||
*/
|
*/
|
||||||
private fun hackCopyRecursively(from: File, dst: File,
|
private fun hackCopyRecursively(from: File, dst: File,
|
||||||
replaceExisting: Boolean,
|
replaceExisting: Boolean,
|
||||||
|
checkTimestamp: Boolean = false,
|
||||||
onError: (File, IOException) -> OnErrorAction =
|
onError: (File, IOException) -> OnErrorAction =
|
||||||
{ file, exception -> throw exception }
|
{ file, exception -> throw exception }
|
||||||
): Boolean {
|
): Boolean {
|
||||||
|
@ -196,9 +198,13 @@ class KFiles {
|
||||||
} else if (src.isDirectory) {
|
} else if (src.isDirectory) {
|
||||||
dstFile.mkdirs()
|
dstFile.mkdirs()
|
||||||
} else {
|
} else {
|
||||||
if (src.copyTo(dstFile, true) != src.length()) {
|
if (dstFile.exists() && Md5.toMd5(src) == Md5.toMd5(dstFile)) {
|
||||||
if (onError(src, IOException("src.length() != dst.length()")) == OnErrorAction.TERMINATE)
|
log(2, " Identical files, not copying $src to $dstFile")
|
||||||
return false
|
} 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")
|
log(2, "Windows detected, not overwriting $to")
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
log(2, "Copy from $from to ${to!!}")
|
if (from != null && to != null) {
|
||||||
Files.copy(from, to, option)
|
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) {
|
} catch(ex: IOException) {
|
||||||
// Windows is anal about this
|
// Windows is anal about this
|
||||||
log(1, "Couldn't copy $from to $to: ${ex.message}")
|
log(1, "Couldn't copy $from to $to: ${ex.message}")
|
||||||
|
|
|
@ -17,6 +17,7 @@ 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.nio.file.Paths
|
||||||
|
import java.util.*
|
||||||
import java.util.jar.JarOutputStream
|
import java.util.jar.JarOutputStream
|
||||||
import java.util.zip.ZipOutputStream
|
import java.util.zip.ZipOutputStream
|
||||||
import javax.inject.Inject
|
import javax.inject.Inject
|
||||||
|
@ -236,19 +237,42 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
|
||||||
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
val fullArchiveName = context.variant.archiveName(project, archiveName, suffix)
|
||||||
val archiveDir = File(libsDir(project))
|
val archiveDir = File(libsDir(project))
|
||||||
val result = File(archiveDir.path, fullArchiveName)
|
val result = File(archiveDir.path, fullArchiveName)
|
||||||
val outStream = outputStreamFactory(FileOutputStream(result))
|
|
||||||
log(2, "Creating $result")
|
log(2, "Creating $result")
|
||||||
JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles)
|
if (isOutdated(project.directory, includedFiles, result)) {
|
||||||
log(2, text = "Added ${includedFiles.size} files to $result")
|
val outStream = outputStreamFactory(FileOutputStream(result))
|
||||||
outStream.flush()
|
JarUtils.addFiles(project.directory, includedFiles, outStream, expandJarFiles)
|
||||||
outStream.close()
|
log(2, text = "Added ${includedFiles.size} files to $result")
|
||||||
log(1, " Created $result")
|
outStream.flush()
|
||||||
|
outStream.close()
|
||||||
|
log(1, " Created $result")
|
||||||
|
} else {
|
||||||
|
log(2, " $result is up to date")
|
||||||
|
}
|
||||||
|
|
||||||
project.projectProperties.put(JAR_NAME, result.absolutePath)
|
project.projectProperties.put(JAR_NAME, result.absolutePath)
|
||||||
|
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun isOutdated(directory: String, includedFiles: List<IncludedFile>, output: File): Boolean {
|
||||||
|
if (! output.exists()) return true
|
||||||
|
|
||||||
|
val lastModified = output.lastModified()
|
||||||
|
includedFiles.forEach { root ->
|
||||||
|
val allFiles = root.allFromFiles(directory)
|
||||||
|
allFiles.forEach { file ->
|
||||||
|
if (file.isFile) {
|
||||||
|
if (file.lastModified() > lastModified) {
|
||||||
|
log(2, " Outdated $file and $output "
|
||||||
|
+ Date(file.lastModified()) + " " + Date(output.lastModified()))
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
fun addPackage(p: PackageConfig) {
|
fun addPackage(p: PackageConfig) {
|
||||||
packages.add(p)
|
packages.add(p)
|
||||||
}
|
}
|
||||||
|
|
18
src/test/kotlin/com/beust/kobalt/misc/JarUtilsTest.kt
Normal file
18
src/test/kotlin/com/beust/kobalt/misc/JarUtilsTest.kt
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
package com.beust.kobalt.misc
|
||||||
|
|
||||||
|
import com.beust.kobalt.IFileSpec
|
||||||
|
import org.testng.Assert
|
||||||
|
import org.testng.annotations.Test
|
||||||
|
import javax.inject.Inject
|
||||||
|
|
||||||
|
@Test
|
||||||
|
class JarUtilsTest @Inject constructor() {
|
||||||
|
|
||||||
|
fun allFromFiles() {
|
||||||
|
val inf = IncludedFile(From("kobaltBuild/classes"), To(""),
|
||||||
|
listOf(IFileSpec.FileSpec("com/beust/kobalt/wrapper/Main.class")))
|
||||||
|
val files = inf.allFromFiles("modules/wrapper")
|
||||||
|
println("Files: $files")
|
||||||
|
Assert.assertEquals(files[0].path, "modules/wrapper/kobaltBuild/classes/com/beust/kobalt/wrapper/Main.class")
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue