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

New install task.

This commit is contained in:
Cedric Beust 2015-11-09 22:47:38 -08:00
parent a4b5b459fe
commit a4d16eddde
3 changed files with 45 additions and 6 deletions

View file

@ -14,4 +14,6 @@ class PluginProperties @Inject constructor() {
pluginProperties.getOrPut(pluginName) { hashMapOf<String, Any>() }.put(key, value) pluginProperties.getOrPut(pluginName) { hashMapOf<String, Any>() }.put(key, value)
fun get(pluginName: String, key: String) = pluginProperties[pluginName]?.get(key) fun get(pluginName: String, key: String) = pluginProperties[pluginName]?.get(key)
fun getString(pluginName: String, key: String) = get(pluginName, key) as String
} }

View file

@ -209,7 +209,7 @@ public class AndroidPlugin @Inject constructor(val javaCompiler: JavaCompiler)
val dx = "${androidHome(project)}/build-tools/$buildToolsDir/dx" + val dx = "${androidHome(project)}/build-tools/$buildToolsDir/dx" +
if (OperatingSystem.current().isWindows()) ".bat" else "" if (OperatingSystem.current().isWindows()) ".bat" else ""
val buildDir = context.pluginProperties.get("java", JvmCompilerPlugin.BUILD_DIR) val buildDir = context.pluginProperties.get("java", JvmCompilerPlugin.BUILD_DIR)
val libsDir = (context.pluginProperties.get("packaging", PackagingPlugin.LIBS_DIR) as File).path val libsDir = context.pluginProperties.getString("packaging", PackagingPlugin.LIBS_DIR)
File(libsDir.toString()).mkdirs() File(libsDir.toString()).mkdirs()
val classesDex = "classes.dex" val classesDex = "classes.dex"
val classesDexDir = KFiles.joinAndMakeDir(libsDir, "intermediates", "dex", flavor) val classesDexDir = KFiles.joinAndMakeDir(libsDir, "intermediates", "dex", flavor)

View file

@ -41,16 +41,19 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() { val executors: KobaltExecutors, val localRepo: LocalRepo) : BasePlugin() {
companion object { companion object {
const val PLUGIN_NAME = "PackagingPlugin"
@ExportedProperty @ExportedProperty
const val LIBS_DIR = "libsDir" const val LIBS_DIR = "libsDir"
@ExportedProperty @ExportedProperty
const val JAR_NAME = "jarName" const val JAR_NAME = "jarName"
const val TASK_ASSEMBLE : String = "assemble" const val TASK_ASSEMBLE: String = "assemble"
const val TASK_INSTALL: String = "install"
} }
override val name = "packaging" override val name = PLUGIN_NAME
private val packages = arrayListOf<Package>() private val packages = arrayListOf<Package>()
@ -59,7 +62,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
context.pluginProperties.put(name, LIBS_DIR, libsDir(project)) context.pluginProperties.put(name, LIBS_DIR, libsDir(project))
} }
private fun libsDir(project: Project) = KFiles.makeDir(buildDir(project).path, "libs") private fun libsDir(project: Project) = KFiles.makeDir(buildDir(project).path, "libs").path
@Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JavaPlugin.TASK_COMPILE)) @Task(name = TASK_ASSEMBLE, description = "Package the artifacts", runAfter = arrayOf(JavaPlugin.TASK_COMPILE))
fun taskAssemble(project: Project) : TaskResult { fun taskAssemble(project: Project) : TaskResult {
@ -225,7 +228,7 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
expandJarFiles : Boolean = false, expandJarFiles : Boolean = false,
outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File { outputStreamFactory: (OutputStream) -> ZipOutputStream = DEFAULT_STREAM_FACTORY) : File {
val fullArchiveName = archiveName ?: arrayListOf(project.name, project.version!!).joinToString("-") + suffix val fullArchiveName = archiveName ?: arrayListOf(project.name, project.version!!).joinToString("-") + suffix
val archiveDir = libsDir(project) val archiveDir = File(libsDir(project))
val result = File(archiveDir.path, fullArchiveName) val result = File(archiveDir.path, fullArchiveName)
val outStream = outputStreamFactory(FileOutputStream(result)) val outStream = outputStreamFactory(FileOutputStream(result))
log(2, "Creating $result") log(2, "Creating $result")
@ -243,15 +246,48 @@ class PackagingPlugin @Inject constructor(val dependencyManager : DependencyMana
fun addPackage(p: Package) { fun addPackage(p: Package) {
packages.add(p) packages.add(p)
} }
@Task(name = PackagingPlugin.TASK_INSTALL, description = "Install the artifacts",
runAfter = arrayOf(PackagingPlugin.TASK_ASSEMBLE))
fun taskInstall(project: Project) : TaskResult {
val config = installConfigs[project.name]
if (config != null) {
val buildDir = context.pluginProperties.getString(PLUGIN_NAME, LIBS_DIR)
log(1, "Installing from $buildDir to ${config.libDir}")
val toDir = KFiles.makeDir(config.libDir)
KFiles.copyRecursively(File(buildDir), toDir)
} else {
log(1, "No install specified for ${project.name}, nothing to do")
}
return TaskResult()
}
private val installConfigs = hashMapOf<String, InstallConfig>()
fun addInstallConfig(project: Project, config: InstallConfig) =
installConfigs.put(project.name, config)
} }
@Directive
fun Project.install(init: InstallConfig.() -> Unit) {
InstallConfig().let {
it.init()
(Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addInstallConfig(this, it)
}
}
class InstallConfig(var libDir : String = "libs")
class Package(val project: Project) : AttributeHolder { class Package(val project: Project) : AttributeHolder {
val jars = arrayListOf<Jar>() val jars = arrayListOf<Jar>()
val wars = arrayListOf<War>() val wars = arrayListOf<War>()
val zips = arrayListOf<Zip>() val zips = arrayListOf<Zip>()
init { init {
(Kobalt.findPlugin("packaging") as PackagingPlugin).addPackage(this) (Kobalt.findPlugin(PackagingPlugin.PLUGIN_NAME) as PackagingPlugin).addPackage(this)
} }
@Directive @Directive
@ -362,6 +398,7 @@ open class Zip(open var name: String? = null) {
* file and the excludePrefix is "build/lib", then "a.jar" will be added at the root of the zip file. * file and the excludePrefix is "build/lib", then "a.jar" will be added at the root of the zip file.
*/ */
val includedFiles = arrayListOf<IncludedFile>() val includedFiles = arrayListOf<IncludedFile>()
} }
open class Direction(open val p: String) { open class Direction(open val p: String) {