Skip to content

Use --aux-classpath for newer PMD versions #110

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/pmdtester/builders/pmd_report_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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 " \
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion lib/pmdtester/builders/project_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 6 additions & 0 deletions lib/pmdtester/semver.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 5 additions & 4 deletions test/test_pmd_report_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -157,14 +157,15 @@ 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 " \
'pmd -d target/repositories/checkstyle -f xml ' \
'-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

Expand Down
2 changes: 1 addition & 1 deletion test/test_project_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down