Skip to content

Commit 56d03ab

Browse files
committed
Merge pull request #120 from adangel:update-pmd-dist-filename-pmd7
Support new PMD 7 binary dist filename #120
2 parents 10efe93 + 4222138 commit 56d03ab

File tree

3 files changed

+91
-17
lines changed

3 files changed

+91
-17
lines changed

History.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
## Enhancements
66
* [#118](https://github.com/pmd/pmd-regression-tester/pull/118): Update js libraries
7+
* [#120](https://github.com/pmd/pmd-regression-tester/pull/120): Support new PMD 7 binary dist filename
78

89
## Fixed Issues
910

lib/pmdtester/builders/pmd_report_builder.rb

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,9 +53,7 @@ def get_pmd_binary_file
5353
def build_pmd(into_dir:)
5454
# in CI there might have been a build performed already. In that case
5555
# we reuse the build result, otherwise we build PMD freshly
56-
pmd_dist_target = "pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
57-
binary_exists = File.exist?(pmd_dist_target)
58-
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
56+
pmd_dist_target, binary_exists = find_pmd_dist_target
5957
if binary_exists
6058
# that's a warning, because we don't know, whether this build really
6159
# belongs to the current branch or whether it's from a previous branch.
@@ -71,6 +69,13 @@ def build_pmd(into_dir:)
7169
' -Dpmd.skip=true' \
7270
' -T1C -B'
7371
Cmd.execute_successfully(package_cmd)
72+
73+
pmd_dist_target, binary_exists = find_pmd_dist_target
74+
unless binary_exists
75+
logger.error "#{@pmd_branch_name}: Dist zip not found at #{pmd_dist_target}!"
76+
raise "No Dist zip found at #{pmd_dist_target}"
77+
end
78+
7479
end
7580

7681
logger.info "#{@pmd_branch_name}: Extracting the zip"
@@ -227,5 +232,17 @@ def determine_run_path
227232
end
228233
run_path
229234
end
235+
236+
def find_pmd_dist_target
237+
pmd_dist_target = "pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
238+
binary_exists = File.exist?(pmd_dist_target)
239+
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
240+
unless binary_exists
241+
pmd_dist_target = "pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"
242+
binary_exists = File.exist?(pmd_dist_target)
243+
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
244+
end
245+
[pmd_dist_target, binary_exists]
246+
end
230247
end
231248
end

test/test_pmd_report_builder.rb

Lines changed: 70 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,10 @@ def setup
1414
def teardown
1515
pmd_repo = 'target/repositories/pmd'
1616
# pre-built PMD binary
17-
pmd_binary = "#{pmd_repo}/pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
18-
File.unlink pmd_binary if File.exist? pmd_binary
17+
["#{pmd_repo}/pmd-dist/target/pmd-bin-#{@pmd_version}.zip",
18+
"#{pmd_repo}/pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"].each do |pmd_binary|
19+
File.unlink pmd_binary if File.exist? pmd_binary
20+
end
1921

2022
# only deleting empty directories in order to leave pmd_repo intact
2123
# for local dev environment, where a local pmd clone might already exist
@@ -30,7 +32,7 @@ def test_build_skip
3032
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
3133
options = PmdTester::Options.new(argv)
3234

33-
record_expectations('sha1abc', 'sha1abc', true)
35+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
3436
record_expectations_after_build
3537

3638
PmdTester::PmdReportBuilder
@@ -51,7 +53,7 @@ def test_build_skip_ci
5153
FileUtils.mkdir_p 'target/repositories/pmd/pmd-dist/target'
5254
FileUtils.touch "target/repositories/pmd/pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
5355

54-
record_expectations('sha1abc', 'sha1abc', false)
56+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
5557
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-bin-#{@pmd_version}.zip" \
5658
' -d pmd-dist/target/exploded').once
5759
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
@@ -63,17 +65,37 @@ def test_build_skip_ci
6365
.build
6466
end
6567

68+
# with PMD7, the dist bin file is called pmd-dist/target/pmd-dist-7.0.0-bin-SNAPSHOT.zip
69+
def test_build_skip_ci_pmd7
70+
projects = []
71+
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.55.0
72+
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
73+
options = PmdTester::Options.new(argv)
74+
75+
FileUtils.mkdir_p 'target/repositories/pmd/pmd-dist/target'
76+
FileUtils.touch "target/repositories/pmd/pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"
77+
78+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
79+
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip" \
80+
' -d pmd-dist/target/exploded').once
81+
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
82+
" #{Dir.getwd}/target/pmd-bin-#{@pmd_version}-master-sha1abc").once
83+
record_expectations_after_build
84+
85+
PmdTester::PmdReportBuilder
86+
.new(projects, options, options.base_config, options.base_branch)
87+
.build
88+
end
89+
6690
def test_build_normal
6791
projects = []
6892
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.1.0
6993
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
7094
options = PmdTester::Options.new(argv)
7195

7296
# PMD binary does not exist yet this time...
73-
record_expectations('sha1abc', 'sha1abc', false)
74-
PmdTester::Cmd.stubs(:execute_successfully).with('./mvnw clean package -Dmaven.test.skip=true' \
75-
' -Dmaven.javadoc.skip=true -Dmaven.source.skip=true' \
76-
' -Dcheckstyle.skip=true -Dpmd.skip=true -T1C -B').once
97+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
98+
stub_pmd_build_maven(binary_name: "pmd-bin-#{@pmd_version}.zip")
7799
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-bin-#{@pmd_version}.zip" \
78100
' -d pmd-dist/target/exploded').once
79101
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
@@ -85,6 +107,26 @@ def test_build_normal
85107
.build
86108
end
87109

110+
def test_build_normal_pmd7
111+
projects = []
112+
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.1.0
113+
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
114+
options = PmdTester::Options.new(argv)
115+
116+
# PMD binary does not exist yet this time...
117+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
118+
stub_pmd_build_maven(binary_name: "pmd-dist-#{@pmd_version}-bin.zip")
119+
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip" \
120+
' -d pmd-dist/target/exploded').once
121+
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
122+
" #{Dir.getwd}/target/pmd-bin-#{@pmd_version}-master-sha1abc").once
123+
record_expectations_after_build
124+
125+
PmdTester::PmdReportBuilder
126+
.new(projects, options, options.base_config, options.base_branch)
127+
.build
128+
end
129+
88130
def test_build_with_projects
89131
project_list = 'test/resources/pmd_report_builder/project-list.xml'
90132
projects = PmdTester::ProjectsParser.new.parse(project_list)
@@ -95,7 +137,7 @@ def test_build_with_projects
95137
options = PmdTester::Options.new(argv)
96138

97139
projects[0].auxclasspath = 'extra:dirs'
98-
record_expectations('sha1abc', 'sha1abc', true)
140+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
99141
record_expectations_after_build
100142
record_expectations_project_build(sha1: 'sha1abc')
101143

@@ -118,7 +160,7 @@ def test_build_error_recovery
118160
options = PmdTester::Options.new(argv)
119161

120162
projects[0].auxclasspath = 'extra:dirs'
121-
record_expectations('sha1abc', 'sha1abc', true)
163+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
122164
record_expectations_after_build
123165
record_expectations_project_build(sha1: 'sha1abc', error: true)
124166

@@ -138,7 +180,7 @@ def test_build_long_cli_options
138180
options = PmdTester::Options.new(argv)
139181

140182
projects[0].auxclasspath = 'extra:dirs'
141-
record_expectations('sha1abc', 'sha1abc', true)
183+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
142184
record_expectations_after_build
143185
record_expectations_project_build(sha1: 'sha1abc', error: true, long_cli_options: true)
144186

@@ -159,7 +201,7 @@ def test_build_pmd7
159201
options = PmdTester::Options.new(argv)
160202

161203
projects[0].auxclasspath = 'extra:dirs'
162-
record_expectations(sha1, sha1, true)
204+
record_expectations(sha1_head: sha1, sha1_base: sha1, zip_file_exists: true)
163205
record_expectations_after_build
164206
record_expectations_project_build(sha1: sha1, error: true, long_cli_options: true,
165207
no_progress_bar: true, base_cmd: 'pmd check')
@@ -188,7 +230,7 @@ def test_build_failing
188230
options = PmdTester::Options.new(argv)
189231

190232
projects[0].auxclasspath = 'extra:dirs'
191-
record_expectations('sha1abc', 'sha1abc', true)
233+
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
192234
record_expectations_after_build
193235
record_expectations_project_build(sha1: 'sha1abc', error: true, exit_status: 1)
194236

@@ -224,7 +266,7 @@ def record_expectations_project_build(sha1:, error: false, long_cli_options: fal
224266
PmdTester::PmdReportDetail.stubs(:create).once.with { |params| params[:exit_code] == exit_status }
225267
end
226268

227-
def record_expectations(sha1_head, sha1_base, zip_file_exists)
269+
def record_expectations(sha1_head:, sha1_base:, zip_file_exists:)
228270
PmdTester::Cmd.stubs(:execute_successfully).with('git rev-parse master^{commit}').returns(sha1_base).once
229271
# inside checkout_build_branch
230272
PmdTester::Cmd.stubs(:execute_successfully).with('git checkout master')
@@ -265,4 +307,18 @@ def cleanup_pmd_dist_dir(base_dir:)
265307
File.unlink("#{base_dir}/pmd")
266308
Dir.rmdir(base_dir)
267309
end
310+
311+
def stub_pmd_build_maven(binary_name:)
312+
PmdTester::Cmd.stubs(:execute_successfully).with do |cmd|
313+
if cmd == './mvnw clean package -Dmaven.test.skip=true' \
314+
' -Dmaven.javadoc.skip=true -Dmaven.source.skip=true' \
315+
' -Dcheckstyle.skip=true -Dpmd.skip=true -T1C -B'
316+
FileUtils.mkdir_p 'pmd-dist/target'
317+
FileUtils.touch "pmd-dist/target/#{binary_name}"
318+
true
319+
else
320+
false
321+
end
322+
end.once
323+
end
268324
end

0 commit comments

Comments
 (0)