Skip to content

Commit

Permalink
[ gradle ] Trying to switch to build.gradle.kts
Browse files Browse the repository at this point in the history
  • Loading branch information
ice1000 committed Mar 10, 2018
1 parent e0132f2 commit bb971b7
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 120 deletions.
112 changes: 0 additions & 112 deletions build.gradle

This file was deleted.

147 changes: 147 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,147 @@
import org.gradle.api.internal.HasConvention
import org.gradle.jvm.tasks.Jar
import org.jetbrains.kotlin.gradle.plugin.KotlinSourceSet
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
import java.io.*
import java.nio.file.*
import java.util.concurrent.TimeUnit
import java.util.stream.Collectors

val commitHash by lazy {
val process: Process = Runtime.getRuntime().exec("git rev-parse --short HEAD")
process.waitFor(2000L, TimeUnit.MILLISECONDS)
val output = process.inputStream.use {
it.bufferedReader().use {
it.readText()
}
}
process.destroy()
output.trim()
}

val isCI = !System.getenv("CI").isNullOrBlank()

val comingVersion = "1.8.3"
val packageName = "org.frice"
val kotlinVersion: String by extra

group = packageName
version = if (isCI) "$comingVersion-$commitHash" else comingVersion

buildscript {
var kotlinVersion: String by extra
var dokkaVersion: String by extra

kotlinVersion = "1.2.30"
dokkaVersion = "0.9.15"

repositories {
mavenCentral()
}

dependencies {
classpath(kotlin("gradle-plugin", kotlinVersion))
classpath("org.jetbrains.dokka:dokka-gradle-plugin:$dokkaVersion")
}
}

plugins {
java
kotlin("jvm") version "1.2.30"
}

allprojects {
apply {
plugin("org.jetbrains.dokka")
}
}

java {
sourceCompatibility = JavaVersion.VERSION_1_8
targetCompatibility = JavaVersion.VERSION_1_8
}

tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = "1.8"
}
}

tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}

val SourceSet.kotlin
get() = (this as HasConvention)
.convention
.getPlugin(KotlinSourceSet::class.java)
.kotlin

java.sourceSets {
"main" {
java.srcDirs("src")
kotlin.srcDirs("src")
resources.srcDirs("res")
}

"test" {
java.srcDirs("test")
kotlin.srcDirs("test")
}
}

repositories {
mavenCentral()
}

configurations {
create("library")
}

val libraries = Files
.list(Paths.get("lib"))
.filter { it.endsWith(".jar") }
.collect(Collectors.toList()).toTypedArray()

dependencies {
compile(kotlin("stdlib-jdk8", kotlinVersion))
"library"(files(libraries))
configurations.compile.extendsFrom(configurations["library"])
testCompile("junit", "junit", "4.12")
testCompile(kotlin("test-junit", kotlinVersion))
}

val jar = tasks["jar"] as Jar
jar.from(*libraries)

val fatJar = task<Jar>("fatJar") {
classifier = "all"
description = "Assembles a jar archive containing the main classes and all the dependencies."
group = "build"
from(*libraries) // TODO change to all libs
with(jar)
}

val sourcesJar = task<Jar>("sourcesJar") {
classifier = "sources"
description = "Assembles a jar archive containing the source code of this project."
group = "build"
from(java.sourceSets["main"].allSource)
}

task("displayCommitHash") {
group = "help"
description = "Display the newest commit hash"
doFirst {
println("Commit hash: $commitHash")
}
}

task("isCI") {
group = "help"
description = "Check if it's running in a continuous-integration"
doFirst {
println(if (isCI) "Yes, I'm on a CI." else "No, I'm not on CI.")
}
}

2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.4-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-bin.zip
2 changes: 0 additions & 2 deletions settings.gradle

This file was deleted.

1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
rootProject.name = "engine"
2 changes: 1 addition & 1 deletion src/org/frice/GameFX.kt
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ open class GameFX @JvmOverloads constructor(
try {
adjust()
if (stopped) break
if (!paused && refresh.ended()) {
if (!paused and refresh.ended()) {
clearScreen(drawer)
dealWithObjects(drawer)
drawer.init()
Expand Down
4 changes: 2 additions & 2 deletions src/org/frice/anim/FAnim.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,5 @@ abstract class FAnim {
protected var lastRefresh: Double = start

@Suppress("FunctionName")
abstract internal fun `{-# do #-}`(obj: FObject)
}
internal abstract fun `{-# do #-}`(obj: FObject)
}
5 changes: 4 additions & 1 deletion src/org/frice/obj/FObject.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,17 @@ import java.util.*
abstract class FObject(x: Double, y: Double) : PhysicalObject(x, y) {
var id = -1
val anims = LinkedList<FAnim>()
@Deprecated("Replace with `addAnim` or `clearAnim`", level = DeprecationLevel.WARNING) get
abstract val resource: FResource

abstract fun scale(x: Double, y: Double)

@Suppress("FunctionName")
@Suppress("FunctionName", "DEPRECATION")
internal fun `{-# runAnims #-}`() = anims.forEach { it.`{-# do #-}`(this) }

@Suppress("DEPRECATION")
fun addAnim(anim: FAnim) = anims.add(anim)

@Suppress("DEPRECATION")
fun stopAnims() = anims.clear()
}
2 changes: 1 addition & 1 deletion test/org/frice/Test.kt
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ class Test3 : Game() {
override fun onInit() {
setSize(1000, 1000)
a = ShapeObject(ColorResource.BLUE, FCircle(10.0), 100.0, 500.0)
a.anims.add(object : CustomMove() {
a.addAnim(object : CustomMove() {
override fun getXDelta(timeFromBegin: Double) =
(a.x * c * Math.sin(d) - a.y * c * Math.cos(d)) * e

Expand Down

0 comments on commit bb971b7

Please sign in to comment.