From 38a3a1205bb737e9f8f3aea5595d1eb994b4e094 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 6 May 2022 08:30:43 +0200 Subject: [PATCH] Use --aux-classpath for newer PMD versions Fixes #107 --- History.md | 2 ++ lib/pmdtester/builders/pmd_report_builder.rb | 12 +++++++++++- lib/pmdtester/builders/project_builder.rb | 2 +- lib/pmdtester/semver.rb | 6 ++++++ test/test_pmd_report_builder.rb | 9 +++++---- test/test_project_builder.rb | 2 +- 6 files changed, 26 insertions(+), 7 deletions(-) diff --git a/History.md b/History.md index ac9b1e7..fad155c 100644 --- a/History.md +++ b/History.md @@ -6,6 +6,8 @@ ## Fixed Issues +* [#107](https://github.com/pmd/pmd-regression-tester/issues/107): Deprecated command line options is used: `-auxclasspath` + ## External Contributions # 1.4.1 / 2022-04-12 diff --git a/lib/pmdtester/builders/pmd_report_builder.rb b/lib/pmdtester/builders/pmd_report_builder.rb index c40502b..cdb5b5a 100644 --- a/lib/pmdtester/builders/pmd_report_builder.rb +++ b/lib/pmdtester/builders/pmd_report_builder.rb @@ -98,12 +98,13 @@ def generate_pmd_report(project) error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : '' run_path = "#{saved_distro_path(@pmd_branch_details.branch_last_sha)}/bin/run.sh" fail_on_violation = should_use_long_cli_options ? '--fail-on-violation false' : '-failOnViolation false' + auxclasspath_option = create_auxclasspath_option(project) pmd_cmd = "#{error_recovery_options}" \ "#{run_path} pmd -d #{project.local_source_path} -f xml " \ "-R #{project.get_config_path(@pmd_branch_name)} " \ "-r #{project.get_pmd_report_path(@pmd_branch_name)} " \ "#{fail_on_violation} -t #{@threads} " \ - "#{project.auxclasspath}" + "#{auxclasspath_option}" start_time = Time.now if File.exist?(project.get_pmd_report_path(@pmd_branch_name)) logger.warn "#{@pmd_branch_name}: Skipping PMD run - report " \ @@ -200,5 +201,14 @@ def should_use_long_cli_options logger.debug "PMD Version: #{@pmd_version}" Semver.compare(@pmd_version, '6.41.0') >= 0 end + + def create_auxclasspath_option(project) + auxclasspath_option = '' + unless project.auxclasspath.empty? + auxclasspath_option = should_use_long_cli_options ? '--aux-classpath ' : '-auxclasspath ' + auxclasspath_option += project.auxclasspath + end + auxclasspath_option + end end end diff --git a/lib/pmdtester/builders/project_builder.rb b/lib/pmdtester/builders/project_builder.rb index cdc10bd..e5c1f54 100644 --- a/lib/pmdtester/builders/project_builder.rb +++ b/lib/pmdtester/builders/project_builder.rb @@ -71,7 +71,7 @@ def prepare_project(project) if project.auxclasspath_command logger.debug "Executing auxclasspath-command: #{project.auxclasspath_command}" auxclasspath = run_as_script(Dir.getwd, project.auxclasspath_command) - project.auxclasspath = "-auxclasspath #{auxclasspath}" + project.auxclasspath = auxclasspath else project.auxclasspath = '' end diff --git a/lib/pmdtester/semver.rb b/lib/pmdtester/semver.rb index 5f0f499..bd526a1 100644 --- a/lib/pmdtester/semver.rb +++ b/lib/pmdtester/semver.rb @@ -4,6 +4,12 @@ module PmdTester # Utility to deal with semantic versions class Semver def self.compare(version_a, version_b) + result = internal_compare(version_a, version_b) + PmdTester.logger.debug " result: #{result}" + result + end + + private_class_method def self.internal_compare(version_a, version_b) PmdTester.logger.debug "Comparing #{version_a} <=> #{version_b}" m = /(\d+)\.(\d+)\.(\d+)(.*)/.match(version_a) a_major = m[1].to_i diff --git a/test/test_pmd_report_builder.rb b/test/test_pmd_report_builder.rb index 2b8ee46..5012147 100644 --- a/test/test_pmd_report_builder.rb +++ b/test/test_pmd_report_builder.rb @@ -94,7 +94,7 @@ def test_build_with_projects argv.push project_list options = PmdTester::Options.new(argv) - projects[0].auxclasspath = '-auxclasspath extra:dirs' + projects[0].auxclasspath = 'extra:dirs' record_expectations('sha1abc', 'sha1abc', true) record_expectations_after_build record_expectations_project_build('sha1abc') @@ -117,7 +117,7 @@ def test_build_error_recovery argv.push project_list options = PmdTester::Options.new(argv) - projects[0].auxclasspath = '-auxclasspath extra:dirs' + projects[0].auxclasspath = 'extra:dirs' record_expectations('sha1abc', 'sha1abc', true) record_expectations_after_build record_expectations_project_build('sha1abc', true) @@ -137,7 +137,7 @@ def test_build_long_cli_options argv.push project_list options = PmdTester::Options.new(argv) - projects[0].auxclasspath = '-auxclasspath extra:dirs' + projects[0].auxclasspath = 'extra:dirs' record_expectations('sha1abc', 'sha1abc', true) record_expectations_after_build record_expectations_project_build('sha1abc', true, true) @@ -157,6 +157,7 @@ def record_expectations_project_build(sha1, error = false, long_cli_options = fa error_prefix = error ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : '' distro_path = "#{Dir.getwd}/target/pmd-bin-#{@pmd_version}-master-#{sha1}" fail_on_violation = long_cli_options ? '--fail-on-violation false' : '-failOnViolation false' + auxclasspath = long_cli_options ? '--aux-classpath extra:dirs' : '-auxclasspath extra:dirs' PmdTester::Cmd.stubs(:execute) .with("#{error_prefix}" \ "#{distro_path}/bin/run.sh " \ @@ -164,7 +165,7 @@ def record_expectations_project_build(sha1, error = false, long_cli_options = fa '-R target/reports/master/checkstyle/config.xml ' \ '-r target/reports/master/checkstyle/pmd_report.xml ' \ "#{fail_on_violation} -t 1 " \ - '-auxclasspath extra:dirs').once + "#{auxclasspath}").once PmdTester::PmdReportDetail.any_instance.stubs(:save).once end diff --git a/test/test_project_builder.rb b/test/test_project_builder.rb index 3191a4b..2c3b2fd 100644 --- a/test/test_project_builder.rb +++ b/test/test_project_builder.rb @@ -30,7 +30,7 @@ def test_build project_builder = PmdTester::ProjectBuilder.new(@projects) project_builder.build_projects - assert_equal('-auxclasspath the-aux', @projects[0].auxclasspath) + assert_equal('the-aux', @projects[0].auxclasspath) assert_equal('', @projects[1].auxclasspath) end