Skip to content

Commit 9bde7fa

Browse files
committed
- make judge inner classpath configurable via env variable
1 parent aa01ca2 commit 9bde7fa

File tree

4 files changed

+17
-12
lines changed

4 files changed

+17
-12
lines changed

src/main/kotlin/com/jalgoarena/ApplicationConfiguration.kt

+10-3
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,17 @@ import com.jalgoarena.codegeneration.JavaCodeGenerator
1111
import com.jalgoarena.compile.InMemoryJavaCompiler
1212
import com.jalgoarena.type.GraphNode
1313
import com.jalgoarena.type.ListNode
14+
import org.springframework.beans.factory.annotation.Value
1415
import org.springframework.context.annotation.Bean
1516
import org.springframework.context.annotation.Configuration
1617
import org.springframework.web.client.RestTemplate
1718

1819
@Configuration
1920
open class ApplicationConfiguration {
2021

22+
@Value("\${jalgoarena.judge.classpath:build/classes/kotlin/main}")
23+
private lateinit var jalgoarenaJudgeClasspath: String
24+
2125
@Bean
2226
open fun objectMapper(): ObjectMapper {
2327
val objectMapper = jacksonObjectMapper()
@@ -36,11 +40,14 @@ open class ApplicationConfiguration {
3640
}
3741

3842
@Bean
39-
open fun restTemplate() = RestTemplate()
43+
open fun restTemplate() =
44+
RestTemplate()
4045

4146
@Bean
42-
open fun javaCompiler() = InMemoryJavaCompiler()
47+
open fun javaCompiler() =
48+
InMemoryJavaCompiler(jalgoarenaJudgeClasspath)
4349

4450
@Bean
45-
open fun javaCodeGenerator() = JavaCodeGenerator()
51+
open fun javaCodeGenerator() =
52+
JavaCodeGenerator()
4653
}

src/main/kotlin/com/jalgoarena/compile/InMemoryJavaCompiler.kt

+5-8
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,9 @@ import java.io.IOException
77
import java.nio.CharBuffer
88
import javax.tools.*
99

10-
open class InMemoryJavaCompiler : JvmCompiler {
10+
open class InMemoryJavaCompiler(
11+
private val jalgoarenaJudgeClasspath: String = "build/classes/kotlin/main"
12+
) : JvmCompiler {
1113

1214
private val logger = LoggerFactory.getLogger(this.javaClass)
1315

@@ -71,22 +73,17 @@ open class InMemoryJavaCompiler : JvmCompiler {
7173
private fun buildClassPath(): String {
7274
val classpath = mutableListOf<String>()
7375

74-
addToClassPath(classpath, "build/classes/kotlin/main")
76+
addToClassPath(classpath, jalgoarenaJudgeClasspath)
7577

7678
val result = classpath.joinToString(File.pathSeparator)
7779
logger.info("Classpath: $result")
7880
return result
7981
}
8082

8183
private fun addToClassPath(classpath: MutableList<String>, path: String) {
82-
val dockerPath = "/app/$path"
83-
val nomadPath = "local/$path"
84-
8584
when {
8685
File(path).exists() -> classpath.add(File(path).absolutePath)
87-
File(dockerPath).exists() -> classpath.add(File(dockerPath).absolutePath)
88-
File(nomadPath).exists() -> classpath.add(File(nomadPath).absolutePath)
89-
else -> logger.warn("[err] Could not find any of paths: [$path, $dockerPath, $nomadPath]")
86+
else -> logger.warn("[err] Could not find class path: $path")
9087
}
9188
}
9289

src/main/resources/application.yml

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ server:
77
jalgoarena:
88
problems:
99
source: ${PROBLEMS_SOURCE:problems.json}
10+
jude:
11+
classpath: ${JUDGE_CLASSPATH:build/classes/kotlin/main}
1012

1113
spring:
1214
kafka:

src/test/kotlin/com/jalgoarena/config/TestApplicationConfiguration.kt

-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package com.jalgoarena.config
33
import com.fasterxml.jackson.databind.ObjectMapper
44
import com.jalgoarena.ApplicationConfiguration
55
import com.jalgoarena.codegeneration.JavaCodeGenerator
6-
import com.jalgoarena.codegeneration.JvmCodeGenerator
76
import com.jalgoarena.compile.InMemoryJavaCompiler
87
import com.jalgoarena.data.JsonProblemsRepository
98
import com.jalgoarena.data.ProblemsRepository

0 commit comments

Comments
 (0)