Files
orx/build.gradle
2021-05-15 09:40:05 +02:00

330 lines
12 KiB
Groovy

import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
buildscript {
repositories {
jcenter()
}
dependencies {
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17"
classpath "com.netflix.nebula:nebula-release-plugin:15.1.0"
classpath "com.github.ben-manes:gradle-versions-plugin:0.28.0"
}
}
plugins {
id 'org.jetbrains.kotlin.jvm' version '1.5.0'
}
def openrndrUseSnapshot = false
apply plugin: 'org.jetbrains.dokka'
ext.isReleaseVersion = !version.endsWith("SNAPSHOT")
project.ext {
openrndrVersion = openrndrUseSnapshot? "0.4.0-SNAPSHOT" : "0.3.58"
kotlinVersion = "1.5.0"
spekVersion = "2.0.15"
libfreenectVersion = "0.5.7-1.5.5"
librealsense2Version = "2.40.0-1.5.5"
gsonVersion = "2.8.6"
antlrVersion = "4.9.1"
tensorflowVersion = "0.3.1"
mklDnnVersion = "0.21.5-1.5.5"
}
switch (org.gradle.internal.os.OperatingSystem.current()) {
case org.gradle.internal.os.OperatingSystem.WINDOWS:
project.ext.openrndrOS = "windows"
break
case org.gradle.internal.os.OperatingSystem.LINUX:
project.ext.openrndrOS = "linux-x64"
break
case org.gradle.internal.os.OperatingSystem.MAC_OS:
project.ext.openrndrOS = "macos"
break
}
dokka {
moduleName = "$rootProject.name"
outputDirectory = "$buildDir/docs"
outputFormat = "html"
includes = ['Module.md']
sourceDirs = files(subprojects.collect { p -> new File(p.projectDir, "/src/main/kotlin") })
}
allprojects {
apply plugin: 'idea'
apply plugin: 'java'
apply plugin: 'kotlin'
apply plugin: 'nebula.release'
apply plugin: "com.github.ben-manes.versions"
group 'org.openrndr.extra'
repositories {
if (openrndrUseSnapshot) {
mavenLocal()
}
mavenCentral()
jcenter()
maven {
url "https://dl.bintray.com/spekframework/spek"
}
}
dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlinVersion"
implementation 'io.github.microutils:kotlin-logging-jvm:2.0.6'
implementation "org.openrndr:openrndr-core:$openrndrVersion"
implementation "org.openrndr:openrndr-filter:$openrndrVersion"
implementation "org.openrndr:openrndr-shape:$openrndrVersion"
implementation group: 'org.jetbrains.kotlinx', name: 'kotlinx-coroutines-core', version: '1.4.3'
testImplementation "org.spekframework.spek2:spek-dsl-jvm:$spekVersion"
testImplementation "org.amshove.kluent:kluent:1.65"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlinVersion"
testRuntimeOnly "org.spekframework.spek2:spek-runner-junit5:$spekVersion"
testRuntimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
runtimeOnly "org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion"
}
java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}
javadoc {
options.addBooleanOption 'Xdoclint:none', true
}
test {
useJUnitPlatform {
includeEngines 'spek2'
}
}
tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
jvmTarget = "1.8"
}
}
}
task buildMainReadme {
doFirst {
def subProjects = project.subprojects
//.findAll { !it.name.contains("kinect-common") && !it.name.contains
// ("kinect-v1-") }
// Load README.md and find [begin, end] section to replace
def mainReadme = file("README.md")
def lines = mainReadme.readLines()
def begin = lines.findIndexOf { it == "<!-- __orxListBegin__ -->" }
def end = lines.findIndexOf { it == "<!-- __orxListEnd__ -->" }
if (begin == -1 || end == -1) {
println("Comments for orx list generation not found in README.md!")
return
}
def header = lines.subList(0, begin + 1)
def footer = lines.subList(end, lines.size())
def newReadme = []
for (line in header) {
newReadme.add(line)
}
newReadme.add("| name" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" +
"&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" + " | description |")
newReadme.add("| --- | --- |")
// Search for the description at the top of the readme.
// Skip the hash character from the headline, then start
// on the next line and continue until the next empty line.
// Don't fall into Windows line breaks.
def descriptionRx = ~/(?s)\#.*?\n(.+?)\n\r?\n/
// Note: the readme needs an empty line after the description
// Build orx list
for (sub in subProjects) {
def orxReadmeFile = sub.file("README.md")
if (orxReadmeFile.exists()) {
def orxReadmeText = orxReadmeFile.getText()
orxReadmeText.find(descriptionRx) {
description ->
def trimmedDescription = description[1].trim() //.strip() supports unicode, java11 only
.replace("\n", " ").replace("\r", "")
newReadme.add("| [`${sub.name}`](${sub.name}/) " +
"| $trimmedDescription |")
}
} else {
println("${sub.name}/README.md not found!")
}
}
for (line in footer) {
newReadme.add(line)
}
// Write result
if (mainReadme.exists()) {
mainReadme.delete()
}
mainReadme.write(newReadme.join("\n"))
}
}
task collectScreenshots {
doFirst {
def demoProjects = project.subprojects.findAll { it.sourceSets.hasProperty("demo") }
for (sub in demoProjects) {
if (sub.name == "openrndr-demos")
continue
if (sub.name == "orx-rabbit-control")
continue
if (sub.name == "orx-runway")
continue
if (sub.name == "orx-chataigne")
continue
if (sub.name == "orx-video-profiles")
continue
if (sub.name == "orx-realsense2")
continue
def set = sub.sourceSets.demo
def ucl = new URLClassLoader(set.runtimeClasspath.collect { it.toURI().toURL() } as URL[])
def runDemos = []
for (x in set.output) {
if (x.exists()) {
for (y in x.listFiles()) {
def name = y.name
if (!name.contains('$') && name.contains(".class")) {
def klassName = y.name.replace(".class", "")
def klass = ucl.loadClass(klassName)
try {
def mainMethod = klass.getMethod("main")
println "Collecting screenshot for ${klassName}"
javaexec {
classpath += set.runtimeClasspath
classpath += set.compileClasspath
def className = y.name.replace(".class", "")
main = className
jvmArgs += "-DtakeScreenshot=true"
jvmArgs += "-DscreenshotPath=${sub.name}/images/${className}.png"
jvmArgs += "-Dorg.openrndr.exceptions=JVM"
}
runDemos.add(klassName)
} catch (e) {
e.printStackTrace()
}
}
}
}
}
runDemos = runDemos.sort()
def readme = sub.file("README.md")
if (readme.exists()) {
def lines = readme.readLines()
def screenshotsLine = lines.findIndexOf { it == "<!-- __demos__ -->" }
if (screenshotsLine != -1) {
lines = lines.subList(0, screenshotsLine)
}
lines.add("<!-- __demos__ -->")
lines.add("## Demos")
for (demo in runDemos) {
lines.add("### ${demo[0..-3]}")
lines.add("[source code](src/demo/kotlin/${demo[0..-3]}.kt)")
lines.add("")
lines.add("![${demo}](https://raw.githubusercontent.com/openrndr/orx/media/${sub.name}/images/${demo}.png)")
lines.add("")
}
readme.delete()
readme.write(lines.join("\n"))
}
}
}
}
configure(allprojects.findAll { it.name != "openrndr-demos" }) {
apply plugin: 'nebula.release'
apply plugin: 'maven-publish'
apply plugin: 'signing'
java {
withJavadocJar()
withSourcesJar()
}
publishing {
publications {
mavenJava(MavenPublication) {
from components.java
groupId = "org.openrndr.extra"
artifactId = "$project.name"
description = "$project.name"
pom {
name = "$project.name"
description = "$project.name"
url = 'http://openrndr.org'
developers {
developer {
id = 'edwinjakobs'
name = 'Edwin Jakobs'
email = 'edwin@openrndr.org'
}
}
license {
licenses {
license {
name = 'BSD-2-Clause'
url = 'https://github.com/openrndr/openrndr/blob/master/LICENSE'
distribution = 'repo'
}
}
}
scm {
connection = "scm:git:git@github.com:openrndr/openrndr.git"
developerConnection = "scm:git:ssh://github.com/openrndr/openrndr.git"
url = "https://github.com/openrndr/openrndr"
}
}
}
}
repositories {
maven {
credentials {
username findProperty("ossrhUsername") ?: System.getenv("OSSRH_USERNAME")
password findProperty("ossrhPassword") ?: System.getenv("OSSRH_PASSWORD")
}
if (!isReleaseVersion) {
url "https://s01.oss.sonatype.org/content/repositories/snapshots"
} else {
url "https://s01.oss.sonatype.org/service/local/staging/deploy/maven2"
}
}
}
}
signing {
required { isReleaseVersion && gradle.taskGraph.hasTask("publish") }
sign publishing.publications.mavenJava
}
}
configure(subprojects) {
tasks.withType(org.jetbrains.kotlin.gradle.tasks.AbstractKotlinCompile).all {
kotlinOptions.freeCompilerArgs += ["-Xuse-experimental=kotlinx.coroutines.InternalCoroutinesApi"]
}
}
collectScreenshots.dependsOn {
project.subprojects.findAll { it.sourceSets.hasProperty("demo") }.collect { it.tasks.demoClasses }
}