Skip to content

Commit 439f4a5

Browse files
committed
Merge branch 'pr-31'
2 parents 4d47db6 + ab2ee3e commit 439f4a5

File tree

9 files changed

+65
-54
lines changed

9 files changed

+65
-54
lines changed

.rubocop.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,11 @@ AllCops:
88

99
Metrics/LineLength:
1010
Max: 100
11+
12+
Metrics/MethodLength:
13+
Exclude:
14+
- 'lib/pmdtester/parsers/options.rb'
15+
16+
Metrics/BlockLength:
17+
Exclude:
18+
- 'lib/pmdtester/parsers/options.rb'

lib/pmdtester/builders/diff_report_builder.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,8 @@ def build_summary_table_body(doc)
7373
def build_summary_row(doc, item, base, patch, diff)
7474
doc.tr do
7575
doc.td(class: 'c') { doc.text item }
76-
doc.td(class: 'a') { doc.text base }
77-
doc.td(class: 'b') { doc.text patch }
76+
doc.td(class: 'b') { doc.text base }
77+
doc.td(class: 'a') { doc.text patch }
7878
doc.td(class: 'c') { doc.text diff }
7979
end
8080
end
@@ -131,7 +131,7 @@ def build_violation_table_body(doc, key, value)
131131
end
132132

133133
def build_violation_table_row(doc, key, pmd_violation, a_index)
134-
doc.tr(class: pmd_violation.branch == 'base' ? 'a' : 'b') do
134+
doc.tr(class: pmd_violation.branch == 'base' ? 'b' : 'a') do
135135
# The anchor
136136
doc.td do
137137
doc.a(id: "A#{a_index}", href: "#A#{a_index}") { doc.text '#' }
@@ -204,7 +204,7 @@ def build_errors_table_body(doc, errors)
204204
doc.tbody do
205205
b_index = 1
206206
errors.each do |pmd_error|
207-
doc.tr(class: pmd_error.branch == 'base' ? 'a' : 'b') do
207+
doc.tr(class: pmd_error.branch == 'base' ? 'b' : 'a') do
208208
# The anchor
209209
doc.td do
210210
doc.a(id: "B#{b_index}", href: "#B#{b_index}") { doc.text '#' }

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ def generate_pmd_reports
9797

9898
sum_time = 0
9999
@projects.each do |project|
100-
logger.info "Generating #{project.name}'s PMD report'"
100+
logger.info "Generating #{project.name}'s PMD report"
101101
execution_time, end_time =
102102
generate_pmd_report(project.local_source_path,
103103
project.get_pmd_report_path(@pmd_branch_name))

lib/pmdtester/parsers/options.rb

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ class Options
1414
LOCAL = 'local'
1515
ONLINE = 'online'
1616
SINGLE = 'single'
17+
DEFAULT_CONFIG_PATH = ResourceLocator.locate('config/all-java.xml')
18+
DEFAULT_LIST_PATH = ResourceLocator.locate('config/project-list.xml')
1719

1820
attr_reader :local_git_repo
1921
attr_reader :base_branch
@@ -68,11 +70,14 @@ def parse(argv)
6870
o.string '-b', '--base-branch', 'name of the base branch in local PMD repository'
6971
o.string '-p', '--patch-branch',
7072
'name of the patch branch in local PMD repository'
71-
o.string '-bc', '--base-config', 'path to the base PMD configuration file'
72-
o.string '-pc', '--patch-config', 'path to the patch PMD configuration file'
73+
o.string '-bc', '--base-config', 'path to the base PMD configuration file',
74+
default: DEFAULT_CONFIG_PATH
75+
o.string '-pc', '--patch-config', 'path to the patch PMD configuration file',
76+
default: DEFAULT_CONFIG_PATH
7377
o.string '-c', '--config', 'path to the base and patch PMD configuration file'
7478
o.string '-l', '--list-of-project',
75-
'path to the file which contains the list of standard projects'
79+
'path to the file which contains the list of standard projects',
80+
default: DEFAULT_LIST_PATH
7681
o.string '-m', '--mode', mode_message, default: 'local'
7782
o.bool '-f', '--html-flag',
7883
'whether to not generate the html diff report in single mode'
@@ -111,20 +116,17 @@ def check_options
111116
def check_local_options
112117
check_option(LOCAL, 'base branch name', @base_branch)
113118
check_option(LOCAL, 'base branch config path', @base_config) unless @auto_config_flag
114-
check_option(LOCAL, 'patch branch name', @patch_branch)
115119
check_option(LOCAL, 'patch branch config path', @patch_config) unless @auto_config_flag
116120
check_option(LOCAL, 'list of projects file path', @project_list)
117121
end
118122

119123
def check_single_options
120-
check_option(SINGLE, 'patch branch name', @patch_branch)
121124
check_option(SINGLE, 'patch branch config path', @patch_config)
122125
check_option(SINGLE, 'list of projects file path', @project_list)
123126
end
124127

125128
def check_online_options
126129
check_option(ONLINE, 'base branch name', @base_branch)
127-
check_option(ONLINE, 'patch branch name', @patch_branch)
128130
end
129131

130132
def check_common_options

lib/pmdtester/runner.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ def run
1818
when Options::SINGLE
1919
run_single_mode
2020
end
21+
introduce_new_pmd_error?
2122
end
2223

2324
def run_local_mode
@@ -116,5 +117,12 @@ def build_diff_html_reports
116117
def get_projects(file_path)
117118
@projects = ProjectsParser.new.parse(file_path)
118119
end
120+
121+
def introduce_new_pmd_error?
122+
@projects.each do |project|
123+
return true if project.introduce_new_errors?
124+
end
125+
false
126+
end
119127
end
120128
end

test/resources/html_report_builder/expected_diff_report_index.html

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ <h2>Summary:</h2>
1717
<tbody>
1818
<tr>
1919
<td class="c">number of errors</td>
20-
<td class="a">0</td>
21-
<td class="b">1</td>
20+
<td class="b">0</td>
21+
<td class="a">1</td>
2222
<td class="c">1</td>
2323
</tr>
2424
<tr>
2525
<td class="c">number of violations</td>
26-
<td class="a">5</td>
27-
<td class="b">8</td>
26+
<td class="b">5</td>
27+
<td class="a">8</td>
2828
<td class="c">7</td>
2929
</tr>
3030
<tr>
3131
<td class="c">execution time</td>
32-
<td class="a">00:02:01</td>
33-
<td class="b">00:01:05</td>
32+
<td class="b">00:02:01</td>
33+
<td class="a">00:01:05</td>
3434
<td class="c">00:00:56</td>
3535
</tr>
3636
<tr>
3737
<td class="c">timestamp</td>
38-
<td class="a">base time stamp</td>
39-
<td class="b">patch time stamp</td>
38+
<td class="b">base time stamp</td>
39+
<td class="a">patch time stamp</td>
4040
<td class="c"></td>
4141
</tr>
4242
</tbody>
@@ -54,7 +54,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
5454
<th>Message</th>
5555
<th>Line</th>
5656
</tr></thead>
57-
<tbody><tr class="a">
57+
<tbody><tr class="b">
5858
<td><a id="A1" href="#A1">#</a></td>
5959
<td>3</td>
6060
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
@@ -76,7 +76,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
7676
<th>Line</th>
7777
</tr></thead>
7878
<tbody>
79-
<tr class="a">
79+
<tr class="b">
8080
<td><a id="A1" href="#A1">#</a></td>
8181
<td>3</td>
8282
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#godclass">GodClass</a></td>
@@ -85,7 +85,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
8585
</td>
8686
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L63">63</a></td>
8787
</tr>
88-
<tr class="b">
88+
<tr class="a">
8989
<td><a id="A2" href="#A2">#</a></td>
9090
<td>3</td>
9191
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#godclass">GodClass</a></td>
@@ -94,7 +94,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
9494
</td>
9595
<td><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.RELEASE/spring-aop/src/main/java/org/springframework/aop/aspectj/AbstractAspectJAdvice.java#L63">63</a></td>
9696
</tr>
97-
<tr class="b">
97+
<tr class="a">
9898
<td><a id="A3" href="#A3">#</a></td>
9999
<td>3</td>
100100
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
@@ -116,7 +116,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
116116
<th>Message</th>
117117
<th>Line</th>
118118
</tr></thead>
119-
<tbody><tr class="b">
119+
<tbody><tr class="a">
120120
<td><a id="A1" href="#A1">#</a></td>
121121
<td>3</td>
122122
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
@@ -137,7 +137,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
137137
<th>Message</th>
138138
<th>Line</th>
139139
</tr></thead>
140-
<tbody><tr class="b">
140+
<tbody><tr class="a">
141141
<td><a id="A1" href="#A1">#</a></td>
142142
<td>3</td>
143143
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_codestyle.html#fielddeclarationsshouldbeatstartofclass">FieldDeclarationsShouldBeAtStartOfClass</a></td>
@@ -158,7 +158,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
158158
<th>Message</th>
159159
<th>Line</th>
160160
</tr></thead>
161-
<tbody><tr class="b">
161+
<tbody><tr class="a">
162162
<td><a id="A1" href="#A1">#</a></td>
163163
<td>1</td>
164164
<td><a href="http://pmd.sourceforge.net/snapshot/pmd_rules_java_design.html#classwithonlyprivateconstructorsshouldbefinal">ClassWithOnlyPrivateConstructorsShouldBeFinal</a></td>
@@ -180,7 +180,7 @@ <h3><a href="https://github.com/spring-projects/spring-framework/tree/v5.0.6.REL
180180
<th>Message</th>
181181
<th>Details</th>
182182
</tr></thead>
183-
<tbody><tr class="b">
183+
<tbody><tr class="a">
184184
<td><a id="B1" href="#B1">#</a></td>
185185
<td>This is an artificial error message.</td>
186186
<td></td>

test/resources/html_report_builder/expected_empty_diff_report.html

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,26 +17,26 @@ <h2>Summary:</h2>
1717
<tbody>
1818
<tr>
1919
<td class="c">number of errors</td>
20-
<td class="a">0</td>
2120
<td class="b">0</td>
21+
<td class="a">0</td>
2222
<td class="c">0</td>
2323
</tr>
2424
<tr>
2525
<td class="c">number of violations</td>
26-
<td class="a">0</td>
2726
<td class="b">0</td>
27+
<td class="a">0</td>
2828
<td class="c">0</td>
2929
</tr>
3030
<tr>
3131
<td class="c">execution time</td>
32-
<td class="a">0</td>
3332
<td class="b">0</td>
33+
<td class="a">0</td>
3434
<td class="c">0</td>
3535
</tr>
3636
<tr>
3737
<td class="c">timestamp</td>
38-
<td class="a"></td>
3938
<td class="b"></td>
39+
<td class="a"></td>
4040
<td class="c"></td>
4141
</tr>
4242
</tbody>

test/test_options.rb

Lines changed: 8 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,14 @@ def test_long_option
3030
assert_equal('config/project_list.txt', opts.project_list)
3131
end
3232

33+
def test_default_value
34+
command_line = %w[-r /path/to/repo -b pmd_releases/6.2.0 -p master]
35+
opts = Options.new(command_line)
36+
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.base_config)
37+
assert_equal(Options::DEFAULT_CONFIG_PATH, opts.patch_config)
38+
assert_equal(Options::DEFAULT_LIST_PATH, opts.project_list)
39+
end
40+
3341
def test_single_mode
3442
command_line =
3543
%w[-r /path/to/repo -p master -pc config.xml -l list.xml -f -m single]
@@ -62,27 +70,6 @@ def test_local_miss_base_name
6270
parse_and_assert_error_messages(argv, expect)
6371
end
6472

65-
def test_local_miss_base_config
66-
argv = %w[-r target/repositories/pmd -b master
67-
-p pmd_releases/6.1.0 -pc config/design.xml -l test/resources/project-test.xml]
68-
expect = 'base branch config path is required in local mode.'
69-
parse_and_assert_error_messages(argv, expect)
70-
end
71-
72-
def test_local_miss_patch_config
73-
argv = %w[-r target/repositories/pmd -bc config/design.xml
74-
-p pmd_releases/6.1.0 -l test/resources/project-test.xml]
75-
expect = 'base branch name is required in local mode.'
76-
parse_and_assert_error_messages(argv, expect)
77-
end
78-
79-
def test_single_miss_patch_config
80-
argv = %w[-r target/repositories/pmd -m single
81-
-p pmd_releases/6.1.0 -l test/resources/project-test.xml]
82-
expect = 'patch branch config path is required in single mode.'
83-
parse_and_assert_error_messages(argv, expect)
84-
end
85-
8673
def test_online_miss_base_name
8774
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0 -m online]
8875
expect = 'base branch name is required in online mode.'

test/test_runner.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ def setup
1010

1111
include PmdTester
1212

13+
def run_runner(argv)
14+
runner = Runner.new(argv)
15+
runner.expects(:introduce_new_pmd_error?).returns(true)
16+
runner.run
17+
end
18+
1319
def test_single_mode
1420
PmdReportBuilder.any_instance.stubs(:build)
1521
.returns(PmdBranchDetail.new('test_branch')).once
@@ -20,7 +26,7 @@ def test_single_mode
2026

2127
argv = %w[-r target/repositories/pmd -p pmd_releases/6.1.0
2228
-pc config/design.xml -l test/resources/project-test.xml -m single]
23-
Runner.new(argv).run
29+
run_runner(argv)
2430
end
2531

2632
def test_local_mode
@@ -31,6 +37,6 @@ def test_local_mode
3137

3238
argv = %w[-r target/repositories/pmd -b master -bc config/design.xml -p pmd_releases/6.1.0
3339
-pc config/design.xml -l test/resources/project-test.xml]
34-
Runner.new(argv).run
40+
run_runner(argv)
3541
end
3642
end

0 commit comments

Comments
 (0)