Skip to content

Commit

Permalink
Merge pull request #120 from adangel:update-pmd-dist-filename-pmd7
Browse files Browse the repository at this point in the history
Support new PMD 7 binary dist filename #120
  • Loading branch information
adangel committed May 26, 2023
2 parents 10efe93 + 4222138 commit 56d03ab
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 17 deletions.
1 change: 1 addition & 0 deletions History.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

## Fixed Issues

Expand Down
23 changes: 20 additions & 3 deletions lib/pmdtester/builders/pmd_report_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,7 @@ def get_pmd_binary_file
def build_pmd(into_dir:)
# in CI there might have been a build performed already. In that case
# we reuse the build result, otherwise we build PMD freshly
pmd_dist_target = "pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
binary_exists = File.exist?(pmd_dist_target)
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
pmd_dist_target, binary_exists = find_pmd_dist_target
if binary_exists
# that's a warning, because we don't know, whether this build really
# belongs to the current branch or whether it's from a previous branch.
Expand All @@ -71,6 +69,13 @@ def build_pmd(into_dir:)
' -Dpmd.skip=true' \
' -T1C -B'
Cmd.execute_successfully(package_cmd)

pmd_dist_target, binary_exists = find_pmd_dist_target
unless binary_exists
logger.error "#{@pmd_branch_name}: Dist zip not found at #{pmd_dist_target}!"
raise "No Dist zip found at #{pmd_dist_target}"
end

end

logger.info "#{@pmd_branch_name}: Extracting the zip"
Expand Down Expand Up @@ -227,5 +232,17 @@ def determine_run_path
end
run_path
end

def find_pmd_dist_target
pmd_dist_target = "pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
binary_exists = File.exist?(pmd_dist_target)
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
unless binary_exists
pmd_dist_target = "pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"
binary_exists = File.exist?(pmd_dist_target)
logger.debug "#{@pmd_branch_name}: Does the file #{pmd_dist_target} exist? #{binary_exists} (cwd: #{Dir.getwd})"
end
[pmd_dist_target, binary_exists]
end
end
end
84 changes: 70 additions & 14 deletions test/test_pmd_report_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ def setup
def teardown
pmd_repo = 'target/repositories/pmd'
# pre-built PMD binary
pmd_binary = "#{pmd_repo}/pmd-dist/target/pmd-bin-#{@pmd_version}.zip"
File.unlink pmd_binary if File.exist? pmd_binary
["#{pmd_repo}/pmd-dist/target/pmd-bin-#{@pmd_version}.zip",
"#{pmd_repo}/pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"].each do |pmd_binary|
File.unlink pmd_binary if File.exist? pmd_binary
end

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

record_expectations('sha1abc', 'sha1abc', true)
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
record_expectations_after_build

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

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

# with PMD7, the dist bin file is called pmd-dist/target/pmd-dist-7.0.0-bin-SNAPSHOT.zip
def test_build_skip_ci_pmd7
projects = []
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.55.0
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
options = PmdTester::Options.new(argv)

FileUtils.mkdir_p 'target/repositories/pmd/pmd-dist/target'
FileUtils.touch "target/repositories/pmd/pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip"

record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip" \
' -d pmd-dist/target/exploded').once
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
" #{Dir.getwd}/target/pmd-bin-#{@pmd_version}-master-sha1abc").once
record_expectations_after_build

PmdTester::PmdReportBuilder
.new(projects, options, options.base_config, options.base_branch)
.build
end

def test_build_normal
projects = []
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.1.0
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
options = PmdTester::Options.new(argv)

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

def test_build_normal_pmd7
projects = []
argv = %w[-r target/repositories/pmd -b master -p pmd_releases/6.1.0
-c config/design.xml -l test/resources/pmd_report_builder/project-test.xml]
options = PmdTester::Options.new(argv)

# PMD binary does not exist yet this time...
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: false)
stub_pmd_build_maven(binary_name: "pmd-dist-#{@pmd_version}-bin.zip")
PmdTester::Cmd.stubs(:execute_successfully).with("unzip -qo pmd-dist/target/pmd-dist-#{@pmd_version}-bin.zip" \
' -d pmd-dist/target/exploded').once
PmdTester::Cmd.stubs(:execute_successfully).with("mv pmd-dist/target/exploded/pmd-bin-#{@pmd_version}" \
" #{Dir.getwd}/target/pmd-bin-#{@pmd_version}-master-sha1abc").once
record_expectations_after_build

PmdTester::PmdReportBuilder
.new(projects, options, options.base_config, options.base_branch)
.build
end

def test_build_with_projects
project_list = 'test/resources/pmd_report_builder/project-list.xml'
projects = PmdTester::ProjectsParser.new.parse(project_list)
Expand All @@ -95,7 +137,7 @@ def test_build_with_projects
options = PmdTester::Options.new(argv)

projects[0].auxclasspath = 'extra:dirs'
record_expectations('sha1abc', 'sha1abc', true)
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
record_expectations_after_build
record_expectations_project_build(sha1: 'sha1abc')

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

projects[0].auxclasspath = 'extra:dirs'
record_expectations('sha1abc', 'sha1abc', true)
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
record_expectations_after_build
record_expectations_project_build(sha1: 'sha1abc', error: true)

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

projects[0].auxclasspath = 'extra:dirs'
record_expectations('sha1abc', 'sha1abc', true)
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
record_expectations_after_build
record_expectations_project_build(sha1: 'sha1abc', error: true, long_cli_options: true)

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

projects[0].auxclasspath = 'extra:dirs'
record_expectations(sha1, sha1, true)
record_expectations(sha1_head: sha1, sha1_base: sha1, zip_file_exists: true)
record_expectations_after_build
record_expectations_project_build(sha1: sha1, error: true, long_cli_options: true,
no_progress_bar: true, base_cmd: 'pmd check')
Expand Down Expand Up @@ -188,7 +230,7 @@ def test_build_failing
options = PmdTester::Options.new(argv)

projects[0].auxclasspath = 'extra:dirs'
record_expectations('sha1abc', 'sha1abc', true)
record_expectations(sha1_head: 'sha1abc', sha1_base: 'sha1abc', zip_file_exists: true)
record_expectations_after_build
record_expectations_project_build(sha1: 'sha1abc', error: true, exit_status: 1)

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

def record_expectations(sha1_head, sha1_base, zip_file_exists)
def record_expectations(sha1_head:, sha1_base:, zip_file_exists:)
PmdTester::Cmd.stubs(:execute_successfully).with('git rev-parse master^{commit}').returns(sha1_base).once
# inside checkout_build_branch
PmdTester::Cmd.stubs(:execute_successfully).with('git checkout master')
Expand Down Expand Up @@ -265,4 +307,18 @@ def cleanup_pmd_dist_dir(base_dir:)
File.unlink("#{base_dir}/pmd")
Dir.rmdir(base_dir)
end

def stub_pmd_build_maven(binary_name:)
PmdTester::Cmd.stubs(:execute_successfully).with do |cmd|
if cmd == './mvnw clean package -Dmaven.test.skip=true' \
' -Dmaven.javadoc.skip=true -Dmaven.source.skip=true' \
' -Dcheckstyle.skip=true -Dpmd.skip=true -T1C -B'
FileUtils.mkdir_p 'pmd-dist/target'
FileUtils.touch "pmd-dist/target/#{binary_name}"
true
else
false
end
end.once
end
end

0 comments on commit 56d03ab

Please sign in to comment.