napperley
12/20/2020, 3:09 AMopen class FlatpakManifestTask : FlatpakManifestTaskBase, DefaultTask() {
private val objFactory = project.objects
@Input
override val appId: Property<String> = objFactory.property()
@Input
override val command: Property<String> = objFactory.property()
@Input
override val runtime: Property<String> = objFactory.property()
@Input
override val runtimeVer: Property<String> = objFactory.property()
@Input
override val sdk: Property<String> = objFactory.property()
@Input
override val modules: ListProperty<Module> = objFactory.listProperty(Module::class.java)
@Input
override val renameIcon: Property<String> = objFactory.property()
@Input
override val renameDesktopFile: Property<String> = objFactory.property()
@Input
override val finishArgs: ListProperty<String> = objFactory.listProperty(String::class.java)
@Input
override val cleanup: ListProperty<String> = objFactory.listProperty(String::class.java)
@Input
override val cleanupCommands: ListProperty<String> = objFactory.listProperty(String::class.java)
init {
@Suppress("LeakingThis")
renameDesktopFile.set("")
@Suppress("LeakingThis")
renameIcon.set("")
}
fun basicModule(init: BasicModule.() -> Unit): BasicModule {
val result = BasicModule()
result.init()
modules.add(result)
return result
}
private fun generateJsonRoot() = buildJsonObject {
put("app-id", appId.get())
put("command", command.get())
put("runtime", runtime.get())
put("runtime-version", runtimeVer.get())
put("sdk", sdk.get())
if (renameDesktopFile.get().isNotEmpty()) put("rename-desktop-file", renameDesktopFile.get())
if (renameIcon.get().isNotEmpty()) put("rename-icon", renameIcon.get())
addFinishArgs(this)
addCleanup(this)
addCleanupCommands(this)
}
private fun addCleanupCommands(builder: JsonObjectBuilder) {
if (cleanupCommands.get().isNotEmpty()) {
builder.putJsonArray("cleanup-commands") {
cleanupCommands.get().forEach { item -> add(item) }
}
}
}
private fun addCleanup(builder: JsonObjectBuilder) {
if (cleanup.get().isNotEmpty()) {
builder.putJsonArray("cleanup") {
cleanup.get().forEach { item -> add(item) }
}
}
}
private fun addFinishArgs(builder: JsonObjectBuilder) {
if (finishArgs.get().isNotEmpty()) {
builder.putJsonArray("finish-args") {
finishArgs.get().forEach { item -> add(item) }
}
}
}
@TaskAction
fun create() {
val manifest = File("${project.rootDir.absolutePath}/${appId.get()}.json")
if (!manifest.exists()) manifest.createNewFile()
manifest.writeText("${generateJsonRoot()}")
}
}
// ...
private fun testTaskExists() = test("Task exists") {
setup()
val appId = "org.example.Hello"
buildFile.writeText("""
$pluginBlock
flatpakManifest {
appId = "$appId"
command = "hello"
runtime = "org.freedesktop.Platform"
runtimeVer = "19.08"
sdk = "org.freedesktop.Sdk"
basicModule {
name = "hello"
simpleBuildSystem {}
fileSource {
path = hello.sh
}
}
}
""".trimIndent())
val result = GradleRunner
.create()
.withProjectDir(projectDir)
.withPluginClasspath()
.withArguments("flatpakLocalRepo")
.build()
result.output shouldContain "BUILD SUCCESSFUL"
tearDown()
}
class FileSource : Source {
override val type: String = "file"
var path: String = ""
}
fun fileSource(init: FileSource.() -> Unit = {}): FileSource {
val source = FileSource()
source.init()
return source
}
Vampire
12/20/2020, 11:22 AMnapperley
12/20/2020, 6:23 PMVampire
12/20/2020, 6:28 PMnapperley
12/21/2020, 12:12 AMVampire
12/21/2020, 12:13 AM