Skip to content

Commit

Permalink
Fixes and move to jvmDemo (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
Vechro authored Jan 15, 2023
1 parent e27f7eb commit 47d4293
Show file tree
Hide file tree
Showing 117 changed files with 75 additions and 310 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jobs:
path: ./orx

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1.0.4
uses: gradle/wrapper-validation-action@v1.0.5

- name: Checkout OPENRNDR repository
uses: actions/checkout@v3
Expand All @@ -33,10 +33,11 @@ jobs:

- name: Test glxinfo
run: |
sudo apt-get update
sudo apt-get install -y mesa-utils xvfb
xvfb-run glxinfo
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
Expand Down
5 changes: 3 additions & 2 deletions .github/workflows/generate-screenshots.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
path: ./orx

- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1.0.4
uses: gradle/wrapper-validation-action@v1.0.5

- name: Checkout OPENRNDR repository
uses: actions/checkout@v3
Expand All @@ -29,10 +29,11 @@ jobs:

- name: Test glxinfo
run: |
sudo apt-get update
sudo apt-get install -y mesa-utils xvfb
xvfb-run glxinfo
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-candidate-to-maven-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ jobs:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release-to-maven-central.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
- name: Get the version
id: get_version
run: echo ::set-output name=VERSION::${GITHUB_REF/refs\/tags\/v/}
- uses: actions/setup-java@v2
- uses: actions/setup-java@v3
with:
distribution: temurin
java-version: 17
Expand Down
84 changes: 43 additions & 41 deletions buildSrc/src/main/kotlin/CollectScreenShots.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,17 @@ 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.process.ExecOperations
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
@get:PathSensitive(PathSensitivity.NAME_ONLY)
@get:InputDirectory
@get:PathSensitive(PathSensitivity.NAME_ONLY)
@get:SkipWhenEmpty
abstract val inputDir: DirectoryProperty

@get:Input
Expand All @@ -27,54 +27,55 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
abstract val outputDir: DirectoryProperty

@get:Input
@get:Optional
abstract val ignore: ListProperty<String>

@get:Inject
abstract val execOperations: ExecOperations

init {
ignore.set(emptyList())
}
@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 ->
println(change)
if (change.fileType == FileType.DIRECTORY) return@forEach
if (change.file.extension == "class") {
val klassName = change.file.nameWithoutExtension
if (klassName.dropLast(2) in ignore.get())
if (klassName.dropLast(2) in ignore.get()) {
return@forEach

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}")
}

try {
val mainMethod = klass.getMethod("main")
project.javaexec {
this.classpath += project.files(inputDir.get().asFile, preloadClass)
this.classpath += runtimeDependencies.get()
this.mainClass.set(klassName)
this.workingDir(project.rootProject.projectDir)
jvmArgs("-DtakeScreenshot=true", "-DscreenshotPath=${outputDir.get().asFile}/$klassName.png", "-Dorg.openrndr.exceptions=JVM")
}
val cp = (runtimeDependencies.get().map { it.toURI().toURL() } + inputDir.get().asFile.toURI()
.toURL()).toTypedArray()
val ucl = URLClassLoader(cp)
val klass = ucl.loadClass(klassName)
klass.getMethod("main")
} catch (e: NoSuchMethodException) {
// silently ignore
return@forEach
}

println("Collecting screenshot for ${klassName}")

execOperations.javaexec {
this.classpath += project.files(inputDir.get().asFile, preloadClass)
this.classpath += runtimeDependencies.get()
this.mainClass.set(klassName)
this.workingDir(project.rootProject.projectDir)
this.jvmArgs(
"-DtakeScreenshot=true",
"-DscreenshotPath=${outputDir.get().asFile}/$klassName.png",
"-Dorg.openrndr.exceptions=JVM"
)
}
}
}
// this is only executed if there are changes in the inputDir
val runDemos = outputDir.get().asFile.listFiles { file: File ->
file.extension == "png"
}.map { it.nameWithoutExtension }.sorted()
}!!.map { it.nameWithoutExtension }.sorted()
val readme = File(project.projectDir, "README.md")
if (readme.exists()) {
var lines = readme.readLines().toMutableList()
Expand All @@ -84,10 +85,18 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
}
lines.add("<!-- __demos__ -->")
lines.add("## Demos")

// Find out if current project is MPP
val demoModuleName = if (project.plugins.hasPlugin("org.jetbrains.kotlin.multiplatform")) {
"jvmDemo"
} else {
"demo"
}

for (demo in runDemos) {
val projectPath = project.projectDir.relativeTo(project.rootDir)
lines.add("### ${demo.dropLast(2)}")
lines.add("[source code](src/demo/kotlin/${demo.dropLast(2)}.kt)")
lines.add("[source code](src/${demoModuleName}/kotlin/${demo.dropLast(2)}.kt)")
lines.add("")
lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/$projectPath/images/${demo}.png)")
lines.add("")
Expand All @@ -99,18 +108,11 @@ abstract class CollectScreenshotsTask @Inject constructor() : DefaultTask() {
}

object ScreenshotsHelper {
fun KotlinJvmCompilation.collectScreenshots(config: CollectScreenshotsTask.() -> Unit): CollectScreenshotsTask {
val task = this.project.tasks.register<CollectScreenshotsTask>("collectScreenshots").get()
task.outputDir.set(project.file(project.projectDir.toString() + "/images"))
task.inputDir.set(output.classesDirs.first())
task.runtimeDependencies.set(runtimeDependencyFiles)
task.config()
task.dependsOn(this.compileKotlinTask)
return task

}

fun collectScreenshots(project: Project, sourceSet: SourceSet, config: CollectScreenshotsTask.() -> Unit): CollectScreenshotsTask {
fun collectScreenshots(
project: Project,
sourceSet: SourceSet,
config: CollectScreenshotsTask.() -> Unit
): CollectScreenshotsTask {
val task = project.tasks.register<CollectScreenshotsTask>("collectScreenshots").get()
task.outputDir.set(project.file(project.projectDir.toString() + "/images"))
task.inputDir.set(File(project.buildDir, "classes/kotlin/${sourceSet.name}"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@ plugins {

repositories {
mavenCentral()
maven {
// This is needed to resolve `com.github.ricardomatias:delaunator`
url = URI("https://maven.openrndr.org")
}
mavenLocal()
}

Expand All @@ -39,6 +35,7 @@ dependencies {
"demoImplementation"(libs.openrndr.application)
"demoImplementation"(libs.openrndr.extensions)
"demoRuntimeOnly"(libs.openrndr.gl3.core)
"demoRuntimeOnly"(libs.slf4j.simple)
}

kotlin {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.openrndr.extra.convention

import CollectScreenshotsTask
import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
Expand All @@ -16,10 +17,6 @@ plugins {

repositories {
mavenCentral()
maven {
// This is needed to resolve `com.github.ricardomatias:delaunator`
url = URI("https://maven.openrndr.org")
}
mavenLocal()
}

Expand All @@ -34,13 +31,15 @@ kotlin {
jvm {
jvmToolchain(libs.versions.jvmTarget.get().toInt())
compilations {
val main by getting
val main by getting
@Suppress("UNUSED_VARIABLE")
val demo by creating {
defaultSourceSet {
dependencies {
implementation(main.output.allOutputs)
}
associateWith(main)
tasks.register<CollectScreenshotsTask>("collectScreenshots") {
inputDir.set(output.classesDirs.singleFile)
runtimeDependencies.set(runtimeDependencyFiles)
outputDir.set(project.file(project.projectDir.toString() + "/images"))
dependsOn(compileKotlinTask)
}
}
}
Expand Down Expand Up @@ -84,6 +83,7 @@ kotlin {
implementation(libs.openrndr.application)
implementation(libs.openrndr.extensions)
runtimeOnly(libs.openrndr.gl3.core)
runtimeOnly(libs.slf4j.simple)
}
}
}
Expand Down
2 changes: 0 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ktor = "2.0.3"
jgit = "5.12.0.202106070339-r"
javaosc = "0.8"
javaparser = "3.15.21"
delaunator = "1.0.2"

[libraries]
kotlin-logging = { group = "io.github.microutils", name = "kotlin-logging", version.ref = "kotlinLogging" }
Expand Down Expand Up @@ -77,7 +76,6 @@ javaparser-core = { group = "com.github.javaparser", name = "javaparser-core", v
gson = { group = "com.google.code.gson", name = "gson", version.ref = "gson" }
antlr-core = { group = "org.antlr", name = "antlr4", version.ref = "antlr" }
antlr-runtime = { group = "org.antlr", name = "antlr4-runtime", version.ref = "antlr" }
delaunator = { group = "com.github.ricardomatias", name = "delaunator", version.ref = "delaunator" }

jupiter-api = { group = "org.junit.jupiter", name = "junit-jupiter-api", version.ref = "junitJupiter" }
jupiter-engine = { group = "org.junit.jupiter", name = "junit-jupiter-engine", version.ref = "junitJupiter" }
Expand Down
10 changes: 0 additions & 10 deletions orx-camera/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,19 +1,9 @@
import ScreenshotsHelper.collectScreenshots

plugins {
org.openrndr.extra.convention.`kotlin-multiplatform`
}

kotlin {
jvm {
@Suppress("UNUSED_VARIABLE")
val demo by compilations.getting {
// TODO: Move demos to /jvmDemo
defaultSourceSet {
kotlin.srcDir("src/demo/kotlin")
}
collectScreenshots { }
}
testRuns["test"].executionTask {
useJUnitPlatform {
includeEngines("spek2")
Expand Down
10 changes: 0 additions & 10 deletions orx-color/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import ScreenshotsHelper.collectScreenshots

@Suppress("DSL_SCOPE_VIOLATION")
plugins {
org.openrndr.extra.convention.`kotlin-multiplatform`
Expand All @@ -11,14 +9,6 @@ plugins {

kotlin {
jvm {
@Suppress("UNUSED_VARIABLE")
val demo by compilations.getting {
// TODO: Move demos to /jvmDemo
defaultSourceSet {
kotlin.srcDir("src/demo/kotlin")
}
collectScreenshots { }
}
testRuns["test"].executionTask {
useJUnitPlatform {
includeEngines("spek2")
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
22 changes: 0 additions & 22 deletions orx-compositor/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import ScreenshotsHelper.collectScreenshots

plugins {
org.openrndr.extra.convention.`kotlin-multiplatform`
}

kotlin {
jvm {
@Suppress("UNUSED_VARIABLE")
val demo by compilations.getting {
// TODO: Move demos to /jvmDemo
defaultSourceSet {
kotlin.srcDir("src/demo/kotlin")
}
collectScreenshots { }
}
}

sourceSets {
@Suppress("UNUSED_VARIABLE")
val commonMain by getting {
Expand All @@ -30,15 +17,6 @@ kotlin {
}
}


@Suppress("UNUSED_VARIABLE")
val jvmTest by getting {
dependencies {
implementation(libs.spek.dsl)
implementation(libs.kluent)
}
}

@Suppress("UNUSED_VARIABLE")
val jvmDemo by getting {
dependencies {
Expand Down
13 changes: 0 additions & 13 deletions orx-easing/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,21 +1,8 @@
import ScreenshotsHelper.collectScreenshots

plugins {
org.openrndr.extra.convention.`kotlin-multiplatform`
}

kotlin {
jvm {
@Suppress("UNUSED_VARIABLE")
val demo by compilations.getting {
// TODO: Move demos to /jvmDemo
defaultSourceSet {
kotlin.srcDir("src/demo/kotlin")
}
collectScreenshots { }
}
}

sourceSets {
@Suppress("UNUSED_VARIABLE")
val commonMain by getting {
Expand Down
File renamed without changes.
Loading

0 comments on commit 47d4293

Please sign in to comment.