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

Commit

Permalink
Add checkstyle suppressions.
Browse files Browse the repository at this point in the history
  • Loading branch information
gchallen committed Oct 31, 2022
1 parent 3b62b03 commit a878a7f
Show file tree
Hide file tree
Showing 12 changed files with 78 additions and 16 deletions.
2 changes: 1 addition & 1 deletion build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
}
subprojects {
group = "com.github.cs125-illinois.questioner"
version = "2022.10.5"
version = "2022.10.6"
tasks.withType<KotlinCompile> {
kotlinOptions {
jvmTarget = JavaVersion.VERSION_17.toString()
Expand Down
8 changes: 4 additions & 4 deletions lib/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ dependencies {
implementation("org.ow2.asm:asm:9.4")

api("com.beyondgrader.resource-agent:agent:2022.9.3")
api("com.github.cs125-illinois.jeed:core:2022.10.5")
api("com.github.cs125-illinois:jenisol:2022.10.1")
api("io.kotest:kotest-runner-junit5:5.5.1")
api("com.github.cs125-illinois.jeed:core:2022.10.8")
api("com.github.cs125-illinois:jenisol:2022.10.5")
api("io.kotest:kotest-runner-junit5:5.5.3")
api("com.google.truth:truth:1.1.3")
api("com.github.cs125-illinois:libcs1:2022.9.1")
api("com.github.cs125-illinois:libcs1:2022.10.0")
}
tasks {
val sourcesJar by creating(Jar::class) {
Expand Down
3 changes: 3 additions & 0 deletions lib/src/main/kotlin/Annotations.kt
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ annotation class Whitelist(val paths: String)
@Target(AnnotationTarget.CLASS)
annotation class Blacklist(val paths: String)

@Target(AnnotationTarget.CLASS)
annotation class CheckstyleSuppress(val suppressions: String)

@Target(AnnotationTarget.CLASS)
annotation class TemplateImports(val paths: String)

Expand Down
1 change: 1 addition & 0 deletions lib/src/main/kotlin/Question.kt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ data class Question(
var kotlinTemplate: String?,
val importWhitelist: Set<String>,
val importBlacklist: Set<String>,
val checkstyleSuppressions: Set<String>,
val slug: String,
val kotlinSolution: FlatFile?,
val detemplatedJavaStarter: String? = incorrect.find { it.language == Language.java && it.starter }?.contents,
Expand Down
9 changes: 8 additions & 1 deletion lib/src/main/kotlin/QuestionHelpers.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,14 @@ suspend fun Question.compileSubmission(
testResults.complete.compileSubmission = CompiledSourceResult(it)
testResults.completedSteps.add(TestResults.Step.compileSubmission)
}
testResults.addCheckstyleResults(source.checkstyle(CheckstyleArguments(failOnError = false)))
testResults.addCheckstyleResults(
source.checkstyle(
CheckstyleArguments(
failOnError = false,
suppressions = checkstyleSuppressions
)
)
)
compiledSource
} catch (e: TemplatingFailed) {
testResults.failed.templateSubmission = e
Expand Down
23 changes: 23 additions & 0 deletions lib/src/test/resources/questions.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "recursive-factorial",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down Expand Up @@ -245,6 +246,7 @@
"javaTemplate": "public class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "equals-88",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -393,6 +395,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "squirrel-equality",
"kotlinSolution": {
"klass": "Squirrel",
Expand Down Expand Up @@ -591,6 +594,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "counter",
"kotlinSolution": {
"klass": "Counter",
Expand Down Expand Up @@ -802,6 +806,7 @@
"kotlinTemplate": "fun printSum(first: Int, second: Int) {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "print-sum",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down Expand Up @@ -938,6 +943,7 @@
"javaTemplate": "public class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "larger-of-two",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1054,6 +1060,7 @@
"java.util.Arrays"
],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "with-template-imports",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1174,6 +1181,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "test-constructor-notnull",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1292,6 +1300,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "classroom-getters-and-setters",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1435,6 +1444,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "test-empty-constructor",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1582,6 +1592,7 @@
"kotlinTemplate": "class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "with-feature-check",
"kotlinSolution": {
"klass": "Question",
Expand Down Expand Up @@ -1722,6 +1733,7 @@
"javaTemplate": "public class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "combine-minus-two",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -1848,6 +1860,7 @@
"javaTemplate": "public class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "fancy-string-compare",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -2068,6 +2081,7 @@
"java.util.HashMap"
],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "string-duplicates",
"kotlinSolution": {
"klass": "Question",
Expand Down Expand Up @@ -2266,6 +2280,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "private-recursive-helper",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -2422,6 +2437,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "maybe-recursive-factorial",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -2554,6 +2570,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "add-one-class",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down Expand Up @@ -2712,6 +2729,7 @@
],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "cougar-feliform",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -2824,6 +2842,7 @@
"javaTemplate": "public class Question {\n public static void printHello() {\n {{{ contents }}}\n }\n}\n",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "print-hello",
"hasKotlin": false,
"published": {
Expand Down Expand Up @@ -2975,6 +2994,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "input-interleaving-test",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down Expand Up @@ -3198,6 +3218,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "with-imports",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down Expand Up @@ -3455,6 +3476,7 @@
"kotlinTemplate": "class Question {\n {{{ contents }}}\n}",
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "add-one",
"kotlinSolution": {
"klass": "Question",
Expand Down Expand Up @@ -3651,6 +3673,7 @@
"common": [],
"importWhitelist": [],
"importBlacklist": [],
"checkstyleSuppressions": [],
"slug": "kotlin-null-test",
"kotlinSolution": {
"klass": "QuestionKt",
Expand Down
2 changes: 1 addition & 1 deletion plugin/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ dependencies {
implementation("com.github.slugify:slugify:3.0.2")
implementation("org.apache.httpcomponents.client5:httpclient5-fluent:5.1.3")

testImplementation("io.kotest:kotest-runner-junit5:5.5.1")
testImplementation("io.kotest:kotest-runner-junit5:5.5.3")
}
tasks.compileKotlin {
dependsOn(tasks.generateGrammarSource)
Expand Down
23 changes: 21 additions & 2 deletions plugin/src/main/kotlin/save/ParseJava.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import edu.illinois.cs.cs125.questioner.antlr.JavaLexer
import edu.illinois.cs.cs125.questioner.antlr.JavaParser
import edu.illinois.cs.cs125.questioner.lib.AlsoCorrect
import edu.illinois.cs.cs125.questioner.lib.Blacklist
import edu.illinois.cs.cs125.questioner.lib.CheckstyleSuppress
import edu.illinois.cs.cs125.questioner.lib.Cite
import edu.illinois.cs.cs125.questioner.lib.Correct
import edu.illinois.cs.cs125.questioner.lib.Incorrect
Expand Down Expand Up @@ -88,7 +89,7 @@ data class ParsedJavaFile(val path: String, val contents: String) {
}
}
}
).toSet().toList()
).toSet()

val blacklist = topLevelClass.getAnnotations(Blacklist::class.java).let { annotations ->
check(annotations.size <= 1) { "Found multiple @Blacklist annotations" }
Expand All @@ -106,7 +107,25 @@ data class ParsedJavaFile(val path: String, val contents: String) {
}
}
}
}
}.toSet()

val checkstyleSuppress = topLevelClass.getAnnotations(CheckstyleSuppress::class.java).let { annotations ->
check(annotations.size <= 1) { "Found multiple @CheckstyleSuppress annotations" }
if (annotations.isEmpty()) {
listOf()
} else {
annotations.first().let { annotation ->
@Suppress("TooGenericExceptionCaught")
try {
annotation.parameterMap().let { it["suppressions"] ?: error("suppressions field not set on @CheckstyleSuppress") }
} catch (e: Exception) {
error("Couldn't parse @CheckstyleSuppress suppressions for $path: $e")
}.let { names ->
names.split(",").map { it.trim() }
}
}
}
}.toSet()

val templateImports = topLevelClass.getAnnotations(TemplateImports::class.java).let { annotations ->
check(annotations.size <= 1) { "Found multiple @TemplateImports annotations" }
Expand Down
9 changes: 6 additions & 3 deletions plugin/src/main/kotlin/save/SaveQuestions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import edu.illinois.cs.cs125.jenisol.core.Verify
import edu.illinois.cs.cs125.questioner.lib.AlsoCorrect
import edu.illinois.cs.cs125.questioner.lib.Blacklist
import edu.illinois.cs.cs125.questioner.lib.CheckFeatures
import edu.illinois.cs.cs125.questioner.lib.CheckstyleSuppress
import edu.illinois.cs.cs125.questioner.lib.Cite
import edu.illinois.cs.cs125.questioner.lib.Correct
import edu.illinois.cs.cs125.questioner.lib.Ignore
Expand Down Expand Up @@ -427,8 +428,9 @@ fun List<ParsedJavaFile>.findQuestions(
common,
javaTemplate,
kotlinTemplate,
solution.whitelist.toSet(),
solution.blacklist.toSet(),
solution.whitelist,
solution.blacklist,
solution.checkstyleSuppress,
solution.correct.path ?: slugify.slugify(solution.correct.name),
kotlinSolution?.toAlternateFile(kotlinCleanSpec)
)
Expand Down Expand Up @@ -459,7 +461,8 @@ val annotationsToRemove =
Configure::class.java.simpleName,
Cite::class.java.simpleName,
Limit::class.java.simpleName,
ProvideSystemIn::class.java.simpleName
ProvideSystemIn::class.java.simpleName,
CheckstyleSuppress::class.java.simpleName
)
val annotationsToDestroy =
setOf(
Expand Down
6 changes: 3 additions & 3 deletions server/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ dependencies {

implementation(project(":lib"))

implementation("io.ktor:ktor-server-netty:2.1.2")
implementation("io.ktor:ktor-server-content-negotiation:2.1.2")
implementation("io.ktor:ktor-server-netty:2.1.3")
implementation("io.ktor:ktor-server-content-negotiation:2.1.3")
implementation("com.squareup.moshi:moshi-kotlin:1.14.0")
implementation("com.github.cs125-illinois:ktor-moshi:2022.9.0")
implementation("org.mongodb:mongodb-driver:3.12.11")

implementation("org.slf4j:slf4j-api:2.0.3")
implementation("ch.qos.logback:logback-classic:1.4.4")
implementation("io.github.microutils:kotlin-logging:3.0.2")
implementation("io.github.microutils:kotlin-logging:3.0.3")
}
task("createProperties") {
doLast {
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1 @@
version=2022.10.5
version=2022.10.6
6 changes: 6 additions & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,2 +1,8 @@
rootProject.name = "questioner"
include("lib", "plugin", "server")
pluginManagement {
repositories {
mavenCentral()
gradlePluginPortal()
}
}

0 comments on commit a878a7f

Please sign in to comment.