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

Commit 88e292e

Browse files
authored
Merge pull request #90 from mathworks/artifact_input_change_nop_decouple
Initial Changes to use data bound constructor.
2 parents 81bbc38 + 94dd63b commit 88e292e

File tree

3 files changed

+94
-170
lines changed

3 files changed

+94
-170
lines changed

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

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,7 @@ public class MatlabBuilderConstants {
2424
static final String STM_RESULTS = "'SimulinkTestResults'";
2525
static final String COBERTURA_CODE_COVERAGE = "'CoberturaCodeCoverage'";
2626
static final String COBERTURA_MODEL_COVERAGE = "'CoberturaModelCoverage'";
27-
static final String PDF_REPORT_PATH = "'PDFReportPath'";
28-
static final String TAP_RESULTS_PATH ="'TAPResultsPath'";
29-
static final String JUNIT_RESULTS_PATH = "'JUnitResultsPath'";
30-
static final String STM_RESULTS_PATH = "'SimulinkTestResultsPath'";
31-
static final String COBERTURA_CODE_COVERAGE_PATH = "'CoberturaCodeCoveragePath'";
32-
static final String COBERTURA_MODEL_COVERAGE_PATH = "'CoberturaModelCoveragePath'";
33-
27+
3428
// Matlab Runner files
3529
static final String BAT_RUNNER_SCRIPT = "run_matlab_command.bat";
3630
static final String SHELL_RUNNER_SCRIPT = "run_matlab_command.sh";

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

Lines changed: 77 additions & 140 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,11 @@
1111
import java.io.IOException;
1212
import java.util.ArrayList;
1313
import java.util.Arrays;
14+
import java.util.HashMap;
1415
import java.util.List;
16+
import java.util.Map;
1517
import javax.annotation.Nonnull;
18+
import org.apache.commons.collections.map.HashedMap;
1619
import org.apache.commons.io.FilenameUtils;
1720
import org.jenkinsci.Symbol;
1821
import org.kohsuke.stapler.DataBoundConstructor;
@@ -222,17 +225,21 @@ public String constructCommandForTest(String inputArguments) {
222225
// Concatenate the input arguments
223226
private String getInputArguments() {
224227

225-
final List<String> inputArgs = new ArrayList<String>();
228+
final List<String> inputArgsList = new ArrayList<String>();
229+
final Map<String,String> args = new HashMap<String,String>();
230+
226231
final List<Artifact> artifactList =
227232
new ArrayList<Artifact>(Arrays.asList(getPdfReportArtifact(), getTapArtifact(),
228233
getJunitArtifact(), getStmResultsArtifact(), getCoberturaArtifact(),
229234
getModelCoverageArtifact()));
230235

231236
for (Artifact artifact : artifactList) {
232-
artifact.addFilePathArgTo(inputArgs);
237+
artifact.addFilePathArgTo(args);
233238
}
234239

235-
return String.join(",", inputArgs);
240+
args.forEach((key, val) -> inputArgsList.add("'" + key + "'" + "," + "'" + val + "'"));
241+
242+
return String.join(",", inputArgsList);
236243
}
237244

238245

@@ -246,212 +253,142 @@ private String getInputArguments() {
246253
* 7Csort:date/jenkinsci-dev/AFYHSG3NUEI/UsVJIKoE4B8J
247254
*
248255
*/
249-
public static class PdfArtifact extends Artifact {
250-
private String pdfReportFilePath;
256+
public static class PdfArtifact extends AbstractArtifactImpl {
251257

252-
@DataBoundConstructor
253-
public PdfArtifact() {
254-
255-
}
258+
private static final String PDF_REPORT_PATH = "PDFReportPath";
256259

257-
@DataBoundSetter
258-
public void setPdfReportFilePath(String pdfReportFilePath) {
259-
this.pdfReportFilePath = pdfReportFilePath;
260-
}
261-
262-
public String getPdfReportFilePath() {
263-
return this.pdfReportFilePath;
264-
}
265-
266-
@Override
267-
public void addFilePathArgTo(List<String> inputArgs) {
268-
inputArgs.add(MatlabBuilderConstants.PDF_REPORT_PATH + "," + "'"
269-
+ getPdfReportFilePath() + "'");
260+
@DataBoundConstructor
261+
public PdfArtifact(String pdfReportFilePath) {
262+
super(pdfReportFilePath);
270263
}
271264

272265
@Override
273-
public String getFilePath() {
274-
return getPdfReportFilePath();
266+
public void addFilePathArgTo(Map<String, String> inputArgs) {
267+
inputArgs.put(PDF_REPORT_PATH, getFilePath());
275268
}
276269
}
277270

278-
public static class TapArtifact extends Artifact {
279-
private String tapReportFilePath;
271+
public static class TapArtifact extends AbstractArtifactImpl {
280272

281-
@DataBoundConstructor
282-
public TapArtifact() {
283-
284-
}
273+
private static final String TAP_RESULTS_PATH = "TAPResultsPath";
285274

286-
@DataBoundSetter
287-
public void setTapReportFilePath(String tapReportFilePath) {
288-
this.tapReportFilePath = tapReportFilePath;
289-
}
290-
291-
public String getTapReportFilePath() {
292-
return tapReportFilePath;
293-
}
294-
295-
@Override
296-
public void addFilePathArgTo(List<String> inputArgs) {
297-
inputArgs.add(MatlabBuilderConstants.TAP_RESULTS_PATH + "," + "'"
298-
+ getTapReportFilePath() + "'");
275+
@DataBoundConstructor
276+
public TapArtifact(String tapReportFilePath) {
277+
super(tapReportFilePath);
299278
}
300279

301280
@Override
302-
public String getFilePath() {
303-
return getTapReportFilePath();
281+
public void addFilePathArgTo(Map<String, String> inputArgs) {
282+
inputArgs.put(TAP_RESULTS_PATH, getFilePath());
304283
}
305284
}
306285

307-
public static class JunitArtifact extends Artifact {
308-
private String junitReportFilePath;
286+
public static class JunitArtifact extends AbstractArtifactImpl {
309287

310-
@DataBoundConstructor
311-
public JunitArtifact() {
312-
313-
}
288+
private static final String JUNIT_RESULTS_PATH = "JUnitResultsPath";
314289

315-
@DataBoundSetter
316-
public void setJunitReportFilePath(String junitReportFilePath) {
317-
this.junitReportFilePath = junitReportFilePath;
318-
}
319-
320-
public String getJunitReportFilePath() {
321-
return this.junitReportFilePath;
322-
}
323-
324-
@Override
325-
public void addFilePathArgTo(List<String> inputArgs) {
326-
inputArgs.add(MatlabBuilderConstants.JUNIT_RESULTS_PATH + "," + "'"
327-
+ getJunitReportFilePath() + "'");
290+
@DataBoundConstructor
291+
public JunitArtifact(String junitReportFilePath) {
292+
super(junitReportFilePath);
328293
}
329294

330295
@Override
331-
public String getFilePath() {
332-
return getJunitReportFilePath();
296+
public void addFilePathArgTo(Map<String, String> inputArgs) {
297+
inputArgs.put(JUNIT_RESULTS_PATH, getFilePath());
333298
}
334299
}
335300

336-
public static class CoberturaArtifact extends Artifact {
337-
private String coberturaReportFilePath;
301+
public static class CoberturaArtifact extends AbstractArtifactImpl {
338302

339-
@DataBoundConstructor
340-
public CoberturaArtifact() {
341-
342-
}
303+
private static final String COBERTURA_CODE_COVERAGE_PATH = "CoberturaCodeCoveragePath";
343304

344-
@DataBoundSetter
345-
public void setCoberturaReportFilePath(String coberturaReportFilePath) {
346-
this.coberturaReportFilePath = coberturaReportFilePath;
347-
}
348-
349-
public String getCoberturaReportFilePath() {
350-
return this.coberturaReportFilePath;
351-
}
352-
353-
@Override
354-
public void addFilePathArgTo(List<String> inputArgs) {
355-
inputArgs.add(MatlabBuilderConstants.COBERTURA_CODE_COVERAGE_PATH + "," + "'"
356-
+ getCoberturaReportFilePath() + "'");
305+
@DataBoundConstructor
306+
public CoberturaArtifact(String coberturaReportFilePath) {
307+
super(coberturaReportFilePath);
357308
}
358309

359310
@Override
360-
public String getFilePath() {
361-
return getCoberturaReportFilePath();
311+
public void addFilePathArgTo(Map<String, String> inputArgs) {
312+
inputArgs.put(COBERTURA_CODE_COVERAGE_PATH, getFilePath());
362313
}
363314
}
364315

365-
public static class StmResultsArtifact extends Artifact {
366-
private String stmResultsFilePath;
316+
public static class StmResultsArtifact extends AbstractArtifactImpl {
317+
318+
private static final String STM_RESULTS_PATH = "SimulinkTestResultsPath";
367319

368320
@DataBoundConstructor
369-
public StmResultsArtifact() {
370-
321+
public StmResultsArtifact(String stmResultsFilePath) {
322+
super(stmResultsFilePath);
371323
}
372324

373-
@DataBoundSetter
374-
public void setStmResultsFilePath(String stmResultsFilePath) {
375-
this.stmResultsFilePath = stmResultsFilePath;
325+
@Override
326+
public void addFilePathArgTo(Map<String, String> inputArgs) {
327+
inputArgs.put(STM_RESULTS_PATH, getFilePath());
376328
}
329+
}
377330

378-
public String getStmResultsFilePath() {
379-
return stmResultsFilePath;
380-
}
331+
public static class ModelCovArtifact extends AbstractArtifactImpl {
381332

382-
@Override
383-
public void addFilePathArgTo(List<String> inputArgs) {
384-
inputArgs.add(MatlabBuilderConstants.STM_RESULTS_PATH + "," + "'"
385-
+ getStmResultsFilePath() + "'");
333+
private static final String COBERTURA_MODEL_COVERAGE_PATH = "CoberturaModelCoveragePath";
334+
335+
@DataBoundConstructor
336+
public ModelCovArtifact(String modelCoverageFilePath) {
337+
super(modelCoverageFilePath);
386338
}
387339

388340
@Override
389-
public String getFilePath() {
390-
return getStmResultsFilePath();
341+
public void addFilePathArgTo(Map<String, String> inputArgs) {
342+
inputArgs.put(COBERTURA_MODEL_COVERAGE_PATH, getFilePath());
391343
}
392344
}
393345

394-
public static class ModelCovArtifact extends Artifact {
395-
private String modelCoverageFilePath;
346+
public static class NullArtifact implements Artifact {
396347

397-
@DataBoundConstructor
398-
public ModelCovArtifact() {
399-
400-
}
401-
402-
@DataBoundSetter
403-
public void setModelCoverageFilePath(String modelCoverageFilePath) {
404-
this.modelCoverageFilePath = modelCoverageFilePath;
405-
}
348+
@Override
349+
public void addFilePathArgTo(Map<String, String> inputArgs) {
406350

407-
public String getModelCoverageFilePath() {
408-
return modelCoverageFilePath;
409351
}
410352

411353
@Override
412-
public void addFilePathArgTo(List<String> inputArgs) {
413-
inputArgs.add(MatlabBuilderConstants.COBERTURA_MODEL_COVERAGE_PATH + "," + "'"
414-
+ getModelCoverageFilePath() + "'");
354+
public boolean getDefault() {
355+
return false;
415356
}
416357

417358
@Override
418359
public String getFilePath() {
419-
420-
return getModelCoverageFilePath();
360+
return null;
421361
}
362+
422363
}
423-
424-
public static class NullArtifact extends Artifact {
425364

426-
@DataBoundConstructor
427-
public NullArtifact() {
365+
public static abstract class AbstractArtifactImpl implements Artifact {
428366

429-
}
430-
431-
@Override
432-
public void addFilePathArgTo(List<String> inputArgs) {
367+
private String filePath;
433368

369+
protected AbstractArtifactImpl(String path) {
370+
this.filePath = path;
434371
}
435372

436-
@Override
437373
public boolean getDefault() {
438-
return false;
374+
return true;
375+
}
376+
377+
public void setFilePath(String path) {
378+
this.filePath = path;
439379
}
440380

441-
@Override
442381
public String getFilePath() {
443-
return null;
382+
return this.filePath;
444383
}
445384
}
446385

447-
448-
public static abstract class Artifact {
449-
public abstract void addFilePathArgTo(List<String> inputArgs);
450386

451-
public abstract String getFilePath();
387+
public interface Artifact {
388+
public void addFilePathArgTo(Map<String, String> inputArgs);
452389

453-
public boolean getDefault() {
454-
return true;
455-
}
390+
public String getFilePath();
391+
392+
public boolean getDefault();
456393
}
457394
}

src/test/java/com/mathworks/ci/RunMatlabTestsBuilderTest.java

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -229,11 +229,9 @@ public void verifyVerlessThan() throws Exception {
229229
public void verifySpecificTestArtifactsParameters() throws Exception {
230230
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
231231
project.getBuildWrappersList().add(this.buildWrapper);
232-
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact();
233-
tap.setTapReportFilePath("mytap/report.tap");
232+
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact("mytap/report.tap");
234233

235-
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact();
236-
stmResults.setStmResultsFilePath("mystm/results.mldatx");
234+
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact("mystm/results.mldatx");
237235

238236
testBuilder.setTapArtifact(tap);
239237
testBuilder.setStmResultsArtifact(stmResults);
@@ -287,23 +285,17 @@ public void verifyDefaultArtifactLocation() throws Exception {
287285
public void verifyAllTestArtifactsParameters() throws Exception {
288286
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2018b"));
289287
project.getBuildWrappersList().add(this.buildWrapper);
290-
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact();
291-
tap.setTapReportFilePath("mytap/report.tap");
288+
RunMatlabTestsBuilder.TapArtifact tap = new TapArtifact("mytap/report.tap");
292289

293-
RunMatlabTestsBuilder.PdfArtifact pdf = new PdfArtifact();
294-
pdf.setPdfReportFilePath("mypdf/report.pdf");
290+
RunMatlabTestsBuilder.PdfArtifact pdf = new PdfArtifact("mypdf/report.pdf");
291+
292+
RunMatlabTestsBuilder.JunitArtifact junit = new JunitArtifact("myjunit/report.xml");
295293

296-
RunMatlabTestsBuilder.JunitArtifact junit = new JunitArtifact();
297-
junit.setJunitReportFilePath("myjunit/report.xml");
294+
RunMatlabTestsBuilder.CoberturaArtifact cobertura = new CoberturaArtifact("mycobertura/report.xml");
298295

299-
RunMatlabTestsBuilder.CoberturaArtifact cobertura = new CoberturaArtifact();
300-
cobertura.setCoberturaReportFilePath("mycobertura/report.xml");
296+
RunMatlabTestsBuilder.ModelCovArtifact modelCov = new ModelCovArtifact("mymodel/report.xml");
301297

302-
RunMatlabTestsBuilder.ModelCovArtifact modelCov = new ModelCovArtifact();
303-
modelCov.setModelCoverageFilePath("mymodel/report.xml");
304-
305-
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact();
306-
stmResults.setStmResultsFilePath("mystm/results.mldatx");
298+
RunMatlabTestsBuilder.StmResultsArtifact stmResults = new StmResultsArtifact("mystm/results.mldatx");
307299

308300
testBuilder.setTapArtifact(tap);
309301
testBuilder.setPdfReportArtifact(pdf);
@@ -316,12 +308,13 @@ public void verifyAllTestArtifactsParameters() throws Exception {
316308
project.getBuildersList().add(this.testBuilder);
317309
FreeStyleBuild build = project.scheduleBuild2(0).get();
318310
jenkins.assertLogContains("run_matlab_command", build);
319-
jenkins.assertLogContains("\'PDFReportPath\',\'mypdf/report.pdf\',"
320-
+ "\'TAPResultsPath\',\'mytap/report.tap\',"
321-
+ "\'JUnitResultsPath\',\'myjunit/report.xml\',"
322-
+ "\'SimulinkTestResultsPath\',\'mystm/results.mldatx\',"
323-
+ "\'CoberturaCodeCoveragePath\',\'mycobertura/report.xml\',"
324-
+ "\'CoberturaModelCoveragePath\',\'mymodel/report.xml\'", build);
311+
jenkins.assertLogContains("\'PDFReportPath\',\'mypdf/report.pdf\'",build);
312+
jenkins.assertLogContains("\'TAPResultsPath\',\'mytap/report.tap\'",build);
313+
jenkins.assertLogContains("\'JUnitResultsPath\',\'myjunit/report.xml\'",build);
314+
jenkins.assertLogContains("\'SimulinkTestResultsPath\',\'mystm/results.mldatx\'",build);
315+
jenkins.assertLogContains("\'CoberturaCodeCoveragePath\',\'mycobertura/report.xml\'",build);
316+
jenkins.assertLogContains("\'CoberturaModelCoveragePath\',\'mymodel/report.xml\'",build);
317+
325318
}
326319

327320
/*

0 commit comments

Comments
 (0)