Commit ce9b40e9 authored by Dominic Althaus's avatar Dominic Althaus

add configuration for java paths

parent 14f92825
......@@ -14,6 +14,23 @@ And then execute:
$ bundle
```
Configure Java Paths:
```ruby
# config/application.rb or config/environments/*.rb
# java paths
JavaSubmissionTester.java_8_path = {
java: '/usr/lib/jvm/java-8-openjdk/bin/java',
javac: '/usr/lib/jvm/java-8-openjdk/bin/javac',
javap: '/usr/lib/jvm/java-8-openjdk/bin/javap'
}
JavaSubmissionTester.java_9_path = {
java: '/usr/lib/jvm/java-9-jdk/bin/java',
javac: '/usr/lib/jvm/java-9-jdk/bin/javac',
javap: '/usr/lib/jvm/java-9-jdk/bin/javap'
}
```
## Useful Information
1. The java source code for JunitReport.jar can be found in the java folder.
2. JunitJSONReportRunner is for running the test and generation a report in the json format. It uses Junits RunListener.
......
......@@ -2,4 +2,17 @@ require 'java_submission_tester/engine'
module JavaSubmissionTester
# Your code goes here...
mattr_accessor :java_8_path
mattr_accessor :java_9_path
self.java_8_path = {
java: '/usr/lib/jvm/java-8-openjdk/bin/java',
javac: '/usr/lib/jvm/java-8-openjdk/bin/javac',
javap: '/usr/lib/jvm/java-8-openjdk/bin/javap'
}
self.java_9_path = {
java: '/usr/lib/jvm/java-9-jdk/bin/java',
javac: '/usr/lib/jvm/java-9-jdk/bin/javac',
javap: '/usr/lib/jvm/java-9-jdk/bin/javap'
}
end
......@@ -53,7 +53,7 @@ module JavaSubmissionTester
class_path = "#{JUNIT_REPORT_PATH}:#{JUNIT_CLASSPATH}:#{submission_test.test.current_path}"
class_path = "#{class_path}:#{submission_test.stub.current_path}" unless submission_test.stub.current_path.nil?
cmd = "java -cp \"#{class_path}\" de.thm.mni.JunitJSONTestList \"#{test_suit_name}\""
cmd = "#{JavaSubmissionTester.java_9_path[:java]} -cp \"#{class_path}\" de.thm.mni.JunitJSONTestList \"#{test_suit_name}\""
stdout_string, stderr_string, status = Open3.capture3(cmd)
if status.exitstatus == 0
......@@ -86,7 +86,7 @@ module JavaSubmissionTester
output_file = Tempfile.new
output_file.close
cmd = "timeout #{TEST_TIMEOUT_DURATION}" +
" java -Djava.security.manager -Djava.security.policy=#{policy_file} -cp" +
" #{JavaSubmissionTester.java_9_path[:java]} -Djava.security.manager -Djava.security.policy=#{policy_file} -cp" +
" \"#{JUNIT_REPORT_PATH}:" +
"#{JUNIT_CLASSPATH}:" +
"#{test_path}\"" +
......@@ -176,7 +176,7 @@ module JavaSubmissionTester
class_path = "#{JUNIT_REPORT_PATH}:#{JUNIT_CLASSPATH}#{library.nil? ? '' : ":#{library}"}:#{source}"
cmd = "javac -cp \"#{class_path}\" \"#{Dir["#{dir}/**/*.java"].join('" "')}\""
cmd = "#{JavaSubmissionTester.java_9_path[:javac]} -cp \"#{class_path}\" \"#{Dir["#{dir}/**/*.java"].join('" "')}\""
stdout_string, stderr_string, status = Open3.capture3(cmd)
end
......
......@@ -47,7 +47,7 @@ module JavaSubmissionTester
class_path = "#{::JavaSubmissionTester::JavaHelper::JUNIT_REPORT_PATH}:#{::JavaSubmissionTester::JavaHelper::JUNIT_CLASSPATH}:#{test.current_path}"
class_path = "#{class_path}:#{stub.current_path}" unless stub.current_path.nil?
cmd = "java -cp \"#{class_path}\" de.thm.mni.JunitJSONTestList \"#{test_suit_name}\""
cmd = "#{JavaSubmissionTester.java_8_path[:java]} -cp \"#{class_path}\" de.thm.mni.JunitJSONTestList \"#{test_suit_name}\""
stdout_string, stderr_string, status = Open3.capture3(cmd)
if status.exitstatus == 0
......@@ -84,14 +84,14 @@ module JavaSubmissionTester
end
def runnable?(jar_file)
cmd = "java -jar \"#{jar_file}\""
cmd = "#{JavaSubmissionTester.java_8_path[:java]} -jar \"#{jar_file}\""
stdout_string, stderr_string, status = Open3.capture3(cmd)
return status.exitstatus == 0, stderr_string, stdout_string
end
def validate_class_version(class_file_path)
cmd = "javap -verbose #{class_file_path} | grep major"
cmd = "#{JavaSubmissionTester.java_8_path[:javap]} -verbose #{class_file_path} | grep major"
stdout_string, stderr_string, status = Open3.capture3(cmd)
......@@ -102,7 +102,7 @@ module JavaSubmissionTester
def compiles?(working_dir)
class_path = "#{JUNIT_REPORT_PATH}:#{JUNIT_CLASSPATH}:#{working_dir}"
cmd = "javac -cp \"#{class_path}\" \"#{Dir["#{working_dir}/**/*.java"].join('" "')}\""
cmd = "#{JavaSubmissionTester.java_8_path[:javac]} -cp \"#{class_path}\" \"#{Dir["#{working_dir}/**/*.java"].join('" "')}\""
stdout_string, stderr_string, status = Open3.capture3(cmd)
......
......@@ -84,7 +84,7 @@ module JavaSubmissionTester
output_file = Tempfile.new
output_file.close
cmd = "java -Dinput=\"#{input_file_path}\" -Dstudent-output=\"#{submission_path}\" -cp \"#{JUNIT_REPORT_PATH}:#{JUNIT_CLASSPATH}:#{jar_file}\" de.thm.mni.JunitJSONReportRunner \"#{output_file.path}\" \"#{test_suit}\""
cmd = "#{JavaSubmissionTester.java_8_path[:java]} -Dinput=\"#{input_file_path}\" -Dstudent-output=\"#{submission_path}\" -cp \"#{JUNIT_REPORT_PATH}:#{JUNIT_CLASSPATH}:#{jar_file}\" de.thm.mni.JunitJSONReportRunner \"#{output_file.path}\" \"#{test_suit}\""
stdout_string, stderr_string, status = Open3.capture3(cmd, stdin_data: File.read(input_file_path))
output_file.open
......
......@@ -77,7 +77,7 @@ module JavaSubmissionTester
private
def run_test(jar_file, input_file_path, submission_path)
cmd = "java -jar \"#{jar_file}\" input=\"#{input_file_path}\" student-output=\"#{submission_path}\""
cmd = "#{JavaSubmissionTester.java_8_path[:java]} -jar \"#{jar_file}\" input=\"#{input_file_path}\" student-output=\"#{submission_path}\""
stdout_string, stderr_string, status = Open3.capture3(cmd, stdin_data: File.read(input_file_path))
raise "There was an problem with the example solution while testing the input:\n#{File.read(input_file_path)}\n\nExcecution ended with error:\n#{stderr_string}" unless status.exitstatus == 0
......
......@@ -98,7 +98,7 @@ module JavaSubmissionTester
output_file.close
cmd = %W[
timeout #{TEST_TIMEOUT_DURATION}
java -Djava.security.manager -Djava.security.policy=#{policy_file.path} -cp
#{JavaSubmissionTester.java_8_path[:java]} -Djava.security.manager -Djava.security.policy=#{policy_file.path} -cp
#{::JavaSubmissionTester::JavaHelper::JUNIT_REPORT_PATH}:#{::JavaSubmissionTester::JavaHelper::JUNIT_CLASSPATH}:#{submission_test.test.current_path}#{compiles ? ':.' : ''}:#{submission.submission.current_path}
de.thm.mni.JunitJSONReportRunner #{output_file.path} #{test_suit}
]
......
module JavaSubmissionTester
VERSION = '1.0.0'
VERSION = '1.1.0'
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment