@@ -97,7 +97,7 @@ def test_build_with_projects
97
97
projects [ 0 ] . auxclasspath = 'extra:dirs'
98
98
record_expectations ( 'sha1abc' , 'sha1abc' , true )
99
99
record_expectations_after_build
100
- record_expectations_project_build ( 'sha1abc' )
100
+ record_expectations_project_build ( sha1 : 'sha1abc' )
101
101
102
102
PmdTester ::PmdReportBuilder
103
103
. new ( projects , options , options . base_config , options . base_branch )
@@ -120,7 +120,7 @@ def test_build_error_recovery
120
120
projects [ 0 ] . auxclasspath = 'extra:dirs'
121
121
record_expectations ( 'sha1abc' , 'sha1abc' , true )
122
122
record_expectations_after_build
123
- record_expectations_project_build ( 'sha1abc' , true )
123
+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true )
124
124
125
125
PmdTester ::PmdReportBuilder
126
126
. new ( projects , options , options . base_config , options . base_branch )
@@ -140,7 +140,7 @@ def test_build_long_cli_options
140
140
projects [ 0 ] . auxclasspath = 'extra:dirs'
141
141
record_expectations ( 'sha1abc' , 'sha1abc' , true )
142
142
record_expectations_after_build
143
- record_expectations_project_build ( 'sha1abc' , true , true )
143
+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true , long_cli_options : true )
144
144
145
145
PmdTester ::PmdReportBuilder
146
146
. new ( projects , options , options . base_config , options . base_branch )
@@ -149,6 +149,7 @@ def test_build_long_cli_options
149
149
150
150
def test_build_pmd7
151
151
@pmd_version = '7.0.0-SNAPSHOT'
152
+ sha1 = 'sha1abc'
152
153
project_list = 'test/resources/pmd_report_builder/project-list.xml'
153
154
projects = PmdTester ::ProjectsParser . new . parse ( project_list )
154
155
assert_equal ( 1 , projects . size )
@@ -158,13 +159,19 @@ def test_build_pmd7
158
159
options = PmdTester ::Options . new ( argv )
159
160
160
161
projects [ 0 ] . auxclasspath = 'extra:dirs'
161
- record_expectations ( 'sha1abc' , 'sha1abc' , true )
162
+ record_expectations ( sha1 , sha1 , true )
162
163
record_expectations_after_build
163
- record_expectations_project_build ( 'sha1abc' , true , true , true )
164
-
165
- PmdTester ::PmdReportBuilder
166
- . new ( projects , options , options . base_config , options . base_branch )
167
- . build
164
+ record_expectations_project_build ( sha1 : sha1 , error : true , long_cli_options : true ,
165
+ no_progress_bar : true , base_cmd : 'pmd check' )
166
+
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
168
175
end
169
176
170
177
#
@@ -183,7 +190,7 @@ def test_build_failing
183
190
projects [ 0 ] . auxclasspath = 'extra:dirs'
184
191
record_expectations ( 'sha1abc' , 'sha1abc' , true )
185
192
record_expectations_after_build
186
- record_expectations_project_build ( 'sha1abc' , true , false , false , 1 )
193
+ record_expectations_project_build ( sha1 : 'sha1abc' , error : true , exit_status : 1 )
187
194
188
195
PmdTester ::PmdReportBuilder
189
196
. new ( projects , options , options . base_config , options . base_branch )
@@ -192,8 +199,8 @@ def test_build_failing
192
199
193
200
private
194
201
195
- def record_expectations_project_build ( sha1 , error = false , long_cli_options = false ,
196
- no_progress_bar = false , exit_status = 0 )
202
+ def record_expectations_project_build ( sha1 : , error : false , long_cli_options : false ,
203
+ no_progress_bar : false , exit_status : 0 , base_cmd : 'run.sh pmd' )
197
204
PmdTester ::ProjectBuilder . any_instance . stubs ( :clone_projects ) . once
198
205
PmdTester ::ProjectBuilder . any_instance . stubs ( :build_projects ) . once
199
206
PmdTester ::SimpleProgressLogger . any_instance . stubs ( :start ) . once
@@ -204,8 +211,8 @@ def record_expectations_project_build(sha1, error = false, long_cli_options = fa
204
211
process_status . expects ( :exitstatus ) . returns ( exit_status ) . once
205
212
PmdTester ::Cmd . stubs ( :execute )
206
213
. with ( "#{ error_prefix } " \
207
- "#{ distro_path } /bin/run.sh " \
208
- 'pmd -d target/repositories/checkstyle -f xml ' \
214
+ "#{ distro_path } /bin/#{ base_cmd } " \
215
+ '-d target/repositories/checkstyle -f xml ' \
209
216
'-R target/reports/master/checkstyle/config.xml ' \
210
217
'-r target/reports/master/checkstyle/pmd_report.xml ' \
211
218
"#{ long_cli_options ? '--fail-on-violation false' : '-failOnViolation false' } -t 1 " \
@@ -244,4 +251,18 @@ def record_expectations_after_build
244
251
PmdTester ::PmdBranchDetail . any_instance . stubs ( :save ) . once
245
252
FileUtils . stubs ( :cp ) . with ( 'config/design.xml' , 'target/reports/master/config.xml' ) . once
246
253
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
247
268
end
0 commit comments