chore(judger): drop java support

This commit is contained in:
Baoshuo Ren 2022-03-16 21:12:09 +08:00
parent 8ce32618b6
commit dcea523cfc
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
7 changed files with 15 additions and 358 deletions

View File

@ -592,12 +592,6 @@ struct RunProgramConfig {
type = "python2";
} else if (lang == "Python3") {
type = "python3";
} else if (lang == "Java8") {
program_name += "." + conf_str(name + "_main_class");
type = "java8";
} else if (lang == "Java11") {
program_name += "." + conf_str(name + "_main_class");
type = "java11";
}
set_argv(program_name.c_str(), NULL);
@ -977,163 +971,6 @@ bool has_illegal_keywords_in_file(const string &name) {
return false;
}
RunCompilerResult prepare_java_source(const string &name, const string &path = work_path) {
FILE *f = fopen((path + "/" + name + ".code").c_str(), "r");
const int L = 1024;
std::string s;
char buf[L + 1];
int mode = 0;
while (!feof(f)) {
buf[fread(buf, 1, L, f)] = '\0';
for (char *p = buf; *p; p++) {
s += *p;
switch (mode) {
case 0:
switch (*p) {
case '/':
mode = 1;
break;
case '\'':
mode = 5;
break;
case '\"':
mode = 6;
break;
}
break;
case 1:
switch (*p) {
case '/':
mode = 2;
s.resize(s.length() - 2);
break;
case '*':
mode = 3;
s.resize(s.length() - 2);
break;
}
break;
case 2:
s.resize(s.length() - 1);
switch (*p) {
case '\n':
s += '\n';
mode = 0;
break;
}
break;
case 3:
s.resize(s.length() - 1);
switch (*p) {
case '*':
mode = 4;
break;
}
break;
case 4:
s.resize(s.length() - 1);
switch (*p) {
case '/':
s += ' ';
mode = 0;
break;
}
break;
case 5:
switch (*p) {
case '\'':
mode = 0;
break;
case '\\':
mode = 7;
break;
}
case 6:
switch (*p) {
case '\"':
mode = 0;
break;
case '\\':
mode = 8;
break;
}
case 7:
mode = 5;
break;
case 8:
mode = 6;
break;
}
}
}
bool valid[256];
fill(valid, valid + 256, false);
for (int c = 'a'; c <= 'z'; c++)
valid[c] = true;
for (int c = 'A'; c <= 'Z'; c++)
valid[c] = true;
valid['.'] = true;
valid['_'] = true;
vector<string> tokens;
for (int p = 0, np = 0; p < (int)s.length(); p = np) {
while (np < (int)s.length() && valid[(unsigned char)s[np]]) {
np++;
}
if (np == p) {
np++;
} else {
tokens.push_back(s.substr(p, np - p));
}
}
if (tokens.size() > 0 && tokens[0] == "package") {
RunCompilerResult res;
res.type = RS_WA;
res.ust = -1;
res.usm = -1;
res.succeeded = false;
res.info = "Please don't specify the package.";
return res;
}
for (int i = 0; i + 1 < (int)tokens.size(); i++) {
if (tokens[i] == "class") {
if (tokens[i + 1].length() <= 100) {
config[name + "_main_class"] = tokens[i + 1];
RunCompilerResult res;
res.type = RS_AC;
res.ust = 0;
res.usm = 0;
res.succeeded = true;
return res;
} else {
RunCompilerResult res;
res.type = RS_WA;
res.ust = -1;
res.usm = -1;
res.succeeded = false;
res.info = "The name of the main class is too long.";
return res;
}
}
}
RunCompilerResult res;
res.type = RS_WA;
res.ust = -1;
res.usm = -1;
res.succeeded = false;
res.info = "Can't find the main class.";
return res;
}
RunCompilerResult compile_c(const string &name, const string &path = work_path) {
return run_compiler(path.c_str(),
"/usr/bin/gcc", "-o", name.c_str(), "-x", "c", (name + ".code").c_str(), "-lm", "-O2", "-DONLINE_JUDGE", NULL);
@ -1159,32 +996,6 @@ RunCompilerResult compile_python3(const string &name, const string &path = work_
return run_compiler(path.c_str(),
"/usr/bin/python3.8", "-I", "-B", "-O", "-c", ("import py_compile\nimport sys\ntry:\n py_compile.compile('" + name + ".code'" + ", '" + name + "', doraise=True)\n sys.exit(0)\nexcept Exception as e:\n print(e)\n sys.exit(1)").c_str(), NULL);
}
RunCompilerResult compile_java8(const string &name, const string &path = work_path) {
RunCompilerResult ret = prepare_java_source(name, path);
if (!ret.succeeded)
return ret;
string main_class = conf_str(name + "_main_class");
executef("rm %s/%s -rf 2>/dev/null; mkdir %s/%s", path.c_str(), name.c_str(), path.c_str(), name.c_str());
executef("echo package %s\\; | cat - %s/%s.code >%s/%s/%s.java", name.c_str(), path.c_str(), name.c_str(), path.c_str(), name.c_str(), main_class.c_str());
return run_compiler((path + "/" + name).c_str(),
"/usr/lib/jvm/java-8-openjdk-amd64/bin/javac", (main_class + ".java").c_str(), NULL);
}
RunCompilerResult compile_java11(const string &name, const string &path = work_path) {
RunCompilerResult ret = prepare_java_source(name, path);
if (!ret.succeeded)
return ret;
string main_class = conf_str(name + "_main_class");
executef("rm %s/%s -rf 2>/dev/null; mkdir %s/%s", path.c_str(), name.c_str(), path.c_str(), name.c_str());
executef("echo package %s\\; | cat - %s/%s.code >%s/%s/%s.java", name.c_str(), path.c_str(), name.c_str(), path.c_str(), name.c_str(), main_class.c_str());
return run_compiler((path + "/" + name).c_str(),
"/usr/lib/jvm/java-11-openjdk-amd64/bin/javac", (main_class + ".java").c_str(), NULL);
}
RunCompilerResult compile(const char *name) {
string lang = conf_str(string(name) + "_language");
@ -1212,12 +1023,6 @@ RunCompilerResult compile(const char *name) {
if (lang == "Python3") {
return compile_python3(name);
}
if (lang == "Java8") {
return compile_java8(name);
}
if (lang == "Java11") {
return compile_java11(name);
}
if (lang == "C") {
return compile_c(name);
}

View File

@ -221,11 +221,8 @@ void parse_args(int argc, char **argv) {
}
}
if (run_program_config.type == "java8" || run_program_config.type == "java11") {
run_program_config.program_name = run_program_config.argv[0];
} else {
run_program_config.program_name = realpath(run_program_config.argv[0]);
}
if (run_program_config.work_path.empty()) {
run_program_config.work_path = dirname(run_program_config.program_name);
run_program_config.program_basename = basename(run_program_config.program_name);
@ -242,12 +239,6 @@ void parse_args(int argc, char **argv) {
} else if (run_program_config.type == "python3") {
string pre[3] = {"/usr/bin/python3.8", "-I", "-B"};
run_program_config.argv.insert(run_program_config.argv.begin(), pre, pre + 3);
} else if (run_program_config.type == "java8") {
string pre[3] = {"/usr/lib/jvm/java-8-openjdk-amd64/bin/java", "-Xmx1024m", "-Xss1024m"};
run_program_config.argv.insert(run_program_config.argv.begin(), pre, pre + 3);
} else if (run_program_config.type == "java11") {
string pre[3] = {"/usr/lib/jvm/java-11-openjdk-amd64/bin/java", "-Xmx1024m", "-Xss1024m"};
run_program_config.argv.insert(run_program_config.argv.begin(), pre, pre + 3);
}
}

View File

@ -297,16 +297,7 @@ void init_conf(const RunProgramConfig &config) {
}
statable_file_name_set.insert(config.work_path + "/");
if (config.type != "java8" && config.type != "java11") {
add_file_permission(config.program_name, 'r');
} else {
int p = config.program_name.find('.');
if (p == string::npos) {
readable_file_name_set.insert(config.work_path + "/");
} else {
readable_file_name_set.insert(config.work_path + "/" + config.program_name.substr(0, p) + "/");
}
}
add_file_permission(config.work_path, 'r');
for (vector<string>::const_iterator it = config.extra_readable_files.begin(); it != config.extra_readable_files.end(); it++) {
@ -398,112 +389,6 @@ void init_conf(const RunProgramConfig &config) {
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
statable_file_name_set.insert("/usr/lib/python38.zip");
# endif
} else if (config.type == "java8") {
syscall_max_cnt[__NR_gettid ] = -1;
syscall_max_cnt[__NR_set_tid_address] = 1;
syscall_max_cnt[__NR_set_robust_list] = 14;
syscall_max_cnt[__NR_futex ] = -1;
syscall_max_cnt[__NR_uname ] = 1;
syscall_max_cnt[__NR_clone ] = 13;
syscall_max_cnt[__NR_getdents ] = 4;
syscall_max_cnt[__NR_getdents64 ] = 4;
syscall_max_cnt[__NR_clock_getres ] = 2;
syscall_max_cnt[__NR_setrlimit ] = 1;
syscall_max_cnt[__NR_sched_getaffinity] = -1;
syscall_max_cnt[__NR_sched_yield ] = -1;
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_prlimit64 ] = -1;
syscall_max_cnt[__NR_getpid ] = -1;
syscall_max_cnt[__NR_sysinfo ] = -1;
syscall_max_cnt[__NR_clone ] = -1;
syscall_max_cnt[__NR_set_robust_list] = -1;
syscall_max_cnt[__NR_prctl ] = -1;
# endif
syscall_should_soft_ban[__NR_socket ] = true;
syscall_should_soft_ban[__NR_connect ] = true;
syscall_should_soft_ban[__NR_geteuid ] = true;
syscall_should_soft_ban[__NR_getuid ] = true;
soft_ban_file_name_set.insert("/etc/nsswitch.conf");
soft_ban_file_name_set.insert("/etc/passwd");
add_file_permission("/usr/lib/jvm/java-8-openjdk-amd64/", 'r');
readable_file_name_set.insert("/sys/devices/system/cpu/");
readable_file_name_set.insert("/proc/");
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
readable_file_name_set.insert("/sys/fs/cgroup/cpu/");
readable_file_name_set.insert("/sys/fs/cgroup/cpu,cpuacct/");
readable_file_name_set.insert("/sys/fs/cgroup/memory/");
readable_file_name_set.insert("/usr/lib/locale/");
# endif
statable_file_name_set.insert("/usr/java/");
statable_file_name_set.insert("/tmp/");
} else if (config.type == "java11") {
syscall_max_cnt[__NR_gettid ] = -1;
syscall_max_cnt[__NR_set_tid_address] = 1;
syscall_max_cnt[__NR_set_robust_list] = 15;
syscall_max_cnt[__NR_futex ] = -1;
syscall_max_cnt[__NR_uname ] = 1;
syscall_max_cnt[__NR_clone ] = 14;
syscall_max_cnt[__NR_getdents ] = 4;
syscall_max_cnt[__NR_getdents64 ] = 4;
syscall_max_cnt[__NR_clock_getres ] = 2;
syscall_max_cnt[__NR_setrlimit ] = 1;
syscall_max_cnt[__NR_sched_getaffinity] = -1;
syscall_max_cnt[__NR_sched_yield ] = -1;
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_prlimit64 ] = -1;
syscall_max_cnt[__NR_getpid ] = -1;
syscall_max_cnt[__NR_sysinfo ] = -1;
syscall_max_cnt[__NR_clone ] = -1;
syscall_max_cnt[__NR_set_robust_list] = -1;
syscall_max_cnt[__NR_uname ] = -1;
syscall_max_cnt[__NR_clock_getres ] = -1;
syscall_max_cnt[__NR_pread64 ] = -1;
syscall_max_cnt[__NR_prctl ] = -1;
syscall_max_cnt[__NR_nanosleep ] = -1;
syscall_max_cnt[__NR_clock_nanosleep] = -1;
# endif
syscall_should_soft_ban[__NR_socket ] = true;
syscall_should_soft_ban[__NR_connect ] = true;
syscall_should_soft_ban[__NR_geteuid ] = true;
syscall_should_soft_ban[__NR_getuid ] = true;
soft_ban_file_name_set.insert("/etc/nsswitch.conf");
soft_ban_file_name_set.insert("/etc/passwd");
add_file_permission("/usr/lib/jvm/java-11-openjdk-amd64/", 'r');
readable_file_name_set.insert("/sys/devices/system/cpu/");
readable_file_name_set.insert("/proc/");
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
readable_file_name_set.insert("/sys/fs/cgroup/cpu/");
readable_file_name_set.insert("/sys/fs/cgroup/cpu,cpuacct/");
readable_file_name_set.insert("/sys/fs/cgroup/memory/");
readable_file_name_set.insert("/usr/share/java/");
readable_file_name_set.insert("/usr/lib/locale/");
readable_file_name_set.insert("/etc/oracle/java/usagetracker.properties");
# endif
statable_file_name_set.insert("/usr/java/");
statable_file_name_set.insert("/tmp/");
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
statable_file_name_set.insert("/usr/share/");
# endif
} else if (config.type == "compiler") {
syscall_max_cnt[__NR_gettid ] = -1;
syscall_max_cnt[__NR_set_tid_address] = -1;
@ -535,13 +420,13 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_chdir ] = -1;
syscall_max_cnt[__NR_fchdir ] = -1;
syscall_max_cnt[__NR_ftruncate ] = -1; // for javac = =
syscall_max_cnt[__NR_ftruncate ] = -1;
syscall_max_cnt[__NR_sched_getaffinity] = -1; // for javac = =
syscall_max_cnt[__NR_sched_yield ] = -1; // for javac = =
syscall_max_cnt[__NR_sched_getaffinity] = -1;
syscall_max_cnt[__NR_sched_yield ] = -1;
syscall_max_cnt[__NR_uname ] = -1; // for javac = =
syscall_max_cnt[__NR_sysinfo ] = -1; // for javac = =
syscall_max_cnt[__NR_uname ] = -1;
syscall_max_cnt[__NR_sysinfo ] = -1;
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_prlimit64 ] = -1;
@ -553,10 +438,10 @@ void init_conf(const RunProgramConfig &config) {
syscall_max_cnt[__NR_socketpair ] = -1;
# endif
syscall_should_soft_ban[__NR_socket ] = true; // for javac
syscall_should_soft_ban[__NR_connect ] = true; // for javac
syscall_should_soft_ban[__NR_geteuid ] = true; // for javac
syscall_should_soft_ban[__NR_getuid ] = true; // for javac
syscall_should_soft_ban[__NR_socket ] = true;
syscall_should_soft_ban[__NR_connect ] = true;
syscall_should_soft_ban[__NR_geteuid ] = true;
syscall_should_soft_ban[__NR_getuid ] = true;
writable_file_name_set.insert("/tmp/");
@ -582,8 +467,8 @@ void init_conf(const RunProgramConfig &config) {
readable_file_name_set.insert("/sys/devices/system/cpu/");
readable_file_name_set.insert("/proc/");
soft_ban_file_name_set.insert("/etc/nsswitch.conf"); // for javac = =
soft_ban_file_name_set.insert("/etc/passwd"); // for javac = =
soft_ban_file_name_set.insert("/etc/nsswitch.conf");
soft_ban_file_name_set.insert("/etc/passwd");
readable_file_name_set.insert("/etc/timezone");
# ifdef UOJ_JUDGER_FPC_VERSION

View File

@ -50,8 +50,6 @@
<p>默认的测评环境是 Ubuntu Linux 20.04 LTS x64。</p>
<p>C的编译器是 gcc 9.4.0,编译命令:<code>gcc code.c -o code -lm -O2 -DONLINE_JUDGE</code></p>
<p>C++的编译器是 g++ 9.4.0,编译命令:<code>g++ code.cpp -o code -lm -O2 -DONLINE_JUDGE</code>。如果选择C++11会在编译命令后面添加<code>-std=c++11</code></p>
<p>Java8的JDK版本是 openjdk 1.8.0_312,编译命令:<code>javac code.java</code></p>
<p>Java11的JDK版本是 openjdk 11.0.14,编译命令:<code>javac code.java</code></p>
<p>Pascal的编译器是 fpc 3.0.4,编译命令:<code>fpc code.pas -O2</code></p>
<p>Python会先编译为优化过的字节码<samp>.pyo</samp>文件。支持的Python版本分别为Python 2.7和3.8</p>
</div>

View File

@ -457,10 +457,6 @@ HTML;
case 'Python3':
$sh_class = 'sh_python';
break;
case 'Java8':
case 'Java11':
$sh_class = 'sh_java';
break;
case 'C':
$sh_class = 'sh_c';
break;
@ -509,10 +505,6 @@ function echoSubmissionContent($submission, $requirement) {
case 'Python3':
$sh_class = 'sh_python';
break;
case 'Java8':
case 'Java11':
$sh_class = 'sh_java';
break;
case 'C':
$sh_class = 'sh_c';
break;

View File

@ -1,6 +1,6 @@
<?php
global $uojSupportedLanguages, $uojMainJudgerWorkPath;
$uojSupportedLanguages = array('C', 'C++', 'C++11', 'Java8', 'Java11', 'Pascal', 'Python2', 'Python3');
$uojSupportedLanguages = array('C', 'C++', 'C++11', 'Pascal', 'Python2', 'Python3');
$uojMainJudgerWorkPath = "/opt/uoj/judger/uoj_judger";
function authenticateJudger() {

View File

@ -607,9 +607,6 @@ function get_codemirror_mode(lang) {
case 'Python2':
case 'Python3':
return 'text/x-python';
case 'Java8':
case 'Java11':
return 'text/x-java';
case 'Pascal':
return 'text/x-pascal';
case 'text':
@ -623,7 +620,6 @@ function require_codemirror_mode(mode, callback) {
switch (mode) {
case 'text/x-c++src':
case 'text/x-csrc':
case 'text/x-java':
name = 'clike';
break;
case 'text/x-python':
@ -713,14 +709,6 @@ $.fn.source_code_form_group = function(name, text, langs_options_html) {
.append($('<span class="help-block" id="' + help_file_id + '"></span>'))
var div_help_language = $('<div id="' + div_help_language_id + '" class="col-sm-12 text-warning top-buffer-sm">');
var show_help_lang = function() {
if ($(this).val() == 'Java8' || $(this).val() == 'Java11') {
div_help_language.text('注意Java 程序源代码中不应指定所在的 package。我们会在源代码中找到第一个被定义的类并以它的 main 函数为程序入口点。');
} else {
div_help_language.text('');
}
};
var advanced_editor = null;
var advanced_editor_init = function() {
require_codemirror({}, function() {
@ -770,8 +758,6 @@ $.fn.source_code_form_group = function(name, text, langs_options_html) {
}
}
input_language.each(show_help_lang);
input_language.change(show_help_lang);
input_language.change(function() {
if (advanced_editor != null) {
var mode = get_codemirror_mode(input_language.val());