可以自由选择裁判机

This commit is contained in:
Jered Ye 2024-03-26 22:38:33 +08:00
parent 32b3c4ac88
commit dd259c48bf
22 changed files with 263 additions and 127 deletions

6
.gitignore vendored
View File

@ -20,3 +20,9 @@ Judger/dist/lib/Common.jar
*.class
*.zip
*.jar
client/nbproject/private/private.properties
*.class
*.log
*.exe
*.class
*.jar

View File

@ -4,4 +4,5 @@
<system systemId="http://127.0.0.1:8080/oj/webservice/OJWS?wsdl" uri="wsdl/127.0.0.1_8080/oj/webservice/OJWS.wsdl"/>
<system systemId="http://106.15.36.190:80/oj/webservice/OJWS?wsdl" uri="wsdl/106.15.36.190_80/oj/webservice/OJWS.wsdl"/>
<system systemId="https://219.228.76.122:443/oj/webservice/OJWS?wsdl" uri="wsdl/219.228.76.122_443/oj/webservice/OJWS.wsdl"/>
<system systemId="https://219.228.76.122:8080/oj/webservice/OJWS?wsdl" uri="wsdl/219.228.76.122_8080/oj/webservice/OJWS.wsdl"/>
</catalog>

View File

@ -872,7 +872,7 @@
</wsdl:binding>
<wsdl:service name="OJWS">
<wsdl:port binding="tns:OJWSSoapBinding" name="OJWSImplPort">
<soap:address location="https://219.228.76.122:443/oj/webservice/OJWS" />
<soap:address location="https://219.228.76.122:8080/oj/webservice/OJWS" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@ -6,6 +6,7 @@
package data;
import cache.ProblemsCachManager;
import common.Const;
import gui.Control;
import java.awt.EventQueue;
import java.util.ArrayList;
@ -27,6 +28,8 @@ import myjdom.model.Solutions;
import persistence.oj_beans.ProblemTestCaseBean;
import swingworker.MySwingWorker;
import log.Log;
import resultData.CompileInfo;
import resultData.Result;
/**
*
@ -129,13 +132,17 @@ public class JudgeFromQueue extends Thread {
//从队列中获取代码并裁判
public void Judge(Solution s) throws Exception {
String solutionId = s.getSolutionId();
String problemId = s.getProblemId();
String language = s.getLangeuage();
String language = s.getLanguage();
String sourceCode = s.getCode();
String compiler=s.getCompiler();
Float timeOut = problemBeanMap.get(problemId).getTimeOut();
List<ProblemTestCaseBean> testCaseBeanList = problemBeanMap.get(problemId).getTestCaseBeanList();
MySwingWorker myswingworker = new MySwingWorker(threadNo, solutionId, problemId, language, sourceCode, timeOut, testCaseBeanList, this::changeMessage, this::submitAnswer);
MySwingWorker myswingworker = new MySwingWorker(threadNo, solutionId, problemId, language,compiler, sourceCode, timeOut, testCaseBeanList, this::changeMessage, this::submitAnswer);
myswingworker.execute();
myswingworker.get();
// int i =1/0;
@ -154,6 +161,11 @@ public class JudgeFromQueue extends Thread {
problemsCachManager.putObject("problemId" + problemId,
problem);
}
if(problem.isEmpty()){
Result.status = Const.CE;
CompileInfo.remark = "»ñÈ¡ÌâÄ¿ÐÅϢʧ°Ü£¡";
return;
}
// System.out.println(Integer.parseInt(problemId));
// System.out.println(xml);

View File

@ -6,17 +6,21 @@
package data;
import gui.Control;
import static gui.Control.getJudgeInfoEditorPane;
import java.awt.EventQueue;
import java.net.URL;
import java.time.LocalTime;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.Lock;
import javax.swing.JEditorPane;
import myjdom.XmlToSolution;
import myjdom.model.Solution;
import myjdom.model.Solutions;
import myjdom.model.ProblemBean;
import persistence.oj_beans.ProblemTestCaseBean;
import web.Webservice;
import static web.Webservice.existDubbo;
/**
*
@ -48,6 +52,7 @@ public class MainForNet extends Thread {
continue;
}
System.out.println("¿ªÊ¼»ñÈ¡solution");
List<Solution> list = getWebServiceSolutions();
System.out.println("»ñÈ¡slolutinÊýÁ¿"+list.size());
// getServerObject();
@ -91,6 +96,7 @@ public class MainForNet extends Thread {
private List<Solution> getWebServiceSolutions() throws Exception {
Control.setWebService(new Webservice(new URL(Control.getUrl()), Control.getQname()));
String xml = Control.getWebService().getSolutions(5);
XmlToSolution xts = new XmlToSolution();
xts.readXmlString(xml);

View File

@ -228,7 +228,12 @@ public class Control {
public static String getChooseDirectory() {
return getChooseDirectory("a");
}
public static String getCppCompilerName(){
return mainFrame.getSelectedCppCompilerName();
}
public static String getJavaCompilerName(){
return mainFrame.getSelectedJavaCompilerName();
}
public static String getChooseDirectory(String lan) {
try {

View File

@ -136,7 +136,7 @@
</Group>
</Group>
<EmptySpace min="-2" pref="21" max="-2" attributes="0"/>
<Component id="jSeparator1" pref="1" max="32767" attributes="0"/>
<Component id="jSeparator1" max="32767" attributes="0"/>
</Group>
</Group>
</DimensionLayout>
@ -531,7 +531,10 @@
</Component>
<Component class="javax.swing.JLabel" name="jLabel8">
<Properties>
<Property name="text" type="java.lang.String" value="C/C++&#x7f16;&#x8bd1;&#x5668;:"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="&#x5b8b;&#x4f53;" size="10" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="&#x9ed8;&#x8ba4;C/C++&#x7f16;&#x8bd1;&#x5668;:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboCppCompiler">
@ -545,10 +548,17 @@
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="comboCppCompilerItemStateChanged"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="comboCppCompilerActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JLabel" name="jLabel10">
<Properties>
<Property name="text" type="java.lang.String" value="Java&#x7f16;&#x8bd1;&#x5668;:"/>
<Property name="font" type="java.awt.Font" editor="org.netbeans.beaninfo.editors.FontEditor">
<Font name="&#x5b8b;&#x4f53;" size="10" style="0"/>
</Property>
<Property name="text" type="java.lang.String" value="&#x9ed8;&#x8ba4;Java&#x7f16;&#x8bd1;&#x5668;:"/>
</Properties>
</Component>
<Component class="javax.swing.JComboBox" name="comboJavaCompiler">
@ -562,6 +572,10 @@
</StringArray>
</Property>
</Properties>
<Events>
<EventHandler event="itemStateChanged" listener="java.awt.event.ItemListener" parameters="java.awt.event.ItemEvent" handler="comboJavaCompilerItemStateChanged"/>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="comboJavaCompilerActionPerformed"/>
</Events>
</Component>
<Component class="javax.swing.JCheckBox" name="jCheckBox2">
<Properties>
@ -571,7 +585,8 @@
<Property name="foreground" type="java.awt.Color" editor="org.netbeans.beaninfo.editors.ColorEditor">
<Color blue="66" green="cc" red="0" type="rgb"/>
</Property>
<Property name="text" type="java.lang.String" value="dubbo"/>
<Property name="selected" type="boolean" value="true"/>
<Property name="text" type="java.lang.String" value="Dubbo"/>
</Properties>
<Events>
<EventHandler event="actionPerformed" listener="java.awt.event.ActionListener" parameters="java.awt.event.ActionEvent" handler="jCheckBox2ActionPerformed"/>

View File

@ -283,17 +283,40 @@ public class MainFrame extends javax.swing.JFrame {
}
});
jLabel8.setText("C/C++编译器:");
jLabel8.setFont(new java.awt.Font("宋体", 0, 10)); // NOI18N
jLabel8.setText("默认C/C++编译器:");
comboCppCompiler.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboCppCompiler.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
comboCppCompilerItemStateChanged(evt);
}
});
comboCppCompiler.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboCppCompilerActionPerformed(evt);
}
});
jLabel10.setText("Java编译器:");
jLabel10.setFont(new java.awt.Font("宋体", 0, 10)); // NOI18N
jLabel10.setText("默认Java编译器:");
comboJavaCompiler.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
comboJavaCompiler.addItemListener(new java.awt.event.ItemListener() {
public void itemStateChanged(java.awt.event.ItemEvent evt) {
comboJavaCompilerItemStateChanged(evt);
}
});
comboJavaCompiler.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
comboJavaCompilerActionPerformed(evt);
}
});
jCheckBox2.setFont(new java.awt.Font("宋体", 2, 12)); // NOI18N
jCheckBox2.setForeground(new java.awt.Color(0, 204, 102));
jCheckBox2.setText("dubbo");
jCheckBox2.setSelected(true);
jCheckBox2.setText("Dubbo");
jCheckBox1.setToolTipText("下次程序启动时,自动开始裁判");
jCheckBox2.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
@ -358,7 +381,7 @@ public class MainFrame extends javax.swing.JFrame {
.addComponent(threadManagerTabb, javax.swing.GroupLayout.PREFERRED_SIZE, 955, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGap(28, 28, 28)))
.addGap(21, 21, 21)
.addComponent(jSeparator1, javax.swing.GroupLayout.DEFAULT_SIZE, 1, Short.MAX_VALUE))
.addComponent(jSeparator1))
);
jPanel2Layout.setVerticalGroup(
jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
@ -439,6 +462,7 @@ public class MainFrame extends javax.swing.JFrame {
if (Control.stopJudgerForNet()) {
this.button_Start.setEnabled(true);
this.buttonStop.setEnabled(false);
this.jCheckBox2.setEnabled(true);
this.jLabel14.setText("正在关闭");
this.button_StartThread.setEnabled(false);
}
@ -466,6 +490,7 @@ public class MainFrame extends javax.swing.JFrame {
this.button_Start.setEnabled(false);
this.buttonStop.setEnabled(true);
this.button_StartThread.setEnabled(true);
this.jCheckBox2.setEnabled(false);
Webservice.existDubbo=false;
// if(!Dubboservice.running){
// Dubboservice.main(null);
@ -489,10 +514,10 @@ public class MainFrame extends javax.swing.JFrame {
private boolean checkForCompile() {
String tmp = null;
tmp = Config.getCompilerDir("c",comboCppCompiler.getSelectedItem().toString());
if (tmp == null || "".equals(tmp) || !FileFinder.isExistFile(tmp + File.separator + "gcc.exe") || !FileFinder.isExistFile(tmp + File.separator + "g++.exe")) {
if (tmp == null || "".equals(tmp) || !FileFinder.isExistFile(tmp + File.separator + "gcc.exe")&&!FileFinder.isExistFile(tmp + File.separator + "g++.exe")&&!FileFinder.isExistFile(tmp + File.separator + "/bin/cl.exe")) {
//弹窗设置保存
JOptionPane.showMessageDialog(this, "请先配置C语言编译器");
JOptionPane.showMessageDialog(this, "请先配置C/C++编译器");
// NewCompileSetting window = new NewCompileSetting("c", this, true);
// window.setVisible(true);
return false;
@ -508,6 +533,12 @@ public class MainFrame extends javax.swing.JFrame {
}
return true;
}
public String getSelectedCppCompilerName(){
return comboCppCompiler.getSelectedItem().toString();
}
public String getSelectedJavaCompilerName(){
return comboJavaCompiler.getSelectedItem().toString();
}
private void button_StartThreadActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_button_StartThreadActionPerformed
String s = jComboBox1.getSelectedItem().toString();
@ -539,6 +570,33 @@ public class MainFrame extends javax.swing.JFrame {
Webservice.ENABLE_DUBBO=jCheckBox2.isSelected();
}//GEN-LAST:event_jCheckBox2ActionPerformed
private void comboCppCompilerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboCppCompilerActionPerformed
try{
LangSelector.setDefaultCompiler("C++", comboCppCompiler.getSelectedItem().toString());
}
catch(Exception e){
//e.printStackTrace();
}
}//GEN-LAST:event_comboCppCompilerActionPerformed
private void comboJavaCompilerActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_comboJavaCompilerActionPerformed
try{
LangSelector.setDefaultCompiler("Java", comboJavaCompiler.getSelectedItem().toString());
}
catch(Exception e){
}
}//GEN-LAST:event_comboJavaCompilerActionPerformed
private void comboCppCompilerItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboCppCompilerItemStateChanged
//LangSelector.setDefaultCompiler("C++", comboCppCompiler.getSelectedItem().toString());
}//GEN-LAST:event_comboCppCompilerItemStateChanged
private void comboJavaCompilerItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_comboJavaCompilerItemStateChanged
//LangSelector.setDefaultCompiler("Java", comboJavaCompiler.getSelectedItem().toString());
}//GEN-LAST:event_comboJavaCompilerItemStateChanged
private void loadConfig() {
this.distributorIP.setText(Config.getValue("distributorIP"));
this.distributorPort.setText(Config.getValue("distributorPort"));

View File

@ -5,6 +5,7 @@
*/
package myjdom;
import common.Const;
import java.util.ArrayList;
import java.util.List;
import myjdom.model.ProblemBean;
@ -13,6 +14,8 @@ import persistence.oj_beans.ProblemTestCaseBean;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import resultData.CompileInfo;
import resultData.Result;
/**
*
@ -24,6 +27,7 @@ public class XmlToProblemBean extends XmlToBase implements XmlConvert<ProblemBea
public ProblemBean convertXML() throws Exception {
ProblemBean pb =new ProblemBean();
List<ProblemTestCaseBean> testCaseList = new ArrayList<>();
String s = doc.getDocumentElement().getElementsByTagName("time_limit").item(0).getTextContent();
pb.setTimeOut(Float.parseFloat(doc.getDocumentElement().getElementsByTagName("time_limit").item(0).getTextContent()));
NodeList list =doc.getDocumentElement().getElementsByTagName("Case");

View File

@ -5,6 +5,7 @@
*/
package myjdom;
import com.sun.media.jfxmedia.logging.Logger;
import java.util.ArrayList;
import java.util.List;
import myjdom.model.Solution;
@ -44,11 +45,22 @@ public class XmlToSolution extends XmlToBase implements XmlConvert<Solutions> {
s.setSubmitTime(e.getElementsByTagName("submitTime").item(0).getTextContent());
}
if (e.getElementsByTagName("language").item(0) != null) {
s.setLangeuage(e.getElementsByTagName("language").item(0).getTextContent());
s.setLanguage(e.getElementsByTagName("language").item(0).getTextContent());
}
if (e.getElementsByTagName("compiler").item(0) != null) {
s.setCompiler(e.getElementsByTagName("compiler").item(0).getTextContent());
Logger.logMsg(Logger.DEBUG,"µ±Ç°±àÒëÆ÷:"+e.getElementsByTagName("compiler").item(0).getTextContent());
System.out.println("µ±Ç°±àÒëÆ÷:"+e.getElementsByTagName("compiler").item(0).getTextContent());
}/////NEW
if (e.getElementsByTagName("code").item(0) != null) {
s.setCode(e.getElementsByTagName("code").item(0).getTextContent());
}
System.out.println(s.toString());
solutionList.add(s);
}
if (solutionList.size() == 1 && solutionList.get(0).getProblemId() == null) {

View File

@ -13,9 +13,17 @@ public class Solution {
private String solutionId;
private String problemId;
private String submitTime;
private String langeuage;
private String language;
private String compiler;
private String code;
public void setCompiler(String compiler){
this.compiler=compiler;
}
public String getCompiler(){
return compiler;
}
/**
* @return the solutionId
*/
@ -75,14 +83,14 @@ public class Solution {
/**
* @return the langeuage
*/
public String getLangeuage() {
return langeuage;
public String getLanguage() {
return language;
}
/**
* @param langeuage the langeuage to set
*/
public void setLangeuage(String langeuage) {
this.langeuage = langeuage;
public void setLanguage(String language) {
this.language = language;
}
}

View File

@ -23,23 +23,28 @@ public class MySwingWorker extends SwingWorker<Answer,String>{
private String solutionId;
private String problemId;
private String language;
private String compiler;
private String sourceCode;
private Float timeOut;
private List<ProblemTestCaseBean> testCaseList;
public MySwingWorker(int threadNo,String solutionId,String problemId,String language,String sourceCode,Float timeOut,List<ProblemTestCaseBean> testCaseList,Consumer<String> changeMessage,Consumer<Answer> submitResult){
public MySwingWorker(int threadNo,String solutionId,String problemId,String language,String compiler,String sourceCode,Float timeOut,List<ProblemTestCaseBean> testCaseList,Consumer<String> changeMessage,Consumer<Answer> submitResult){
this.solutionId = solutionId;
this.problemId = problemId;
this.language = language;
this.compiler=compiler;
this.sourceCode = sourceCode;
this.timeOut = timeOut;
this.testCaseList = testCaseList;
this.con1 = changeMessage;
this.con2 = submitResult;
}
@Override
protected Answer doInBackground() throws Exception {
return new Process().Judge(getSolutionId(),getProblemId(),getLanguage(), getSourceCode(), timeOut, getTestCaseList(),this::writeToGui);
return new Process().Judge(getSolutionId(),getProblemId(),getLanguage(),getCompiler(), getSourceCode(), timeOut, getTestCaseList(),this::writeToGui);
}
public void writeToGui(String s){
@ -66,7 +71,12 @@ public class MySwingWorker extends SwingWorker<Answer,String>{
}
public void setCompier(String compiler){
this.compiler=compiler;
}
public String getCompiler(){
return compiler;
}
/**
* @return the language
*/

View File

@ -55,7 +55,7 @@ public class Webservice implements java.rmi.Remote{
reference.setApplication(application);
reference.setInterface(OJWS.class);
reference.setUrl(url); // 设置远程服务的 URL
reference.setTimeout(3000);
// 初始化
return reference.get();
}
@ -71,8 +71,10 @@ public class Webservice implements java.rmi.Remote{
JEditorPane infoPane=getJudgeInfoEditorPane(0);
if(!existDubbo&&infoPane!=null)
infoPane.setText(infoPane.getText()+LocalTime.now().toString()+"正在请求Dubbo服务...\n");
//String url = "dubbo://219.228.76.122:20880/edu.dhu.ws.OJWS";//todo:需要改成用户自己输入
dubboPort = initDubboPort(url);
//infoPane.setText(infoPane.getText()+LocalTime.now().toString()+"测试test请求..."+dubboPort.test("aa")+"\n");
}
catch(Exception e){
JEditorPane infoPane=getJudgeInfoEditorPane(1);

View File

@ -223,7 +223,7 @@ public class ExeCommand {
errorInfoWrite.join();
JudgerInfo.exitValue = result;
JudgerInfo.info = infoWrite.returnInfo();
JudgerInfo.errorInfo = errorInfoWrite.returnInfo();
JudgerInfo.errorInfo = errorInfoWrite.returnInfo()+JudgerInfo.info;
return result;
} catch (Exception ex) {

View File

@ -15,6 +15,8 @@ import java.io.BufferedWriter;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import log.Log;
@ -59,13 +61,13 @@ public class Judger {
public Boolean checkForCompiler(){
File file1 = new File(Config.getCompilerDir("c",null) + File.separator + "gcc.exe");
File file2 = new File(Config.getCompilerDir("c",null) + File.separator + "gcc.exe");
if (!file1.exists() || !file2.exists()) {
System.out.println("编译器未找到");
isFound = false;
return false;
}
//File file1 = new File(Config.getCompilerDir("c",null) + File.separator + "gcc.exe");
//File file2 = new File(Config.getCompilerDir("c",null) + File.separator + "gcc.exe");
//if (!file1.exists() || !file2.exists()) {
// System.out.println("编译器未找到");
// isFound = false;
// return false;
//}
isFound = true;
return true;
}
@ -106,38 +108,64 @@ public class Judger {
}
private String linkCommand(String language) {
private String linkCommand(String language,String compiler) {
if(compiler==null){
compiler=LangSelector.getDefaultCompilerName(language);
}
//String language = "c";
String linkCommand = Config.getCompilerDir(language) + File.separator + "g++ " +"\""+ Config.getTargetPath() +File.separator+"output"+File.separator+ "Main"+".o"+"\"" + " -o " +"\""+ Config.getTargetPath()+File.separator+"output"+File.separator + "Main"+".exe"+"\"\n";
HashMap<String,String>map=new HashMap<>();
map.put(LangSelector.PlaceHolder.CompilerPath.getStr(),Config.getCompilerDir(language,compiler));
map.put(LangSelector.PlaceHolder.SourceFile.getStr(),sourceFile);
if(!compiler.toLowerCase().equals("msvc"))
map.put(LangSelector.PlaceHolder.ObjFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.o");
else
map.put(LangSelector.PlaceHolder.ObjFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.obj");
map.put(LangSelector.PlaceHolder.ExeFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.exe");
String linkCommand = LangSelector.matchPlaceHolder(LangSelector.getCompileCommand("C++",compiler), map);
//String linkCommand = Config.getCompilerDir(language) + File.separator + "g++ " +"\""+ Config.getTargetPath() +File.separator+"output"+File.separator+ "Main"+".o"+"\"" + " -o " +"\""+ Config.getTargetPath()+File.separator+"output"+File.separator + "Main"+".exe"+"\"\n";
return linkCommand;
}
/////////////////////////////////////////////////////////////////////////////////////////////////TODO
//mingw32-g++.exe -Wall -g -c E:\Downloads\aaa\aa.cpp -o obj\Debug\aa.o
//mingw32-g++.exe -o bin\Debug\aaa.exe obj\Debug\aa.o
private String compileCommand(String language) {
private String compileCommand(String language,String compiler) {////////////TODO
String compileCommand = "";
if(compiler==null){
compiler=LangSelector.getDefaultCompilerName(language);
}
language = language.toLowerCase();//todo
if (language.equals("c")) {
compileCommand += "\"" + Config.getCompilerDir(language) + File.separator + "gcc\" -c " + "\""+sourceFile +"\""+ " -o " +"\""+Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main"+".o"+"\"\n";
compileCommand += "\"" + Config.getCompilerDir(language,compiler) + File.separator + "gcc\" -c " + "\""+sourceFile +"\""+ " -o " +"\""+Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main"+".o"+"\"\n";
} else if (language.equals("java")) {
compileCommand += "\"" + Config.getCompilerDir(language) + File.separator + "javac\" " + sourceFile; //todo文件路径
compileCommand += "\"" + Config.getCompilerDir(language,compiler) + File.separator + "javac\" " + sourceFile; //todo文件路径
} else if (language.equals("cpp")||language.equals("c++")) {
//compileCommand +=Config.getCompilerDir(language) + File.separator +LangSelector.getCompileCommand("C++",null);
compileCommand += "\"" + Config.getCompilerDir(language) + File.separator + "g++\" -Wall -g -c -std=c++14 "//todo:C++14
+ "\""+sourceFile+"\"" + " -o " + "\""+Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main"+".o"+"\"\n";
HashMap<String,String>map=new HashMap<>();
map.put(LangSelector.PlaceHolder.CompilerPath.getStr(),Config.getCompilerDir(language,compiler));
map.put(LangSelector.PlaceHolder.SourceFile.getStr(),sourceFile);
if(!compiler.toLowerCase().equals("msvc"))
map.put(LangSelector.PlaceHolder.ObjFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.o");
else
map.put(LangSelector.PlaceHolder.ObjFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.obj");
map.put(LangSelector.PlaceHolder.ExeFile.getStr(),Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main.exe");
compileCommand = LangSelector.matchPlaceHolder(LangSelector.getCompileCommand("C++",compiler), map);
//compileCommand += "\"" + Config.getCompilerDir(language) + File.separator + "g++\" -Wall -g -c -std=c++1y "//todo:C++14
// + "\""+sourceFile+"\"" + " -o " + "\""+Config.getTargetPath()+ File.separator+"output"+ File.separator + "Main"+".o"+"\"\n";
} else {
CompileInfo.info = "this programing language is not support!!!";
}
return compileCommand;
}
private String runCommand(String language) {
private String runCommand(String language,String compiler) {
String runCommand = "";
if (language.equals("c")) {
runCommand +="\""+ Config.getTargetPath()+ File.separator+"output"+File.separator + "Main"+"\"";
} else if (language.equals("java")) {
runCommand += Config.getCompilerDir(language) + File.separator + "java"+ " -cp " + Config.getSourcePath()+ File.separator+"output"+File.separator+ " "+mainClassName; // TODO 文件路径 start
runCommand += Config.getCompilerDir(language,compiler) + File.separator + "java"+ " -cp " + Config.getSourcePath()+ File.separator+"output"+File.separator+ " "+mainClassName; // TODO 文件路径 start
//System.err.println(runCommand);
} else if (language.equals("cpp")||language.equals("c++")) {
runCommand += "\""+ Config.getTargetPath()+ File.separator+"output"+File.separator + "Main"+"\"";
@ -146,7 +174,7 @@ public class Judger {
return runCommand;
}
public int compile(String sourceCode, String language) {
public int compile(String sourceCode, String language,String compiler) {
int result = -1;
//¼ì²éÓïÑÔÊÇ·ñÔڷΧÄÚ
language = language.toLowerCase();
@ -170,12 +198,12 @@ public class Judger {
saveSourceCodeFile(language, sourceCode);
int repeatTime = 3;
String compileCom = compileCommand(language);
String compileCom = compileCommand(language,compiler);
for (int i = 0; i < repeatTime; i++) {
result = exe.exeCompile(compileCom,"Path="+Config.getCompilerDir(language));
result = exe.exeCompile(compileCom,"Path="+Config.getCompilerDir(language,compiler));
if (result == 0) {
if (language.equals("c") || language.equals("cpp")||language.equals("c++")) {
result = exe.exeLink(linkCommand(language),"Path="+Config.getCompilerDir(language));
result = exe.exeLink(linkCommand(language,compiler),"Path="+Config.getCompilerDir(language,compiler));
if(result==0){
break;
}
@ -187,9 +215,9 @@ public class Judger {
return result;
}
public int run(String language, String input, int timeLimit) {
public int run(String language,String compiler, String input, int timeLimit) {
language = language.toLowerCase();
return exe.exeRun(runCommand(language), "Path="+Config.getCompilerDir(language), input, timeLimit);
return exe.exeRun(runCommand(language,compiler), "Path="+Config.getCompilerDir(language,compiler), input, timeLimit);
}
public boolean check(String stdAns) {

View File

@ -96,7 +96,7 @@ public class Process {
}
//WebServiceÆÀÅÐ
public Answer Judge(String solutionId, String problemId, String language, String sourceCode, Float timeOut, List<ProblemTestCaseBean> testCaseBeans, Consumer<String> con) {
public Answer Judge(String solutionId, String problemId, String language,String compiler, String sourceCode, Float timeOut, List<ProblemTestCaseBean> testCaseBeans, Consumer<String> con) {
CompileInfo.init();
RunInfo.init();
this.con = con;
@ -108,6 +108,7 @@ public class Process {
this.judger = new Judger();
Boolean is = this.judger.checkForCompiler();
this.solutionBean.setLanguage(language);
this.solutionBean.setCompiler(compiler);
this.solutionBean.setSourceCode(sourceCode);
this.problemBean.setTime_limit(timeOut);
// if(is == false) return ;
@ -143,7 +144,7 @@ public class Process {
}
//µÃµ½ÆÀÅнá¹û
public Answer Judge(String language, String sourceCode, Float timeOut, List<ProblemTestCaseBean> testCaseBeans) {
public Answer Judge(String language,String compiler, String sourceCode, Float timeOut, List<ProblemTestCaseBean> testCaseBeans) {
CompileInfo.init();
RunInfo.init();
Result.status = 0;
@ -154,6 +155,7 @@ public class Process {
this.judger = new Judger();
//Boolean is = this.judger.checkForCompiler();
this.solutionBean.setLanguage(language);
this.solutionBean.setCompiler(compiler);
this.solutionBean.setSourceCode(sourceCode);
this.problemBean.setTime_limit(timeOut);
// if(is == false) return ;
@ -242,7 +244,7 @@ public class Process {
//step 2
private void judgeForAllTestcase() {
if (judger.compileFound() && 0 == judger.compile(solutionBean.getSourceCode(), solutionBean.getLanguage())) {
if (judger.compileFound() && 0 == judger.compile(solutionBean.getSourceCode(), solutionBean.getLanguage(),solutionBean.getCompiler())) {
for (int i = 0; i < sumTestcaseNum; i++) {
ProblemTestCaseBean caseBean = (ProblemTestCaseBean) testCaseBeans.get(i);
@ -252,7 +254,7 @@ public class Process {
}else{
Shared.maxOutputLength=caseBean.getOutput().length()+2000;
}
if (judger.run(solutionBean.getLanguage(), caseBean.getInput(), problemBean.getTime_limit().intValue()) == 0) {
if (judger.run(solutionBean.getLanguage(),solutionBean.getCompiler(), caseBean.getInput(), problemBean.getTime_limit().intValue()) == 0) {
if (willCheck) {
judger.check(caseBean.getOutput());
} else {

View File

@ -66,7 +66,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
//根据radiobutton的选择情况判断写入
if (cSystem.isSelected()||cRegistry.isSelected()||cSelf.isSelected()) {
//路径为自带编译器路径
Config.getProp().setProperty(Const.MinGWDir, Config.CompilerDir("c"));
Config.getProp().setProperty(Const.MinGWDir, Config.CompilerDir("c",null));
Config.getProp().setProperty(Const.MinGWRelative, "1");
Config.getProp().setProperty(Const.MinGWDir, lblCRegistryMessage.getText());
Config.getProp().setProperty(Const.MinGWRelative, "2");
@ -74,7 +74,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
Config.getProp().setProperty(Const.MinGWRelative, "3");
}
if (javaSystem.isSelected()||javaRegistry.isSelected()||javaSelf.isSelected()) {
Config.getProp().setProperty(Const.JavaCompilerDir, Config.CompilerDir("java"));
Config.getProp().setProperty(Const.JavaCompilerDir, Config.CompilerDir("java",null));
Config.getProp().setProperty(Const.JavaRelative, "1");
Config.getProp().setProperty(Const.JavaCompilerDir, lblJavaRegistryMessage.getText());
Config.getProp().setProperty(Const.JavaRelative, "2");
@ -110,7 +110,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
cRegistryList.removeAllItems();
javaRegistryList.removeAllItems();
//第一优先级为内置编译器第二为注册表搜索到的最后为用户自定义
String MinGWDir = Config.CompilerDir("c");
String MinGWDir = Config.CompilerDir("c",null);
if (!FileFinder.isExistFile(MinGWDir)) {
cSystem.setEnabled(false);
}
@ -129,7 +129,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
cRegistry.setEnabled(false);
}
String javaDirString = Config.CompilerDir("java"); // SXZ530
String javaDirString = Config.CompilerDir("java",null); // SXZ530
if (!FileFinder.isExistFile(javaDirString)) {
javaSystem.setEnabled(false);
}
@ -200,7 +200,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
} else if (Config.MinGWRelative == 2) {
//设置保存为选择计算机注册的东西故路径应该是有的无视其他情况
cRegistry.setSelected(true);
MinGWDir = Config.getCompilerDir("c");
MinGWDir = Config.getCompilerDir("c",null);
tmpHashtable = CRegistryMessage;
Iterator iter = tmpHashtable.entrySet().iterator();
while (iter.hasNext()) {
@ -216,7 +216,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
lblCRegistryMessage.setText(MinGWDir);
} else if (Config.MinGWRelative == 3) {
cSystem.setSelected(true);
MinGWDir = Config.getCompilerDir("c");
MinGWDir = Config.getCompilerDir("c",null);
cDir.setText(MinGWDir);
setCFindPathGroupEnable(true);
setCRegistryGroupEnable(false);
@ -228,7 +228,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
setJavaRegistryGroupEnable(false);
} else if (Config.JavaRelative == 2) {
javaRegistry.setSelected(true);
javaDirString = Config.getCompilerDir("java");
javaDirString = Config.getCompilerDir("java",null);
tmpHashtable = JavaRegistryMessage;
Iterator iter = tmpHashtable.entrySet().iterator();
while (iter.hasNext()) {
@ -244,7 +244,7 @@ public class NewCompileSetting extends javax.swing.JDialog {
setJavaRegistryGroupEnable(true);
} else if (Config.JavaRelative == 3) {
javaSystem.setSelected(true);
javaDirString = Config.getCompilerDir("java");
javaDirString = Config.getCompilerDir("java",null);
javaDir.setText(javaDirString);
setJavaFindPathGroupEnable(true);
setJavaRegistryGroupEnable(false);

View File

@ -569,7 +569,7 @@
</wsdl:binding>
<wsdl:service name="OJWS">
<wsdl:port binding="tns:OJWSSoapBinding" name="OJWSImplPort">
<soap:address location="http://106.15.36.190/oj/webservice/OJWS" />
<soap:address location="https://219.228.76.122:8080/oj/webservice/OJWS" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@ -487,7 +487,17 @@ public class CodePanel extends JPanel implements ActionListener {
CodePanel.this.toLoad = codeString;
System.out.println("-----" + codeString);
Float time_limit = Float.parseFloat(Control.getMainFrame().getInformation(String.valueOf(submitProblemId)).getTime_limit());
Answer answer = new Process().Judge(language, codeString, time_limit+2, testCaseBeans); //loss of timelimit
//////////todo:自主选择编译器
String compiler="";
Answer answer = new Process().Judge(language,compiler, codeString, time_limit+2, testCaseBeans); //loss of timelimit
if (answer.getStatus().equals("NF")) {
JOptionPane.showMessageDialog(CodePanel.this,
"编译器未找到,请检查编译器设置", "提交失败", JOptionPane.ERROR_MESSAGE
@ -693,7 +703,14 @@ public class CodePanel extends JPanel implements ActionListener {
temp.setOutput(testCaseAns);
testCaseBeans.add(temp);
//System.out.println(language+JEP_Code.getText()+to+testCaseBeans);
outAll = new Process().Judge(language, JEP_Code.getText(), to+2, testCaseBeans);
String compiler="";
outAll = new Process().Judge(language,compiler, JEP_Code.getText(), to+2, testCaseBeans);
//System.out.println(JEP_Code.getText());
//System.out.println(outAll.getUsersOutput()[0]);

View File

@ -872,7 +872,7 @@
</wsdl:binding>
<wsdl:service name="OJWS">
<wsdl:port binding="tns:OJWSSoapBinding" name="OJWSImplPort">
<soap:address location="http://106.15.36.190/oj/webservice/OJWS" />
<soap:address location="https://219.228.76.122:443/oj/webservice/OJWS" />
</wsdl:port>
</wsdl:service>
</wsdl:definitions>

View File

@ -1,63 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<languages>
<language id="C++" alias="c++,c,cpp,CPP,C">
<compiler name="MinGW">
<path>K:\Dev-Cpp\MinGW64\bin</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>"$exeFile$"</runCmd>
</compiler>
<compiler name="MSVC">
<path>C:/MinGW/bin/</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>msvc</runCmd>
</compiler>
</language>
<language id="Java" alias="java,JAVA">
<compiler name="JDK8">
<path>C:/JDK8/bin</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>"$compilerPath$ java -cp $sourceFile$\output\$exeFile$"</runCmd>
</compiler>
<compiler name="JDK9">
<path>C:/MinGW/bin/</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>
</runCmd>
</compiler>
</language>
<language id="Python" alias="python,PYTHON">
<compiler name="Python2">
<path>C:/MinGW/bin/</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>$exeFile$</runCmd>
</compiler>
<compiler name="Python3">
<path>C:/MinGW/bin/</path>
<compileCmd>g++.exe -Wall -g -std=c++14 -c $sourceFile$ -o $objFile$</compileCmd>
<!-- g++.exe -Wall -g -std=c++14 -c D:\prog_old\test\main.cpp -o obj\Debug\main.o-->
<linkCmd>g++.exe -o $exeFile$ $objFile$ -O1</linkCmd>
<!-- g++.exe -o bin\Debug\test.exe obj\Debug\main.o -O1-->
<runCmd>
</runCmd>
</compiler>
</language>
<!-- sourceFile-->
<!-- objFile-->
<!-- exeFile-->
<language id="VB" />
</languages>

13
自选编译器文档.md Normal file
View File

@ -0,0 +1,13 @@
# persistence.oj_beans包
SolutionBean:新增字段String compiler
Solution,MySwingWorker
XML中增加新元素compiler
![image-20240306000021628](C:\Users\tange\AppData\Roaming\Typora\typora-user-images\image-20240306000021628.png)