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

Commit dfd6dec

Browse files
author
Nikhil Bhoski
committed
changed runner file name and changed the copy location.
1 parent 7220a07 commit dfd6dec

File tree

9 files changed

+37
-39
lines changed

9 files changed

+37
-39
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,11 @@ default String getUniqueNameForRunnerFile() {
9999

100100
// This method prepares the temp folder by coping all helper files in it.
101101
default void prepareTmpFldr(FilePath tmpFldr) throws IOException, InterruptedException {
102+
// Copy MATLAB scratch file in temp.
103+
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
104+
MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX
105+
+ tmpFldr.getBaseName().replaceAll("-", "_") + ".m",
106+
tmpFldr);
102107
// copy genscript package
103108
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_SCRIPT_GENERATOR,
104109
MatlabBuilderConstants.MATLAB_SCRIPT_GENERATOR, tmpFldr);

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,7 @@ public class MatlabBuilderConstants {
3131

3232
//Matlab Script generator package
3333
static final String MATLAB_SCRIPT_GENERATOR = "matlab-script-generator.zip";
34+
35+
//Test runner file prefix
36+
static final String MATLAB_TEST_RUNNER_FILE_PREFIX = "test_runner_";
3437
}

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,11 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
6161
FilePath genScriptLocation =
6262
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
6363
final String cmdPrefix = "addpath(genpath('" + genScriptLocation.getRemote() + "')); ";
64+
final String matlabFunctionName = MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX
65+
+ genScriptLocation.getBaseName().replaceAll("-", "_");
6466

6567
ProcStarter matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener,
66-
envVars, cmdPrefix + envVars.expand(getCommand()), uniqueTmpFldrName);
67-
68-
//Copy Scratch file needed to run MATLAB tests in workspace
69-
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
70-
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, workspace);
68+
envVars, cmdPrefix + matlabFunctionName+ "("+envVars.expand(getCommand()+")"), uniqueTmpFldrName);
7169

7270
//prepare temp folder by coping genscript package.
7371
prepareTmpFldr(genScriptLocation);

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

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,6 @@
1515
import java.util.List;
1616
import java.util.Map;
1717
import javax.annotation.Nonnull;
18-
import org.apache.commons.collections.map.HashedMap;
19-
import org.apache.commons.io.FilenameUtils;
20-
import org.jenkinsci.Symbol;
2118
import org.kohsuke.stapler.DataBoundConstructor;
2219
import org.kohsuke.stapler.DataBoundSetter;
2320
import org.kohsuke.stapler.StaplerRequest;
@@ -242,13 +239,9 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
242239
getFilePathForUniqueFolder(launcher, uniqueTmpFldrName, workspace);
243240

244241
matlabLauncher = getProcessToRunMatlabCommand(workspace, launcher, listener, envVars,
245-
constructCommandForTest(getInputArguments(), genScriptLocation.getRemote()),
242+
constructCommandForTest(getInputArguments(), genScriptLocation),
246243
uniqueTmpFldrName);
247244

248-
// Copy MATLAB scratch file into the workspace.
249-
copyFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
250-
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, workspace);
251-
252245
// copy genscript package in temp folder
253246
prepareTmpFldr(genScriptLocation);
254247

@@ -266,10 +259,11 @@ private synchronized int execMatlabCommand(FilePath workspace, Launcher launcher
266259
}
267260
}
268261

269-
public String constructCommandForTest(String inputArguments, String scriptPath) {
270-
final String matlabFunctionName =
271-
FilenameUtils.removeExtension(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE);
272-
final String runCommand = "addpath(genpath('"+scriptPath+"')); " + matlabFunctionName + "(" + inputArguments + ")";
262+
public String constructCommandForTest(String inputArguments, FilePath scriptPath) {
263+
final String matlabFunctionName = MatlabBuilderConstants.MATLAB_TEST_RUNNER_FILE_PREFIX
264+
+ scriptPath.getBaseName().replaceAll("-", "_");
265+
final String runCommand = "addpath(genpath('" + scriptPath.getRemote() + "')); "
266+
+ matlabFunctionName + "(" + inputArguments + ")";
273267
return runCommand;
274268
}
275269

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

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import java.util.List;
1010
import java.util.Map;
1111
import java.util.Set;
12-
import org.apache.commons.io.FilenameUtils;
1312
import org.jenkinsci.plugins.workflow.steps.Step;
1413
import org.jenkinsci.plugins.workflow.steps.StepContext;
1514
import org.jenkinsci.plugins.workflow.steps.StepDescriptor;
@@ -97,7 +96,7 @@ public void setModelCoverageCobertura(String modelCoverageCobertura) {
9796

9897
@Override
9998
public StepExecution start(StepContext context) throws Exception {
100-
return new MatlabRunTestsStepExecution(context, constructCommandForTest(getInputArgs()));
99+
return new MatlabRunTestsStepExecution(context, getInputArgs());
101100
}
102101

103102
@Extension
@@ -120,14 +119,6 @@ public String getDisplayName() {
120119
}
121120
}
122121

123-
public String constructCommandForTest(String inputArguments) {
124-
final String matlabFunctionName =
125-
FilenameUtils.removeExtension(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE);
126-
final String runCommand = matlabFunctionName + "(" + inputArguments + ")";
127-
return runCommand;
128-
}
129-
130-
131122
private String getInputArgs() {
132123
final List<String> inputArgs = new ArrayList<>();
133124
final Map<String, String> args = getMatlabArgs();

src/main/resources/com/mathworks/ci/RunMatlabTestsBuilder/runMatlabTests.m

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,16 @@ function runMatlabTests(varargin)
2121
coberturaReportPath = p.Results.CoberturaCodeCoveragePath;
2222
modelCoveragePath = p.Results.CoberturaModelCoveragePath;
2323

24-
testScript = genscript('Test','PDFTestReport',pdfReportPath,'TAPTestResults',tapReportPath,'JUnitTestResults',junitReportPath,'SimulinkTestResults',stmReportPath,'CoberturaCodeCoverage',coberturaReportPath,'CoberturaModelCoverage',modelCoveragePath);
24+
srcFldr = getenv('WORKSPACE');
25+
26+
testScript = genscript('Test',...
27+
'PDFTestReport',pdfReportPath,...
28+
'TAPTestResults',tapReportPath,...
29+
'JUnitTestResults',junitReportPath,...
30+
'SimulinkTestResults',stmReportPath,...
31+
'CoberturaCodeCoverage',coberturaReportPath,...
32+
'CoberturaModelCoverage',modelCoveragePath,...
33+
'SourceFolder',srcFldr);
2534

2635
disp('Running MATLAB script with content:\n');
2736
disp(strtrim(testScript.writeToText()));

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
import java.util.List;
1616
import java.util.Map;
1717
import java.util.Optional;
18-
import org.codehaus.groovy.vmplugin.v5.JUnit4Utils;
1918
import org.junit.After;
2019
import org.junit.Assert;
2120
import org.junit.Before;
@@ -26,7 +25,6 @@
2625
import com.gargoylesoftware.htmlunit.WebAssert;
2726
import com.gargoylesoftware.htmlunit.html.HtmlCheckBoxInput;
2827
import com.gargoylesoftware.htmlunit.html.HtmlPage;
29-
import com.mathworks.ci.MatlabBuilder.RunTestsAutomaticallyOption;
3028
import com.mathworks.ci.RunMatlabTestsBuilder.CoberturaArtifact;
3129
import com.mathworks.ci.RunMatlabTestsBuilder.JunitArtifact;
3230
import com.mathworks.ci.RunMatlabTestsBuilder.ModelCovArtifact;
@@ -142,7 +140,7 @@ public void verifyMATLABlaunchedWithDefaultArgumentsBatch() throws Exception {
142140
project.getBuildersList().add(this.testBuilder);
143141
FreeStyleBuild build = project.scheduleBuild2(0).get();
144142
jenkins.assertLogContains("run_matlab_command", build);
145-
jenkins.assertLogContains("runMatlabTests", build);
143+
jenkins.assertLogContains("test_runner", build);
146144
jenkins.assertLogContains("addpath(genpath", build);
147145
}
148146

@@ -158,7 +156,7 @@ public void verifyMATLABlaunchedWithDefaultArgumentsRWindows() throws Exception
158156
project.getBuildersList().add(testBuilder);
159157
FreeStyleBuild build = project.scheduleBuild2(0).get();
160158
jenkins.assertLogContains("run_matlab_command", build);
161-
jenkins.assertLogContains("runMatlabTests", build);
159+
jenkins.assertLogContains("test_runner", build);
162160
}
163161

164162
/*
@@ -319,7 +317,7 @@ public void verifyAllTestArtifactsParameters() throws Exception {
319317
}
320318

321319
/*
322-
* Test to verify no parameters are sent in runMatlabTests when no artifacts are selected.
320+
* Test to verify no parameters are sent in test_runner when no artifacts are selected.
323321
*/
324322

325323
@Test
@@ -329,7 +327,7 @@ public void veriyEmptyParameters() throws Exception {
329327
project.getBuildersList().add(this.testBuilder);
330328
FreeStyleBuild build = project.scheduleBuild2(0).get();
331329
jenkins.assertLogContains("run_matlab_command", build);
332-
jenkins.assertLogContains("runMatlabTests()", build);
330+
jenkins.assertLogContains("test_runner", build);
333331
}
334332

335333

@@ -407,7 +405,7 @@ public void verifyMatrixBuildPasses() throws Exception {
407405
}
408406

409407
/*
410-
* Test to verify if MATALB scratch file is generated in workspace.
408+
* Test to verify if MATALB scratch file is not in workspace.
411409
*/
412410
@Test
413411
public void verifyMATLABscratchFileGenerated() throws Exception {
@@ -416,6 +414,6 @@ public void verifyMATLABscratchFileGenerated() throws Exception {
416414
project.getBuildersList().add(testBuilder);
417415
FreeStyleBuild build = project.scheduleBuild2(0).get();
418416
File matlabRunner = new File(build.getWorkspace() + File.separator + "runMatlabTests.m");
419-
Assert.assertTrue(matlabRunner.exists());
417+
Assert.assertFalse(matlabRunner.exists());
420418
}
421419
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public void verifyCmdOptions() throws Exception {
8888
"node {runMATLABTests(testResultsPDF:'myresult/result.pdf')}", true));
8989
WorkflowRun build = project.scheduleBuild2(0).get();
9090
j.assertLogContains("addpath(genpath", build);
91-
j.assertLogContains("runMatlabTests", build);
91+
j.assertLogContains("test_runner", build);
9292
}
9393

9494
/*
@@ -117,7 +117,7 @@ public void verifyEmptyParameter() throws Exception {
117117
project.setDefinition(new CpsFlowDefinition(
118118
"node {runMATLABTests()}", true));
119119
WorkflowRun build = project.scheduleBuild2(0).get();
120-
j.assertLogContains("runMatlabTests()", build);
120+
j.assertLogContains("test_runner", build);
121121
j.assertLogNotContains("PDFReportPath", build);
122122
j.assertLogNotContains("TAPResultsPath", build);
123123
j.assertLogNotContains("JUnitResultsPath", build);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public StepExecution start(StepContext context) throws Exception {
3434
FilePath targetWorkspace = new FilePath(launcher.getChannel(), workspace.getRemote());
3535
copyScratchFileInWorkspace(MatlabBuilderConstants.MATLAB_TESTS_RUNNER_RESOURCE,
3636
MatlabBuilderConstants.MATLAB_TESTS_RUNNER_TARGET_FILE, targetWorkspace);
37-
return new TestStepExecution(context, constructCommandForTest(getInputArgs()));
37+
return new TestStepExecution(context, getInputArgs());
3838
}
3939

4040
private void copyScratchFileInWorkspace(String sourceFile, String targetFile,

0 commit comments

Comments
 (0)