1010
1111import java .io .IOException ;
1212import java .util .ArrayList ;
13+ import java .util .Arrays ;
1314import java .util .List ;
1415import javax .annotation .Nonnull ;
1516import org .apache .commons .io .FilenameUtils ;
@@ -48,7 +49,6 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep, M
4849 private String stmResultsFilePath ;
4950 private String modelCoverageFilePath ;
5051
51- private List <String > inputArgs = new ArrayList <String >();
5252
5353 @ DataBoundConstructor
5454 public RunMatlabTestsBuilder () {
@@ -235,28 +235,14 @@ public String constructCommandForTest(String inputArguments) {
235235 // Concatenate the input arguments
236236 private String getInputArguments () {
237237
238- if (getPdfReportArtifact () != null ) {
239- getPdfReportArtifact ().addFilePathArgTo (inputArgs );
240- }
241-
242- if (getTapArtifact () != null ) {
243- getTapArtifact ().addFilePathArgTo (inputArgs );
244- }
245-
246- if (getJunitArtifact () != null ) {
247- getJunitArtifact ().addFilePathArgTo (inputArgs );
248- }
249-
250- if (getStmResultsArtifact () != null ) {
251- getStmResultsArtifact ().addFilePathArgTo (inputArgs );
252- }
238+ final List <String > inputArgs = new ArrayList <String >();
239+ final List <Artifact > artifactList =
240+ new ArrayList <Artifact >(Arrays .asList (getPdfReportArtifact (), getTapArtifact (),
241+ getJunitArtifact (), getStmResultsArtifact (), getCoberturaArtifact (),
242+ getModelCoverageArtifact ()));
253243
254- if (getCoberturaArtifact () != null ) {
255- getCoberturaArtifact ().addFilePathArgTo (inputArgs );
256- }
257-
258- if (getModelCoverageArtifact () != null ) {
259- getModelCoverageArtifact ().addFilePathArgTo (inputArgs );
244+ for (Artifact artifact : artifactList ) {
245+ addInputArgs (artifact , inputArgs );
260246 }
261247
262248 if (inputArgs .isEmpty ()) {
@@ -266,7 +252,13 @@ private String getInputArguments() {
266252 return String .join ("," , inputArgs );
267253 }
268254
269-
255+ public void addInputArgs (Artifact artifactType , List <String > inputArgs ) {
256+ if (artifactType != null ) {
257+ artifactType .addFilePathArgTo (inputArgs );
258+ }
259+ }
260+
261+
270262 /*
271263 * Classes for each optional block in jelly file.This is restriction from Stapler architecture
272264 * when we use <f:optionalBlock> as it creates a object for each block in JSON. This could be
@@ -277,7 +269,7 @@ private String getInputArguments() {
277269 * 7Csort:date/jenkinsci-dev/AFYHSG3NUEI/UsVJIKoE4B8J
278270 *
279271 */
280- public static class PdfArtifact {
272+ public static class PdfArtifact implements Artifact {
281273 private String pdfReportFilePath ;
282274
283275 @ DataBoundConstructor
@@ -293,14 +285,15 @@ public void setPdfReportFilePath(String pdfReportFilePath) {
293285 public String getPdfReportFilePath () {
294286 return this .pdfReportFilePath ;
295287 }
296-
288+
289+ @ Override
297290 public void addFilePathArgTo (List <String > inputArgs ) {
298291 inputArgs .add (MatlabBuilderConstants .PDF_REPORT_PATH + "," + "'"
299292 + getPdfReportFilePath () + "'" );
300293 }
301294 }
302295
303- public static class TapArtifact {
296+ public static class TapArtifact implements Artifact {
304297 private String tapReportFilePath ;
305298
306299 @ DataBoundConstructor
@@ -317,13 +310,14 @@ public String getTapReportFilePath() {
317310 return tapReportFilePath ;
318311 }
319312
313+ @ Override
320314 public void addFilePathArgTo (List <String > inputArgs ) {
321315 inputArgs .add (MatlabBuilderConstants .TAP_RESULTS_PATH + "," + "'"
322316 + getTapReportFilePath () + "'" );
323317 }
324318 }
325319
326- public static class JunitArtifact {
320+ public static class JunitArtifact implements Artifact {
327321 private String junitReportFilePath ;
328322
329323 @ DataBoundConstructor
@@ -340,13 +334,14 @@ public String getJunitReportFilePath() {
340334 return this .junitReportFilePath ;
341335 }
342336
337+ @ Override
343338 public void addFilePathArgTo (List <String > inputArgs ) {
344339 inputArgs .add (MatlabBuilderConstants .JUNIT_RESULTS_PATH + "," + "'"
345340 + getJunitReportFilePath () + "'" );
346341 }
347342 }
348343
349- public static class CoberturaArtifact {
344+ public static class CoberturaArtifact implements Artifact {
350345 private String coberturaReportFilePath ;
351346
352347 @ DataBoundConstructor
@@ -363,13 +358,14 @@ public String getCoberturaReportFilePath() {
363358 return this .coberturaReportFilePath ;
364359 }
365360
361+ @ Override
366362 public void addFilePathArgTo (List <String > inputArgs ) {
367363 inputArgs .add (MatlabBuilderConstants .COBERTURA_CODE_COVERAGE_PATH + "," + "'"
368364 + getCoberturaReportFilePath () + "'" );
369365 }
370366 }
371367
372- public static class StmResultsArtifact {
368+ public static class StmResultsArtifact implements Artifact {
373369 private String stmResultsFilePath ;
374370
375371 @ DataBoundConstructor
@@ -386,13 +382,14 @@ public String getStmResultsFilePath() {
386382 return stmResultsFilePath ;
387383 }
388384
385+ @ Override
389386 public void addFilePathArgTo (List <String > inputArgs ) {
390387 inputArgs .add (MatlabBuilderConstants .STM_RESULTS_PATH + "," + "'"
391388 + getStmResultsFilePath () + "'" );
392389 }
393390 }
394391
395- public static class ModelCovArtifact {
392+ public static class ModelCovArtifact implements Artifact {
396393 private String modelCoverageFilePath ;
397394
398395 @ DataBoundConstructor
@@ -409,9 +406,15 @@ public String getModelCoverageFilePath() {
409406 return modelCoverageFilePath ;
410407 }
411408
409+ @ Override
412410 public void addFilePathArgTo (List <String > inputArgs ) {
413411 inputArgs .add (MatlabBuilderConstants .COBERTURA_MODEL_COVERAGE_PATH + "," + "'"
414412 + getModelCoverageFilePath () + "'" );
415413 }
416414 }
415+
416+ public interface Artifact {
417+ public void addFilePathArgTo (List <String > inputArgs );
418+ }
419+
417420}
0 commit comments