lib/spotbugs/entity/bug_instance.rb in danger-spotbugs-0.0.2 vs lib/spotbugs/entity/bug_instance.rb in danger-spotbugs-0.0.3
- old
+ new
@@ -8,19 +8,15 @@
def initialize(prefix, source_dirs, bug_instance)
@source_dirs = source_dirs
@bug_instance = bug_instance
- source_path = bug_instance.xpath('SourceLine').attribute('sourcepath').first.value.to_s
+ source_path = get_source_path(bug_instance)
@absolute_path = get_absolute_path(source_path)
prefix += (prefix.end_with?(file_separator) ? '' : file_separator)
- @relative_path = if @absolute_path.start_with?(prefix)
- @absolute_path[prefix.length, @absolute_path.length - prefix.length]
- else
- @absolute_path
- end
+ @relative_path = get_relative_path(prefix, @absolute_path)
end
def rank
@rank ||= bug_instance.attribute('rank').value.to_i
end
@@ -28,21 +24,33 @@
def type
@type ||= rank > RANK_ERROR_THRESHOLD ? :warn : :fail
end
def line
- @line ||= bug_instance.xpath('SourceLine').attribute('start').first.value.to_i
+ @line ||= bug_instance.xpath('SourceLine').attribute('start').compact.first.value.to_i
end
def description
@description ||= bug_instance.xpath('LongMessage').text
end
private
+ def get_source_path(bug_instance)
+ bug_instance.xpath('SourceLine').attribute('sourcepath').compact.first.value.to_s
+ end
+
def get_absolute_path(source_path)
@source_dirs.map do |source_dir|
return source_dir if source_dir.end_with?(source_path)
+ end
+ end
+
+ def get_relative_path(prefix, absolute_path)
+ if absolute_path.start_with?(prefix)
+ absolute_path[prefix.length, absolute_path.length - prefix.length]
+ else
+ absolute_path
end
end
def file_separator
File::ALT_SEPARATOR || File::SEPARATOR