Skip to content

Commit f1c5a6a

Browse files
committed
Merge pull request #75 from adangel/pmd-regression-tester
Add new option "--error-recovery" #75
2 parents 3b8b9d4 + 5d1db97 commit f1c5a6a

File tree

13 files changed

+91
-36
lines changed

13 files changed

+91
-36
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ 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"
1819

1920
## External Contributions
2021

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
@@ -8,16 +8,17 @@ module PmdTester
88
# projects and branch of pmd source code
99
class PmdReportBuilder
1010
include PmdTester
11-
def initialize(branch_config, projects, local_git_repo, pmd_branch_name, threads = 1)
12-
@branch_config = branch_config
11+
def initialize(projects, options, branch_config, branch_name)
1312
@projects = projects
14-
@local_git_repo = local_git_repo
15-
@pmd_branch_name = pmd_branch_name
16-
@threads = threads
13+
@local_git_repo = options.local_git_repo
14+
@threads = options.threads
15+
@error_recovery = options.error_recovery
16+
@branch_config = branch_config
17+
@pmd_branch_name = branch_name
1718
@pwd = Dir.getwd
1819

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

2324
def get_pmd_binary_file
@@ -82,8 +83,10 @@ def get_last_commit_message
8283
end
8384

8485
def generate_pmd_report(project)
86+
error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : ''
8587
run_path = "target/pmd-bin-#{@pmd_version}/bin/run.sh"
86-
pmd_cmd = "#{run_path} pmd -d #{project.local_source_path} -f xml " \
88+
pmd_cmd = "#{error_recovery_options}" \
89+
"#{run_path} pmd -d #{project.local_source_path} -f xml " \
8790
"-R #{project.get_config_path(@pmd_branch_name)} " \
8891
"-r #{project.get_pmd_report_path(@pmd_branch_name)} " \
8992
"-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/runner.rb

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,10 @@ def run_local_mode
3535
return if rule_sets&.empty?
3636

3737
PmdReportBuilder
38-
.new(@options.base_config, @projects, @options.local_git_repo, @options.base_branch,
39-
@options.threads)
38+
.new(@projects, @options, @options.base_config, @options.base_branch)
4039
.build
4140
PmdReportBuilder
42-
.new(@options.patch_config, @projects, @options.local_git_repo, @options.patch_branch,
43-
@options.threads)
41+
.new(@projects, @options, @options.patch_config, @options.patch_branch)
4442
.build
4543

4644
build_html_reports
@@ -66,8 +64,7 @@ def run_online_mode
6664
end
6765

6866
PmdReportBuilder
69-
.new(@options.patch_config, @projects,
70-
@options.local_git_repo, @options.patch_branch, @options.threads)
67+
.new(@projects, @options, @options.patch_config, @options.patch_branch)
7168
.build
7269

7370
build_html_reports
@@ -113,9 +110,8 @@ def run_single_mode
113110

114111
get_projects(@options.project_list) unless @options.nil?
115112
branch_details = PmdReportBuilder
116-
.new(@options.patch_config, @projects,
117-
@options.local_git_repo, @options.patch_branch,
118-
@options.threads)
113+
.new(@projects, @options,
114+
@options.patch_config, @options.patch_branch)
119115
.build
120116
# copy list of projects file to the patch baseline
121117
FileUtils.cp(@options.project_list, branch_details.target_branch_project_list_path)

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>

test/resources/project-test.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ xsi:noNamespaceSchemaLocation="projectlist_1_1_0.xsd">
99
<type>git</type>
1010
<connection>https://github.com/checkstyle/checkstyle</connection>
1111
<tag>checkstyle-8.0</tag>
12-
<exclude-pattern>.*/src/test/resources-noncompilable/.*</exclude-pattern>
13-
<exclude-pattern>.*/src/test/resources/.*</exclude-pattern>
12+
<exclude-pattern>.*/target/test-classes/com/puppycrawl/tools/checkstyle/.*</exclude-pattern>
13+
<exclude-pattern>.*/target/generated-sources/.*</exclude-pattern>
1414

1515
<build-command><![CDATA[#!/usr/bin/env bash
1616
if test -e classpath.txt; then
@@ -23,6 +23,7 @@ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=classpath.t
2323
<auxclasspath-command>echo -n "$(pwd)/target/classes:$(pwd)/target/test-classes:"; cat classpath.txt</auxclasspath-command>
2424
</project>
2525

26+
<!-- this project configuration is here, so that PMD's repo is cloned into target/repositories for integration tests -->
2627
<project>
2728
<name>pmd</name>
2829
<type>git</type>

test/test_options.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ def test_default_value
3838
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.base_config)
3939
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.patch_config)
4040
assert_equal(Options::DEFAULT_LIST_PATH, opts.project_list)
41+
assert_false(opts.error_recovery)
42+
end
43+
44+
def test_enable_error_recovery
45+
command_line = %w[-r /path/to/repo -b pmd_releases/6.2.0 -p master --error-recovery]
46+
opts = Options.new(command_line)
47+
assert_true(opts.error_recovery)
4148
end
4249

4350
def test_single_mode

0 commit comments

Comments
 (0)