上传部分漏掉的java文件
This commit is contained in:
parent
f515ccd590
commit
77e8b31392
|
|
@ -13,7 +13,7 @@ import java.util.List;
|
|||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import log.Log;
|
||||
|
||||
import java.nio.file.Paths;
|
||||
public class Config {
|
||||
|
||||
public static int DEBUG;
|
||||
|
|
@ -100,7 +100,12 @@ public class Config {
|
|||
|
||||
//临时代码输出路径 若要改回配置文件读取 从const里获取字段
|
||||
public static String getSourcePath() {
|
||||
return "./test"; //
|
||||
String curDir = Paths.get(".").toAbsolutePath().normalize().toString();
|
||||
return curDir+"/test";
|
||||
}
|
||||
public static String getLogPath(){
|
||||
String curDir = Paths.get(".").toAbsolutePath().normalize().toString();
|
||||
return curDir+"/log";
|
||||
}
|
||||
//临时代码输出路径
|
||||
|
||||
|
|
@ -108,7 +113,8 @@ public class Config {
|
|||
// if (isTestRelative) {
|
||||
// return System.getProperty("user.dir") + prop.getProperty("relativeExeDir");
|
||||
// } else {
|
||||
return "./test";
|
||||
String curDir = Paths.get(".").toAbsolutePath().normalize().toString();
|
||||
return curDir+"/test";
|
||||
//}
|
||||
|
||||
}
|
||||
|
|
@ -116,28 +122,29 @@ public class Config {
|
|||
public static String getCompilerDir(String language,String compiler) {
|
||||
String dir = null;
|
||||
//todo
|
||||
if (language.equals("c") || language.equals("cpp") || language.equals("c++")) {
|
||||
dir=LangSelector.getCompilerPath("C++", compiler);
|
||||
dir=LangSelector.getCompilerPath(language,compiler);
|
||||
//if (language.equals("c") || language.equals("cpp") || language.equals("c++")) {
|
||||
// dir=LangSelector.getCompilerPath("C++", compiler);
|
||||
//dir = prop.getProperty(Const.MinGWDir);
|
||||
} else if (language.equals("java")) {
|
||||
dir=LangSelector.getCompilerPath("Java", compiler);
|
||||
//} else if (language.equals("java")) {
|
||||
// dir=LangSelector.getCompilerPath("Java", compiler);
|
||||
//dir = prop.getProperty(Const.JavaCompilerDir);
|
||||
}
|
||||
//}
|
||||
return dir;
|
||||
}
|
||||
|
||||
public static String getCompilerDir(String language) {
|
||||
String dir = null;
|
||||
//public static String getCompilerDir(String language) {
|
||||
// String dir = null;
|
||||
//todo
|
||||
if (language.equals("c") || language.equals("cpp") || language.equals("c++")) {
|
||||
dir=LangSelector.getCompilerPath("C++", null);
|
||||
//dir = prop.getProperty(Const.MinGWDir);
|
||||
} else if (language.equals("java")) {
|
||||
dir=LangSelector.getCompilerPath("Java", null);
|
||||
//dir = prop.getProperty(Const.JavaCompilerDir);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
// if (language.equals("c") || language.equals("cpp") || language.equals("c++")) {
|
||||
// dir=LangSelector.getCompilerPath("C++", null);
|
||||
// //dir = prop.getProperty(Const.MinGWDir);
|
||||
// } else if (language.equals("java")) {
|
||||
// dir=LangSelector.getCompilerPath("Java", null);
|
||||
// //dir = prop.getProperty(Const.JavaCompilerDir);
|
||||
// }
|
||||
// return dir;
|
||||
// }
|
||||
public static String CompilerDir(String language,String compiler) {
|
||||
String dir = null;
|
||||
|
||||
|
|
@ -151,17 +158,17 @@ public class Config {
|
|||
}
|
||||
return dir;
|
||||
}
|
||||
public static String CompilerDir(String language) {
|
||||
String dir = null;
|
||||
|
||||
if (language.equals("c") || language.equals("cpp") || language.equals("c++")) //返回各种语言的编译器地址
|
||||
{
|
||||
//dir = System.getProperty("user.dir") + Const.MinGWDir;
|
||||
dir=LangSelector.getCompilerPath("C++",null);
|
||||
} else if (language.equals("java")) {
|
||||
//dir = System.getProperty("user.dir") + Const.JavaCompilerDir;
|
||||
dir=LangSelector.getCompilerPath("Java",null);
|
||||
}
|
||||
return dir;
|
||||
}
|
||||
// public static String CompilerDir(String language) {
|
||||
// String dir = null;
|
||||
//
|
||||
// if (language.equals("c") || language.equals("cpp") || language.equals("c++")) //返回各种语言的编译器地址
|
||||
// {
|
||||
// //dir = System.getProperty("user.dir") + Const.MinGWDir;
|
||||
// dir = LangSelector.getCompilerPath("C++", compiler);
|
||||
// } else if (language.equals("java")) {
|
||||
// //dir = System.getProperty("user.dir") + Const.JavaCompilerDir;
|
||||
// dir = LangSelector.getCompilerPath("Java", null);
|
||||
// }
|
||||
// return dir;
|
||||
// }
|
||||
}
|
||||
|
|
@ -37,6 +37,8 @@ public class Const {
|
|||
return ".cpp";
|
||||
} else if (language.equals("java")) {
|
||||
return ".java";
|
||||
}else if(language.equals("python")){
|
||||
return ".py";
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,12 +5,14 @@ import javax.xml.parsers.DocumentBuilder;
|
|||
import javax.xml.parsers.DocumentBuilderFactory;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
import javax.swing.JOptionPane;
|
||||
|
||||
import javax.xml.xpath.XPath;
|
||||
import javax.xml.xpath.XPathConstants;
|
||||
import javax.xml.xpath.XPathExpression;
|
||||
import javax.xml.xpath.XPathExpressionException;
|
||||
import javax.xml.xpath.XPathFactory;
|
||||
|
||||
|
|
@ -24,12 +26,22 @@ import org.w3c.dom.NodeList;
|
|||
*/
|
||||
public abstract class LangSelector {
|
||||
//
|
||||
private static Map<String,String>customDefaultCompiler;
|
||||
|
||||
public static String getDefaultCompiler(String language) {
|
||||
return customDefaultCompiler.get(language);
|
||||
}
|
||||
|
||||
public static void setDefaultCompiler(String language,String compiler) {
|
||||
customDefaultCompiler.put(language, compiler);
|
||||
}
|
||||
private static String ConfigPath="";
|
||||
private static Document Data;
|
||||
public static boolean Loaded=false;
|
||||
private static XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
static {
|
||||
try {
|
||||
customDefaultCompiler=new HashMap<>();
|
||||
init();
|
||||
Loaded=true;
|
||||
} catch (Exception e) {
|
||||
|
|
@ -69,8 +81,48 @@ public abstract class LangSelector {
|
|||
public static String getConfigPath(){
|
||||
return ConfigPath;
|
||||
}
|
||||
public static String parseStandardLanguageName(String languageName) {
|
||||
try {
|
||||
|
||||
|
||||
// 创建 XPath 对象
|
||||
XPath xpath = XPathFactory.newInstance().newXPath();
|
||||
|
||||
// 编译 XPath 表达式
|
||||
XPathExpression expr = xpath.compile("//language");
|
||||
|
||||
// 评估 XPath 表达式
|
||||
Object result = expr.evaluate(Data, XPathConstants.NODESET);
|
||||
NodeList nodes = (NodeList) result;
|
||||
|
||||
// 遍历每个语言节点
|
||||
for (int i = 0; i < nodes.getLength(); i++) {
|
||||
String id = nodes.item(i).getAttributes().getNamedItem("id").getNodeValue();
|
||||
String aliasString = nodes.item(i).getAttributes().getNamedItem("alias").getNodeValue();
|
||||
String[] aliases = aliasString.split(",");
|
||||
|
||||
// 检查 languageName 是否与 ID 匹配
|
||||
if (id.equalsIgnoreCase(languageName)) {
|
||||
return id;
|
||||
}
|
||||
|
||||
// 检查 languageName 是否与别名匹配
|
||||
for (String alias : aliases) {
|
||||
if (alias.equalsIgnoreCase(languageName)) {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
// 如果没有匹配项,则返回原始 languageName
|
||||
return languageName;
|
||||
}
|
||||
public static String getDefaultCompilerName(String languageName){
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
if(customDefaultCompiler.containsKey(languageName))
|
||||
return customDefaultCompiler.get(languageName);
|
||||
//if(languageName.charAt(0)>='a')languageName
|
||||
try{
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"/compiler[1]/@name";
|
||||
|
|
@ -98,6 +150,8 @@ public abstract class LangSelector {
|
|||
return doc;
|
||||
}
|
||||
public static List<String> getCompilerNames(String languageName){
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
|
||||
ArrayList<String>arrayListStr=new ArrayList<>();
|
||||
try {
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"//compiler";
|
||||
|
|
@ -117,6 +171,7 @@ public abstract class LangSelector {
|
|||
}
|
||||
|
||||
public static String getCompilerPath(String languageName,String compilerName) {
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
if(compilerName==null)compilerName=getDefaultCompilerName(languageName);
|
||||
try{
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"//compiler[@name='"+compilerName+"']//path/text()";
|
||||
|
|
@ -127,6 +182,7 @@ public abstract class LangSelector {
|
|||
}
|
||||
}
|
||||
public static String getCompileCommand(String languageName,String compilerName){
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
if(compilerName==null)compilerName=getDefaultCompilerName(languageName);
|
||||
try{
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"//compiler[@name='"+compilerName+"']//compileCmd/text()";
|
||||
|
|
@ -137,6 +193,7 @@ public abstract class LangSelector {
|
|||
}
|
||||
}
|
||||
public static String getLinkCommand(String languageName,String compilerName){
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
if(compilerName==null)compilerName=getDefaultCompilerName(languageName);
|
||||
try{
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"//compiler[@name='"+compilerName+"']//linkCmd/text()";
|
||||
|
|
@ -147,6 +204,7 @@ public abstract class LangSelector {
|
|||
}
|
||||
}
|
||||
public static String getRunCommand(String languageName,String compilerName){
|
||||
languageName=parseStandardLanguageName(languageName);
|
||||
if(compilerName==null)compilerName=getDefaultCompilerName(languageName);
|
||||
try{
|
||||
String exp="/languages/language"+ "[@id='" +languageName+ "']"+"//compiler[@name='"+compilerName+"']//runCmd/text()";
|
||||
|
|
@ -171,12 +229,12 @@ public abstract class LangSelector {
|
|||
}
|
||||
}
|
||||
public static String matchPlaceHolder(String src, HashMap<String,String>map){
|
||||
if(src==null||src.trim().isEmpty())return null;
|
||||
for (java.util.Map.Entry<String, String> Entry : map.entrySet()) {
|
||||
src = src.replace(Entry.getKey(), Entry.getValue());
|
||||
System.out.println(Entry.getKey() + "已替换:" + Entry.getValue());
|
||||
//System.out.println(Entry.getKey() + "已替换:" + Entry.getValue());
|
||||
}
|
||||
return src;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,20 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package common;
|
||||
|
||||
public enum LogLevel{
|
||||
INFO("INFO"),
|
||||
WARNING("WARNING"),
|
||||
ERROR("ERROR");
|
||||
|
||||
private final String info;
|
||||
private LogLevel(String info){
|
||||
this.info=info;
|
||||
}
|
||||
public String getString(){
|
||||
return info;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,89 @@
|
|||
/*
|
||||
* To change this license header, choose License Headers in Project Properties.
|
||||
* To change this template file, choose Tools | Templates
|
||||
* and open the template in the editor.
|
||||
*/
|
||||
package common;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
import java.io.IOException;
|
||||
import java.io.PrintWriter;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
|
||||
public class Logger {
|
||||
private static Logger instance;
|
||||
private PrintWriter writer;
|
||||
private String logFileName;
|
||||
private static final String LOG_FILE_PREFIX = "log";
|
||||
private static final String LOG_FILE_SUFFIX = ".txt";
|
||||
private static final long HOUR_IN_MILLISECONDS = 3600000L; // 1 hour in milliseconds
|
||||
private static String Logdir = Config.getLogPath();
|
||||
private Logger() {
|
||||
createLogFile();
|
||||
startFileUpdateThread();
|
||||
}
|
||||
|
||||
public static synchronized Logger getInstance() {
|
||||
if (instance == null) {
|
||||
instance = new Logger();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
private void createLogFile() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
logFileName = Logdir+File.separator+LOG_FILE_PREFIX + "_" + now.format(DateTimeFormatter.ofPattern("yyyyMMddHH")) + LOG_FILE_SUFFIX;
|
||||
System.out.println("日志文件"+logFileName+"已创建!");
|
||||
try {
|
||||
writer = new PrintWriter(new FileWriter(logFileName, true));
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private void startFileUpdateThread() {
|
||||
Thread fileUpdateThread = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(HOUR_IN_MILLISECONDS);
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
updateLogFile();
|
||||
}
|
||||
});
|
||||
fileUpdateThread.setDaemon(true);
|
||||
fileUpdateThread.start();
|
||||
}
|
||||
|
||||
private void updateLogFile() {
|
||||
writer.close(); // Close the current log file
|
||||
createLogFile(); // Create a new log file
|
||||
}
|
||||
|
||||
public void log(String msg, LogLevel level) {
|
||||
String txt = getTimeStamp() + "[" + level.getString() + "]" + msg;
|
||||
System.out.println(txt);
|
||||
writer.println(txt);
|
||||
writer.flush();
|
||||
}
|
||||
private String getTimeStamp() {
|
||||
LocalDateTime now = LocalDateTime.now();
|
||||
return now.format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
Logger logger = Logger.getInstance();
|
||||
for (int i = 0; i < 10; i++) {
|
||||
logger.log("Log message " + i, LogLevel.INFO);
|
||||
try {
|
||||
Thread.sleep(50); // Sleep for 5 seconds
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -18,6 +18,9 @@ public class SolutionBean {
|
|||
Integer userId;
|
||||
Date submitTime;
|
||||
String language;
|
||||
//NEW
|
||||
String compiler;
|
||||
//
|
||||
String SourceCode;
|
||||
Integer codelength;
|
||||
String status;
|
||||
|
|
@ -27,6 +30,7 @@ public class SolutionBean {
|
|||
Float score;
|
||||
String remark;
|
||||
|
||||
|
||||
public SolutionBean() {
|
||||
this.id = 1;
|
||||
this.examId = 1;
|
||||
|
|
@ -34,6 +38,7 @@ public class SolutionBean {
|
|||
this.userId = 1;
|
||||
this.submitTime = new Date();
|
||||
this.language = "";
|
||||
this.compiler="";
|
||||
this.SourceCode = "";
|
||||
this.codelength = 3;
|
||||
this.status = "";
|
||||
|
|
@ -44,6 +49,13 @@ public class SolutionBean {
|
|||
this.remark = "";
|
||||
}
|
||||
|
||||
public void setCompiler(String compiler){
|
||||
this.compiler=compiler;
|
||||
}
|
||||
public String getCompiler(){
|
||||
return compiler;
|
||||
}
|
||||
|
||||
public Integer getId() {
|
||||
return id;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1090,7 +1090,7 @@ public class CodePanel extends JPanel implements ActionListener {
|
|||
private boolean checkForCompile() {
|
||||
String tmp = null;
|
||||
if (language.toLowerCase().equals("c") || language.toLowerCase().equals("cpp") || language.toLowerCase().equals("c++")) {
|
||||
tmp = Config.getCompilerDir("c");
|
||||
tmp = Config.getCompilerDir("c",null);
|
||||
if (tmp == null || "".equals(tmp) || !FileFinder.isExistFile(tmp + File.separator + "gcc.exe") || !FileFinder.isExistFile(tmp + File.separator + "g++.exe")) {
|
||||
//µ¯´°ÉèÖñ£´æ
|
||||
Object t = this.getParent();
|
||||
|
|
@ -1104,7 +1104,7 @@ public class CodePanel extends JPanel implements ActionListener {
|
|||
}
|
||||
}
|
||||
if (language.toLowerCase().equals("java")) {
|
||||
tmp = Config.getCompilerDir("java");
|
||||
tmp = Config.getCompilerDir("java",null);
|
||||
if (tmp == null || "".equals(tmp) || !FileFinder.isExistFile(tmp + File.separator + "javac.exe")) {
|
||||
//µ¯´°ÉèÖñ£´æ
|
||||
Object t = this.getParent();
|
||||
|
|
@ -1119,7 +1119,7 @@ public class CodePanel extends JPanel implements ActionListener {
|
|||
}
|
||||
|
||||
if (language.toLowerCase().equals("python")) {
|
||||
tmp = Config.getCompilerDir("python");
|
||||
tmp = Config.getCompilerDir("python",null);
|
||||
if (tmp == null || "".equals(tmp) || !FileFinder.isExistFile(tmp + File.separator + "javac.exe")) {
|
||||
//µ¯´°ÉèÖñ£´æ
|
||||
Object t = this.getParent();
|
||||
|
|
|
|||
Loading…
Reference in New Issue