Add ApplicationPreload mechanism to collectScreenshots
This commit is contained in:
@@ -1,51 +0,0 @@
|
||||
|
||||
project.ext.lwjglVersion = "3.2.3"
|
||||
def osArch = System.getProperty("os.arch")
|
||||
project.ext.arch = osArch.startsWith("armv8") || osArch.contains("64") ? "x86-64" : "x86"
|
||||
|
||||
//switch ( OperatingSystem.current() ) {
|
||||
// case OperatingSystem.WINDOWS:
|
||||
// project.ext.OS = "windows"
|
||||
// break
|
||||
// case OperatingSystem.LINUX:
|
||||
// project.ext.OS = "linux"
|
||||
// break
|
||||
// case OperatingSystem.MAC_OS:
|
||||
// project.ext.OS = "macos"
|
||||
// break
|
||||
//}
|
||||
project.ext.OS = "linux"
|
||||
|
||||
class LwjglRule implements ComponentMetadataRule { //val os: String, val arch: String, val classifier: String)
|
||||
private def nativeVariants = [
|
||||
[os: OperatingSystemFamily.LINUX, arch: "arm32", classifier: "natives-linux-arm32"],
|
||||
[os: OperatingSystemFamily.LINUX, arch: "arm64", classifier: "natives-linux-arm64"],
|
||||
[os: OperatingSystemFamily.LINUX, arch: "x86-64", classifier: "natives-linux"],
|
||||
[os: OperatingSystemFamily.WINDOWS, arch: "x86", classifier: "natives-windows-x86"],
|
||||
[os: OperatingSystemFamily.WINDOWS, arch: "x86-64", classifier: "natives-windows"],
|
||||
[os: OperatingSystemFamily.MACOS, arch: "x86-64", classifier: "natives-macos"]
|
||||
]
|
||||
|
||||
@javax.inject.Inject
|
||||
ObjectFactory getObjects() { }
|
||||
|
||||
void execute(ComponentMetadataContext context) {
|
||||
context.details.withVariant("runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, "none"))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, "none"))
|
||||
}
|
||||
}
|
||||
nativeVariants.each { variantDefinition ->
|
||||
context.details.addVariant("${variantDefinition.classifier}-runtime", "runtime") {
|
||||
attributes {
|
||||
attributes.attribute(OperatingSystemFamily.OPERATING_SYSTEM_ATTRIBUTE, objects.named(OperatingSystemFamily, variantDefinition.os))
|
||||
attributes.attribute(MachineArchitecture.ARCHITECTURE_ATTRIBUTE, objects.named(MachineArchitecture, variantDefinition.arch))
|
||||
}
|
||||
withFiles {
|
||||
addFile("${context.details.id.name}-${context.details.id.version}-${variantDefinition.classifier}.jar")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -3,12 +3,36 @@ plugins {
|
||||
`kotlin-dsl`
|
||||
}
|
||||
|
||||
sourceSets {
|
||||
|
||||
val preload by creating {
|
||||
this.java {
|
||||
srcDir("src/preload/kotlin")
|
||||
}
|
||||
}
|
||||
val main by getting {
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
mavenLocal()
|
||||
gradlePluginPortal()
|
||||
}
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.30")
|
||||
val preloadImplementation by configurations.getting { }
|
||||
preloadImplementation("org.openrndr:openrndr-application:0.5.1-SNAPSHOT")
|
||||
preloadImplementation("org.openrndr:openrndr-extensions:0.5.1-SNAPSHOT")
|
||||
}
|
||||
|
||||
tasks.all {
|
||||
println(this.name)
|
||||
|
||||
}
|
||||
tasks.getByName("compileKotlin").dependsOn("compilePreloadKotlin")
|
||||
@@ -1,5 +1,17 @@
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileCollection
|
||||
import org.gradle.api.file.FileType
|
||||
import org.gradle.api.provider.ListProperty
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.kotlin.dsl.register
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
import org.jetbrains.kotlin.gradle.plugin.mpp.KotlinJvmCompilation
|
||||
import java.io.File
|
||||
import java.net.URLClassLoader
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
|
||||
@get:Incremental
|
||||
@@ -22,6 +34,11 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
|
||||
}
|
||||
@TaskAction
|
||||
fun execute(inputChanges: InputChanges) {
|
||||
val preloadClass = File(project.rootProject.projectDir, "buildSrc/build/classes/kotlin/preload")
|
||||
require(preloadClass.exists()) {
|
||||
"preload class not found: '${preloadClass.absolutePath}'"
|
||||
|
||||
}
|
||||
inputChanges.getFileChanges(inputDir).forEach { change ->
|
||||
if (change.fileType == FileType.DIRECTORY) return@forEach
|
||||
if (change.file.extension == "class" && !(change.file.name.contains("$"))) {
|
||||
@@ -29,21 +46,19 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
|
||||
if (klassName.dropLast(2) in ignore.get())
|
||||
return@forEach
|
||||
|
||||
val cp = (runtimeDependencies.get().map { it.toURI().toURL() } + inputDir.get().asFile.toURI().toURL())
|
||||
val cp = (runtimeDependencies.get().map { it.toURI().toURL() } +
|
||||
inputDir.get().asFile.toURI().toURL()
|
||||
)
|
||||
.toTypedArray()
|
||||
|
||||
val ucl = URLClassLoader(cp)
|
||||
|
||||
|
||||
|
||||
|
||||
val klass = ucl.loadClass(klassName)
|
||||
println("Collecting screenshot for ${klassName} ${klass}")
|
||||
|
||||
val mainMethod = klass.getMethod("main")
|
||||
println(mainMethod)
|
||||
project.javaexec {
|
||||
this.classpath += project.files(inputDir.get().asFile)
|
||||
this.classpath += project.files(inputDir.get().asFile, preloadClass)
|
||||
this.classpath += runtimeDependencies.get()
|
||||
this.mainClass.set(klassName)
|
||||
this.workingDir(project.rootProject.projectDir)
|
||||
@@ -84,7 +99,9 @@ object ScreenshotsHelper {
|
||||
task.inputDir.set(output.classesDirs.first())
|
||||
task.runtimeDependencies.set(runtimeDependencyFiles)
|
||||
task.config()
|
||||
task.dependsOn(this.compileKotlinTask)
|
||||
return task
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,12 @@
|
||||
import org.gradle.api.DefaultTask
|
||||
import org.gradle.api.file.DirectoryProperty
|
||||
import org.gradle.api.file.FileType
|
||||
import org.gradle.api.provider.Property
|
||||
import org.gradle.api.tasks.*
|
||||
import org.gradle.work.ChangeType
|
||||
import org.gradle.work.Incremental
|
||||
import org.gradle.work.InputChanges
|
||||
import org.gradle.workers.WorkerExecutor
|
||||
import javax.inject.Inject
|
||||
|
||||
abstract class EmbedShadersTask : DefaultTask() {
|
||||
@@ -28,6 +37,7 @@ abstract class EmbedShadersTask : DefaultTask() {
|
||||
|
||||
@TaskAction
|
||||
fun execute(inputChanges: InputChanges) {
|
||||
|
||||
inputChanges.getFileChanges(inputDir).forEach { change ->
|
||||
if (change.fileType == FileType.DIRECTORY) return@forEach
|
||||
val name = "${namePrefix.get()}${change.file.nameWithoutExtension.replace("-", "_")}"
|
||||
18
buildSrc/src/preload/kotlin/ApplicationPreload.kt
Normal file
18
buildSrc/src/preload/kotlin/ApplicationPreload.kt
Normal file
@@ -0,0 +1,18 @@
|
||||
package org.openrndr
|
||||
|
||||
import org.openrndr.ApplicationPreload
|
||||
import org.openrndr.extensions.SingleScreenshot
|
||||
|
||||
class Preload : ApplicationPreload() {
|
||||
override fun onConfiguration(configuration: Configuration) {
|
||||
// configuration.width = 1280
|
||||
// configuration.height = 720
|
||||
}
|
||||
override fun onProgramSetup(program: Program) {
|
||||
println("installing single screenshot extension at 0")
|
||||
program.extensions.add(0, SingleScreenshot().apply {
|
||||
this.outputFile = System.getProperty("screenshotPath")
|
||||
setup(program)
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user