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

Commit 68a9054

Browse files
authored
Merge pull request #144 from mathworks/github_issue_138
GitHub issue 138
2 parents 5cd5df0 + 0efb33a commit 68a9054

File tree

13 files changed

+90
-22
lines changed

13 files changed

+90
-22
lines changed

azure-pipelines.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ strategy:
1010
mac:
1111
imageName: 'macOS-10.15'
1212
windows:
13-
imageName: 'vs2017-win2016'
13+
imageName: 'windows-latest'
1414

1515
pool:
1616
vmImage: $(imageName)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package com.mathworks.ci;
2+
3+
/**
4+
* Copyright 2020 The MathWorks, Inc.
5+
*
6+
*/
7+
8+
import java.io.FileNotFoundException;
9+
10+
public class MatlabNotFoundError extends Error {
11+
12+
private static final long serialVersionUID = 7918595075502022644L;
13+
14+
MatlabNotFoundError(String errorMessage){
15+
super(errorMessage);
16+
}
17+
18+
}

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

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

1111
import java.io.File;
12+
import java.io.FileNotFoundException;
1213
import java.io.IOException;
1314
import java.util.ArrayList;
1415
import java.util.List;
@@ -133,18 +134,20 @@ public synchronized void setUp(Context context, Run<?, ?> build, FilePath worksp
133134
// Set Environment variable
134135

135136
setEnv(initialEnvironment);
136-
String nodeSpecificFileSep = getNodeSpecificFileSeperator(launcher);
137+
138+
FilePath matlabExecutablePath = new FilePath(launcher.getChannel(),
139+
getLocalMatlab() + "/bin/" + getNodeSpecificExecutable(launcher));
140+
141+
if (!matlabExecutablePath.exists()) {
142+
throw new MatlabNotFoundError(Message.getValue("matlab.not.found.error"));
143+
}
137144
// Add "matlabroot" without bin as env variable which will be available across the build.
138145
context.env("matlabroot", getLocalMatlab());
139146
// Add matlab bin to path to invoke MATLAB directly on command line.
140-
context.env("PATH+matlabroot", getLocalMatlab() + nodeSpecificFileSep + "bin");
147+
context.env("PATH+matlabroot", matlabExecutablePath.getParent().getRemote());
141148
}
142-
143-
private String getNodeSpecificFileSeperator(Launcher launcher) {
144-
if (launcher.isUnix()) {
145-
return "/";
146-
} else {
147-
return "\\";
148-
}
149+
150+
private String getNodeSpecificExecutable(Launcher launcher) {
151+
return (launcher.isUnix()) ? "matlab" : "matlab.exe";
149152
}
150153
}

src/main/resources/config.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Builder.matlab.test.support.error = To run tests with the Jenkins plugin, use MA
1212
builder.matlab.automatictestoption.display.name = Automatic
1313
builder.matlab.customcommandoption.display.name = Custom
1414
Releaseinfo.matlab.version.not.found.error = Error finding MATLAB release for given MATLAB root. Verify MATLAB root path.
15+
matlab.not.found.error = Unable to launch MATLAB from the specified location. Verify the path to MATLAB root folder.
1516
Builder.matlab.modelcoverage.support.warning = To generate a Cobertura model coverage report, use MATLAB R2018b or a newer release.
1617
Builder.matlab.exportstmresults.support.warning = To export Simulink Test Manager results, use MATLAB R2019a or a newer release.
1718
Builder.matlab.runner.script.target.file.linux.name = run_matlab_command.sh

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

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.junit.BeforeClass;
2222
import org.junit.Rule;
2323
import org.junit.Test;
24+
import org.junit.rules.Timeout;
2425
import org.jvnet.hudson.test.JenkinsRule;
2526
import hudson.EnvVars;
2627
import hudson.matrix.Axis;
@@ -47,6 +48,9 @@ public class RunMatlabCommandBuilderTest {
4748

4849
@Rule
4950
public JenkinsRule jenkins = new JenkinsRule();
51+
52+
@Rule
53+
public Timeout globalTimeout = Timeout.seconds(500);
5054

5155
@BeforeClass
5256
public static void classSetup() throws URISyntaxException, IOException {
@@ -261,7 +265,20 @@ public void verifyMATLABrunnerFileGenerated() throws Exception {
261265
scriptBuilder.setMatlabCommand("pwd");
262266
project.getBuildersList().add(scriptBuilder);
263267
FreeStyleBuild build = project.scheduleBuild2(0).get();
264-
jenkins.assertLogContains("MATLAB_ROOT", build);
268+
jenkins.assertLogContains("run_matlab_command", build);
269+
}
270+
271+
/*
272+
* Verify default MATLAB is not picked if invalid MATLAB path is provided
273+
*/
274+
@Test
275+
public void verifyDefaultMatlabNotPicked() throws Exception {
276+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2020b"));
277+
project.getBuildWrappersList().add(this.buildWrapper);
278+
scriptBuilder.setMatlabCommand("pwd");
279+
project.getBuildersList().add(scriptBuilder);
280+
FreeStyleBuild build = project.scheduleBuild2(0).get();
281+
jenkins.assertLogContains("MatlabNotFoundError", build);
265282
}
266283

267284
/*
@@ -273,7 +290,7 @@ public void verifyMATLABrunnerFileGenerated() throws Exception {
273290
@Test
274291
public void verifyMatrixBuildFails() throws Exception {
275292
MatrixProject matrixProject = jenkins.createProject(MatrixProject.class);
276-
Axis axes = new Axis("VERSION", "R2018a", "R2018b");
293+
Axis axes = new Axis("VERSION", "R2018a", "R2015b");
277294
matrixProject.setAxes(new AxisList(axes));
278295
String matlabRoot = getMatlabroot("R2018b");
279296
this.buildWrapper.setMatlabRootFolder(matlabRoot.replace("R2018b", "$VERSION"));
@@ -285,12 +302,12 @@ public void verifyMatrixBuildFails() throws Exception {
285302
vals.put("VERSION", "R2018a");
286303
Combination c1 = new Combination(vals);
287304
MatrixRun build = matrixProject.scheduleBuild2(0).get().getRun(c1);
288-
jenkins.assertLogContains("MATLAB_ROOT", build);
305+
jenkins.assertLogContains("run_matlab_command", build);
289306
jenkins.assertBuildStatus(Result.FAILURE, build);
290-
vals.put("VERSION", "R2018b");
307+
vals.put("VERSION", "R2015b");
291308
Combination c2 = new Combination(vals);
292309
MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2);
293-
jenkins.assertLogContains("MATLAB_ROOT", build2);
310+
jenkins.assertLogContains("MatlabNotFoundError", build2);
294311
jenkins.assertBuildStatus(Result.FAILURE, build2);
295312
}
296313

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

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,19 @@ public void verifyMATLABrunnerFileGeneratedForAutomaticOption() throws Exception
347347
project.getBuildWrappersList().add(this.buildWrapper);
348348
project.getBuildersList().add(testBuilder);
349349
FreeStyleBuild build = project.scheduleBuild2(0).get();
350-
jenkins.assertLogContains("MATLAB_ROOT", build);
350+
jenkins.assertLogContains("run_matlab_command", build);
351+
}
352+
353+
/*
354+
* Verify default MATLAB is not picked if invalid MATLAB path is provided
355+
*/
356+
@Test
357+
public void verifyDefaultMatlabNotPicked() throws Exception {
358+
this.buildWrapper.setMatlabRootFolder(getMatlabroot("R2020b"));
359+
project.getBuildWrappersList().add(this.buildWrapper);
360+
project.getBuildersList().add(testBuilder);
361+
FreeStyleBuild build = project.scheduleBuild2(0).get();
362+
jenkins.assertLogContains("MatlabNotFoundError", build);
351363
}
352364

353365
/*
@@ -359,7 +371,7 @@ public void verifyMATLABrunnerFileGeneratedForAutomaticOption() throws Exception
359371
@Test
360372
public void verifyMatrixBuildFails() throws Exception {
361373
MatrixProject matrixProject = jenkins.createProject(MatrixProject.class);
362-
Axis axes = new Axis("VERSION", "R2018a", "R2018b");
374+
Axis axes = new Axis("VERSION", "R2018a", "R2015b");
363375
matrixProject.setAxes(new AxisList(axes));
364376
String matlabRoot = getMatlabroot("R2018b");
365377
this.buildWrapper.setMatlabRootFolder(matlabRoot.replace("R2018b", "$VERSION"));
@@ -374,15 +386,16 @@ public void verifyMatrixBuildFails() throws Exception {
374386
Combination c1 = new Combination(vals);
375387
MatrixRun build1 = matrixProject.scheduleBuild2(0).get().getRun(c1);
376388

377-
jenkins.assertLogContains("MATLAB_ROOT", build1);
389+
jenkins.assertLogContains("run_matlab_command", build1);
378390
jenkins.assertBuildStatus(Result.FAILURE, build1);
379391

380392
// Check for second Matrix combination
381-
393+
394+
vals.put("VERSION", "R2015b");
382395
Combination c2 = new Combination(vals);
383396
MatrixRun build2 = matrixProject.scheduleBuild2(0).get().getRun(c2);
384397

385-
jenkins.assertLogContains("MATLAB_ROOT", build2);
398+
jenkins.assertLogContains("MatlabNotFoundError", build2);
386399
jenkins.assertBuildStatus(Result.FAILURE, build2);
387400
}
388401

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import org.jvnet.hudson.test.JenkinsRule;
2222
import com.gargoylesoftware.htmlunit.WebAssert;
2323
import com.gargoylesoftware.htmlunit.html.HtmlPage;
24+
import hudson.model.FreeStyleBuild;
2425
import hudson.model.FreeStyleProject;
2526
import hudson.tasks.BuildWrapper;
2627

@@ -90,17 +91,32 @@ public void verifyBuildEnvForMatlab() throws Exception {
9091

9192
/*
9293
* Verify if given MATLAB root is added in the PATH.
94+
* Should be added to integration test.
9395
*/
94-
@Test
96+
9597
public void verifyPATHupdated() throws Exception {
9698
this.buildWrapper.setMatlabRootFolder("/test/MATLAB/R2019a");
9799
project.getBuildWrappersList().add(this.buildWrapper);
98100
RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("","");
99101
project.getBuildersList().add(buildTester);
100-
project.scheduleBuild2(0).get();
102+
FreeStyleBuild build = project.scheduleBuild2(0).get();
101103
Assert.assertTrue("Build does not have MATLAB build environment", this.buildWrapper.getMatlabRootFolder().equalsIgnoreCase(buildTester.getMatlabRoot()));
102104
}
103105

106+
/*
107+
* Verify if invalid MATLAB path throes error on console.
108+
*/
109+
@Test
110+
public void verifyInvalidPATHError() throws Exception {
111+
this.buildWrapper.setMatlabRootFolder("/test/MATLAB/R2019a");
112+
project.getBuildWrappersList().add(this.buildWrapper);
113+
RunMatlabTestsBuilderTester buildTester = new RunMatlabTestsBuilderTester("","");
114+
project.getBuildersList().add(buildTester);
115+
project.scheduleBuild2(0).get();
116+
FreeStyleBuild build = project.scheduleBuild2(0).get();
117+
jenkins.assertLogContains("MatlabNotFoundError", build);
118+
}
119+
104120
/*
105121
* Test To verify if UI throws an error when MATLAB root is empty.
106122
*

src/test/resources/versioninfo/R2017a/bin/matlab

Whitespace-only changes.

src/test/resources/versioninfo/R2017a/bin/matlab.exe

Whitespace-only changes.

src/test/resources/versioninfo/R2018a/bin/matlab

Whitespace-only changes.

0 commit comments

Comments
 (0)