Commit bbfa801d authored by Gian Saß's avatar Gian Saß

Compile and test JAR containing both student and test code

parent fe568530
......@@ -124,18 +124,24 @@ module JavaSubmissionTester
run_unzipped submission.submission, *testJars do |working_dir|
#before execution: generate a fresh jar from students code
fresh_jar, error = create_fresh_jar(submission.submission)
student_jar, error = create_fresh_jar(submission.submission)
raise "error occured while generating jar: #{error}" if error
fresh_jar, error = create_fresh_jar_from_directory(working_dir)
raise "error occured while generating jar: #{error}" if error
result = run_json_reporter(working_dir,
test_suit,
{jars: testJars.map {|e| e.current_path.to_s} << fresh_jar,
properties: ["-Dstudent-jar=./#{File.basename(fresh_jar)}",
{jars: [fresh_jar, student_jar],
properties: ["-Dstudent-jar=./#{File.basename(student_jar)}",
encoding_property()
]
})
File.delete(fresh_jar) #remove our garbage ;)
File.delete(student_jar)
# removes unnecessary exception text if it is a result from the static code analyser
if result != nil
result.each do |key, value|
......@@ -192,5 +198,21 @@ module JavaSubmissionTester
end
end
end
end
def create_fresh_jar_from_directory(path)
Dir[path+"/**.jar"].each{ |f| File.delete(f) }
compiled, error = compiles?(path)
if compiled
#generate a new jar with fresh '.class' files from the current working directory
orig_name = File.basename(path, '.jar')
jarpath = "/tmp/submission-#{orig_name}-#{SecureRandom.uuid}.jar"
Rails.logger.debug "Generating #{jarpath}"
stdout = `cd #{path} ; zip -r #{jarpath} ./**`
Rails.logger.debug "zipping returned: #{stdout}"
return jarpath, nil
else #compiler error
return nil, error
end
end
end
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