@@ -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
248268end
0 commit comments