Skip to content
This repository has been archived by the owner on Mar 28, 2023. It is now read-only.

Commit

Permalink
Handle Kotlin failures with new intermediary task.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Oct 18, 2021
1 parent f7d2908 commit bcc117f
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 14 deletions.
6 changes: 5 additions & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@ plugins {
}

group = "com.github.cs125-illinois"
version = "2021.10.5"
version = "2021.10.6"

dependencies {
implementation("org.jetbrains.kotlin:kotlin-stdlib:1.5.31")
implementation("org.jetbrains.kotlin:kotlin-reflect:1.5.31")
implementation("org.jetbrains.kotlin:kotlin-gradle-plugin:1.5.31")
implementation(gradleApi())
implementation("com.google.code.gson:gson:2.8.8")
implementation("org.apache.httpcomponents:httpclient:4.5.13")
Expand Down Expand Up @@ -50,3 +51,6 @@ tasks.withType<KotlinCompile>().configureEach {
languageVersion = "1.4"
}
}
tasks.shadowJar {
isZip64 = true
}
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,22 @@ open class GradeTask : DefaultTask() {
pointsEarned += if (passed) gradedAnnotation.points else 0
}
}

val testingSucceeded = project.tasks.getByName("grade").state.executed

gradedTests.forEach { task ->
// Process the report XML files with a class loader that can access test classes
var compiled = false
@Suppress("DEPRECATION")
URLClassLoader(task.classpath.map { it.toURI().toURL() }.toTypedArray(), javaClass.classLoader).use { loader ->
task.reports.junitXml.destination.listFiles { _, name -> name.endsWith(".xml") }?.forEach { file ->
compiled = true
processTestFile(task, loader, file)
if (testingSucceeded) {
@Suppress("DEPRECATION")
URLClassLoader(
task.classpath.map { it.toURI().toURL() }.toTypedArray(),
javaClass.classLoader
).use { loader ->
task.reports.junitXml.destination.listFiles { _, name -> name.endsWith(".xml") }?.forEach { file ->
compiled = true
processTestFile(task, loader, file)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.gradle.api.tasks.Delete
import org.gradle.api.tasks.compile.JavaCompile
import org.gradle.api.tasks.testing.Test
import java.nio.file.Files
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile

/**
* The gradlegrader Gradle plugin.
Expand All @@ -38,13 +39,19 @@ class GradleGraderPlugin : Plugin<Project> {
return config.subprojects ?: listOf(project)
}

val compileTasks = mutableSetOf<JavaCompile>()
val javaCompileTasks = mutableSetOf<JavaCompile>()
val kotlinCompileTasks = mutableSetOf<KotlinCompile>()

val testTasks = mutableMapOf<Project, Test>()
var currentCheckpoint: String? = null

val checkstyleTask = project.tasks.register("relentlessCheckstyle", RelentlessCheckstyle::class.java).get()
val detektTask = project.tasks.register("ourDetekt", Detekt::class.java).get()
val gradeTask: GradeTask = project.tasks.register("grade", GradeTask::class.java).get()

val targetTask = project.tasks.register("grade").get()
val gradeTask: GradeTask = project.tasks.register("score", GradeTask::class.java).get()
gradeTask.mustRunAfter(targetTask)

val reconfTask = project.task("prepareForGrading").doLast {
// Check projects' test tasks
findSubprojects().forEach { subproject ->
Expand Down Expand Up @@ -146,33 +153,37 @@ class GradleGraderPlugin : Plugin<Project> {
}

// Configure compilation tasks
compileTasks.forEach {
javaCompileTasks.forEach {
gradeTask.listenTo(it)
it.options.isFailOnError = false
it.outputs.upToDateWhen { false }
}
kotlinCompileTasks.forEach {
gradeTask.listenTo(it)
it.outputs.upToDateWhen { false }
}
}

// Logic that depends on all projects having been evaluated
val onAllProjectsReady = {
val cleanTasks = findSubprojects().map { it.tasks.getByName("clean") }
if (config.forceClean) {
// Require a clean first
gradeTask.dependsOn(cleanTasks)
targetTask.dependsOn(cleanTasks)
}

// Depend on checkstyle
if (config.checkstyle.enabled) {
checkstyleTask.mustRunAfter(reconfTask)
checkstyleTask.mustRunAfter(cleanTasks)
gradeTask.dependsOn(checkstyleTask)
targetTask.dependsOn(checkstyleTask)
gradeTask.gatherCheckstyleInfo(checkstyleTask)
}

if (config.detekt.enabled) {
detektTask.mustRunAfter(reconfTask)
detektTask.mustRunAfter(cleanTasks)
gradeTask.dependsOn(detektTask)
targetTask.dependsOn(detektTask)
gradeTask.gatherDetektInfo(detektTask)
}

Expand All @@ -182,7 +193,12 @@ class GradleGraderPlugin : Plugin<Project> {
subproject.tasks.withType(JavaCompile::class.java) { compile ->
compile.mustRunAfter(cleanTasks)
compile.mustRunAfter(reconfTask)
compileTasks.add(compile)
javaCompileTasks.add(compile)
}
subproject.tasks.withType(KotlinCompile::class.java) { compile ->
compile.mustRunAfter(cleanTasks)
compile.mustRunAfter(reconfTask)
kotlinCompileTasks.add(compile)
}

// Depend on tests
Expand All @@ -191,7 +207,7 @@ class GradleGraderPlugin : Plugin<Project> {
testTasks[subproject] = test
test.mustRunAfter(cleanTasks)
test.mustRunAfter(reconfTask)
gradeTask.dependsOn(test)
targetTask.dependsOn(test)
}
}
}
Expand Down

0 comments on commit bcc117f

Please sign in to comment.