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

Commit 86a9bd2

Browse files
committed
Address review to refactor MatlabBuild
1 parent 0f20db0 commit 86a9bd2

File tree

6 files changed

+50
-29
lines changed

6 files changed

+50
-29
lines changed

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,9 +123,4 @@ default String getValidMatlabFileName(String actualName) {
123123
return MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX
124124
+ actualName.replaceAll("-", "_");
125125
}
126-
127-
default String getCellArrayFrmList(List<String> listOfStr){
128-
listOfStr.replaceAll(val -> "'" + val.replaceAll("'", "''") + "'");
129-
return "{" + String.join(",", listOfStr) + "}";
130-
}
131126
}

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
import java.util.ArrayList;
1616
import java.util.Optional;
1717
import java.util.Arrays;
18+
import java.util.function.Predicate;
19+
import java.util.stream.Collectors;
1820
import javax.annotation.Nonnull;
1921
import hudson.EnvVars;
2022
import hudson.Extension;
@@ -37,7 +39,6 @@ public class RunMatlabTestsBuilder extends Builder implements SimpleBuildStep, M
3739

3840
private int buildResult;
3941
private EnvVars env;
40-
private static final String SOURCE_FOLDER = "SourceFolder";
4142

4243
// Make all old values transient which protects them writing back on disk.
4344
private transient boolean tapChkBx;
@@ -282,6 +283,15 @@ public String constructCommandForTest(FilePath scriptPath) {
282283
return runCommand;
283284
}
284285

286+
private String getCellArrayFrmList(List<String> listOfStr){
287+
// Ignore empty string values in the list
288+
Predicate<String> isEmpty = String::isEmpty;
289+
Predicate<String> isNotEmpty = isEmpty.negate();
290+
List<String> filteredListOfStr = listOfStr.stream().filter(isNotEmpty).collect(Collectors.toList());
291+
filteredListOfStr.replaceAll(val -> "'" + val.replaceAll("'", "''") + "'");
292+
return "{" + String.join(",", filteredListOfStr) + "}";
293+
}
294+
285295
// Concatenate the input arguments
286296
private String getInputArguments() {
287297

@@ -299,20 +309,16 @@ private String getInputArguments() {
299309
artifact.addFilePathArgTo(args);
300310
}
301311

312+
args.forEach((key, val) -> inputArgsList.add("'" + key + "'" + "," + "'" + val + "'"));
313+
302314
// Add source folder options to argument
303315
SourceFolder sf = getSourceFolder();
304316
if(sf != null && !sf.getSourceFolderPaths().isEmpty()){
305-
sf.addFilePathArgTo(SOURCE_FOLDER, args);
317+
sf.addSourceToInputArgs(inputArgsList, getCellArrayFrmList(sf.getSourceFolderPaths().stream()
318+
.map(SourceFolderPaths::getSrcFolderPath)
319+
.collect(Collectors.toList())));
306320
}
307321

308-
args.forEach((key, val) -> {
309-
if(key.equals(SOURCE_FOLDER)){
310-
inputArgsList.add("'" + key + "'" + "," + val);
311-
}else{
312-
inputArgsList.add("'" + key + "'" + "," + "'" + val + "'");
313-
}
314-
});
315-
316322
return String.join(",", inputArgsList);
317323
}
318324

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import java.util.List;
1010
import java.util.Map;
1111
import java.util.Set;
12+
import java.util.function.Predicate;
13+
import java.util.stream.Collectors;
14+
1215
import org.jenkinsci.plugins.workflow.steps.Step;
1316
import org.jenkinsci.plugins.workflow.steps.StepContext;
1417
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
@@ -24,7 +27,7 @@
2427
import hudson.model.TaskListener;
2528
import hudson.Util;
2629

27-
public class RunMatlabTestsStep extends Step implements MatlabBuild{
30+
public class RunMatlabTestsStep extends Step {
2831

2932
private String testResultsPDF;
3033
private String testResultsTAP;
@@ -158,4 +161,13 @@ private Map<String, String> getGenscriptArgs() {
158161
}
159162
return args;
160163
}
164+
165+
private String getCellArrayFrmList(List<String> listOfStr){
166+
// Ignore empty string values in the list
167+
Predicate<String> isEmpty = String::isEmpty;
168+
Predicate<String> isNotEmpty = isEmpty.negate();
169+
List<String> filteredListOfStr = listOfStr.stream().filter(isNotEmpty).collect(Collectors.toList());
170+
filteredListOfStr.replaceAll(val -> "'" + val.replaceAll("'", "''") + "'");
171+
return "{" + String.join(",", filteredListOfStr) + "}";
172+
}
161173
}

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

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,10 @@
1616
import java.util.Map;
1717
import java.util.stream.Collectors;
1818

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

2121
private List<SourceFolderPaths> sourceFolderPaths;
22+
private static final String SOURCE_FOLDER = "SourceFolder";
2223

2324
@DataBoundConstructor
2425
public SourceFolder(List<SourceFolderPaths> sourceFolderPaths) {
@@ -29,11 +30,9 @@ public List<SourceFolderPaths> getSourceFolderPaths() {
2930
return this.sourceFolderPaths;
3031
}
3132

32-
public void addFilePathArgTo(String sourceKeyVal, Map<String, String> inputArgs) {
33+
public void addSourceToInputArgs(List<String> inputArgsList, String cellArraySourceVal) {
3334
// Concatenate all source folders to MATLAB cell array string.
34-
inputArgs.put(sourceKeyVal, getCellArrayFrmList(this.sourceFolderPaths.stream()
35-
.map(SourceFolderPaths::getSrcFolderPath)
36-
.collect(Collectors.toList())));
35+
inputArgsList.add("'" + SOURCE_FOLDER + "'" + "," + cellArraySourceVal);
3736
}
3837

3938
@Extension public static class DescriptorImpl extends Descriptor<SourceFolder> {
Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,32 @@
11
<?jelly escape-by-default='true'?>
22
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
33

4-
<f:entry field="testResultsPDF">
4+
<f:entry field="testResultsPDF" title="testResultsPDF: ">
55
<f:textbox/>
66
</f:entry>
77

8-
<f:entry field="testResultsTAP">
8+
<f:entry field="testResultsTAP" title="testResultsTAP: ">
99
<f:textbox/>
1010
</f:entry>
1111

12-
<f:entry field="testResultsJUnit">
12+
<f:entry field="testResultsJUnit" title="testResultsJUnit: ">
1313
<f:textbox/>
1414
</f:entry>
1515

16-
<f:entry field="codeCoverageCobertura">
16+
<f:entry field="codeCoverageCobertura" title="codeCoverageCobertura: ">
1717
<f:textbox/>
1818
</f:entry>
1919

20-
<f:entry field="testResultsSimulinkTest">
20+
<f:entry field="testResultsSimulinkTest" title="testResultsSimulinkTest: ">
2121
<f:textbox/>
2222
</f:entry>
2323

24-
<f:entry field="modelCoverageCobertura">
24+
<f:entry field="modelCoverageCobertura" title="modelCoverageCobertura: ">
2525
<f:textbox/>
26-
</f:entry>
26+
</f:entry>
27+
28+
<f:entry field="sourceFolder" title="sourceFolder: ">
29+
<f:textbox/>
30+
</f:entry>
2731

28-
</j:jelly>
32+
</j:jelly>
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<div>
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 box in a list format.</p>
4+
<p>Example: ["src/folderA", "src/folderB"]</p>
5+
</div>

0 commit comments

Comments
 (0)