Skip to content
This repository was archived by the owner on Mar 27, 2025. It is now read-only.

Commit 275f108

Browse files
author
Nikhil Bhoski
committed
Null object pattern.
1 parent 9603369 commit 275f108

File tree

2 files changed

+153
-54
lines changed

2 files changed

+153
-54
lines changed

src/main/java/com/mathworks/ci/RunMatlabTestsBuilder.java

Lines changed: 147 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.kohsuke.stapler.DataBoundConstructor;
1919
import org.kohsuke.stapler.DataBoundSetter;
2020
import org.kohsuke.stapler.StaplerRequest;
21+
import org.w3c.dom.views.AbstractView;
2122
import hudson.EnvVars;
2223
import hudson.Extension;
2324
import hudson.FilePath;
@@ -36,20 +37,13 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep, M
3637

3738
private int buildResult;
3839
private EnvVars env;
39-
private TapArtifact tapArtifact;
40-
private JunitArtifact junitArtifact;
41-
private CoberturaArtifact coberturaArtifact;
42-
private StmResultsArtifact stmResultsArtifact;
43-
private ModelCovArtifact modelCoverageArtifact;
44-
private PdfArtifact pdfReportArtifact;
45-
private String tapReportFilePath;
46-
private String pdfReportFilePath;
47-
private String junitReportFilePath;
48-
private String coberturaReportFilePath;
49-
private String stmResultsFilePath;
50-
private String modelCoverageFilePath;
40+
private Artifact tapArtifact = new NullArtifact();
41+
private Artifact junitArtifact = new NullArtifact();
42+
private Artifact coberturaArtifact = new NullArtifact();
43+
private Artifact stmResultsArtifact = new NullArtifact();
44+
private Artifact modelCoverageArtifact = new NullArtifact();
45+
private Artifact pdfReportArtifact = new NullArtifact();
5146

52-
5347
@DataBoundConstructor
5448
public RunMatlabTestsBuilder() {
5549

@@ -60,87 +54,81 @@ public RunMatlabTestsBuilder() {
6054

6155

6256
@DataBoundSetter
63-
public void setTapArtifact(TapArtifact tapArtifact) {
57+
public void setTapArtifact(Artifact tapArtifact) {
6458
this.tapArtifact = tapArtifact;
65-
this.tapReportFilePath = this.tapArtifact.getTapReportFilePath();
6659
}
6760

6861
@DataBoundSetter
69-
public void setJunitArtifact(JunitArtifact junitArtifact) {
62+
public void setJunitArtifact(Artifact junitArtifact) {
7063
this.junitArtifact = junitArtifact;
71-
this.junitReportFilePath = this.junitArtifact.getJunitReportFilePath();
7264
}
7365

7466
@DataBoundSetter
75-
public void setCoberturaArtifact(CoberturaArtifact coberturaArtifact) {
67+
public void setCoberturaArtifact(Artifact coberturaArtifact) {
7668
this.coberturaArtifact = coberturaArtifact;
77-
this.coberturaReportFilePath = this.coberturaArtifact.getCoberturaReportFilePath();
7869
}
7970

8071
@DataBoundSetter
81-
public void setStmResultsArtifact(StmResultsArtifact stmResultsArtifact) {
72+
public void setStmResultsArtifact(Artifact stmResultsArtifact) {
8273
this.stmResultsArtifact = stmResultsArtifact;
83-
this.stmResultsFilePath = this.stmResultsArtifact.getStmResultsFilePath();
8474
}
8575

8676
@DataBoundSetter
87-
public void setModelCoverageArtifact(ModelCovArtifact modelCoverageArtifact) {
77+
public void setModelCoverageArtifact(Artifact modelCoverageArtifact) {
8878
this.modelCoverageArtifact = modelCoverageArtifact;
89-
this.modelCoverageFilePath = this.modelCoverageArtifact.getModelCoverageFilePath();
9079
}
9180

9281
@DataBoundSetter
93-
public void setPdfReportArtifact(PdfArtifact pdfReportArtifact) {
82+
public void setPdfReportArtifact(Artifact pdfReportArtifact) {
9483
this.pdfReportArtifact = pdfReportArtifact;
95-
this.pdfReportFilePath = this.pdfReportArtifact.getPdfReportFilePath();
9684
}
9785

9886
public String getTapReportFilePath() {
99-
return this.tapReportFilePath;
87+
return this.getTapArtifact().getFilePath();
10088
}
10189

102-
public TapArtifact getTapArtifact() {
90+
public Artifact getTapArtifact() {
10391
return this.tapArtifact;
10492
}
10593

106-
public JunitArtifact getJunitArtifact() {
94+
public Artifact getJunitArtifact() {
10795
return this.junitArtifact;
10896
}
10997

11098
public String getJunitReportFilePath() {
111-
return this.junitReportFilePath;
99+
return this.getJunitArtifact().getFilePath();
112100
}
113101

114-
public CoberturaArtifact getCoberturaArtifact() {
102+
public Artifact getCoberturaArtifact() {
115103
return this.coberturaArtifact;
116104
}
117105

118106
public String getCoberturaReportFilePath() {
119-
return this.coberturaReportFilePath;
107+
return this.getCoberturaArtifact().getFilePath();
120108
}
121109

122-
public StmResultsArtifact getStmResultsArtifact() {
110+
public Artifact getStmResultsArtifact() {
123111
return this.stmResultsArtifact;
124112
}
125113

126114
public String getStmResultsFilePath() {
127-
return this.stmResultsFilePath;
115+
return this.getStmResultsArtifact().getFilePath();
128116
}
129117

130-
public ModelCovArtifact getModelCoverageArtifact() {
118+
public Artifact getModelCoverageArtifact() {
131119
return this.modelCoverageArtifact;
132120
}
133121

134122
public String getModelCoverageFilePath() {
135-
return modelCoverageFilePath;
123+
return this.getModelCoverageArtifact().getFilePath();
136124
}
137125

138-
public PdfArtifact getPdfReportArtifact() {
126+
public Artifact getPdfReportArtifact() {
139127
return this.pdfReportArtifact;
140128
}
141129

142130
public String getPdfReportFilePath() {
143-
return this.pdfReportFilePath;
131+
return this.getPdfReportArtifact().getFilePath();
144132
}
145133

146134
private void setEnv(EnvVars env) {
@@ -242,7 +230,8 @@ private String getInputArguments() {
242230
getModelCoverageArtifact()));
243231

244232
for (Artifact artifact : artifactList) {
245-
addInputArgs(artifact, inputArgs);
233+
//addInputArgs(artifact, inputArgs);
234+
artifact.addFilePathArgTo(inputArgs);
246235
}
247236

248237
if (inputArgs.isEmpty()) {
@@ -252,11 +241,11 @@ private String getInputArguments() {
252241
return String.join(",", inputArgs);
253242
}
254243

255-
public void addInputArgs(Artifact artifactType, List<String> inputArgs) {
244+
/*public void addInputArgs(Artifact artifactType, List<String> inputArgs) {
256245
if (artifactType != null) {
257246
artifactType.addFilePathArgTo(inputArgs);
258247
}
259-
}
248+
}*/
260249

261250

262251
/*
@@ -269,11 +258,12 @@ public void addInputArgs(Artifact artifactType, List<String> inputArgs) {
269258
* 7Csort:date/jenkinsci-dev/AFYHSG3NUEI/UsVJIKoE4B8J
270259
*
271260
*/
272-
public static class PdfArtifact implements Artifact {
261+
public static class PdfArtifact extends Artifact {
273262
private String pdfReportFilePath;
274263

275264
@DataBoundConstructor
276265
public PdfArtifact() {
266+
277267

278268
}
279269

@@ -291,13 +281,25 @@ public void addFilePathArgTo(List<String> inputArgs) {
291281
inputArgs.add(MatlabBuilderConstants.PDF_REPORT_PATH + "," + "'"
292282
+ getPdfReportFilePath() + "'");
293283
}
284+
285+
@Override
286+
public String getFilePath() {
287+
return getPdfReportFilePath();
288+
}
289+
290+
291+
public boolean getDefault() {
292+
293+
return true;
294+
}
294295
}
295296

296-
public static class TapArtifact implements Artifact {
297+
public static class TapArtifact extends Artifact {
297298
private String tapReportFilePath;
298299

299300
@DataBoundConstructor
300301
public TapArtifact() {
302+
301303

302304
}
303305

@@ -315,13 +317,24 @@ public void addFilePathArgTo(List<String> inputArgs) {
315317
inputArgs.add(MatlabBuilderConstants.TAP_RESULTS_PATH + "," + "'"
316318
+ getTapReportFilePath() + "'");
317319
}
320+
321+
@Override
322+
public String getFilePath() {
323+
return getTapReportFilePath();
324+
}
325+
326+
327+
public boolean getDefault() {
328+
return true;
329+
}
318330
}
319331

320-
public static class JunitArtifact implements Artifact {
332+
public static class JunitArtifact extends Artifact {
321333
private String junitReportFilePath;
322334

323335
@DataBoundConstructor
324336
public JunitArtifact() {
337+
325338

326339
}
327340

@@ -339,13 +352,24 @@ public void addFilePathArgTo(List<String> inputArgs) {
339352
inputArgs.add(MatlabBuilderConstants.JUNIT_RESULTS_PATH + "," + "'"
340353
+ getJunitReportFilePath() + "'");
341354
}
355+
356+
@Override
357+
public String getFilePath() {
358+
return getJunitReportFilePath();
359+
}
360+
361+
362+
public boolean getDefault() {
363+
return true;
364+
}
342365
}
343366

344-
public static class CoberturaArtifact implements Artifact {
367+
public static class CoberturaArtifact extends Artifact {
345368
private String coberturaReportFilePath;
346369

347370
@DataBoundConstructor
348371
public CoberturaArtifact() {
372+
349373

350374
}
351375

@@ -363,13 +387,24 @@ public void addFilePathArgTo(List<String> inputArgs) {
363387
inputArgs.add(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH + "," + "'"
364388
+ getCoberturaReportFilePath() + "'");
365389
}
390+
391+
@Override
392+
public String getFilePath() {
393+
return getCoberturaReportFilePath();
394+
}
395+
396+
397+
public boolean getDefault() {
398+
return true;
399+
}
366400
}
367401

368-
public static class StmResultsArtifact implements Artifact{
402+
public static class StmResultsArtifact extends Artifact {
369403
private String stmResultsFilePath;
370404

371405
@DataBoundConstructor
372406
public StmResultsArtifact() {
407+
373408

374409
}
375410

@@ -387,13 +422,24 @@ public void addFilePathArgTo(List<String> inputArgs) {
387422
inputArgs.add(MatlabBuilderConstants.STM_RESULTS_PATH + "," + "'"
388423
+ getStmResultsFilePath() + "'");
389424
}
425+
426+
@Override
427+
public String getFilePath() {
428+
return getStmResultsFilePath();
429+
}
430+
431+
432+
public boolean getDefault() {
433+
return true;
434+
}
390435
}
391436

392-
public static class ModelCovArtifact implements Artifact {
437+
public static class ModelCovArtifact extends Artifact {
393438
private String modelCoverageFilePath;
394439

395440
@DataBoundConstructor
396441
public ModelCovArtifact() {
442+
397443

398444
}
399445

@@ -411,10 +457,63 @@ public void addFilePathArgTo(List<String> inputArgs) {
411457
inputArgs.add(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH + "," + "'"
412458
+ getModelCoverageFilePath() + "'");
413459
}
460+
461+
@Override
462+
public String getFilePath() {
463+
464+
return getModelCoverageFilePath();
465+
}
466+
467+
@Override
468+
public boolean getDefault() {
469+
return true;
470+
}
414471
}
415472

416-
public interface Artifact {
417-
public void addFilePathArgTo(List<String> inputArgs);
473+
public static class NullArtifact extends Artifact {
474+
475+
@DataBoundConstructor
476+
public NullArtifact() {
477+
478+
}
479+
480+
@Override
481+
public void addFilePathArgTo(List<String> inputArgs) {
482+
483+
}
484+
485+
486+
public boolean getDefault() {
487+
return false;
488+
}
489+
490+
@Override
491+
public String getFilePath() {
492+
return null;
493+
}
494+
418495
}
496+
419497

498+
public static class Artifact {
499+
500+
@DataBoundConstructor
501+
public Artifact() {
502+
503+
}
504+
505+
506+
507+
public void addFilePathArgTo(List<String> inputArgs) {
508+
509+
}
510+
511+
public String getFilePath() {
512+
return null;
513+
}
514+
515+
public boolean getDefault() {
516+
return false;
517+
}
518+
}
420519
}

0 commit comments

Comments
 (0)