| import os |
| import tempfile |
| from src.safe_subprocess import run |
| from pathlib import Path |
| from src.generic_eval import main |
|
|
| LANG_NAME = "Java" |
| LANG_EXT = ".java" |
|
|
| |
| |
| |
| |
|
|
| def eval_script(path: Path): |
|
|
| sys_env = os.environ.copy() |
| javatuples_path = Path("/usr/multiple/javatuples-1.2.jar") |
|
|
| sys_env["CLASSPATH"] = f"{javatuples_path}" |
|
|
| with tempfile.TemporaryDirectory() as outdir: |
| |
| |
| |
| |
| result = run(["javac", "-encoding", "UTF8", "-d", outdir, path], env=sys_env) |
| |
| if result.exit_code != 0: |
| |
| |
| status = "SyntaxError" |
| else: |
| result = run(["java", "-ea", "-cp", f"{outdir}:{javatuples_path}", "Problem"], env = sys_env) |
| if result.timeout: |
| status = "Timeout" |
| elif result.exit_code == 0: |
| status = "OK" |
| else: |
| status = "Exception" |
|
|
| return { |
| "status": status, |
| "exit_code": result.exit_code, |
| "stdout": result.stdout, |
| "stderr": result.stderr, |
| } |
|
|
| if __name__ == "__main__": |
| main(eval_script, LANG_NAME, LANG_EXT) |
|
|