Skip to content

Commit 8c296cc

Browse files
committed
Fix usage of --fail-on-violation with PMD 7
1 parent b8aa960 commit 8c296cc

File tree

3 files changed

+30
-6
lines changed

3 files changed

+30
-6
lines changed

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def get_last_commit_message
9191

9292
def generate_pmd_report(project)
9393
error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : ''
94-
fail_on_violation = should_use_long_cli_options? ? '--fail-on-violation false' : '-failOnViolation false'
94+
fail_on_violation = create_failonviolation_option
9595
auxclasspath_option = create_auxclasspath_option(project)
9696
pmd_cmd = "#{error_recovery_options}" \
9797
"#{determine_run_path} -d #{project.local_source_path} -f xml " \
@@ -208,6 +208,16 @@ def create_auxclasspath_option(project)
208208
auxclasspath_option
209209
end
210210

211+
def create_failonviolation_option
212+
if pmd7?
213+
'--no-fail-on-violation'
214+
elsif should_use_long_cli_options?
215+
'--fail-on-violation false'
216+
else
217+
'-failOnViolation false'
218+
end
219+
end
220+
211221
def pmd7?
212222
Semver.compare(@pmd_version, '7.0.0-SNAPSHOT') >= 0
213223
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, "Cl\u00E9ment Fournier".freeze]
14-
s.date = "2023-05-26"
14+
s.date = "2023-05-27"
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, "[email protected]".freeze]
1717
s.executables = ["pmdtester".freeze]

test/test_pmd_report_builder.rb

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ def test_build_pmd7
204204
record_expectations(sha1_head: sha1, sha1_base: sha1, zip_file_exists: true)
205205
record_expectations_after_build
206206
record_expectations_project_build(sha1: sha1, error: true, long_cli_options: true,
207-
no_progress_bar: true, base_cmd: 'pmd check')
207+
no_progress_bar: true, pmd7: true)
208208

209209
pmd_cli_cmd = prepare_pmd_dist_dir(version: @pmd_version, sha1: sha1)
210210
begin
@@ -241,8 +241,23 @@ def test_build_failing
241241

242242
private
243243

244+
def determine_cli_cmd_and_options(pmd7:, long_cli_options:)
245+
if pmd7
246+
base_cmd = 'pmd check'
247+
fail_on_violation = '--no-fail-on-violation'
248+
auxclasspath_option = '--aux-classpath extra:dirs'
249+
else
250+
base_cmd = 'run.sh pmd'
251+
fail_on_violation = long_cli_options ? '--fail-on-violation false' : '-failOnViolation false'
252+
auxclasspath_option = long_cli_options ? '--aux-classpath extra:dirs' : '-auxclasspath extra:dirs'
253+
end
254+
[base_cmd, fail_on_violation, auxclasspath_option]
255+
end
256+
244257
def record_expectations_project_build(sha1:, error: false, long_cli_options: false,
245-
no_progress_bar: false, exit_status: 0, base_cmd: 'run.sh pmd')
258+
no_progress_bar: false, exit_status: 0, pmd7: false)
259+
base_cmd, fail_on_violation, auxclasspath_option = determine_cli_cmd_and_options(pmd7: pmd7,
260+
long_cli_options: long_cli_options)
246261
PmdTester::ProjectBuilder.any_instance.stubs(:clone_projects).once
247262
PmdTester::ProjectBuilder.any_instance.stubs(:build_projects).once
248263
PmdTester::SimpleProgressLogger.any_instance.stubs(:start).once
@@ -257,8 +272,7 @@ def record_expectations_project_build(sha1:, error: false, long_cli_options: fal
257272
'-d target/repositories/checkstyle -f xml ' \
258273
'-R target/reports/master/checkstyle/config.xml ' \
259274
'-r target/reports/master/checkstyle/pmd_report.xml ' \
260-
"#{long_cli_options ? '--fail-on-violation false' : '-failOnViolation false'} -t 1 " \
261-
"#{long_cli_options ? '--aux-classpath extra:dirs' : '-auxclasspath extra:dirs'}" \
275+
"#{fail_on_violation} -t 1 #{auxclasspath_option}" \
262276
"#{no_progress_bar ? ' --no-progress' : ''}",
263277
'target/reports/master/checkstyle').once
264278
.returns(process_status)

0 commit comments

Comments
 (0)