mirror of
https://github.com/ethauvin/kobalt.git
synced 2025-04-26 08:27:12 -07:00
Variants working in simple scenarios.
This commit is contained in:
parent
432e673e90
commit
63acc32513
2 changed files with 53 additions and 3 deletions
|
@ -135,12 +135,58 @@ class KFiles {
|
||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
fun copyRecursively(from: File, to: File, deleteFirst: Boolean = true) {
|
fun copyRecursively(from: File, to: File, replaceExisting: Boolean = true, deleteFirst: Boolean = true) {
|
||||||
// Need to wait until copyRecursively supports an overwrite: Boolean = false parameter
|
// Need to wait until copyRecursively supports an overwrite: Boolean = false parameter
|
||||||
// Until then, wipe everything first
|
// Until then, wipe everything first
|
||||||
if (deleteFirst) to.deleteRecursively()
|
if (deleteFirst) to.deleteRecursively()
|
||||||
to.mkdirs()
|
to.mkdirs()
|
||||||
from.copyRecursively(to)
|
hackCopyRecursively(from, to, replaceExisting)
|
||||||
|
}
|
||||||
|
|
||||||
|
/** Private exception class, used to terminate recursive copying */
|
||||||
|
private class TerminateException(file: File) : FileSystemException(file) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Copy/pasted from kotlin/io/Utils.kt to add support for overwriting.
|
||||||
|
*/
|
||||||
|
private fun hackCopyRecursively(from: File, dst: File,
|
||||||
|
replaceExisting: Boolean,
|
||||||
|
onError: (File, IOException) -> OnErrorAction =
|
||||||
|
{ file, exception -> throw exception }
|
||||||
|
): Boolean {
|
||||||
|
if (!from.exists()) {
|
||||||
|
return onError(from, NoSuchFileException(file = from, reason = "The source file doesn't exist")) !=
|
||||||
|
OnErrorAction.TERMINATE
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
// We cannot break for loop from inside a lambda, so we have to use an exception here
|
||||||
|
for (src in from.walkTopDown().fail { f, e -> if (onError(f, e) == OnErrorAction.TERMINATE) throw TerminateException(f) }) {
|
||||||
|
if (!src.exists()) {
|
||||||
|
if (onError(src, NoSuchFileException(file = src, reason = "The source file doesn't exist")) ==
|
||||||
|
OnErrorAction.TERMINATE)
|
||||||
|
return false
|
||||||
|
} else {
|
||||||
|
val relPath = src.relativeTo(from)
|
||||||
|
val dstFile = File(dst, relPath)
|
||||||
|
if (dstFile.exists() && !replaceExisting && !(src.isDirectory() && dstFile.isDirectory())) {
|
||||||
|
if (onError(dstFile, FileAlreadyExistsException(file = src,
|
||||||
|
other = dstFile,
|
||||||
|
reason = "The destination file already exists")) == OnErrorAction.TERMINATE)
|
||||||
|
return false
|
||||||
|
} 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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true
|
||||||
|
} catch (e: TerminateException) {
|
||||||
|
return false
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun findDotDir(startDir: File) : File {
|
fun findDotDir(startDir: File) : File {
|
||||||
|
|
|
@ -152,11 +152,15 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* TODO: not implemented yet, just copying the resources into the variant dir
|
* TODO: not implemented yet, just copying the resources into the variant dir
|
||||||
|
* Spec: http://developer.android.com/sdk/installing/studio-build.html
|
||||||
*/
|
*/
|
||||||
private fun mergeResources(project: Project, variant: Variant) {
|
private fun mergeResources(project: Project, variant: Variant) {
|
||||||
val dest = mergedResources(project, variant)
|
val dest = mergedResources(project, variant)
|
||||||
log(1, "Resource merging not implemented, copying app/src/main/res to $dest")
|
log(1, "Resource merging not implemented, copying app/src/main/res to $dest")
|
||||||
KFiles.copyRecursively(File("app/src/main/res"), File(dest))
|
listOf("main", variant.productFlavor.name, variant.buildType.name).forEach {
|
||||||
|
log(1, " Copying app/src/$it/res into $dest")
|
||||||
|
KFiles.copyRecursively(File("app/src/$it/res"), File(dest), deleteFirst = false)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
inner open class AndroidCommand(project: Project, command: String, cwd: File = File(project.directory))
|
inner open class AndroidCommand(project: Project, command: String, cwd: File = File(project.directory))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue