Skip to content

Commit

Permalink
Use Alchemist-primer basis
Browse files Browse the repository at this point in the history
  • Loading branch information
DanySK committed Apr 10, 2020
1 parent 501238f commit cac1c25
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 34 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ before_install:
- source $GRAVIS/install-jdk

script:
- travis_retry ./gradlew check
- travis_retry ./gradlew check runAll

before_cache:
- $GRAVIS/clean-gradle-cache
Expand Down
64 changes: 43 additions & 21 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,59 @@ plugins {
repositories { mavenCentral() }

sourceSets {
test {
main {
resources {
srcDir("src/main/protelis")
}
}
}

dependencies {
implementation("it.unibo.alchemist:alchemist:${extra["alchemistVersion"].toString()}")
testImplementation("io.kotlintest:kotlintest-runner-junit5:${extra["junitVersion"].toString()}")
implementation("it.unibo.alchemist:alchemist:_")
testImplementation("io.kotlintest:kotlintest-runner-junit5:_")
}

val jar by tasks.getting(Jar::class) {
archiveName = "classpath.jar"
manifest {
attributes["Class-Path"] = files(configurations.runtimeClasspath)
.map { it.toURI() }
.joinToString(" ")
}
}
val simulation = extra["simulation"].toString()
tasks.register<JavaExec>("runAlchemist") {
dependsOn("compileJava")
dependsOn("jar")
// clean up the classpath because the launcher jar has it.
classpath = files(jar.archivePath)
classpath("src/main/protelis")
main = "it.unibo.alchemist.Alchemist"
args("-y", "src/main/yaml/$simulation.yml", "-g", "effects/$simulation.aes")

val batch: String by project
val maxTime: String by project

val alchemistGroup = "Run Alchemist"
/*
* This task is used to run all experiments in sequence
*/
val runAll by tasks.register<DefaultTask>("runAll") {
group = alchemistGroup
description = "Launches all simulations"
}

defaultTasks("runAlchemist")
/*
* Scan the folder with the simulation files, and create a task for each one of them.
*/
File(rootProject.rootDir.path + "/src/main/yaml").listFiles()
.filter { it.extension == "yml" }
.sortedBy { it.nameWithoutExtension }
.forEach {
val task by tasks.register<JavaExec>("run${it.nameWithoutExtension.capitalize()}") {
group = alchemistGroup
description = "Launches simulation ${it.nameWithoutExtension}"
main = "it.unibo.alchemist.Alchemist"
classpath = sourceSets["main"].runtimeClasspath
val exportsDir = File("${projectDir.path}/build/exports/${it.nameWithoutExtension}")
doFirst {
if (!exportsDir.exists()) {
exportsDir.mkdirs()
}
}
args("-y", it.absolutePath, "-e", "$exportsDir/${it.nameWithoutExtension}-${System.currentTimeMillis()}")
if (System.getenv("CI") == "true" || batch == "true") {
args("-hl", "-t", maxTime)
} else {
args("-g", "effects/${it.nameWithoutExtension}.aes")
}
outputs.dir(exportsDir)
}
// task.dependsOn(classpathJar) // Uncomment to switch to jar-based cp resolution
runAll.dependsOn(task)
}

tasks.test { useJUnitPlatform() }
6 changes: 2 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,2 @@
alchemistVersion = +
junitVersion = 3.3.2

simulation = 00-minimal
batch = false
maxTime = 5
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
10 changes: 10 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import de.fayard.dependencies.bootstrapRefreshVersionsAndDependencies

rootProject.name = "protelis-alchemist-tutorial"

buildscript {
repositories { gradlePluginPortal() }
dependencies.classpath("de.fayard:dependencies:+")
}

bootstrapRefreshVersionsAndDependencies()
2 changes: 1 addition & 1 deletion src/main/protelis/org/protelis/tutorial/distanceTo.pt
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ rep (d <- 100) {
} else {
minHood(nbr(d) + nbrRange())
}
}
}
14 changes: 8 additions & 6 deletions src/test/kotlin/RunSimulationTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,17 @@ class RunSimulationTest<T : Any?> : StringSpec() {

"run simulations not should throw exception" {
listOfSimulationPaths
.map { Pair(it, YamlLoader(it.inputStream()).getDefault<T, Euclidean2DPosition>()) }
.map { Pair(it.first, Engine(it.second, DoubleTime(simulationTime)).also {
.asSequence()
.map { YamlLoader(it.inputStream()).getDefault<T, Euclidean2DPosition>() }
.map { Engine(it, DoubleTime(simulationTime)) }
.onEach {
it.play()
it.run()
}) }
}
.forEach {
it.second.waitFor(Status.TERMINATED, 0, TimeUnit.MILLISECONDS)
assert(it.second.error.isEmpty) {
"Error in simulation of: ${it.second.error.get().message.orEmpty()}"
it.waitFor(Status.TERMINATED, 0, TimeUnit.MILLISECONDS)
assert(it.error.isEmpty) {
"Error in simulation of: ${it.error.get().message.orEmpty()}"
}
}
}
Expand Down
9 changes: 9 additions & 0 deletions versions.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
## suppress inspection "SpellCheckingInspection" for whole file
##
## Dependencies and Plugin versions with their available updates
## Generated by $ ./gradlew refreshVersions
## Please, don't put extra comments in that file yet, keeping them is not supported yet.

version.it.unibo.alchemist..alchemist=9.3.0

version.kotlintest=3.4.2

0 comments on commit cac1c25

Please sign in to comment.