Skip to content

Commit bca28ef

Browse files
authored
Add support for debugging grading process (#295)
* Add enableDebug to GraderConfiguration * Work on support for jvm debugging * Update copyrights
1 parent 6836382 commit bca28ef

File tree

7 files changed

+43
-20
lines changed

7 files changed

+43
-20
lines changed

core/src/main/kotlin/org/sourcegrade/jagr/core/CommonModule.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -88,7 +88,7 @@ class CommonModule(private val configuration: LaunchConfiguration) : AbstractMod
8888
with(Multibinder.newSetBinder(binder(), RuntimeTester::class.java)) {
8989
addBinding().to(JavaRuntimeTester::class.java)
9090
}
91-
bind(RuntimeInvoker::class.java).toInstance(configuration.runtimeInvoker)
91+
bind(RuntimeInvoker::class.java).toInstance(configuration.runtimeInvokerFactory.create(configuration.logger))
9292
bind(SerializerFactory.Locator::class.java).to(SerializationFactoryLocatorImpl::class.java)
9393
bind(SubmissionExporter.Eclipse::class.java).to(EclipseSubmissionExporter::class.java)
9494
bind(SubmissionExporter.Gradle::class.java).to(GradleSubmissionExporter::class.java)

launcher/gradle-plugin/src/main/kotlin/org/sourcegrade/jagr/gradle/extension/GraderConfiguration.kt

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -30,6 +30,7 @@ import org.gradle.kotlin.dsl.getByType
3030
import org.gradle.kotlin.dsl.property
3131
import org.sourcegrade.jagr.launcher.env.Config
3232
import org.sourcegrade.jagr.launcher.env.Jagr
33+
import org.sourcegrade.jagr.launcher.env.copyExecutor
3334
import org.sourcegrade.jagr.launcher.env.copyTimeout
3435
import org.sourcegrade.jagr.launcher.env.copyTransformers
3536

@@ -131,4 +132,13 @@ abstract class GraderConfiguration(
131132
fun disableTimeouts() = mutateConfig {
132133
copyTransformers { copyTimeout { copy(enabled = false) } }
133134
}
135+
136+
fun enableDebug(port: Int = 5005) = mutateConfig {
137+
copyExecutor {
138+
copy(
139+
jvmArgs = jvmArgs +
140+
"-agentlib:jdwp=transport=dt_socket,server=n,address=localhost:$port,suspend=y",
141+
)
142+
}
143+
}
134144
}

launcher/gradle-plugin/src/main/kotlin/org/sourcegrade/jagr/gradle/task/grader/GradleLaunchConfiguration.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -37,5 +37,8 @@ internal class GradleLaunchConfiguration(
3737
"log4j2-console-only.xml",
3838
).getLogger("jagr")
3939
}
40-
override val runtimeInvoker: RuntimeInvoker = RuntimeJarInvoker(jagrJar, config.executor.jvmArgs)
40+
41+
override val runtimeInvokerFactory: RuntimeInvoker.Factory = RuntimeInvoker.Factory { jagr ->
42+
RuntimeJarInvoker(jagr, jagrJar, config.executor.jvmArgs)
43+
}
4144
}

launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/env/LaunchConfiguration.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -30,7 +30,7 @@ import java.io.File
3030
interface LaunchConfiguration {
3131
val config: Config
3232
val logger: Logger
33-
val runtimeInvoker: RuntimeInvoker
33+
val runtimeInvokerFactory: RuntimeInvoker.Factory
3434

3535
object Standard : LaunchConfiguration {
3636
override val config: Config by lazy {
@@ -57,6 +57,6 @@ interface LaunchConfiguration {
5757
override val logger: Logger by lazy {
5858
LogManager.getLogger("Jagr")
5959
}
60-
override val runtimeInvoker: RuntimeInvoker = RuntimeJarInvoker()
60+
override val runtimeInvokerFactory: RuntimeInvoker.Factory = RuntimeInvoker.Factory { jagr -> RuntimeJarInvoker(jagr) }
6161
}
6262
}

launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/env/SystemResourceJagrFactory.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -19,7 +19,6 @@
1919

2020
package org.sourcegrade.jagr.launcher.env
2121

22-
import kotlinx.serialization.decodeFromString
2322
import kotlinx.serialization.json.Json
2423

2524
object SystemResourceJagrFactory : Jagr.Factory {

launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/executor/RuntimeInvoker.kt

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -19,7 +19,13 @@
1919

2020
package org.sourcegrade.jagr.launcher.executor
2121

22+
import org.apache.logging.log4j.Logger
23+
2224
interface RuntimeInvoker {
2325
// TODO: For now use Process, later use a custom interface to abstract communication
2426
fun createRuntime(): Process
27+
28+
fun interface Factory {
29+
fun create(logger: Logger): RuntimeInvoker
30+
}
2531
}

launcher/src/main/kotlin/org/sourcegrade/jagr/launcher/executor/RuntimeJarInvoker.kt

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* Jagr - SourceGrade.org
3-
* Copyright (C) 2021-2022 Alexander Staeding
4-
* Copyright (C) 2021-2022 Contributors
3+
* Copyright (C) 2021-2025 Alexander Städing
4+
* Copyright (C) 2021-2025 Contributors
55
*
66
* This program is free software: you can redistribute it and/or modify
77
* it under the terms of the GNU Affero General Public License as published by
@@ -19,11 +19,13 @@
1919

2020
package org.sourcegrade.jagr.launcher.executor
2121

22+
import org.apache.logging.log4j.Logger
2223
import java.nio.file.Path
2324
import java.nio.file.Paths
2425
import kotlin.io.path.pathString
2526

2627
class RuntimeJarInvoker(
28+
private val logger: Logger,
2729
private val jagrLocation: Path = Paths.get(RuntimeJarInvoker::class.java.protectionDomain.codeSource.location.toURI()),
2830
private val jvmArgs: List<String> = emptyList(),
2931
) : RuntimeInvoker {
@@ -37,5 +39,8 @@ class RuntimeJarInvoker(
3739
add("--child")
3840
}
3941

40-
override fun createRuntime(): Process = ProcessBuilder().command(commands).start()
42+
override fun createRuntime(): Process {
43+
logger.info("Starting process $commands")
44+
return ProcessBuilder().command(commands).start()
45+
}
4146
}

0 commit comments

Comments
 (0)