Skip to content
This repository was archived by the owner on Mar 28, 2019. It is now read-only.

Commit e08bf6a

Browse files
committed
java compiler server added in directory codejudge-compiler
1 parent 4b875a0 commit e08bf6a

File tree

9 files changed

+403
-0
lines changed

9 files changed

+403
-0
lines changed

codejudge-compiler/.classpath

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<classpath>
3+
<classpathentry kind="src" path="src"/>
4+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
5+
<classpathentry kind="output" path="bin"/>
6+
</classpath>

codejudge-compiler/.project

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<projectDescription>
3+
<name>codejudge-compiler</name>
4+
<comment></comment>
5+
<projects>
6+
</projects>
7+
<buildSpec>
8+
<buildCommand>
9+
<name>org.eclipse.jdt.core.javabuilder</name>
10+
<arguments>
11+
</arguments>
12+
</buildCommand>
13+
</buildSpec>
14+
<natures>
15+
<nature>org.eclipse.jdt.core.javanature</nature>
16+
</natures>
17+
</projectDescription>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
eclipse.preferences.version=1
2+
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
4+
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
5+
org.eclipse.jdt.core.compiler.compliance=1.6
6+
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
7+
org.eclipse.jdt.core.compiler.debug.localVariable=generate
8+
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
9+
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
10+
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
11+
org.eclipse.jdt.core.compiler.source=1.6
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package codejudge.compiler;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.OutputStreamWriter;
8+
9+
public class C {
10+
11+
String file, contents, dir;
12+
13+
public C(String file, String contents, String dir) {
14+
this.file = file;
15+
this.contents = contents;
16+
this.dir = dir;
17+
}
18+
public void compile() {
19+
try {
20+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file)));
21+
out.write(contents);
22+
out.close();
23+
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh")));
24+
out.write("cd \"" + dir +"\"\n");
25+
out.write("gcc -lm " + file + " 2> err.txt");
26+
out.close();
27+
Runtime r = Runtime.getRuntime();
28+
Process p = r.exec("chmod +x " + dir + "/compile.sh");
29+
p.waitFor();
30+
p = r.exec(dir + "/compile.sh");
31+
p.waitFor();
32+
} catch (FileNotFoundException e) {
33+
e.printStackTrace();
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
} catch (InterruptedException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
public void execute() {
42+
try {
43+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh")));
44+
out.write("cd \"" + dir +"\"\n");
45+
out.write("./a.out < in.txt > out.txt");
46+
out.close();
47+
Runtime r = Runtime.getRuntime();
48+
Process p = r.exec("chmod +x " + dir + "/run.sh");
49+
p.waitFor();
50+
p = r.exec(dir + "/run.sh");
51+
p.waitFor();
52+
} catch (FileNotFoundException e) {
53+
e.printStackTrace();
54+
} catch (IOException e) {
55+
e.printStackTrace();
56+
} catch (InterruptedException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package codejudge.compiler;
2+
3+
import java.io.IOException;
4+
import java.net.ServerSocket;
5+
import java.net.Socket;
6+
7+
public class CodejudgeCompiler {
8+
9+
public static void main(String args[]) {
10+
int n=0;
11+
try {
12+
ServerSocket server = new ServerSocket(3029);
13+
System.out.println("Codejudge compilation server running ...");
14+
while(true) {
15+
n++;
16+
Socket s = server.accept();
17+
RequestThread request = new RequestThread(s, n);
18+
request.start();
19+
}
20+
} catch (IOException e) {
21+
e.printStackTrace();
22+
}
23+
24+
}
25+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package codejudge.compiler;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.OutputStreamWriter;
8+
9+
public class Cpp {
10+
11+
String file, contents, dir;
12+
13+
public Cpp(String file, String contents, String dir) {
14+
this.file = file;
15+
this.contents = contents;
16+
this.dir = dir;
17+
}
18+
public void compile() {
19+
try {
20+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file)));
21+
out.write(contents);
22+
out.close();
23+
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh")));
24+
out.write("cd \"" + dir +"\"\n");
25+
out.write("g++ -lm " + file + " 2> err.txt");
26+
out.close();
27+
Runtime r = Runtime.getRuntime();
28+
Process p = r.exec("chmod +x " + dir + "/compile.sh");
29+
p.waitFor();
30+
p = r.exec(dir + "/compile.sh");
31+
p.waitFor();
32+
} catch (FileNotFoundException e) {
33+
e.printStackTrace();
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
} catch (InterruptedException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
public void execute() {
42+
try {
43+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh")));
44+
out.write("cd \"" + dir +"\"\n");
45+
out.write("./a.out < in.txt > out.txt");
46+
out.close();
47+
Runtime r = Runtime.getRuntime();
48+
Process p = r.exec("chmod +x " + dir + "/run.sh");
49+
p.waitFor();
50+
p = r.exec(dir + "/run.sh");
51+
p.waitFor();
52+
} catch (FileNotFoundException e) {
53+
e.printStackTrace();
54+
} catch (IOException e) {
55+
e.printStackTrace();
56+
} catch (InterruptedException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package codejudge.compiler;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.OutputStreamWriter;
8+
9+
public class Java {
10+
11+
String file, contents, dir;
12+
13+
public Java(String file, String contents, String dir) {
14+
this.file = file;
15+
this.contents = contents;
16+
this.dir = dir;
17+
}
18+
public void compile() {
19+
try {
20+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file)));
21+
out.write(contents);
22+
out.close();
23+
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/compile.sh")));
24+
out.write("cd \"" + dir +"\"\n");
25+
out.write("javac " + file + " 2> err.txt");
26+
out.close();
27+
Runtime r = Runtime.getRuntime();
28+
Process p = r.exec("chmod +x " + dir + "/compile.sh");
29+
p.waitFor();
30+
p = r.exec(dir + "/compile.sh");
31+
p.waitFor();
32+
} catch (FileNotFoundException e) {
33+
e.printStackTrace();
34+
} catch (IOException e) {
35+
e.printStackTrace();
36+
} catch (InterruptedException e) {
37+
e.printStackTrace();
38+
}
39+
}
40+
41+
public void execute() {
42+
try {
43+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh")));
44+
out.write("cd \"" + dir +"\"\n");
45+
out.write("java " + file.substring(0, file.length() - 5) + " < in.txt > out.txt");
46+
out.close();
47+
Runtime r = Runtime.getRuntime();
48+
Process p = r.exec("chmod +x " + dir + "/run.sh");
49+
p.waitFor();
50+
p = r.exec(dir + "/run.sh");
51+
p.waitFor();
52+
} catch (FileNotFoundException e) {
53+
e.printStackTrace();
54+
} catch (IOException e) {
55+
e.printStackTrace();
56+
} catch (InterruptedException e) {
57+
e.printStackTrace();
58+
}
59+
}
60+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package codejudge.compiler;
2+
3+
import java.io.BufferedWriter;
4+
import java.io.FileNotFoundException;
5+
import java.io.FileOutputStream;
6+
import java.io.IOException;
7+
import java.io.OutputStreamWriter;
8+
9+
public class Python {
10+
11+
String file, contents, dir;
12+
13+
public Python(String file, String contents, String dir) {
14+
this.file = file;
15+
this.contents = contents;
16+
this.dir = dir;
17+
}
18+
19+
public void execute() {
20+
try {
21+
BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/" + file)));
22+
out.write(contents);
23+
out.close();
24+
out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(dir + "/run.sh")));
25+
out.write("cd \"" + dir +"\"\n");
26+
out.write("python " + file + "< in.txt > out.txt 2>err.txt");
27+
out.close();
28+
Runtime r = Runtime.getRuntime();
29+
Process p = r.exec("chmod +x " + dir + "/run.sh");
30+
p.waitFor();
31+
p = r.exec(dir + "/run.sh");
32+
p.waitFor();
33+
} catch (FileNotFoundException e) {
34+
e.printStackTrace();
35+
} catch (IOException e) {
36+
e.printStackTrace();
37+
} catch (InterruptedException e) {
38+
e.printStackTrace();
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)