Skip to content

Commit 6a30bc7

Browse files
committed
Copy full pmd report for download
1 parent 1eeb92a commit 6a30bc7

File tree

8 files changed

+44
-1
lines changed

8 files changed

+44
-1
lines changed

lib/pmdtester/builders/liquid_renderer.rb

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,9 @@ def write_project_index(project, root)
5757
write_file("#{root}/index.html", render_liquid('project_diff_report.html', liquid_env))
5858
# generate array of violations in json
5959
write_file("#{root}/project_data.js", dump_violations_json(project))
60+
# copy original pmd reports
61+
copy_file("#{root}/base_pmd_report.xml", project.report_diff.base_report.file)
62+
copy_file("#{root}/patch_pmd_report.xml", project.report_diff.patch_report.file)
6063
end
6164

6265
def dump_violations_json(project)
@@ -69,5 +72,16 @@ def dump_violations_json(project)
6972
project_data = JSON.fast_generate(h)
7073
"let project = #{project_data}"
7174
end
75+
76+
private
77+
78+
def copy_file(target_file, source_file)
79+
if File.exist? source_file
80+
FileUtils.cp(source_file, target_file)
81+
logger&.info "Written #{target_file}"
82+
else
83+
logger&.warn "File #{source_file} not found"
84+
end
85+
end
7286
end
7387
end

lib/pmdtester/pmd_tester_utils.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ def parse_pmd_report(report_file, branch, report_details, filter_set = nil)
2929
parser.parse_file(report_file) if File.exist?(report_file)
3030
Report.new(
3131
report_document: doc,
32+
file: report_file,
3233

3334
timestamp: report_details.timestamp,
3435
exec_time: report_details.execution_time

lib/pmdtester/report_diff.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,18 @@ class Report
5757
:configerrors_by_rule,
5858
:exec_time,
5959
:timestamp,
60-
:infos_by_rule
60+
:infos_by_rule,
61+
:file
6162

6263
def initialize(report_document: nil,
64+
file: '',
6365
exec_time: 0,
6466
timestamp: '0')
6567
initialize_empty
6668
initialize_with_report_document report_document unless report_document.nil?
6769
@exec_time = exec_time
6870
@timestamp = timestamp
71+
@file = file
6972
end
7073

7174
def self.empty

resources/project_diff_report.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,12 @@ <h2>Summary</h2>
7171
<td class="patch">{{diff.patch_timestamp}}</td>
7272
<td class="diff"></td>
7373
</tr>
74+
<tr>
75+
<td class="item">Full Report</td>
76+
<td class="base"><a href="base_pmd_report.xml">Base pmd_report.xml</a></td>
77+
<td class="patch"><a href="patch_pmd_report.xml">Patch pmd_report.xml</a></td>
78+
<td class="diff"></td>
79+
</tr>
7480
</tbody>
7581
</table>
7682
</div>

test/resources/html_report_builder/expected_diff_report_index.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ <h2>Summary</h2>
8989
<td class="patch">patch time stamp</td>
9090
<td class="diff"></td>
9191
</tr>
92+
<tr>
93+
<td class="item">Full Report</td>
94+
<td class="base"><a href="base_pmd_report.xml">Base pmd_report.xml</a></td>
95+
<td class="patch"><a href="patch_pmd_report.xml">Patch pmd_report.xml</a></td>
96+
<td class="diff"></td>
97+
</tr>
9298
</tbody>
9399
</table>
94100
</div>

test/resources/html_report_builder/expected_empty_diff_report.html

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,12 @@ <h2>Summary</h2>
8989
<td class="patch">0</td>
9090
<td class="diff"></td>
9191
</tr>
92+
<tr>
93+
<td class="item">Full Report</td>
94+
<td class="base"><a href="base_pmd_report.xml">Base pmd_report.xml</a></td>
95+
<td class="patch"><a href="patch_pmd_report.xml">Patch pmd_report.xml</a></td>
96+
<td class="diff"></td>
97+
</tr>
9298
</tbody>
9399
</table>
94100
</div>

test/test_helper.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,8 @@ def assert_file_equals(expected_path, actual_path)
1616
actual_file = normalize_text(File.open(actual_path).read)
1717
assert_equal(expected_file, actual_file, actual_path)
1818
end
19+
20+
def assert_file_exists(path)
21+
assert File.exist?(path)
22+
end
1923
end

test/test_project_diff_report.rb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,9 @@ def test_diff_report_builder
3636

3737
# Checking the content of diff report is expected.
3838
assert_file_equals(EXPECTED_REPORT_PATH, "#{actual_report_path}/index.html")
39+
assert_file_exists("#{actual_report_path}/project_data.js")
40+
assert_file_exists("#{actual_report_path}/base_pmd_report.xml")
41+
assert_file_exists("#{actual_report_path}/patch_pmd_report.xml")
3942
end
4043

4144
def test_report_diffs_empty

0 commit comments

Comments
 (0)