Skip to content

Commit

Permalink
Merge pull request #24 from ToxicBakery/feature/experiment-with-platf…
Browse files Browse the repository at this point in the history
…orm-modules

Experiment using platform modules
  • Loading branch information
ToxicBakery authored Jul 25, 2018
2 parents c2d6c93 + 9a0edab commit 2c8e950
Show file tree
Hide file tree
Showing 18 changed files with 80 additions and 35 deletions.
13 changes: 10 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,21 +13,28 @@ buildscript {
}
dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.16"
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.17"
classpath "me.champeau.gradle:jmh-gradle-plugin:0.4.5"
classpath "gradle.plugin.io.morethan.jmhreport:gradle-jmh-report:0.7.0"
}
}

allprojects {
subprojects {
group 'com.ToxicBakery.kfinstatemachine'
version "2.3.${buildNumber()}" + (isTag() ? "" : "-SNAPSHOT")
version "2.4.${buildNumber()}" + (isTag() ? "" : "-SNAPSHOT")

repositories {
mavenCentral()
jcenter()
google()
}

tasks.withType(Test) {
testLogging {
showStandardStreams = true
events 'passed', 'failed'
}
}
}

static boolean isTag() { return !System.getenv('TRAVIS_TAG')?.isEmpty() ?: false }
Expand Down
9 changes: 5 additions & 4 deletions core/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'org.jetbrains.dokka'

sourceCompatibility = 1.8

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation "junit:junit:4.12"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}

compileKotlin {
Expand Down
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.8.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-4.9-all.zip
2 changes: 2 additions & 0 deletions graph-common/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/build
/out
20 changes: 20 additions & 0 deletions graph-common/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
apply plugin: 'kotlin-platform-common'
apply plugin: 'org.jetbrains.dokka'

dependencies {
testImplementation "org.jetbrains.kotlin:kotlin-test-common:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test-annotations-common:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-common:$kotlin_version"
}

dokka {
outputFormat = 'html'
outputDirectory = "$buildDir/javadoc"
}

// Seems it's not possible to run dokka on a common project so create a blank javadoc jar for central
task dokkaJavadoc() {
}

apply from: "${rootDir}/publish.gradle"
1 change: 1 addition & 0 deletions graph-common/gradle.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
POM_ARTIFACT_ID=graph-common
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,6 @@ open class DirectedGraph<N, E>(
override fun edges(
node: N,
defaultValue: () -> Map<E, N>
): Map<E, N> = mappedEdges[node] ?: defaultValue()
): Map<E, N> = mappedEdges.getOrElse(node, defaultValue)

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.toxicbakery.kfinstatemachine.graph

import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.test.Test
import kotlin.test.assertEquals
import kotlin.test.fail

class DirectedGraphTest {

Expand Down Expand Up @@ -34,11 +35,14 @@ class DirectedGraphTest {
}
}

@Test(expected = Exception::class)
@Test()
fun nodeNotInGraph() {
mapOf("node_1" to mapOf("edge_1" to "node_2"))
.let { edges -> DirectedGraph(edges) }
.edges("node_3")
try {
mapOf("node_1" to mapOf("edge_1" to "node_2"))
.let { edges -> DirectedGraph(edges) }
.edges("node_3")
fail("Expected Exception")
} catch (e: Exception) {}
}

@Test
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.toxicbakery.kfinstatemachine.graph

import org.junit.Assert.assertEquals
import org.junit.Test
import kotlin.test.Test
import kotlin.test.assertEquals

class MapPathsKtTest {

Expand Down
9 changes: 5 additions & 4 deletions graph-util/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'org.jetbrains.dokka'

sourceCompatibility = 1.8

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation "junit:junit:4.12"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation project(':core')
implementation project(':graph')
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package com.toxicbakery.kfinstatemachine.graph
import com.toxicbakery.kfinstatemachine.StateMachine.Companion.transition
import com.toxicbakery.kfinstatemachine.TransitionRule

val <S, T : Any> IDirectedGraph<S, T>.transitionRules: List<TransitionRule<S, out T>>
val <S, T : Any> IDirectedGraph<S, T>.toTransitionRules: List<TransitionRule<S, out T>>
get() = nodes
.flatMap { leftNode ->
edges(leftNode)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import kotlin.reflect.KClass
class DirectedGraphKtTest {

@Test
fun getTransitionRules() {
fun getToTransitionRules() {
DirectedGraph(
mapOf(
Potential to mapOf(Release::class to Kinetic),
Kinetic to mapOf(Store::class to Potential)
))
.transitionRules
.toTransitionRules
.also { transitions: List<TransitionRule<Energy, out KClass<out Action>>> ->
transitions.first { it.oldState == Potential && it.newState == Kinetic }
transitions.first { it.oldState == Kinetic && it.newState == Potential }
Expand Down
10 changes: 6 additions & 4 deletions graph/build.gradle
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'org.jetbrains.dokka'

sourceCompatibility = 1.8

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation "junit:junit:4.12"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
expectedBy project(':graph-common')
}

compileKotlin {
Expand Down
11 changes: 6 additions & 5 deletions rx/build.gradle
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
apply plugin: 'java-library'
apply plugin: 'kotlin'
apply plugin: 'kotlin-platform-jvm'
apply plugin: 'org.jetbrains.dokka'

sourceCompatibility = 1.8

dependencies {
testImplementation group: 'junit', name: 'junit', version: '4.12'
testImplementation "junit:junit:4.12"
testImplementation "org.jetbrains.kotlin:kotlin-test-junit:$kotlin_version"
testImplementation "org.jetbrains.kotlin:kotlin-test:$kotlin_version"

api project(':core')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
compile project(':core')
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation "io.reactivex.rxjava2:rxjava:$rxjava_version"
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@ package com.toxicbakery.sample.dungeon

import com.toxicbakery.kfinstatemachine.StateMachine
import com.toxicbakery.kfinstatemachine.graph.DirectedGraph
import com.toxicbakery.kfinstatemachine.graph.transitionRules
import com.toxicbakery.kfinstatemachine.graph.toTransitionRules
import java.util.*

class MapMachine private constructor(
private val directedGraph: DirectedGraph<Point, Direction>,
initialState: Point
) : StateMachine<Point>(
initialState,
directedGraph.transitionRules
directedGraph.toTransitionRules
) {

/**
Expand Down
6 changes: 6 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
enableFeaturePreview('GRADLE_METADATA')

// Common code
include ':graph-common'

// Exported libraries
include ':core'
include ':graph'
include ':graph-util'
Expand Down

0 comments on commit 2c8e950

Please sign in to comment.