Skip to content

Commit b2d6a9a

Browse files
committed
Merge branch 'master' into better-html-reports
2 parents c446a49 + 9a9069b commit b2d6a9a

16 files changed

+818
-44
lines changed

History.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ Typeresolution is now supported by two new tags in the project-list.xml file:
1515
* [#69](https://github.com/pmd/pmd-regression-tester/pull/69): Detect single rules with auto-gen-config
1616
* [#70](https://github.com/pmd/pmd-regression-tester/pull/70): Add link to PR on github in HTML report
1717
* [#74](https://github.com/pmd/pmd-regression-tester/pull/74): Merge violations that have just changed messages
18+
* [#75](https://github.com/pmd/pmd-regression-tester/pull/75): Add new option "--error-recovery"
19+
* [#76](https://github.com/pmd/pmd-regression-tester/pull/76): Speedup XML parsing
1820

1921
## External Contributions
2022

README.rdoc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ on a list of standard projects(Spring Framework, Hibernate, Solr, etc.)
3939
-a, --auto-gen-config whether to generate configurations automatically based on branch differences,this option only works in online and local mode
4040
--keep-reports whether to keep old reports and skip running PMD again if possible
4141
-d, --debug whether change log level to DEBUG to see more information
42+
--error-recovery enable error recovery mode when executing PMD. Might help to analyze errors.
4243
-v, --version
4344
-h, --help
4445

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,17 @@ module PmdTester
99
class PmdReportBuilder
1010
include PmdTester
1111

12-
def initialize(branch_config, projects, local_git_repo, pmd_branch_name, threads = 1)
13-
@branch_config = branch_config
12+
def initialize(projects, options, branch_config, branch_name)
1413
@projects = projects
15-
@local_git_repo = local_git_repo
16-
@pmd_branch_name = pmd_branch_name
17-
@threads = threads
14+
@local_git_repo = options.local_git_repo
15+
@threads = options.threads
16+
@error_recovery = options.error_recovery
17+
@branch_config = branch_config
18+
@pmd_branch_name = branch_name
1819
@pwd = Dir.getwd
1920

20-
@pmd_branch_details = PmdBranchDetail.new(pmd_branch_name)
21-
@project_builder = ProjectBuilder.new(projects)
21+
@pmd_branch_details = PmdBranchDetail.new(@pmd_branch_name)
22+
@project_builder = ProjectBuilder.new(@projects)
2223
end
2324

2425
def get_pmd_binary_file
@@ -84,8 +85,10 @@ def get_last_commit_message
8485
end
8586

8687
def generate_pmd_report(project)
88+
error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : ''
8789
run_path = "target/pmd-bin-#{@pmd_version}/bin/run.sh"
88-
pmd_cmd = "#{run_path} pmd -d #{project.local_source_path} -f xml " \
90+
pmd_cmd = "#{error_recovery_options}" \
91+
"#{run_path} pmd -d #{project.local_source_path} -f xml " \
8992
"-R #{project.get_config_path(@pmd_branch_name)} " \
9093
"-r #{project.get_pmd_report_path(@pmd_branch_name)} " \
9194
"-failOnViolation false -t #{@threads} " \

lib/pmdtester/builders/project_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ def run_as_script(path, command)
8989
def execute_reset_cmd(type, tag)
9090
case type
9191
when 'git'
92-
reset_cmd = "git reset --hard #{tag}"
92+
reset_cmd = "git checkout #{tag}; git reset --hard #{tag}"
9393
when 'hg'
9494
reset_cmd = "hg up #{tag}"
9595
end

lib/pmdtester/parsers/options.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class Options
3131
attr_reader :debug_flag
3232
attr_accessor :filter_set
3333
attr_reader :keep_reports
34+
attr_reader :error_recovery
3435

3536
def initialize(argv)
3637
options = parse(argv)
@@ -48,6 +49,7 @@ def initialize(argv)
4849
@debug_flag = options[:d]
4950
@filter_set = nil
5051
@keep_reports = options.keep_reports?
52+
@error_recovery = options.error_recovery?
5153

5254
# if the 'config' option is selected then `config` overrides `base_config` and `patch_config`
5355
@base_config = @config if !@config.nil? && @mode == 'local'
@@ -94,6 +96,8 @@ def parse(argv)
9496
'whether to keep old reports and skip running PMD again if possible'
9597
o.bool '-d', '--debug',
9698
'whether change log level to DEBUG to see more information'
99+
o.bool '--error-recovery',
100+
'enable error recovery mode when executing PMD. Might help to analyze errors.'
97101
o.on '-v', '--version' do
98102
puts VERSION
99103
exit

lib/pmdtester/parsers/pmd_report_document.rb

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,9 @@ def end_element(name)
6262
@violations.add_all(@current_filename, @current_violations)
6363
@current_filename = nil
6464
when 'violation'
65-
v = @current_violation
66-
if match_filter_set?(v)
67-
v.message = finish_text!
68-
@current_violations.push(v)
69-
@infos_by_rules[v.rule_name] = RuleInfo.new(v.rule_name, v.info_url) unless @infos_by_rules.key?(v.rule_name)
65+
if match_filter_set?(@current_violation)
66+
@current_violation.message = finish_text!
67+
@current_violations.push(@current_violation)
7068
end
7169
@current_violation = nil
7270
when 'error'
@@ -87,15 +85,12 @@ def finish_text!
8785
def match_filter_set?(violation)
8886
return true if @filter_set.nil?
8987

90-
@filter_set.each do |filter_rule_ref|
91-
ruleset_attr = violation.ruleset_file
92-
rule = violation.rule_name
93-
rule_ref = "#{ruleset_attr}/#{rule}"
94-
return true if filter_rule_ref.eql?(ruleset_attr)
95-
return true if filter_rule_ref.eql?(rule_ref)
96-
end
88+
ruleset_attr = violation.attrs['ruleset'].delete(' ').downcase + '.xml'
89+
return true if @filter_set.include?(ruleset_attr)
90+
91+
rule_ref = "#{ruleset_attr}/#{violation.rule_name}"
9792

98-
false
93+
@filter_set.include?(rule_ref)
9994
end
10095
end
10196
end

lib/pmdtester/runner.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -142,9 +142,7 @@ def summarize_diffs
142142
private
143143

144144
def make_branch_details(config:, branch:)
145-
PmdReportBuilder
146-
.new(config, @projects, @options.local_git_repo, branch, @options.threads)
147-
.build
145+
PmdReportBuilder.new(@projects, @options, config, branch).build
148146
end
149147
end
150148
end

pmdtester.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ Gem::Specification.new do |s|
1111
s.metadata = { "bug_tracker_uri" => "https://github.com/pmd/pmd-regression-tester/issues", "homepage_uri" => "https://pmd.github.io", "source_code_uri" => "https://github.com/pmd/pmd-regression-tester" } if s.respond_to? :metadata=
1212
s.require_paths = ["lib".freeze]
1313
s.authors = ["Andreas Dangel".freeze, "Binguo Bao".freeze]
14-
s.date = "2020-11-19"
14+
s.date = "2020-11-23"
1515
s.description = "A regression testing tool ensure that new problems and unexpected behaviors will not be introduced to PMD project after fixing an issue , and new rules can work as expected.".freeze
1616
s.email = ["[email protected]".freeze, "[email protected]".freeze]
1717
s.executables = ["pmdtester".freeze]

test/integration_test_pmd_report_builder.rb

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,16 @@ def setup
1010
end
1111

1212
def test_build
13-
logger.level = Logger::INFO
14-
projects = ProjectsParser.new.parse('test/resources/project-test.xml')
15-
builder = PmdReportBuilder.new('config/design.xml', projects,
16-
'target/repositories/pmd', 'pmd_releases/6.7.0')
13+
argv = %w[-r target/repositories/pmd -b master -p origin/pmd/7.0.x
14+
-c test/resources/pmd7-config.xml -l test/resources/project-test.xml
15+
--error-recovery --debug]
16+
options = PmdTester::Options.new(argv)
17+
projects = ProjectsParser.new.parse(options.project_list)
18+
19+
builder = PmdReportBuilder.new(projects, options, options.config, options.patch_branch)
1720
builder.build
1821

1922
assert_equal(0, $CHILD_STATUS.exitstatus)
23+
assert_path_exist('target/reports/origin_pmd_7.0.x/checkstyle/pmd_report.xml')
2024
end
2125
end

test/resources/pmd7-config.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0"?>
2+
3+
<ruleset name="Java Rules for PMD7 integration test"
4+
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
5+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
6+
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
7+
<description>Java Rules for PMD7 integration test</description>
8+
9+
<rule ref="category/java/bestpractices.xml/MissingOverride"/>
10+
<rule ref="category/java/bestpractices.xml/UnusedAssignment"/>
11+
</ruleset>

0 commit comments

Comments
 (0)