Skip to content

Commit e60274c

Browse files
committed
Test whether the new PMD start script is available
Don't check the version. That way, the regression tester is forward compatible.
1 parent 85fd2d2 commit e60274c

File tree

3 files changed

+38
-8
lines changed

3 files changed

+38
-8
lines changed

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,10 @@ def get_last_commit_message
9696

9797
def generate_pmd_report(project)
9898
error_recovery_options = @error_recovery ? 'PMD_JAVA_OPTS="-Dpmd.error_recovery -ea" ' : ''
99-
run_path = "#{saved_distro_path(@pmd_branch_details.branch_last_sha)}/bin/#{pmd7? ? 'pmd analyze' : 'run.sh pmd'}"
10099
fail_on_violation = should_use_long_cli_options? ? '--fail-on-violation false' : '-failOnViolation false'
101100
auxclasspath_option = create_auxclasspath_option(project)
102101
pmd_cmd = "#{error_recovery_options}" \
103-
"#{run_path} -d #{project.local_source_path} -f xml " \
102+
"#{determine_run_path} -d #{project.local_source_path} -f xml " \
104103
"-R #{project.get_config_path(@pmd_branch_name)} " \
105104
"-r #{project.get_pmd_report_path(@pmd_branch_name)} " \
106105
"#{fail_on_violation} -t #{@threads} " \
@@ -217,5 +216,16 @@ def create_auxclasspath_option(project)
217216
def pmd7?
218217
Semver.compare(@pmd_version, '7.0.0-SNAPSHOT') >= 0
219218
end
219+
220+
def determine_run_path
221+
run_path = "#{saved_distro_path(@pmd_branch_details.branch_last_sha)}/bin"
222+
run_path = if File.exist?("#{run_path}/pmd")
223+
# New PMD 7 CLI script (pmd/pmd#4059)
224+
"#{run_path}/pmd analyze"
225+
else
226+
"#{run_path}/run.sh pmd"
227+
end
228+
run_path
229+
end
220230
end
221231
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 = "2022-10-07"
14+
s.date = "2022-10-13"
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: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ def test_build_long_cli_options
149149

150150
def test_build_pmd7
151151
@pmd_version = '7.0.0-SNAPSHOT'
152+
sha1 = 'sha1abc'
152153
project_list = 'test/resources/pmd_report_builder/project-list.xml'
153154
projects = PmdTester::ProjectsParser.new.parse(project_list)
154155
assert_equal(1, projects.size)
@@ -158,14 +159,19 @@ def test_build_pmd7
158159
options = PmdTester::Options.new(argv)
159160

160161
projects[0].auxclasspath = 'extra:dirs'
161-
record_expectations('sha1abc', 'sha1abc', true)
162+
record_expectations(sha1, sha1, true)
162163
record_expectations_after_build
163-
record_expectations_project_build(sha1: 'sha1abc', error: true, long_cli_options: true,
164+
record_expectations_project_build(sha1: sha1, error: true, long_cli_options: true,
164165
no_progress_bar: true, base_cmd: 'pmd analyze')
165166

166-
PmdTester::PmdReportBuilder
167-
.new(projects, options, options.base_config, options.base_branch)
168-
.build
167+
pmd_cli_cmd = prepare_pmd_dist_dir(version: @pmd_version, sha1: sha1)
168+
begin
169+
PmdTester::PmdReportBuilder
170+
.new(projects, options, options.base_config, options.base_branch)
171+
.build
172+
ensure
173+
cleanup_pmd_dist_dir(base_dir: pmd_cli_cmd)
174+
end
169175
end
170176

171177
#
@@ -245,4 +251,18 @@ def record_expectations_after_build
245251
PmdTester::PmdBranchDetail.any_instance.stubs(:save).once
246252
FileUtils.stubs(:cp).with('config/design.xml', 'target/reports/master/config.xml').once
247253
end
254+
255+
# Creates a fake pmd script file as .../bin/pmd.
256+
# This is used in the new PMD 7 CLI interface
257+
def prepare_pmd_dist_dir(version:, sha1:)
258+
pmd_cli_cmd = "#{Dir.getwd}/target/pmd-bin-#{version}-master-#{sha1}/bin"
259+
FileUtils.mkdir_p(pmd_cli_cmd)
260+
File.new("#{pmd_cli_cmd}/pmd", 'w')
261+
pmd_cli_cmd
262+
end
263+
264+
def cleanup_pmd_dist_dir(base_dir:)
265+
File.unlink("#{base_dir}/pmd")
266+
Dir.rmdir(base_dir)
267+
end
248268
end

0 commit comments

Comments
 (0)