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

Commit d1c2fca

Browse files
committed
Address review comments
1 parent d1fb9ea commit d1c2fca

File tree

8 files changed

+53
-43
lines changed

8 files changed

+53
-43
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
import java.io.IOException;
1010
import java.io.InputStream;
11+
import java.util.List;
1112
import java.util.UUID;
1213
import hudson.EnvVars;
1314
import hudson.FilePath;
@@ -122,4 +123,9 @@ default String getValidMatlabFileName(String actualName) {
122123
return MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX
123124
+ actualName.replaceAll("-", "_");
124125
}
126+
127+
default String getCellArrayFrmList(List<String> listOfStr){
128+
listOfStr.replaceAll(val -> "'" + val.replaceAll("'", "''") + "'");
129+
return "{" + String.join(",", listOfStr) + "}";
130+
}
125131
}

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

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,21 @@
99
*/
1010

1111
import java.io.IOException;
12-
import java.util.*;
12+
import java.util.Map;
13+
import java.util.HashMap;
14+
import java.util.List;
15+
import java.util.ArrayList;
16+
import java.util.Optional;
17+
import java.util.Arrays;
1318
import javax.annotation.Nonnull;
14-
import hudson.*;
15-
import hudson.model.*;
19+
import hudson.EnvVars;
20+
import hudson.Extension;
21+
import hudson.FilePath;
22+
import hudson.Launcher;
23+
import hudson.model.AbstractProject;
24+
import hudson.model.Result;
25+
import hudson.model.Run;
26+
import hudson.model.TaskListener;
1627
import org.kohsuke.stapler.DataBoundConstructor;
1728
import org.kohsuke.stapler.DataBoundSetter;
1829
import org.kohsuke.stapler.StaplerRequest;
@@ -26,7 +37,8 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep, M
2637

2738
private int buildResult;
2839
private EnvVars env;
29-
40+
private static final String SOURCE_FOLDER = "SourceFolder";
41+
3042
// Make all old values transient which protects them writing back on disk.
3143
private transient boolean tapChkBx;
3244
private transient boolean junitChkBx;
@@ -289,11 +301,17 @@ private String getInputArguments() {
289301

290302
// Add source folder options to argument
291303
SourceFolder sf = getSourceFolder();
292-
if(sf != null && sf.getSourceFolderPaths().size() != 0){
293-
sf.addFilePathArgTo(args);
304+
if(sf != null && !sf.getSourceFolderPaths().isEmpty()){
305+
sf.addFilePathArgTo(SOURCE_FOLDER, args);
294306
}
295307

296-
args.forEach((key, val) -> inputArgsList.add("'" + key + "'" + "," + "'" + val + "'"));
308+
args.forEach((key, val) -> {
309+
if(key.equals(SOURCE_FOLDER)){
310+
inputArgsList.add("'" + key + "'" + "," + val);
311+
}else{
312+
inputArgsList.add("'" + key + "'" + "," + "'" + val.replaceAll("'", "''") + "'");
313+
}
314+
});
297315

298316
return String.join(",", inputArgsList);
299317
}

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,15 @@
2424
import hudson.model.TaskListener;
2525
import hudson.Util;
2626

27-
public class RunMatlabTestsStep extends Step {
27+
public class RunMatlabTestsStep extends Step implements MatlabBuild{
2828

2929
private String testResultsPDF;
3030
private String testResultsTAP;
3131
private String testResultsJUnit;
3232
private String codeCoverageCobertura;
3333
private String testResultsSimulinkTest;
3434
private String modelCoverageCobertura;
35-
private List<String> sourceFolder;
36-
35+
private List<String> sourceFolder = new ArrayList<>();
3736

3837
@DataBoundConstructor
3938
public RunMatlabTestsStep() {
@@ -104,7 +103,6 @@ public void setSourceFolder(List<String> sourceFolder) {
104103
this.sourceFolder = Util.fixNull(sourceFolder);
105104
}
106105

107-
108106
@Override
109107
public StepExecution start(StepContext context) throws Exception {
110108
return new MatlabRunTestsStepExecution(context, getInputArgs());
@@ -137,7 +135,9 @@ private String getInputArgs() {
137135
inputArgs.add("'Test'");
138136

139137
args.forEach((key, val) -> {
140-
if (val != null) {
138+
if(key.equals("SourceFolder") && val != null){
139+
inputArgs.add("'" + key + "'" + "," + val);
140+
}else if(val != null){
141141
inputArgs.add("'" + key + "'" + "," + "'" + val.replaceAll("'", "''") + "'");
142142
}
143143
});
@@ -153,11 +153,9 @@ private Map<String, String> getGenscriptArgs() {
153153
args.put("SimulinkTestResults", getTestResultsSimulinkTest());
154154
args.put("CoberturaCodeCoverage", getCodeCoverageCobertura());
155155
args.put("CoberturaModelCoverage", getModelCoverageCobertura());
156-
if(getSourceFolder() != null && getSourceFolder().size() != 0){
157-
String sourceStr = String.join(";", getSourceFolder());
158-
args.put("SourceFolder", sourceStr);
156+
if(!getSourceFolder().isEmpty()){
157+
args.put("SourceFolder", getCellArrayFrmList(getSourceFolder()));
159158
}
160-
161159
return args;
162160
}
163161
}

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2019-2020 The MathWorks, Inc.
4+
* Copyright 2020 The MathWorks, Inc.
55
*
66
* Describable class for Source Folder Option in RunMATLABTest Build step.
77
*
@@ -12,36 +12,28 @@
1212
import hudson.model.AbstractDescribableImpl;
1313
import hudson.model.Descriptor;
1414
import org.kohsuke.stapler.DataBoundConstructor;
15-
import org.kohsuke.stapler.DataBoundSetter;
16-
import java.util.ArrayList;
1715
import java.util.List;
1816
import java.util.Map;
1917
import java.util.stream.Collectors;
2018

21-
public class SourceFolder extends AbstractDescribableImpl<SourceFolder> {
19+
public class SourceFolder extends AbstractDescribableImpl<SourceFolder> implements MatlabBuild {
2220

23-
private List<SourceFolderPaths> sourceFolderPaths = new ArrayList<>();
24-
private static final String SOURCE_FOLDER = "SourceFolder";
21+
private List<SourceFolderPaths> sourceFolderPaths;
2522

2623
@DataBoundConstructor
27-
public SourceFolder() {
28-
29-
}
30-
31-
@DataBoundSetter
32-
public void setSourceFolderPaths(List<SourceFolderPaths> sourceFolderPaths) {
24+
public SourceFolder(List<SourceFolderPaths> sourceFolderPaths) {
3325
this.sourceFolderPaths = Util.fixNull(sourceFolderPaths);
3426
}
3527

3628
public List<SourceFolderPaths> getSourceFolderPaths() {
3729
return this.sourceFolderPaths;
3830
}
3931

40-
public void addFilePathArgTo(Map<String, String> inputArgs) {
41-
// Concatenate all source folders to a single ";" separated string
42-
inputArgs.put(SOURCE_FOLDER, this.sourceFolderPaths.stream()
32+
public void addFilePathArgTo(String sourceKeyVal, Map<String, String> inputArgs) {
33+
// Concatenate all source folders to MATLAB cell array string.
34+
inputArgs.put(sourceKeyVal, getCellArrayFrmList(this.sourceFolderPaths.stream()
4335
.map(SourceFolderPaths::getSrcFolderPath)
44-
.collect(Collectors.joining(";")));
36+
.collect(Collectors.toList())));
4537
}
4638

4739
@Extension public static class DescriptorImpl extends Descriptor<SourceFolder> {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.mathworks.ci;
22

33
/**
4-
* Copyright 2019-2020 The MathWorks, Inc.
4+
* Copyright 2020 The MathWorks, Inc.
55
*
66
* Describable class for Repeatable Source Folder text boxes in Source Folder option
77
* in RunMATLABTest Build step.
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
<div>
2-
<p>Optionally specify the location of the folder containing source code, relative to the project root folder. The specified folder and its subfolders are added to the top of the MATLAB search path. To generate a code coverage report, MATLAB uses only the source code in the specified folder and its subfolders. </p>
3-
<p>Specify a source folder path in the input box. Click on 'Add folder' to add more values.</p>
2+
<p>Specify the location of folders containing source code, relative to the project root folder. The specified folders and their subfolders are added to the top of the MATLAB search path. To generate a coverage report, MATLAB uses only the source code in the specified folders and their subfolders.</p>
3+
<p>Paste the source folder path in the File path box. To add more folders, click Add folder.</p>
44
</div>

src/main/resources/com/mathworks/ci/SourceFolder/config.jelly

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:f="/lib/form">
33
<f:entry title="Folder path:">
4-
<f:repeatable minimum="1" field="sourceFolderPaths" noAddButton="true">
4+
<f:repeatable minimum="1" name="sourceFolderPaths" field="sourceFolderPaths" add="Add folder">
55
<table width="100%">
66
<f:textbox field="srcFolderPath"/>
7-
<div align ="right">
8-
<input type="button" value="Add folder" class="repeatable-add show-if-last" />
9-
<input type="button" value="Delete" class="repeatable-delete show-if-not-only" />
10-
</div>
7+
<input type="button" value="Delete" class="repeatable-delete show-if-not-only" style="margin-left: 0px; margin-top: 0px; padding-top: 0px"/>
118
</table>
129
</f:repeatable>
1310
</f:entry>

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.mathworks.ci;
22
/**
3-
* Copyright 2019-2020 The MathWorks, Inc.
3+
* Copyright 2020 The MathWorks, Inc.
44
*
55
* Test class for RunMatlabTestsBuilder Persistence
66
*
@@ -101,8 +101,7 @@ public void verifySourceFolderSpecPersistence() {
101101

102102
FreeStyleProject project = r.createFreeStyleProject();
103103
RunMatlabTestsBuilder testBuilder = new RunMatlabTestsBuilder();
104-
SourceFolder sf = new SourceFolder();
105-
sf.setSourceFolderPaths(paths);
104+
SourceFolder sf = new SourceFolder(paths);
106105
testBuilder.setSourceFolder(sf);
107106
project.getBuildersList().add(testBuilder);
108107
project.save();

0 commit comments

Comments
 (0)