Skip to content

Commit cce8d2b

Browse files
committed
Introduce new option "--filter-with-patch-config"
1 parent 412b4c7 commit cce8d2b

File tree

8 files changed

+94
-17
lines changed

8 files changed

+94
-17
lines changed

README.rdoc

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,29 +20,30 @@ on a list of standard projects(Spring Framework, Hibernate, Solr, etc.)
2020
== SYNOPSIS:
2121

2222
=== Options:
23-
-r, --local-git-repo path to the local PMD repository
24-
-b, --base-branch name of the base branch in local PMD repository
25-
-p, --patch-branch name of the patch branch in local PMD repository
26-
-bc, --base-config path to the base PMD configuration file default:PMDTESTER_INSTALLED_DIR/config/all-java.xml
27-
-pc, --patch-config path to the patch PMD configuration file default:PMDTESTER_INSTALLED_DIR/config/all-java.xml
28-
-c, --config path to the base and patch PMD configuration file
29-
-l, --list-of-project path to the file which contains the list of standard projects default:PMDTESTER_INSTALLED_DIR/config/project-list.xml
30-
-m, --mode the mode of the tool: 'local', 'online' or 'single'
23+
-r, --local-git-repo path to the local PMD repository
24+
-b, --base-branch name of the base branch in local PMD repository
25+
-p, --patch-branch name of the patch branch in local PMD repository
26+
-bc, --base-config path to the base PMD configuration file
27+
-pc, --patch-config path to the patch PMD configuration file
28+
-c, --config path to the base and patch PMD configuration file
29+
-l, --list-of-project path to the file which contains the list of standard projects
30+
-m, --mode the mode of the tool: 'local', 'online' or 'single'
3131
single: Set this option to 'single' if your patch branch contains changes
3232
for any option that can't work on master/base branch
3333
online: Set this option to 'online' if you want to download
3434
the PMD report of master/base branch rather than generating it locally
3535
local: Default option is 'local', PMD reports for the base and patch branches are generated locally.
3636

37-
-t, --threads Sets the number of threads used by PMD. Set threads to 0 to disable multi-threading processing. default:1
38-
-f, --html-flag whether to not generate the html diff report in single mode
39-
-a, --auto-gen-config whether to generate configurations automatically based on branch differences,this option only works in online and local mode
40-
--keep-reports whether to keep old reports and skip running PMD again if possible
41-
-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.
43-
--baseline-download-url download url prefix from where to download the baseline in online mode default:https://sourceforge.net/projects/pmd/files/pmd-regression-tester/
44-
-v, --version
45-
-h, --help
37+
-t, --threads Sets the number of threads used by PMD. Set threads to 0 to disable multi-threading processing.
38+
-f, --html-flag whether to not generate the html diff report in single mode
39+
-a, --auto-gen-config whether to generate configurations automatically based on branch differences,this option only works in online and local mode
40+
--filter-with-patch-config whether to use patch config to filter baseline result as if --auto-gen-config has been used. This option only works in online mode.
41+
--keep-reports whether to keep old reports and skip running PMD again if possible
42+
-d, --debug whether change log level to DEBUG to see more information
43+
--error-recovery enable error recovery mode when executing PMD. Might help to analyze errors.
44+
--baseline-download-url download url prefix from where to download the baseline in online mode
45+
-v, --version
46+
-h, --help
4647

4748
=== Quick start
4849

lib/pmdtester/parsers/options.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ class Options
2929
attr_reader :threads
3030
attr_reader :html_flag
3131
attr_reader :auto_config_flag
32+
attr_reader :filter_with_patch_config
3233
attr_reader :debug_flag
3334
attr_accessor :filter_set
3435
attr_reader :keep_reports
@@ -48,6 +49,7 @@ def initialize(argv)
4849
@threads = options[:t]
4950
@html_flag = options[:f]
5051
@auto_config_flag = options[:a]
52+
@filter_with_patch_config = options.filter_with_patch_config?
5153
@debug_flag = options[:d]
5254
@filter_set = nil
5355
@keep_reports = options.keep_reports?
@@ -100,6 +102,9 @@ def parse(argv)
100102
o.bool '-a', '--auto-gen-config',
101103
'whether to generate configurations automatically based on branch differences,' \
102104
'this option only works in online and local mode'
105+
o.bool '--filter-with-patch-config',
106+
'whether to use patch config to filter baseline result as if --auto-gen-config ' \
107+
'has been used. This option only works in online mode.'
103108
o.bool '--keep-reports',
104109
'whether to keep old reports and skip running PMD again if possible'
105110
o.bool '-d', '--debug',

lib/pmdtester/runner.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ def run_online_mode
5959
@options.patch_config = "#{baseline_path}/config.xml"
6060
else
6161
logger.info "Using config #{@options.patch_config} which might differ from baseline"
62+
RuleSetBuilder.new(@options).calculate_filter_set if @options.filter_with_patch_config
6263
end
6364

6465
patch_branch_details = create_pmd_report(config: @options.patch_config, branch: @options.patch_branch)
4.14 KB
Binary file not shown.
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ruleset xmlns="http://pmd.sourceforge.net/ruleset/2.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd" name="Dynamic PmdTester Ruleset">
3+
<description>The ruleset generated by PmdTester dynamically</description>
4+
<rule ref="category/java/performance.xml/ConsecutiveLiteralAppends"/>
5+
</ruleset>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<pmd xmlns="http://pmd.sourceforge.net/report/2.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://pmd.sourceforge.net/report/2.0.0 http://pmd.sourceforge.net/report_2_0_0.xsd"
5+
version="6.3.0-SNAPSHOT" timestamp="2018-04-16T22:41:45.065">
6+
<file name="Base1.java">
7+
<violation beginline="51" endline="51" begincolumn="9" endcolumn="46" rule="ConsecutiveLiteralAppends" ruleset="Performance" package="org.springframework.aop" class="Pointcut" variable="TRUE" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass" priority="3">
8+
This stays in the report.
9+
</violation>
10+
<violation beginline="151" endline="151" begincolumn="9" endcolumn="46" rule="ConsecutiveLiteralAppends" ruleset="Performance" package="org.springframework.aop" class="Pointcut" variable="TRUE" externalInfoUrl="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass" priority="3">
11+
This is a new violation.
12+
</violation>
13+
</file>
14+
</pmd>
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?xml version="1.0"?>
2+
3+
<projectlist xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:noNamespaceSchemaLocation="projectlist_1_1_0.xsd">
5+
<description>Standard Projects</description>
6+
7+
<project>
8+
<name>checkstyle</name>
9+
<type>git</type>
10+
<connection>https://github.com/checkstyle/checkstyle</connection>
11+
<exclude-pattern>**/src/test/resources-noncompilable/**/*</exclude-pattern>
12+
<exclude-pattern>**/src/test/resources/**/*</exclude-pattern>
13+
<build-command></build-command>
14+
<auxclasspath-command>echo -n "$(pwd)/target/classes:"</auxclasspath-command>
15+
</project>
16+
17+
</projectlist>

test/test_runner.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -136,6 +136,40 @@ def test_online_mode_multithreading
136136
assert_summarized_diffs(summarized_results)
137137
end
138138

139+
def test_online_mode_keep_reports_second_run_filtering
140+
FileUtils.mkdir_p 'target/reports/pmd_releases_6.7.0/checkstyle'
141+
# placing the baseline zip here avoid downloading it during test run - and we can craft it for the test
142+
FileUtils.cp 'test/resources/runner/master-baseline.zip', 'target/reports'
143+
# placing the report here avoids running PMD again - and we can craft it for the test
144+
FileUtils.cp 'test/resources/runner/pmd_report.xml', 'target/reports/pmd_releases_6.7.0/checkstyle/pmd_report.xml'
145+
146+
# create a empty directory for PMD build to avoid building PMD during test
147+
fake_pmd_bin = 'target/pmd-bin-6.7.0-pmd_releases_6.7.0-b98bd0bb961d9f82437acccfe64923d992970310'
148+
FileUtils.mkdir_p fake_pmd_bin unless Dir.exist?(fake_pmd_bin)
149+
150+
begin
151+
argv = %w[-r target/repositories/pmd -m online -b master -p pmd_releases/6.7.0
152+
--list-of-project test/resources/runner/project-list.xml
153+
--keep-reports --filter-with-patch-config
154+
--patch-config test/resources/runner/patch-config.xml]
155+
summarized_results = run_runner(argv)
156+
assert_equal(0, summarized_results[:violations][:changed])
157+
assert_equal(1, summarized_results[:violations][:new])
158+
# while the baseline has also a violation for a different rule (AbstractClassWithoutAbstractMethod)
159+
# the patch-config.xml ruleset only contains the rule ConsecutiveLiteralAppends
160+
# and so does the prepared result pmd_report.xml.
161+
# with "--filter-with-patch-config" the irrelevant rules from baseline are ignored
162+
assert_equal(0, summarized_results[:violations][:removed])
163+
# baseline has only one violation for rule ConsecutiveLiteralAppends
164+
assert_equal(1, summarized_results[:violations][:base_total])
165+
# patch has two violations for rule ConsecutiveLiteralAppends
166+
assert_equal(2, summarized_results[:violations][:patch_total])
167+
ensure
168+
# cleanup
169+
Dir.rmdir fake_pmd_bin if Dir.empty?(fake_pmd_bin)
170+
end
171+
end
172+
139173
private
140174

141175
def assert_summarized_diffs(diffs)

0 commit comments

Comments
 (0)