Skip to content

Commit 6a0d3db

Browse files
committedJul 16, 2018
Merge branch 'pr-25'
2 parents c45dcdb + af748e1 commit 6a0d3db

15 files changed

+43
-41
lines changed
 

‎History.md

+1
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,4 @@
2929
* [#22](https://github.com/pmd/pmd-regression-tester/pull/22): Add 'introduce new errors' table head for html summary report - [BBG](https://github.com/djydewang)
3030
* [#23](https://github.com/pmd/pmd-regression-tester/pull/23): Preparing for the release of PmdTester - [BBG](https://github.com/djydewang)
3131
* [#24](https://github.com/pmd/pmd-regression-tester/pull/24): Adding a logging framework for PmdTester - [BBG](https://github.com/djydewang)
32+
* [#25](https://github.com/pmd/pmd-regression-tester/pull/25): Remove working directory substring from filename of pmd violation - [BBG](https://github.com/djydewang)

‎lib/pmdtester/builders/diff_builder.rb

+7-5
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ class DiffBuilder
1414
# http://pmd.sourceforge.net/report_2_0_0.xsd
1515
def build(base_report_filename, patch_report_filename, base_info, patch_info, filter_set = nil)
1616
report_diffs = ReportDiff.new
17-
base_violations, base_errors = parse_pmd_report(base_report_filename, 'base', filter_set)
18-
patch_violations, patch_errors = parse_pmd_report(patch_report_filename, 'patch')
17+
base_details, patch_details = report_diffs.calculate_details(base_info, patch_info)
18+
base_violations, base_errors = parse_pmd_report(base_report_filename, 'base',
19+
base_details.working_dir, filter_set)
20+
patch_violations, patch_errors = parse_pmd_report(patch_report_filename, 'patch',
21+
patch_details.working_dir)
1922
report_diffs.calculate_violations(base_violations, patch_violations)
2023
report_diffs.calculate_errors(base_errors, patch_errors)
21-
report_diffs.calculate_details(base_info, patch_info)
2224

2325
report_diffs
2426
end
2527

26-
def parse_pmd_report(report_filename, branch, filter_set = nil)
27-
doc = PmdReportDocument.new(branch, filter_set)
28+
def parse_pmd_report(report_filename, branch, working_dir, filter_set = nil)
29+
doc = PmdReportDocument.new(branch, working_dir, filter_set)
2830
parser = Nokogiri::XML::SAX::Parser.new(doc)
2931
parser.parse_file(report_filename) unless report_filename.nil?
3032
[doc.violations, doc.errors]

‎lib/pmdtester/parsers/pmd_report_document.rb

+10-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ module PmdTester
99
class PmdReportDocument < Nokogiri::XML::SAX::Document
1010
attr_reader :violations
1111
attr_reader :errors
12-
def initialize(branch_name, filter_set = nil)
12+
def initialize(branch_name, working_dir, filter_set = nil)
1313
@violations = PmdViolations.new
1414
@errors = PmdErrors.new
1515
@current_violations = []
@@ -18,6 +18,7 @@ def initialize(branch_name, filter_set = nil)
1818
@current_element = ''
1919
@filename = ''
2020
@filter_set = filter_set
21+
@working_dir = working_dir
2122
@branch_name = branch_name
2223
end
2324

@@ -28,15 +29,20 @@ def start_element(name, attrs = [])
2829
case name
2930
when 'file'
3031
@current_violations = []
31-
@current_filename = attrs['name']
32+
@current_filename = remove_work_dir!(attrs['name'])
3233
when 'violation'
3334
@current_violation = PmdViolation.new(attrs, @branch_name)
3435
when 'error'
35-
@current_filename = attrs['filename']
36+
@current_filename = remove_work_dir!(attrs['filename'])
37+
remove_work_dir!(attrs['msg'])
3638
@current_error = PmdError.new(attrs, @branch_name)
3739
end
3840
end
3941

42+
def remove_work_dir!(str)
43+
str.sub!(/#{@working_dir}/, '')
44+
end
45+
4046
def characters(string)
4147
@current_violation.text = string unless @current_violation.nil?
4248
end
@@ -59,6 +65,7 @@ def end_element(name)
5965
end
6066

6167
def cdata_block(string)
68+
remove_work_dir!(string)
6269
@current_error.text = string unless @current_error.nil?
6370
end
6471

‎lib/pmdtester/pmd_report_detail.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,16 @@ module PmdTester
77
class PmdReportDetail
88
attr_accessor :execution_time
99
attr_accessor :timestamp
10+
attr_reader :working_dir
1011

1112
def initialize
1213
@execution_time = 0
1314
@timestamp = ''
15+
@working_dir = Dir.getwd
1416
end
1517

1618
def save(report_info_path)
17-
hash = { execution_time: @execution_time, timestamp: @timestamp }
19+
hash = { execution_time: @execution_time, timestamp: @timestamp, working_dir: @working_dir }
1820
file = File.new(report_info_path, 'w')
1921
file.puts JSON.generate(hash)
2022
file.close
@@ -25,6 +27,7 @@ def load(report_info_path)
2527
hash = JSON.parse(File.read(report_info_path))
2628
@execution_time = hash['execution_time']
2729
@timestamp = hash['timestamp']
30+
@working_dir = hash['working_dir']
2831
hash
2932
else
3033
puts "#{report_info_path} doesn't exist"

‎lib/pmdtester/project.rb

+3-3
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,13 @@ def default_webview_url
5151
# Change the file path from 'LOCAL_DIR/SOURCE_CODE_PATH' to
5252
# 'WEB_VIEW_URL/SOURCE_CODE_PATH'
5353
def get_webview_url(file_path)
54-
file_path.gsub(/#{local_source_path}/, @webview_url)
54+
file_path.gsub(%r{/#{local_source_path}}, @webview_url)
5555
end
5656

5757
# Change the file path from 'LOCAL_DIR/SOURCE_CODE_PATH' to
5858
# 'PROJECT_NAME/SOURCE_CODE_PATH'
5959
def get_path_inside_project(file_path)
60-
file_path.gsub(/#{local_source_path}/, @name)
60+
file_path.gsub(%r{/#{local_source_path}}, @name)
6161
end
6262

6363
def get_pmd_report_path(branch_name)
@@ -84,7 +84,7 @@ def get_project_target_dir(branch_name)
8484
end
8585

8686
def local_source_path
87-
"#{Dir.getwd}/#{REPOSITORIES_PATH}/#{@name}"
87+
"#{REPOSITORIES_PATH}/#{@name}"
8888
end
8989

9090
def target_diff_report_path

‎lib/pmdtester/report_diff.rb

+1
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ def calculate_details(base_info, patch_info)
7777

7878
@base_timestamp = base_details.timestamp
7979
@patch_timestamp = patch_details.timestamp
80+
[base_details, patch_details]
8081
end
8182

8283
def build_diffs(base_hash, patch_hash)

‎test/integration_test_runner.rb

+5-4
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,15 @@ def test_single_mode
3939
end
4040

4141
def test_online_mode
42-
argv = '-r target/repositories/pmd -m online -b test_branch -p pmd_releases/6.3.0'
42+
base_branch = 'test_branch_2'
43+
argv = "-r target/repositories/pmd -m online -b #{base_branch} -p pmd_releases/6.3.0"
4344
# This test depends on the file test_branch-baseline.zip being available on sourceforge.
4445

4546
system("bundle exec bin/pmdtester #{argv}")
4647

47-
assert_path_exist('target/reports/test_branch-baseline.zip')
48-
assert_path_exist('target/reports/test_branch/checkstyle/pmd_report.xml')
49-
assert_path_exist('target/reports/test_branch/spring-framework/pmd_report.xml')
48+
assert_path_exist("target/reports/#{base_branch}-baseline.zip")
49+
assert_path_exist("target/reports/#{base_branch}/checkstyle/pmd_report.xml")
50+
assert_path_exist("target/reports/#{base_branch}/spring-framework/pmd_report.xml")
5051
assert_path_exist('target/reports/pmd_releases_6.3.0/checkstyle/pmd_report.xml')
5152
assert_path_exist('target/reports/pmd_releases_6.3.0/spring-framework/pmd_report.xml')
5253
assert_path_exist('target/reports/diff/checkstyle/index.html')
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"execution_time":121,"timestamp":"base time stamp","working_dir":""}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"execution_time":65,"timestamp":"patch time stamp","working_dir":""}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"execution_time":121,"timestamp":"base time stamp"}
1+
{"execution_time":121,"timestamp":"base time stamp","working_dir":"SHOULD_BE_REPLACED"}
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"execution_time":65,"timestamp":"patch time stamp"}
1+
{"execution_time":65,"timestamp":"patch time stamp","working_dir":"SHOULD_BE_REPLACED"}

‎test/test_diff_builder.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77
# Unit test class for PmdTester::DiffBuilder
88
class TestDiffBuilder < Test::Unit::TestCase
99
include PmdTester
10-
BASE_REPORT_INFO_PATH = 'test/resources/html_report_builder/base_report_info.json'
11-
PATCH_REPORT_INFO_PATH = 'test/resources/html_report_builder/patch_report_info.json'
10+
BASE_REPORT_INFO_PATH = 'test/resources/diff_builder/base_report_info.json'
11+
PATCH_REPORT_INFO_PATH = 'test/resources/diff_builder/patch_report_info.json'
1212

1313
def setup
1414
`rake clean`

‎test/test_diff_report_builder.rb

+3-19
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,11 @@
77

88
# Unit test class for PmdTester::DiffReportBuilder
99
class TestDiffReportBuilder < Test::Unit::TestCase
10-
ORIGINAL_BASE_PMD_REPORT_PATH =
10+
BASE_PMD_REPORT_PATH =
1111
'test/resources/html_report_builder/test_html_report_builder_base.xml'
12-
ORIGINAL_PATCH_PMD_REPORT_PATH =
12+
PATCH_PMD_REPORT_PATH =
1313
'test/resources/html_report_builder/test_html_report_builder_patch.xml'
1414

15-
TARGET_TEST_RESOURCES_PATH = 'target/test/resources'
16-
BASE_PMD_REPORT_PATH = "#{TARGET_TEST_RESOURCES_PATH}/test_html_report_builder_base.xml"
17-
PATCH_PMD_REPORT_PATH = "#{TARGET_TEST_RESOURCES_PATH}/test_html_report_builder_patch.xml"
18-
1915
BASE_REPORT_INFO_PATH = 'test/resources/html_report_builder/base_report_info.json'
2016
PATCH_REPORT_INFO_PATH = 'test/resources/html_report_builder/patch_report_info.json'
2117

@@ -24,16 +20,7 @@ class TestDiffReportBuilder < Test::Unit::TestCase
2420
EXPECTED_EMPTY_REPORT_PATH =
2521
'test/resources/html_report_builder/expected_empty_diff_report.html'
2622
def setup
27-
# `rake clean`
28-
end
29-
30-
def build_pmd_report(original_filename, build_filename)
31-
FileUtils.mkdir_p(TARGET_TEST_RESOURCES_PATH) unless File.directory?(TARGET_TEST_RESOURCES_PATH)
32-
File.open(build_filename, 'w') do |build_file|
33-
File.open(original_filename, 'r') do |file|
34-
build_file.write file.read.gsub(/SHOULD_BE_REPLACED/, Dir.getwd)
35-
end
36-
end
23+
`rake clean`
3724
end
3825

3926
def test_diff_report_builder
@@ -43,9 +30,6 @@ def test_diff_report_builder
4330
actual_report_path = "target/reports/diff/#{project.name}"
4431
css_path = "#{actual_report_path}/css"
4532

46-
build_pmd_report(ORIGINAL_BASE_PMD_REPORT_PATH, BASE_PMD_REPORT_PATH)
47-
build_pmd_report(ORIGINAL_PATCH_PMD_REPORT_PATH, PATCH_PMD_REPORT_PATH)
48-
4933
diff_builder = PmdTester::DiffBuilder.new
5034
project.report_diff = diff_builder.build(BASE_PMD_REPORT_PATH, PATCH_PMD_REPORT_PATH,
5135
BASE_REPORT_INFO_PATH, PATCH_REPORT_INFO_PATH)

‎test/test_pmd_report_detail.rb

+1
Original file line numberDiff line numberDiff line change
@@ -19,5 +19,6 @@ def test_save_and_load
1919
assert_equal(121, hash['execution_time'])
2020
assert_equal('timestamp', hash['timestamp'])
2121
assert_equal('00:02:01', details.format_execution_time)
22+
assert_equal(Dir.getwd, hash['working_dir'])
2223
end
2324
end

‎test/test_pmd_report_document.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
class TestPmdReportDocument < Test::Unit::TestCase
99
include PmdTester
1010
def test_document
11-
doc = PmdReportDocument.new('base')
11+
doc = PmdReportDocument.new('base', 'SHOULD_BE_REPLACED')
1212
parser = Nokogiri::XML::SAX::Parser.new(doc)
1313
parser.parse(File.open('test/resources/pmd_report_document/test_document.xml'))
1414
assert_equal(8, doc.violations.violations_size)
@@ -19,7 +19,7 @@ def test_document
1919

2020
def test_filter_set
2121
filter_set = Set['documentation']
22-
doc = PmdReportDocument.new('base', filter_set)
22+
doc = PmdReportDocument.new('base', 'SHOULD_BE_REPLACED', filter_set)
2323
parser = Nokogiri::XML::SAX::Parser.new(doc)
2424
parser.parse(File.open('test/resources/pmd_report_document/test_document.xml'))
2525
assert_equal(1, doc.violations.violations_size)

0 commit comments

Comments
 (0)
Please sign in to comment.