feat(judger,web): drop Java7, add Java11 with OpenJDK

Java 7 is now out of support. A large number of people use Java 8.
As the latest Java LTS version, now add support for Java 11.
Due to the policies from Oracle, SunJDK is replaced.
This commit is contained in:
Masco Skray 2019-06-28 16:00:10 +08:00
parent d650f87f32
commit d030c261b2
6 changed files with 53 additions and 38 deletions

View File

@ -592,12 +592,12 @@ struct RunProgramConfig {
type = "python2.7";
} else if (lang == "Python3") {
type = "python3";
} else if (lang == "Java7") {
program_name += "." + conf_str(name + "_main_class");
type = "java7";
} 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);
@ -1159,19 +1159,6 @@ RunCompilerResult compile_python3(const string &name, const string &path = work_
return run_compiler(path.c_str(),
"/usr/bin/python3", "-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_java7(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(),
(main_path + "/run/runtime/jdk1.7.0/bin/javac").c_str(), (main_class + ".java").c_str(), NULL);
}
RunCompilerResult compile_java8(const string &name, const string &path = work_path) {
RunCompilerResult ret = prepare_java_source(name, path);
if (!ret.succeeded)
@ -1183,7 +1170,20 @@ RunCompilerResult compile_java8(const string &name, const string &path = work_pa
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(),
(main_path + "/run/runtime/jdk1.8.0/bin/javac").c_str(), (main_class + ".java").c_str(), NULL);
"/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) {
@ -1212,12 +1212,12 @@ RunCompilerResult compile(const char *name) {
if (lang == "Python3") {
return compile_python3(name);
}
if (lang == "Java7") {
return compile_java7(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,7 +221,7 @@ void parse_args(int argc, char **argv) {
}
}
if (run_program_config.type == "java7" || run_program_config.type == "java8") {
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]);
@ -242,11 +242,11 @@ void parse_args(int argc, char **argv) {
} else if (run_program_config.type == "python3") {
string pre[3] = {"/usr/bin/python3", "-I", "-B"};
run_program_config.argv.insert(run_program_config.argv.begin(), pre, pre + 3);
} else if (run_program_config.type == "java7") {
string pre[3] = {abspath(0, string(self_path) + "/../runtime/jdk1.7.0/bin/java"), "-Xmx1024m", "-Xss1024m"};
run_program_config.argv.insert(run_program_config.argv.begin(), pre, pre + 3);
} else if (run_program_config.type == "java8") {
string pre[3] = {abspath(0, string(self_path) + "/../runtime/jdk1.8.0/bin/java"), "-Xmx1024m", "-Xss1024m"};
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

@ -296,7 +296,7 @@ void init_conf(const RunProgramConfig &config) {
}
statable_file_name_set.insert(config.work_path + "/");
if (config.type != "java7" && config.type != "java8") {
if (config.type != "java8" && config.type != "java11") {
add_file_permission(config.program_name, 'r');
} else {
int p = config.program_name.find('.');
@ -398,12 +398,10 @@ void init_conf(const RunProgramConfig &config) {
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
statable_file_name_set.insert("/usr/lib/python36.zip");
# endif
} else if (config.type == "java7") {
} else if (config.type == "java8") {
syscall_max_cnt[__NR_gettid ] = -1;
syscall_max_cnt[__NR_set_tid_address] = 1;
# ifndef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_set_robust_list] = 14;
# endif
syscall_max_cnt[__NR_futex ] = -1;
syscall_max_cnt[__NR_uname ] = 1;
@ -435,20 +433,20 @@ void init_conf(const RunProgramConfig &config) {
soft_ban_file_name_set.insert("/etc/nsswitch.conf");
soft_ban_file_name_set.insert("/etc/passwd");
add_file_permission(abspath(0, string(self_path) + "/../runtime/jdk1.7.0") + "/", 'r');
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/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 == "java8") {
} else if (config.type == "java11") {
syscall_max_cnt[__NR_gettid ] = -1;
syscall_max_cnt[__NR_set_tid_address] = 1;
# ifndef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_set_robust_list] = 15;
# endif
syscall_max_cnt[__NR_futex ] = -1;
syscall_max_cnt[__NR_uname ] = 1;
@ -470,6 +468,11 @@ void init_conf(const RunProgramConfig &config) {
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;
# endif
syscall_should_soft_ban[__NR_socket ] = true;
@ -480,15 +483,21 @@ void init_conf(const RunProgramConfig &config) {
soft_ban_file_name_set.insert("/etc/nsswitch.conf");
soft_ban_file_name_set.insert("/etc/passwd");
add_file_permission(abspath(0, string(self_path) + "/../runtime/jdk1.8.0") + "/", 'r');
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/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;
@ -530,6 +539,10 @@ void init_conf(const RunProgramConfig &config) {
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
syscall_max_cnt[__NR_prlimit64 ] = -1;
syscall_max_cnt[__NR_getrandom ] = -1;
syscall_max_cnt[__NR_pread64 ] = -1;
syscall_max_cnt[__NR_prctl ] = -1;
syscall_max_cnt[__NR_nanosleep ] = -1;
syscall_max_cnt[__NR_socketpair ] = -1;
# endif
syscall_should_soft_ban[__NR_socket ] = true; // for javac
@ -544,6 +557,8 @@ void init_conf(const RunProgramConfig &config) {
readable_file_name_set.insert(abspath(0, string(self_path) + "/../runtime") + "/");
# ifdef UOJ_JUDGER_BASESYSTEM_UBUNTU1804
readable_file_name_set.insert("/sys/fs/cgroup/cpu/");
readable_file_name_set.insert("/sys/fs/cgroup/memory/");
readable_file_name_set.insert("/etc/oracle/java/usagetracker.properties");
# endif

View File

@ -406,8 +406,8 @@ function echoSubmissionContent($submission, $requirement) {
case 'Python3':
$sh_class = 'sh_python';
break;
case 'Java7':
case 'Java8':
case 'Java11':
$sh_class = 'sh_java';
break;
case 'C':

View File

@ -1,6 +1,6 @@
<?php
global $uojSupportedLanguages, $uojMainJudgerWorkPath;
$uojSupportedLanguages = array('C++', 'Python2.7', 'Java7', 'C++11', 'Python3', 'Java8', 'C', 'Pascal');
$uojSupportedLanguages = array('C++', 'Python2.7', 'Java8', 'C++11', 'Python3', 'Java11', 'C', 'Pascal');
$uojMainJudgerWorkPath = "/home/local_main_judger/judge_client/uoj_judger";
function authenticateJudger() {

View File

@ -607,8 +607,8 @@ function get_codemirror_mode(lang) {
case 'Python2.7':
case 'Python3':
return 'text/x-python';
case 'Java7':
case 'Java8':
case 'Java11':
return 'text/x-java';
case 'Pascal':
return 'text/x-pascal';
@ -714,7 +714,7 @@ $.fn.source_code_form_group = function(name, text, langs_options_html) {
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() == 'Java7' || $(this).val() == 'Java8') {
if ($(this).val() == 'Java8' || $(this).val() == 'Java11') {
div_help_language.text('注意Java 程序源代码中不应指定所在的 package。我们会在源代码中找到第一个被定义的类并以它的 main 函数为程序入口点。');
} else {
div_help_language.text('');