diff --git a/app/controllers/concerns/course/assessment/question/codaveri_question_concern.rb b/app/controllers/concerns/course/assessment/question/codaveri_question_concern.rb index 294cdda9d07..27eaeacb9fa 100644 --- a/app/controllers/concerns/course/assessment/question/codaveri_question_concern.rb +++ b/app/controllers/concerns/course/assessment/question/codaveri_question_concern.rb @@ -15,4 +15,12 @@ def safe_create_or_update_codaveri_question(question) create_or_update_question(question, question.attachment) end end + + def extract_pathname_from_java_file(file_content) + # extracts pathname based on public class of java file + class_name_extractor = /(?:^|;)\s*public\s+class\s+([A-Za-z_][A-Za-z0-9_]*)/ + match = file_content.match(class_name_extractor) + + match ? "#{match[1]}.java" : nil + end end diff --git a/app/services/course/assessment/programming_codaveri_evaluation_service.rb b/app/services/course/assessment/programming_codaveri_evaluation_service.rb index 145ff0052b1..4d1877a6378 100644 --- a/app/services/course/assessment/programming_codaveri_evaluation_service.rb +++ b/app/services/course/assessment/programming_codaveri_evaluation_service.rb @@ -141,7 +141,8 @@ def construct_grading_object @answer.files.each do |file| file_template = default_codaveri_student_file_template - file_template[:path] = extract_pathname_from_file(file.content, file.filename) + file_template[:path] = + (!@question.multiple_file_submission && extract_pathname_from_java_file(file.content)) || file.filename file_template[:content] = file.content @answer_object[:files].append(file_template) @@ -232,11 +233,4 @@ def default_codaveri_student_file_template content: '' } end - - def extract_pathname_from_file(file_content, filename) - class_name_extractor = /public\s+class\s+([A-Za-z_][A-Za-z0-9_]*)/ - match = file_content.match(class_name_extractor) - - match ? "#{match[1]}.java" : filename - end end diff --git a/app/services/course/assessment/question/programming_codaveri/java/java_package_service.rb b/app/services/course/assessment/question/programming_codaveri/java/java_package_service.rb index 78ee92c2887..253e4e07f30 100644 --- a/app/services/course/assessment/question/programming_codaveri/java/java_package_service.rb +++ b/app/services/course/assessment/question/programming_codaveri/java/java_package_service.rb @@ -2,6 +2,8 @@ # rubocop:disable Metrics/abcSize class Course::Assessment::Question::ProgrammingCodaveri::Java::JavaPackageService < Course::Assessment::Question::ProgrammingCodaveri::LanguagePackageService + include Course::Assessment::Question::CodaveriQuestionConcern + def process_solutions extract_main_solution end @@ -112,7 +114,9 @@ def extract_template submission_files.each_key do |pathname| main_template_object = default_codaveri_template_template - main_template_object[:path] = extract_pathname_from_file(submission_files[pathname], pathname) + main_template_object[:path] = + (!@question.multiple_file_submission && extract_pathname_from_java_file(submission_files[pathname])) || + pathname.to_s main_template_object[:content] = submission_files[pathname] main_template_object[:prefix] = strip_autograding_definition_from(test_files[Pathname.new('prepend')]) # TODO: fill in the suffix properly when we have aligned our append file convention with Codaveri @@ -128,13 +132,6 @@ def preload_question_test_cases @question.test_cases.pluck(:identifier, :id).to_h { |x| [x[0].match(/[^\/]+$/).to_s, x[1]] } end - def extract_pathname_from_file(file_content, pathname) - class_name_extractor = /public\s+class\s+([A-Za-z_][A-Za-z0-9_]*)/ - match = file_content.match(class_name_extractor) - - match ? "#{match[1]}.java" : pathname.to_s - end - def strip_autograding_definition_from(file_content) # we strip away all the definitions inside the Autograder class defined within prepend, # which has 6256 characters. Those definitions are defined within our java_autograded_pre.java