Skip to content

Commit

Permalink
fix(regex): capture non-commented public class name
Browse files Browse the repository at this point in the history
- only match the filename from class name if question is not file submission
  • Loading branch information
bivanalhar authored and cysjonathan committed Dec 24, 2024
1 parent 24bf9f3 commit e962ab6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down

0 comments on commit e962ab6

Please sign in to comment.